Program exempel ;

Uses Windows, Messages, CommCtrl;
{$R *.RES}

Var WinClass: TWndClassA;
    Inst: HINST;
    hWindow: HWND;
    TheMessage: TMsg;
    Label1: HWND;
    OldFont: HFONT;
    Image1: HWND;
    hImage1: HBITMAP;
    Edit1: HWND;
    Memo1: HWND;
    Button1: HWND;
    CheckBox1: HWND;
    GroupBox1: HWND;
    RadioButton1: HWND;
    RadioButton2: HWND;
    RadioButton3: HWND;
    CheckBox2: HWND;
    ListBox1: HWND;
    ComboBox1: HWND;
    CheckBox3: HWND;
    CheckBox4: HWND;
    BitBtn1: HWND;
    hBitBtn1: HBITMAP;
    TrackBar1: HWND;
    StatusBar1: HWND;
    ProgressBar1: HWND;
    PaintStruct: TPaintStruct;
    PaintDC: HDC;
    OldPoint: PPoint;
    OldPen: HPEN;
    Pen1: HPEN;
    Pen2: HPEN;
    Pen3: HPEN;
    OldBrush: HBRUSH;
    Brush1: HBRUSH;
    hFont1: HFONT;
    hFont2: HFONT;

{ Custom WindowProc function }
function WindowProc(hWindow: HWnd; Message,wParam,lParam: Integer): Integer; stdcall;
begin
  Result := 0;
  { Checks for messages }
  case Message of
    WM_CREATE: begin
      { Load Image }
      hImage1 := LoadBitmap(Inst,PChar('BMP_Image1'));
      { Load Image }
      hBitBtn1 := LoadBitmap(Inst,PChar('BMP_BitBtn1'));
      InitCommonControls;
      { Create Pens }
      Pen1 := CreatePen(PS_INSIDEFRAME,1,RGB(128,128,128));
      Pen2 := CreatePen(PS_INSIDEFRAME,1,RGB(255,255,255));
      Pen3 := CreatePen(PS_INSIDEFRAME,3,RGB(0,0,128));
      { Create Brushes }
      Brush1 := CreateSolidBrush(RGB(255,255,0));
    end;
    WM_COMMAND: begin
      if HWND(lParam) = Button1 then MessageBox(hWindow,'Button1Click','Check',MB_OK);
      if HWND(lParam) = CheckBox1 then MessageBox(hWindow,'CheckBox1Click','Check',MB_OK);
      if HWND(lParam) = CheckBox2 then MessageBox(hWindow,'CheckBox2Click','Check',MB_OK);
      if HWND(lParam) = CheckBox3 then MessageBox(hWindow,'CheckBox3Click','Check',MB_OK);
      if HWND(lParam) = CheckBox4 then MessageBox(hWindow,'CheckBox4Click','Check',MB_OK);
      if HWND(lParam) = BitBtn1 then MessageBox(hWindow,'BitBtn1Click','Check',MB_OK);
      exit;
    end;
    WM_SIZE: begin
      SendMessage(StatusBar1,WM_SIZE,wParam,lParam);
    end;
    WM_PAINT: begin
      PaintDC := BeginPaint(hWindow,PaintStruct);
      { Paint Colors text: Label2 }
      OldFont := SelectObject(PaintDC,hFont1);
      SetTextColor(PaintDC,RGB(0,0,128));
      SetBkColor(PaintDC,GetSysColor(COLOR_BTNFACE));
      TextOut(PaintDC,24,24,Pchar('Label2'),6);
      SelectObject(PaintDC,OldFont);
      { Paint Colors text: Label3 }
      OldFont := SelectObject(PaintDC,hFont2);
      SetTextColor(PaintDC,RGB(0,128,0));
      SetBkColor(PaintDC,GetSysColor(COLOR_BTNFACE));
      TextOut(PaintDC,24,48,Pchar('Label3'),6);
      SelectObject(PaintDC,OldFont);
      { Create bevel: Bevel1 }
      OldPen  := SelectObject(PaintDC,Pen1);
      MoveToEx(PaintDC,328,168,OldPoint);
      LineTo(PaintDC,465,168); LineTo(PaintDC,465,249); LineTo(PaintDC,328,249); LineTo(PaintDC,328,168); 
      OldPen  := SelectObject(PaintDC,Pen2);
      MoveToEx(PaintDC,329,169,OldPoint);
      LineTo(PaintDC,466,169); LineTo(PaintDC,466,250); LineTo(PaintDC,329,250); LineTo(PaintDC,329,169);
      { Create shape: Shape1 }
      OldBrush := SelectObject(PaintDC,Brush1);
      OldPen := SelectObject(PaintDC,Pen3);
      Rectangle(PaintDC,176,232,241,297);
      EndPaint(hWindow,PaintStruct);
    end;
    WM_DESTROY: begin
      DeleteObject(hImage1);
      DeleteObject(hBitBtn1);
      { Delete Pens and Brushes }
      DeleteObject(Pen1);
      DeleteObject(Pen2);
      DeleteObject(Pen3);
      DeleteObject(Brush1);
      { Delete Fonts }
      DeleteObject(hFont1);
      DeleteObject(hFont2);
      PostQuitMessage(0);
      Exit;
    end;
  else
    Result := DefWindowProc(hWindow, Message, wParam, lParam);
  end;
