program HelloWin; {$WARN SYMBOL_PLATFORM OFF} uses Windows,Messages; var WndClass:TWndClass; WndHandle:HWND; Msg:TMsg; const szAppName:PChar='Hellowin'; szAppTitle:PChar='The Hello Program!'; function WndProc(Handle:HWND;Msg:UINT;wPar:WPARAM;lPar:LPARAM):Cardinal;stdcall; var DC:HDC; PS:PAINTSTRUCT; RT:TRECT; begin Result:=0; case Msg of WM_PAINT: begin DC:=BeginPaint(WndHandle,PS); GetClientRect(WndHandle,Rt); DrawText(DC,'Hello,Windows!',-1,RT,DT_SINGLELINE or DT_CENTER or DT_VCENTER); EndPaint(WndHandle,PS); end; WM_DESTROY: PostQuitMessage(0); else Result:=DefWindowProc(Handle,Msg,wPar,lPar); end; end; begin with WndClass do begin Style:=CS_HREDRAW or CS_VREDRAW; lpfnWndProc:=@WndProc; cbClsExtra:=0; cbWndExtra:=0; hInstance:=MainInstance; hIcon:=LoadIcon(HInstance,'MAINICON'); hCursor:=LoadCursor(0,IDC_ARROW); hbrBackground:=HBRUSH(GetStockObject(WHITE_BRUSH)); lpszMenuName:=nil; lpszClassName:=szAppName; end; if RegisterClass(WndClass)=0 then begin MessageBox(0,'Can''t create window!',szAppTitle,MB_OK or MB_ICONERROR); Exit; end; WndHandle:=CreateWindow(szAppName,szAppTitle,WS_OVERLAPPEDWINDOW, Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT), Integer(CW_USEDEFAULT),Integer(CW_USEDEFAULT), 0,0,hInstance,nil); ShowWindow(WndHandle,CmdShow); UpdateWindow(WndHandle); while GetMessage(Msg,0,0,0) do begin TranslateMessage(Msg); DispatchMessage(Msg); end; end.
运行效果图:
源代码下载:http://www.ctdisk.com/file/13413113