Uses Win2K2,CoolKey,Graph,ccontr;

var
 gCol : Integer;
 Parent : hWNd;
 gP   : POINT;
 gText : String;

Function WindowProc(ahWnd:HWND;aMsg,wParam,lParam:UINT32):UINT32;far;
var
 ps : LPPAINTSTRUCT;
 rt : RECT;
begin
  case aMsg of
    WM_COMMAND:
     begin
      if lParam = 1 then gText:='Button Pressed';
      if lParam = 0 then gText:='Button Released';
      PostMessage(ahWnd,WM_PAINT,0,0);
     end;
    WM_DESTROY:
      PostQuitMessage(ahwnd);
    WM_KEYDOWN:
      if wParam = ord(SC_ESCAPE) then PostQuitMessage(ahWnd);
    WM_PAINT:
     begin
       ps := BeginPaint(ahWNd);
        wSetColor(ps,gCol);
        wSetBgColor(ps,GlobalPalette.ThreeDColor1);
        wSetStyle(ps,SolidFill);
        wSetFontJustify(ps,CenterText,CenterText);
        GetClientRect(ahWnd,@rt);
        wBar(ps,0,(rt.b.y - TextHeight(gText)) shr 1,
                rt.b.x,(rt.b.y + TextHeight(gText)) shr 1);
        wTextOut(ps,rt.b.x shr 1, rt.b.y shr 1, @gText);
       EndPaint(ps);
     end;
  end;
end;

begin
 if InitWin2K2 = ERR_OK then
 if RegisterClass('TestClass',WindowProc) = ERR_OK then
  begin
    InitCommonControls;
    Parent:=CreateWindow('My Cool Application','TestClass',
                         WS_TITLE OR WS_SIZEABLE OR WS_MINMAX,
                         100,100,300,200,
                         NULL,NULL);
    CreateWindow('Cool Button','BUTTON',WS_CHILD,
                 20,120,120,40,Parent,NULL);
    CreateWindow('Text','EDIT',WS_CHILD,
                 20,20,120,20,Parent,NULL);
    CreateWindow('Hello My Label','LABEL',WS_CHILD,
                 20,60,120,20,Parent,NULL);
    MainRunLoop;
  end;
 DoneWin2K2;
end.