program MyProgram;
{*******************************************************}
{                                                       }
{ <Program> v<1.0> - <description>                      }
{                                                       }
{ Copyright (c) <@username>                             }
{                                                       }
{*******************************************************}

uses Windows, Messages;

const
  cLeft         = CW_USEDEFAULT;
  cTop          = CW_USEDEFAULT;
  cWidth        = CW_USEDEFAULT;
  cHeight       = CW_USEDEFAULT;

var
  MainWindowClass : TWndClassEx;
  wndMain         : HWND;
  Msg             : TMsg;

resourcestring
  cClassName    = 'MyWindowClass';
  cWinName      = 'MyWindowName';

function WndProc(AWnd: HWND; AMsg : integer; wParam: WPARAM; lParam: LPARAM): LRESULT; stdcall;
begin
  case AMsg of
    WM_DESTROY:
      begin
        PostQuitMessage(0);
        Result := 0;
        Exit;
      end;
  end;
  Result := DefWindowProc(AWnd, AMsg, wParam, lParam);
end;

procedure DoRegisterClass;
begin
  MainWindowClass.cbSize := SizeOf(MainWindowClass);
  MainWindowClass.style := CS_HREDRAW or CS_VREDRAW;
  MainWindowClass.lpfnWndProc := @WndProc;
  MainWindowClass.cbClsExtra := 0;
  MainWindowClass.cbWndExtra := 0;
  MainWindowClass.hInstance := hInstance;
  MainWindowClass.hIcon := LoadIcon(0, IDI_APPLICATION);
  MainWindowClass.hCursor := LoadCursor(0, IDC_ARROW);
  MainWindowClass.hbrBackground := COLOR_BTNFACE + 1;
  MainWindowClass.lpszMenuName := nil;
  MainWindowClass.lpszClassName := PChar(cClassName);

  RegisterClassEx(MainWindowClass);
end;

procedure MainWindow;
begin
  DoRegisterClass;

  wndMain := CreateWindowEx(
    0,
    PChar(cClassName),
    PChar(cWinName),
    WS_OVERLAPPEDWINDOW,
    integer(cLeft),
    integer(cTop),
    integer(cWidth),
    integer(cHeight),
    0,
    0,
    hInstance,
    nil
  );

  if wndMain <> 0 then
  begin
    ShowWindow(wndMain, SW_SHOW);
    UpdateWindow(wndMain);
    while GetMessage(Msg, 0, 0, 0) do begin
      TranslateMessage(Msg);
      DispatchMessage(Msg);
    end;
  end;
end;

begin
  MainWindow;
end.
