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.