看看这个例子吧,对学API很有帮助的:<br>program myapiapplication;<br><br>uses<br> Windows,<br> Messages;<br><br>var<br> wc: TWndClass;<br> hWnd: Integer;<br> lpMSG: TMsg;<br><br>function WndProc( hWnd,Msg,wParam,lParam:integer) :integer ;stdcall; <br>var<br> myhdc : hdc;<br> ps : TPaintstruct;<br> myrect : TRect;<br> po : TPoint;<br> ClientHdc : hdc;<br>begin<br> Result := 0;<br> case Msg of<br> WM_LBUTTONDOWN: begin<br> if wParam=vk_lbutton then messagebox(hWnd,'请不要在窗口上乱点鼠标左键!','提示',o+mb_iconinformation);<br> if wParam=vk_rbutton then messagebox(hWnd,'请不要在窗口上乱点鼠标右键!','提示',o+mb_iconinformation);<br> end;<br> WM_MOUSEMOVE: begin<br> GetCursorPos(po);<br> ClientHdc :=getDc(hWnd);<br> Ellipse(hWnd,po.x-100,po.y-100,po.x,po.y);<br> releaseDc(hWnd,hdc); <br> end;<br> WM_DESTROY:begin<br> PostQuitMessage(0);<br> end;<br> WM_PAINT : begin<br> myhdc :=BeginPaint(hwnd,ps);<br> GetClientRect(hwnd,myrect);<br> DrawText(myhdc,'你好,欢迎学习API函数!',-1,myrect,DT_SINGLELINE OR DT_CENTER OR DT_VCENTER);<br> endPaint(hwnd,ps);<br> end;<br> end;<br> Result := DefWindowProc(hWnd, Msg, wParam, lParam);<br>end;<br><br>begin <br> wc.style := CS_VREDRAW or CS_HREDRAW;<br> wc.lpfnWndProc := @wndProc;<br> wc.cbClsExtra := 0;<br> wc.cbWndExtra := 0;<br> wc.hInstance := HInstance;<br> wc.hIcon := LoadIcon(0, IDI_APPLICATION);<br> wc.hCursor := LoadCursor(0, IDC_ARROW);<br> wc.hbrBackground := (COLOR_BTNFACE+1);<br> wc.lpszMenuName := nil;<br> wc.lpszClassName := 'My App';<br> if RegisterClass(wc)=0 then Exit;<br> hWnd := CreateWindow( wc.lpszClassName,<br> '用Pascal语言加api函数编制的Windows程序',<br> WS_OVERLAPPEDWINDOW,<br> 100,<br> 50,<br> 400,<br> 300,<br> 0,<br> 0,<br> HInstance,<br> nil);<br> ShowWindow(hWnd, SW_SHOWNORMAL);<br> UpdateWindow(hWnd);<br> while GetMessage(lpMSG, 0, 0, 0) do<br> begin<br> TranslateMessage(lpMSG);<br> DispatchMessage(lpMSG);<br> end;<br> Halt(lpMSG.wParam);<br><br>end.<br>