Текст программы:
program win32api;
uses
Windows, Messages;
const
ClassName = 'MyWindow';
var
hMain: HWND;
function WindowProc(Handle: HWND; Msg: cardinal; wparam: integer; lparam: integer): integer; stdcall;
begin
Result:=0;
case Msg of
WM_DESTROY:
PostQuitMessage(0);
else
Result:=DefWindowProc(Handle,Msg,wParam,lParam);
end;
end;
function InitWindow: boolean;
var
wc: WNDCLASS;
begin
Result:=true;
FillChar(wc,SizeOf(wc),0);
wc.style:=CS_VREDRAW or CS_HREDRAW;
wc.lpfnWndProc:=@WindowProc;
wc.hInstance:=SysInit.HInstance;
wc.hIcon:=LoadIcon(0,IDI_APPLICATION);
wc.hCursor:=LoadCursor(0,IDC_ARROW);
wc.hbrBackground:=COLOR_BTNFACE + 1;
wc.lpszClassName:=ClassName;
if RegisterClass(wc)=0 then begin
MessageBox(0,'Can''t register the class','Error',MB_ICONERROR);
Result:=false;
exit;
end;
hMain:=CreateWindowEx(WS_EX_TOOLWINDOW,ClassName,'Win32 API Program',WS_SYSMENU,100,100,400,300,0,0,SysInit.HInstance,nil);
if hMain=0 then begin
MessageBox(0,'Can''t create the window','Error',MB_ICONERROR);
Result:=false;
exit;
end;
ShowWindow(hMain,SW_SHOW);
end;
procedure MainLoop;
var
MSG: TMSG;
begin
while GetMessage(MSG,0,0,0) do begin
TranslateMessage(MSG);
DispatchMessage(MSG);
end;
end;
begin
InitWindow;
MainLoop;
end.