刚刚使用delphi,准备自己作一个Button按钮。在WM_CREATE里添加按钮属性BS_OWNERDRAW,但是WM_DRAWITEM消息函数却没有执行。
  还有delphi是怎么创建窗口的,我没有发现CreateWindow函数,而且我发现进入WM_CREATE消息函数的时候,窗口句柄就已经存在了,看了《天方夜谭VCL》、《深入BCB理解VCL的消息机制》也没有发现什么踪迹。
  望众位高手解惑!

解决方案 »

  1.   

    用API呀!你认真找就可以找到CreateWindow(),仔细找VCL中的源码
      

  2.   

    SaleForm:=TSaleForm.Create(Application);
      SaleForm.Show;
      

  3.   

    不是用 CreateWindow 而是 CreateWindowEx
      

  4.   

    program FirstWinMain;uses Windows,Messages;//窗口函数,窗口接到消息时被WINDOWS调用
    function WindowFunc(hwnd:HWND;uMsg:Cardinal;wParam:WPARAM;
     lParam:LPARAM):LResult;stdcall;
     begin
      Result := 0;
        case uMsg of    WM_CLOSE : PostMessage(hwnd, WM_QUIT, 0, 0);    else
            Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
        end;
    end;var
        wcl : WNDCLASS;
        hwnd : THandle;
        Msg : tagMSG;
    begin
       wcl.hInstance := hInstance; //将hThisInst所指定的当前实例的句柄赋给hInstance。
       wcl.lpszClassName := 'FirstWinMain'; //指向窗口类的名字
       wcl.lpfnWndProc := @WindowFunc; //窗口函数的地址被赋给lpfnWndProc
       wcl.style := 0; // default style
       wcl.hIcon := 0; //定义标准图标
      // wcl.hIconSm := 0;(呀,这个我忘了对应的Delphi里的小图标是什么去了)
       wcl.hCursor := LoadCursor(hInstance,'IDC_ARROW'); //读取鼠标光标
      
       wcl.lpszMenuName := nil; // no menu
       wcl.cbClsExtra := 0; // no extra information needed
       wcl.cbWndExtra := 0; // no extra information needed
       wcl.hbrBackground :=COLOR_WINDOWFRAME;  //框架所创建的背景颜色   // Register the window class.
       if RegisterClass(wcl) = 0 then
            Exit;   //创建窗口
       hwnd := CreateWindow(
         'FirstWinMain', // name of window class
         'Windows 98 Skeleton', //name of window
         WS_OVERLAPPEDWINDOW, // window style - normal
         Integer(CW_USEDEFAULT),
         Integer(CW_USEDEFAULT),
         Integer(CW_USEDEFAULT),
         Integer(CW_USEDEFAULT),
         0,
         0,
         hInstance,
         nil
        );    if hwnd=0 then
           Exit;   // Display the window.
      //显示窗口
      ShowWindow(hwnd, SW_SHOWNORMAL);
        UpdateWindow(hWnd);   // Create the message loop.
      //消息循环
      while GetMessage(msg, hwnd, 0, 0) do
      begin
         TranslateMessage(msg); // translate keyboard messages
         DispatchMessage(msg); // return control to Windows 98
      end;  end.
      

  5.   

    创建模式窗体begin
      if not assigned(form2) then
         begin
           application.createform(Tform2.form2);
           try
              form2.showmodal;
           finally
              form2.free;
              form2:=nil;
           end;
         end else
            form2.showmodal;
    end;
      

  6.   

    跟踪Application.Run看看,应该有所发现吧