Development of Windows native programs using Object Pascal

Source: Internet
Author: User

Program Project1;

Uses
Windows, Messages, SysUtils;
Const
Appname = 'fancydemo ';
Function windowproc (window: HWND; amessage: UINT; wparam: WPARAM;
Lparam: LPARAM): LRESULT; stdcall; export;
Var
Dc: HDC;
Ps: TPaintStruct;
R: TRect;

Begin
Windowproc: = 0;
Case amessage
WM_PAINT:
Begin
Dc: = BeginPaint (window, ps );
GetClientRect (window, r );
DrawText (dc, 'windows program written in op ',-1, r, DT_SINGLELINE or DT_CENTER );
EndPaint (window, ps );
Exit;
End;
WM_DESTROY:
Begin
PostQuitMessage (0 );
Exit;
End;
End;
Windowproc: = DefWindowProc (window, amessage, wparam, lparam );
End;
Function winregister: Boolean;
Var
Windowclass: WNDCLASS;
Begin
Windowclass. style: = CS_HREDRAW or CS_VREDRAW;
Windowclass. lpfnWndProc: = TFNWndProc (@ windowproc );
Windowclass. cbClsExtra: = 0;
Windowclass. cbWndExtra: = 0;
Windowclass. hInstance: = SYSTEM. MainInstance;
Windowclass. hIcon: = LoadIcon (0, IDI_APPLICATION );
Windowclass. hCursor: = LoadCursor (0, IDC_ARROW );
Windowclass. hbrBackground: = GetStockObject (WHITE_BRUSH );
Windowclass. lpszMenuName: = nil;
Windowclass. lpszClassName: = appname;
Result: = RegisterClass (windowclass) <> 0;
End;
Function wincreate: hwnd;
VaR
Hwindow: hwnd;
Begin
Hwindow: = createwindow (appname, 'Hello, fancy ', ws_overlappedwindow, cw_usedefault, 0, 0, system. maininstance, nil );
If hwindow <> 0 then
Begin
Showwindow (hwindow, cmdshow );
Showwindow (hwindow, sw_show );
Updatewindow (hwindow );
End;
Result: = hwindow;
End;
VaR
Amessage: tmsg;
Hwindow: hwnd;
Begin
If not winregister then
Begin
MessageBox (0, 'Register failed', nil, MB_ OK );
Exit;
End;
Hwindow: = wincreate;
If LongInt (hwindow) = 0 then
Begin
MessageBox (0, 'wincreate failed', nil, MB_ OK );
Exit;
End;
While GetMessage (amessage, 0, 0) do
Begin
TranslateMessage (amessage );
DispatchMessage (amessage );
End;
Halt (amessage. wParam );
End.


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.