Author: Jonas Bilinkevicius
How can I create a form without using the Forms unit?
Answer:
1 program InputAPI;
2
3 uses
4 Windows, Messages;
5
6 var
7 WinClass: TWndClassA;
8 Inst, Handle, Button1, Button2: Integer;
9 Msg: TMsg;
10 hFont: Integer;
11
12 { Custom WindowProc function }
13
14 function WindowProc(hWnd, uMsg, wParam, lParam: Integer): Integer; stdcall;
15 begin
16 Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
17 { Checks for messages }
18 if uMsg = WM_DESTROY then
19 Halt;
20 end;
21
22 begin
23 { Register Custom WndClass }
24 Inst := hInstance;
25 with WinClass do
26 begin
27 style := CS_CLASSDC or CS_PARENTDC;
28 lpfnWndProc := @WindowProc;
29 hInstance := Inst;
30 hbrBackground := color_btnface + 1;
31 lpszClassname := 'Test';
32 hCursor := LoadCursor(0, IDC_ARROW);
33 end;
34 RegisterClass(WinClass);
35 { Create Main Window }
36 Handle := CreateWindowEx(WS_EX_WINDOWEDGE or WS_EX_CONTROLPARENT, 'Test',
37 'TestWindow', WS_VISIBLE or WS_CAPTION or WS_SYSMENU, 300, 200, 300, 100,
38 0, 0, Inst, nil);
39 { Create a button }
40 Button1 := CreateWindow('Button', 'Ok', WS_VISIBLE or WS_CHILD or WS_TABSTOP or
41 BS_PUSHLIKE or BS_TEXT, 50, 20, 75, 25, handle, 0, Inst, nil);
42 Button2 := CreateWindow('Button', 'Cancel', WS_VISIBLE or WS_CHILD or WS_TABSTOP
43 or
44 BS_PUSHLIKE or BS_TEXT, 150, 20, 75, 25, handle, 0, Inst, nil);
45 { Create Font Handle }
46 hFont := CreateFont(-15, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET,
47 OUT_DEFAULT_PRECIS,
48 CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH or FF_DONTCARE,
49 'MS Sans Serif');
50 { Change fonts }
51 if hFont <> 0 then
52 begin
53 SendMessage(Button1, WM_SETFONT, hFont, 0);
54 SendMessage(Button2, WM_SETFONT, hFont, 0);
55 end;
56 SetFocus(Button1);
57 UpdateWindow(Handle);
58 { Message Loop }
59 while (GetMessage(Msg, 0, 0, 0)) do
60 if not IsDialogMessage(handle, msg) then
61 begin
62 TranslateMessage(msg);
63 DispatchMessage(msg);
64 end;
65 end.
|