createwindow 创建一个窗口(它的许多参数实在难搞懂),请附实例。我找遍dfw和csdn也没搞明白,它就这么难吗?靠! (100分)

  • 主题发起人 主题发起人 puma4993
  • 开始时间 开始时间
P

puma4993

Unregistered / Unconfirmed
GUEST, unregistred user!
createwindow 创建一个窗口(它的许多参数实在难搞懂),请附实例。我找遍dfw和csdn也没搞明白,它就这么难吗?靠! &nbsp;<br><br>
 
Delphi的源码里边有很多实例嘛<br>看看TWinControl.CreateHandle TWinControl.CreateWnd TWinControl.CreateParams TWinControl.CreateWindowHandle<br>具体参数的含义请参考MSDN
 
procedure TApplication.CreateHandle;<br>var<br>&nbsp; TempClass: TWndClass;<br>&nbsp; SysMenu: HMenu;<br>begin<br>&nbsp; if not FHandleCreated<br>{$IFDEF MSWINDOWS}<br>&nbsp; &nbsp; and not IsConsole then<br>{$ENDIF}<br>{$IFDEF LINUX}<br>&nbsp; &nbsp; then<br>{$ENDIF}<br>&nbsp; begin<br>{$IFDEF LINUX}<br>&nbsp; &nbsp; FObjectInstance := WinUtils.MakeObjectInstance(WndProc);<br>{$ENDIF}<br>{$IFDEF MSWINDOWS}<br>&nbsp; &nbsp; FObjectInstance := Classes.MakeObjectInstance(WndProc);<br>{$ENDIF}<br>&nbsp; &nbsp; WindowClass.lpfnWndProc := @DefWindowProc;<br>&nbsp; &nbsp; if not GetClassInfo(HInstance, WindowClass.lpszClassName, TempClass) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; WindowClass.hInstance := HInstance;<br>&nbsp; &nbsp; &nbsp; if Windows.RegisterClass(WindowClass) = 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; raise EOutOfResources.Create(SWindowClass);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; FHandle := CreateWindow(WindowClass.lpszClassName, PChar(FTitle),<br>&nbsp; &nbsp; &nbsp; WS_POPUP or WS_CAPTION or WS_CLIPSIBLINGS or WS_SYSMENU<br>&nbsp; &nbsp; &nbsp; or WS_MINIMIZEBOX,////////////////////////////////////使用<br>&nbsp; &nbsp; &nbsp; GetSystemMetrics(SM_CXSCREEN) div 2,<br>&nbsp; &nbsp; &nbsp; GetSystemMetrics(SM_CYSCREEN) div 2,<br>&nbsp; &nbsp; &nbsp; 0, 0, 0, 0, HInstance, nil);<br>&nbsp; &nbsp; FTitle := '';<br>&nbsp; &nbsp; FHandleCreated := True;<br>&nbsp; &nbsp; SetWindowLong(FHandle, GWL_WNDPROC, Longint(FObjectInstance));<br>&nbsp; &nbsp; if NewStyleControls then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; SendMessage(FHandle, WM_SETICON, 1, GetIconHandle);<br>&nbsp; &nbsp; &nbsp; SetClassLong(FHandle, GCL_HICON, GetIconHandle);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; SysMenu := GetSystemMenu(FHandle, False);<br>&nbsp; &nbsp; DeleteMenu(SysMenu, SC_MAXIMIZE, MF_BYCOMMAND);<br>&nbsp; &nbsp; DeleteMenu(SysMenu, SC_SIZE, MF_BYCOMMAND);<br>&nbsp; &nbsp; if NewStyleControls then DeleteMenu(SysMenu, SC_MOVE, MF_BYCOMMAND);<br>&nbsp; end;<br>end;<br>--------------------------<br>forms.pas源文件
 
没人回答吗?都是小儿科吗?
 
失望.........
 
;********************************************************************<br>; 建立并显示窗口<br>;********************************************************************<br> invoke CreateWindowEx,WS_EX_CLIENTEDGE,offset szClassName,offset szCaptionMain,/<br> WS_OVERLAPPEDWINDOW,/<br> 100,100,600,400,/<br> NULL,NULL,hInstance,NULL<br> mov hWinMain,eax<br> invoke ShowWindow,hWinMain,SW_SHOWNORMAL<br> invoke UpdateWindow,hWinMain
 
强烈建议楼主去看《Windows程序设计》<br>这里有下载:http://www.ufoit.com/bbs/viewtopic.php?t=251<br><br>再用一个COREAPI.HLP中带的一个程序例子:<br>{this is used for extra window creation information}<br>&nbsp; TMyData = record<br>&nbsp; &nbsp; lpszInfo: PChar;<br>&nbsp; &nbsp; dwNumber: DWORD;<br>&nbsp; end;<br><br>&nbsp; PMyData = ^TMyData;<br><br>var<br>&nbsp; Form1: TForm1;<br><br>implementation<br><br>{$R *.DFM}<br><br>function WindowProc(TheWindow: HWnd; TheMessage, WParam,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LParam: Longint): Longint; stdcall;<br>var<br>&nbsp; {these variables will be assigned the extra window creation information }<br><br>&nbsp; lpszInfoString: PChar;<br>&nbsp; dwInfoNumber: DWORD;<br>begin<br>&nbsp; case TheMessage of<br>&nbsp; &nbsp; {get our extra creation information when the window is created}<br>&nbsp; &nbsp; WM_CREATE: <br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; {retrieve the extra creation data from the TCreateStruct data structure}<br>&nbsp; &nbsp; &nbsp; &nbsp; lpszInfoString:=PMyData(PCreateStruct(LParam).lpCreateParams).lpszInfo;<br>&nbsp; &nbsp; &nbsp; &nbsp; dwInfoNumber:=PMyData(PCreateStruct(LParam).lpCreateParams).dwNumber;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; {display this information. the developer could use this information<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for any initialization needed during the creation of the window}<br>&nbsp; &nbsp; &nbsp; &nbsp; ShowMessage(Format('String: %s'+Chr(13)+'Number: %d',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [lpszInfoString,dwInfoNumber]));<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; {upon getting the WM_DESTROY message, we exit the application}<br>&nbsp; &nbsp; WM_DESTROY: begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PostQuitMessage(0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Exit;<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br><br>&nbsp; {call the default window procedure for all unhandled messages}<br>&nbsp; Result := DefWindowProc(TheWindow, TheMessage, WParam, LParam);<br>end;<br><br>{ Register the Window Class }<br>function RegisterClass: Boolean;<br>var<br>&nbsp; WindowClass: TWndClass;<br>begin<br>&nbsp; {setup our new window class}<br>&nbsp; WindowClass.Style := CS_HREDRAW or CS_VREDRAW; &nbsp; &nbsp; {set the class styles}<br><br>&nbsp; WindowClass.lpfnWndProc := @WindowProc; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{our window procedure}<br>&nbsp; WindowClass.cbClsExtra := 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {no extra class memory}<br>&nbsp; WindowClass.cbWndExtra := 0; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {no extra window memory}<br>&nbsp; WindowClass.hInstance := hInstance; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{the application instance}<br>&nbsp; WindowClass.hIcon := LoadIcon(0, IDI_WINLOGO); &nbsp; &nbsp; {load a predefined logo}<br>&nbsp; WindowClass.hCursor := LoadCursor(0, IDC_APPSTARTING); {load a predefined <br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; cursor}<br>&nbsp; WindowClass.hbrBackground := COLOR_WINDOW; &nbsp; &nbsp; &nbsp; &nbsp; {use a predefined color}<br>&nbsp; WindowClass.lpszMenuName := nil; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {no menu}<br>&nbsp; WindowClass.lpszClassName := 'TestClass'; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{the registered class name}<br><br>&nbsp; {now that we have our class set up, register it with the system}<br>&nbsp; Result := Windows.RegisterClass(WindowClass) &lt;&gt; 0;<br>end;<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; hWindow: HWND;<br>&nbsp; ExtraCreationData: TMyData;<br>begin<br>&nbsp; {register our new class first}<br>&nbsp; if not RegisterClass then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('RegisterClass failed');<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; {fill in our extra creation data structure}<br>&nbsp; ExtraCreationData.lpszInfo:='ExtraCreationData information string';<br>&nbsp; ExtraCreationData.dwNumber:=12345;<br><br>&nbsp; {now, create a window based on our new class}<br>&nbsp; hWindow := CreateWindow('TestClass', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {the registered class name}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'API Window', &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{the title bar text}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WS_OVERLAPPEDWINDOW, &nbsp; {a normal window style}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT, &nbsp; &nbsp; &nbsp; &nbsp; {default horizontal position}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT, &nbsp; &nbsp; &nbsp; &nbsp; {default vertical position}<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT, &nbsp; &nbsp; &nbsp; &nbsp; {default width}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CW_USEDEFAULT, &nbsp; &nbsp; &nbsp; &nbsp; {default height}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Form1.Handle, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{handle of the parent window}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {no menu}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hInstance, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {the application instance}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @ExtraCreationData &nbsp; &nbsp; {additional creation <br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; information}<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br><br>&nbsp; {if our window was created successfully, show it}<br>&nbsp; if hWindow &lt;&gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowWindow(hWindow, SW_SHOWNORMAL);<br>&nbsp; &nbsp; UpdateWindow(hWindow);<br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; ShowMessage('CreateWindow failed');<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>end;<br><br>The Tomes of Delphi 3: Win32 Core API Help File by Larry Diehl.
 
to bini:<br>&nbsp; &nbsp;Thanks a lot and 100fen to you.
 
接受答案了.
 
后退
顶部