function AppWindowProc(hWnd:HWND; uMsg:UINT;wParam:WPARAM; lParam:LPARAM):LRESULT; stdcall;
begin
Result := 0;
case uMsg of
WM_DESTROY: begin
PostQuitMessage(0);
Exit;
end;
end;
Result:=DefWindowProc(hWnd, uMsg, wParam, lParam);
end;
var
wc: TWndClass;
hWnd: Integer;
MSG: TMsg;
begin
wc.style := CS_VREDRAW or CS_HREDRAW;
wc.lpfnWndProc := @AppWindowProc;
wc.cbClsExtra := 0;
wc.cbWndExtra := 0;
wc.hInstance := HInstance;
wc.hIcon := LoadIcon(0, IDI_APPLICATION);
wc.hCursor := LoadCursor(0, IDC_ARROW);
wc.hbrBackground := (COLOR_BTNFACE+1);
wc.lpszMenuName := nil;
wc.lpszClassName := 'My App';
if RegisterClass(wc)=0 then Exit;
hWnd:= CreateWindow(wc.lpszClassName,'TEST',WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,0,0,HInstance,nil);
if hWnd=0 then Exit;
ShowWindow(hWnd, SW_SHOWNORMAL);
while GetMessage(MSG, 0, 0, 0) do begin
TranslateMessage(MSG);
DispatchMessage(MSG);
end;
Halt(MSG.wParam);
end.
procedure WinMain;
var
Wnd: hWnd;
Msg: TMsg;
cls: TWndClass;
begin
{ Previous instance running ? If so, exit }
if FindWindow (AppName, Nil) <> 0 then Panic (AppName + ' is already running.');