program Window;

uses Windows, Messages;

const AppName='IC Window';

function WindowProc(Window:HWnd; AMessage, WParam, LParam:longint):longint;stdcall; export;
begin
 WindowProc:=0;
 case AMessage of
  wm_Destroy: begin PostQuitMessage(0); Exit; end;
 end;
 WindowProc:=DefWindowProc(Window, AMessage, WParam, LParam);
end;

function WinRegister: boolean;
var WindowClass: TWndClass;
begin
 WindowClass.Style:=cs_hRedraw or cs_vRedraw;
 WindowClass.lpfnWndProc:=@WindowProc;
 WindowClass.cbClsExtra:=0;
 WindowClass.cbWndExtra:=0;
 WindowClass.hInstance:=SysInit.HInstance;
 WindowClass.hIcon:=LoadIcon(0, idi_Application);
 WindowClass.hCursor:=LoadCursor(0, idc_Arrow);
 WindowClass.hbrBackGround:=HBrush(Color_Window);
 WindowClass.lpszMenuName:=nil;
 WindowClass.lpszClassName:=AppName;
 Result:=RegisterClass(WindowClass)<>0;
end;

function WinCreate: HWnd;
var hWindow: HWnd;
begin
 hWindow:=CreateWindow(AppName, 'Only Window',ws_OverlappedWindow, cw_UseDefault,
  cw_UseDefault, cw_UseDefault, cw_UseDefault, 0, 0, HInstance, nil);
 if hWindow<>0 then
 begin
  ShowWindow(hWindow, CmdShow);
  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 hWindow=0 then
 begin
  MessageBox(0, 'WinCreate failed', nil, mb_Ok);
  Exit;
 end;
 while GetMessage(AMessage,0,0,0) do
 begin
  TranslateMessage(AMessage);
  DispatchMessage(AMessage);
 end;
 Halt(AMessage.wParam);
end.