end;

begin
  { Register Custom WndClass }
  Inst := hInstance;
  with WinClass do
  begin
    style              := CS_CLASSDC or CS_PARENTDC;
    lpfnWndProc        := @WindowProc;
    hInstance          := Inst;
    hbrBackground      := color_btnface + 1;
    lpszClassname      := 'MyWindowClass';
    hIcon              := LoadIcon(0, IDI_APPLICATION);
    hCursor            := LoadCursor(0, IDC_ARROW);
  end; { with }

  RegisterClass(WinClass);

  { Create Main Window }
  hWindow := CreateWindowEx(WS_EX_WINDOWEDGE, 'MyWindowClass','Form1',
            WS_OVERLAPPEDWINDOW or WS_VISIBLE,
            190,128,545,426,0, 0, Inst, nil);


  { Create a label (static) ========================================= }
  Label1:= Createwindow('Static','Label1', WS_VISIBLE or WS_CHILD or SS_LEFT,
           24,8,32,13, hWindow, 0, Inst, nil);

  { Create a static image =========================================== }
  Image1:= CreateWindow('Static','', WS_VISIBLE or WS_CHILD or SS_BITMAP,
           32,248,49,41, hWindow, 0, Inst, nil);
  { set image to static control }
  SendMessage(Image1,STM_SETIMAGE,IMAGE_BITMAP,LParam(hImage1));

  { Create an edit field ============================================ }
  Edit1:= CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit','Edit1', WS_CHILD or WS_VISIBLE or WS_BORDER or WS_TABSTOP,
          96,8,121,21, hWindow, 0, Inst, nil);

  { Create a memo =================================================== }
  Memo1:= CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit','', WS_CHILD or WS_VISIBLE or WS_BORDER or
          ES_LEFT or ES_MULTILINE or ES_WANTRETURN or ES_AUTOVSCROLL or WS_VSCROLL,
          96,40,185,89, hWindow, 0, Inst, nil);
  { add lines  to memo }
  SendMessage(Memo1,WM_SETTEXT, 0, lParam(pChar('Memo1')));

  { Create a button ================================================= }
  Button1:= CreateWindow('Button','Button1',WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT or WS_TABSTOP,
            304,16,75,25, hWindow, 0, Inst, nil);

  { Create a checkbox =============================================== }
  CheckBox1:= CreateWindow('Button','CheckBox1',WS_VISIBLE or WS_CHILD or BS_AUTOCHECKBOX or WS_TABSTOP,
              304,48,97,17, hWindow, 0, Inst, nil);

  { Create a groupbox =============================================== }
  GroupBox1:= CreateWindow('Button','GroupBox1',WS_VISIBLE or WS_CHILD or BS_GROUPBOX,
              328,72,121,89, hWindow, 0, Inst, nil);

  { Create a radiobox =============================================== }
  RadioButton1:= CreateWindow('Button','RadioButton1',WS_VISIBLE or WS_CHILD or BS_AUTORADIOBUTTON or WS_TABSTOP,
                 344,88,113,17, hWindow, 0, Inst, nil);

  { Create a radiobox =============================================== }
  RadioButton2:= CreateWindow('Button','RadioButton2',WS_VISIBLE or WS_CHILD or BS_AUTORADIOBUTTON or WS_TABSTOP,
                 344,112,113,17, hWindow, 0, Inst, nil);

  { Create a radiobox =============================================== }
  RadioButton3:= CreateWindow('Button','RadioButton3',WS_VISIBLE or WS_CHILD or BS_AUTORADIOBUTTON or WS_TABSTOP,
                 344,136,113,17, hWindow, 0, Inst, nil);

  { Create a checkbox =============================================== }
  CheckBox2:= CreateWindow('Button','CheckBox2',WS_VISIBLE or WS_CHILD or BS_AUTOCHECKBOX or WS_TABSTOP,
              392,48,97,17, hWindow, 0, Inst, nil);

  { Create a listbox ================================================ }
  ListBox1:= CreateWindow('listbox', 'listbox' ,WS_VISIBLE or WS_CHILD or LBS_STANDARD or WS_TABSTOP,
             32,144,121,97, hWindow, 0, Inst, nil);
  { add items to listbox }
  SendMessage(ListBox1,LB_ADDSTRING , 0 ,LParam(PChar('aaaa1')) );
  SendMessage(ListBox1,LB_ADDSTRING , 0 ,LParam(PChar('aaaa2')) );
  SendMessage(ListBox1,LB_ADDSTRING , 0 ,LParam(PChar('aaaa3')) );

  { Create a combobox =============================================== }
  ComboBox1:= CreateWindow('combobox','ComboBox1',WS_VISIBLE or WS_CHILD or CBS_DROPDOWNLIST or WS_TABSTOP,
              168,152,137,189, hWindow, 0, Inst, nil);
  { add items to combobox }
  SendMessage(ComboBox1,CB_ADDSTRING , 0 ,LParam(PChar('kkkkk1')) );
  SendMessage(ComboBox1,CB_ADDSTRING , 0 ,LParam(PChar('kkkkk2')) );
  SendMessage(ComboBox1,CB_ADDSTRING , 0 ,LParam(PChar('kkkk3')) );
  SendMessage(ComboBox1,CB_ADDSTRING , 0 ,LParam(PChar('kkkkk4')) );
  SendMessage(ComboBox1,CB_ADDSTRING , 0 ,LParam(PChar('kkkkk5')) );
  { select current item }
  SendMessage(ComboBox1,CB_SELECTSTRING,0,LParam(PChar('kkkkk1')) );

  { Create a checkbox =============================================== }
  CheckBox3:= CreateWindow('Button','CheckBox3',WS_VISIBLE or WS_CHILD or BS_AUTOCHECKBOX or WS_TABSTOP,
              344,184,97,17, hWindow, 0, Inst, nil);

  { Create a checkbox =============================================== }
  CheckBox4:= CreateWindow('Button','CheckBox4',WS_VISIBLE or WS_CHILD or BS_AUTOCHECKBOX or WS_TABSTOP,
              344,208,97,17, hWindow, 0, Inst, nil);

  { Create a bit button ============================================= }
  BitBtn1:= CreateWindow('Button','', WS_VISIBLE or WS_CHILD or WS_TABSTOP or BS_BITMAP,
            176,184,75,25, hWindow, 0, Inst, nil);
  { set image to button }
  SendMessage(BitBtn1,BM_SETIMAGE,IMAGE_BITMAP,LParam(hBitBtn1));

  { Create a trackbar =============================================== }
  TrackBar1:= CreateWindow('msctls_trackbar32','trackbar',WS_VISIBLE or WS_CHILD or WS_BORDER,
              304,264,150,41, hWindow, 0, Inst, nil);
  SendMessage(TrackBar1,TBM_SETRANGE,1,MakeLong( 0,10));
  SendMessage(TrackBar1,TBM_SETPOS,1,3);

  { Create a statusbar ============================================== }
  StatusBar1:= CreateStatusWindow(WS_VISIBLE or WS_CHILD ,''
               , hWindow, 0);

  { Create a progressbar ============================================ }
  ProgressBar1:= CreateWindow('msctls_progress32','progressbar',WS_VISIBLE or WS_CHILD or WS_BORDER,
                 48,320,150,18, hWindow, 0, Inst, nil);
  SendMessage(ProgressBar1,PBM_SETRANGE,0,MakeLong(0,100));
  SendMessage(ProgressBar1,PBM_SETPOS,50,0) ;


  { Create Font Handle =================================================== }
  hFont1 := CreateFont(-13,0,0,0,700,0,0,0,DEFAULT_CHARSET,0,0,0,0,'MS Sans Serif');
  hFont2 := CreateFont(-13,0,0,0,700,1,0,0,DEFAULT_CHARSET,0,0,0,0,'MS Sans Serif');

  { Change fonts ============================================== }
  if hFont1 <> 0 then SendMessage(Memo1,WM_SETFONT,hFont1,0);

  SetFocus(Edit1);

  UpdateWindow(hWindow);

  {the standard message loop}
  while GetMessage(TheMessage,0,0,0) do begin
    if not IsDialogMessage(hWindow,TheMessage) then begin
      TranslateMessage(TheMessage);
      DispatchMessage(TheMessage);
    end;
  end;
end.


