program PlainAPI;
uses
Windows,
Messages;
{$R *.res}
function PlainWinProc (hWnd: THandle; nMsg: UINT;
wParam, lParam: Cardinal): Cardinal; export; stdcall;
var
hdc: THandle;
ps: TPaintStruct;
begin
Result := 0;
case nMsg of
wm_lButtonDown:
MessageBox (hWnd, 'Mouse Clicked',
'Plain API', MB_OK);
wm_Paint:
begin
hdc := BeginPaint (hWnd, ps);
Ellipse (hdc, 100, 100, 300, 300);
EndPaint (hWnd, ps);
end;
wm_Destroy:
PostQuitMessage (0);
else
Result := DefWindowProc (hWnd, nMsg, wParam, lParam);
end;
end;
procedure WinMain;
var
hWnd: THandle;
Msg: TMsg;
WndClassEx: TWndClassEx;
begin
// initialize the window class structure
WndClassEx.cbSize := sizeOf (TWndClassEx);
WndClassEx.lpszClassName := 'PlainWindow';
WndClassEx.style := cs_VRedraw or cs_HRedraw;
WndClassEx.hInstance := HInstance;
WndClassEx.lpfnWndProc := @PlainWinProc;
WndClassEx.cbClsExtra := 0;
WndClassEx.cbWndExtra := 0;
WndClassEx.hIcon := LoadIcon (hInstance,
MakeIntResource ('MAINICON'));
WndClassEx.hIconSm := LoadIcon (hInstance,
MakeIntResource ('MAINICON'));
WndClassEx.hCursor := LoadCursor (0, idc_Arrow);;
WndClassEx.hbrBackground := GetStockObject (white_Brush);
WndClassEx.lpszMenuName := nil;
// register the class
if RegisterClassEx (WndClassEx) = 0 then
MessageBox (0, 'Invalid class registration',
'Plain API', MB_OK)
else
begin
hWnd := CreateWindowEx (
ws_Ex_OverlappedWindow, // extended styles
WndClassEx.lpszClassName, // class name
'Plain API Demo', // title
ws_OverlappedWindow, // styles
cw_UseDefault, 0, // position
cw_UseDefault, 0, // size
0, // parent window
0, // menu
HInstance, // instance handle
nil); // initial parameters
if hWnd = 0 then
MessageBox (0, 'Window not created',
'Plain API', MB_OK)
else
begin
ShowWindow (hWnd, sw_ShowNormal);
while GetMessage (Msg, 0, 0, 0) do
begin
TranslateMessage (Msg);
DispatchMessage (Msg);
end;
end;
end;
end;
begin
WinMain;
end.
|