怎样使用platform sdk来编程?(50分)

  • 主题发起人 主题发起人 nitemade
  • 开始时间 开始时间
N

nitemade

Unregistered / Unconfirmed
GUEST, unregistred user!
谁能给一个用platform sdk编程的例子
 
program WinApp;<br><br>uses<br>&nbsp; Windows, Messages;<br><br>var<br>&nbsp; GAppClass: PChar &nbsp; &nbsp;= 'TWinApp';<br>&nbsp; GAppCaption: PChar &nbsp;= 'A Standard Windows Application';<br>&nbsp; AMessage: MSG;<br>&nbsp; hWindow: HWND;<br>&nbsp; btnAbout: HWND;<br>&nbsp; btnClose: HWND;<br>&nbsp; <br>{$R *.RES}<br><br>// 窗口的消息处理函数<br>function WindowProc(AhWnd: HWND; AMessage: UINT; wParam: WPARAM;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lParam: LPARAM): LRESULT; stdcall; export;<br>begin<br>&nbsp; WindowProc := 0;<br>&nbsp; case AMessage of<br>&nbsp; &nbsp; WM_COMMAND:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp;if HWND(lParam) = btnAbout then<br>&nbsp; &nbsp; &nbsp;MessageBox(hWindow, 'SDK Application demo by Rainux',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'About', MB_OK);<br>&nbsp; &nbsp; &nbsp; &nbsp; if HWND(lParam) = btnClose then<br>&nbsp; &nbsp; &nbsp;PostMessage(hWindow, WM_DESTROY, 0, 0);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; WM_DESTROY:<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; PostQuitMessage(0);<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; end;<br>&nbsp; WindowProc := DefWindowProc(AhWnd, AMessage, wParam, lParam);<br>end;<br><br>// 窗口注册函数<br>function WinRegister: Boolean;<br>var<br>&nbsp; wc: WNDCLASS;<br>begin<br>&nbsp; { Define the Window class 's style }<br>&nbsp; wc.style &nbsp; &nbsp; &nbsp; &nbsp; := CS_HREDRAW or CS_VREDRAW or CS_DBLCLKS;<br>&nbsp; { Define the WindowProc function }<br>&nbsp; wc.lpfnWndProc &nbsp; := @WindowProc;<br>&nbsp; wc.cbClsExtra &nbsp; &nbsp;:= 0;<br>&nbsp; wc.cbWndExtra &nbsp; &nbsp;:= 0;<br>&nbsp; wc.hInstance &nbsp; &nbsp; := HInstance;<br>&nbsp; { Load common MAINICON from resource }<br>&nbsp; wc.hIcon &nbsp; &nbsp; &nbsp; &nbsp; := LoadIcon(HInstance, 'MAINICON');<br>&nbsp; wc.hCursor &nbsp; &nbsp; &nbsp; := LoadCursor(0, IDC_ARROW);<br>&nbsp; { Should be COLOR_BTNFACE + 1, why? }<br>&nbsp; wc.hbrBackground := COLOR_BTNFACE + 1;<br>&nbsp; { If use menu, must be the resource name }<br>&nbsp; wc.lpszMenuName &nbsp;:= nil;<br>&nbsp; wc.lpszClassName := GAppClass;<br>&nbsp; Result := Windows.RegisterClass(wc) &lt;&gt; 0;<br>end;<br><br>// 窗口建立函数<br>function WinCreate: HWND;<br>var<br>&nbsp; hWindow: HWND;<br>begin<br>&nbsp; { The window with WS_PUPOP style will like TForm.BorderStyle := bsNone }<br>&nbsp; hWindow := CreateWindowEx(WS_EX_OVERLAPPEDWINDOW, GAppClass, GAppCaption,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; WS_OVERLAPPEDWINDOW,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 200, 200, 400, 200,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, 0,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HInstance, nil);<br>&nbsp; btnAbout := CreateWindow('Button','About',WS_VISIBLE or WS_CHILD or <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BS_PUSHLIKE or BS_TEXT or WS_TABSTOP,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;210, 130, 75, 25, hWindow, 0, HInstance, nil);<br>&nbsp; btnClose := CreateWindow('Button','Close',WS_VISIBLE or WS_CHILD or <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BS_PUSHLIKE or BS_TEXT or WS_TABSTOP,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;300, 130, 75, 25, hWindow, 0, HInstance, nil);<br>&nbsp; if hWindow &lt;&gt; 0 then ShowWindow(hWindow, SW_SHOW);<br>&nbsp; if btnAbout &lt;&gt; 0 then ShowWindow(btnAbout, SW_SHOW);<br>&nbsp; if btnClose &lt;&gt; 0 then ShowWindow(btnClose, SW_SHOW);<br>&nbsp; Result := hWindow;<br>end;<br><br>// WinMain<br>begin<br>&nbsp; if not WinRegister then<br>&nbsp; begin<br>&nbsp; &nbsp; MessageBox(0, '注册窗口失败!', nil, MB_OK);<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; hWindow := WinCreate;<br>&nbsp; if hWindow = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; MessageBox(0, '建立窗口失败!', nil, MB_OK);<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; { The standard message loop }<br>&nbsp; { If the hWnd is 0, will retrieves messages for any window<br>&nbsp; &nbsp; that belongs to the calling thread and thread messages posted<br>&nbsp; &nbsp; to the calling thread }<br>&nbsp; while GetMessage(AMessage, 0, 0, 0) do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if not IsDialogMessage(hWindow, AMessage) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; TranslateMessage(AMessage);<br>&nbsp; &nbsp; &nbsp; &nbsp; DispatchMessage(AMessage);<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end;<br><br>end.<br>
 
后退
顶部