1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
| {******************************************************************************
* *
* Exemple de creation de divers boutons *
* *
******************************************************************************}
Program bouton ;
{$APPTYPE GUI}
Uses Windows;
Var WinClass: TWndClassa;
Inst: HINST;
hWindow: HWND;
hBouton1 : HWND;
hbitbouton : HWND;
hicobouton : HWND;
hradiobutton1 : HWND;
hradiobutton2 : HWND;
hradiobutton3 : HWND;
TheMessage: TMsg;
{ fonction qui gere les evenements de votre fenetre }
function WindowProc(hWindow: HWnd; Message,wParam,lParam: Integer): Integer; stdcall;
begin
Result := 0;
{ Gestion des messages }
case Message of
WM_DESTROY:
begin
postquitmessage(0);
end;
else
Result := DefWindowProc(hWindow, Message, wParam, lParam);
end;
end;
begin
{ enregistrement 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; { du with }
RegisterClass(WinClass);
{ Creation de la fenetre }
hWindow := CreateWindowEx(WS_EX_WINDOWEDGE,'MyWindowClass','Boutons',
WS_SYSMENU or WS_VISIBLE,
(Getsystemmetrics(SM_CXSCREEN) div 2)-(160 div 2),
(Getsystemmetrics(SM_CYSCREEN) div 2)-(446 div 2),
160,446,0,0,Inst,nil);
hBouton1 := CreateWindow('Button','Bouton normal',WS_VISIBLE or WS_CHILD or BS_TEXT or WS_TABSTOP,
10,8,130,25, hWindow, 0, Inst, nil);
CreateWindow('Button','Bouton2',WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_AUTORADIOBUTTON or BS_TEXT or WS_TABSTOP,
10,44,60,25, hWindow, 0, Inst, nil);
CreateWindow('Button','Bouton3',WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_AUTORADIOBUTTON or BS_TEXT or WS_TABSTOP,
80,44,60,25, hWindow, 0, Inst, nil);
CreateWindow('Button','BS_AUTO3STATE',WS_VISIBLE or WS_CHILD or BS_AUTO3STATE or BS_TEXT or WS_TABSTOP,
10,70,130,25, hWindow, 0, Inst, nil);
CreateWindow('Button','GroupBox1',WS_VISIBLE or WS_CHILD or BS_GROUPBOX,
5,95,140,95, hWindow, 0, Inst, nil);
CreateWindow('Button','RadioButton1',WS_VISIBLE or WS_CHILD or BS_AUTORADIOBUTTON or WS_TABSTOP,
10,118,113,17, hWindow, 0, Inst, nil);
CreateWindow('Button','RadioButton2',WS_VISIBLE or WS_CHILD or BS_AUTORADIOBUTTON or WS_TABSTOP,
10,142,113,17, hWindow, 0, Inst, nil);
CreateWindow('Button','RadioButton3',WS_VISIBLE or WS_CHILD or BS_AUTORADIOBUTTON or WS_TABSTOP,
10,166,113,17, hWindow, 0, Inst, nil);
CreateWindow('Button','CheckBox1',WS_VISIBLE or WS_CHILD or BS_AUTOCHECKBOX or WS_TABSTOP,
20,195,97,17, hWindow, 0, Inst, nil);
CreateWindow('Button','CheckBox2',WS_VISIBLE or WS_CHILD or BS_AUTOCHECKBOX or WS_TABSTOP,
20,215,97,17, hWindow, 0, Inst, nil);
CreateWindow('Button','texte à gauche',BS_LEFTTEXT or WS_VISIBLE or WS_CHILD or BS_AUTOCHECKBOX or WS_TABSTOP,
15,235,115,17, hWindow, 0, Inst, nil);
CreateWindow('Button','BS_MULTILINE Quand on a un texte long à mettre sur le bouton',BS_MULTILINE or WS_VISIBLE or WS_CHILD or WS_TABSTOP,
15,265,115,87, hWindow, 0, Inst, nil);
hicobouton := CreateWindow('Button','',BS_ICON or WS_VISIBLE or WS_CHILD or WS_TABSTOP,
15,360,45,37, hWindow, 0, Inst, nil);
sendmessage(hicobouton,BM_setimage,IMAGE_ICON,loadICON(0,IDI_EXCLAMATION));
hbitbouton := CreateWindow('Button','',BS_BITMAP or WS_VISIBLE or WS_CHILD or WS_TABSTOP,
85,360,45,37, hWindow, 0, Inst, nil);
sendmessage(hbitbouton,BM_setimage,IMAGE_BITMAP,loadBITMAP(0,MAKEINTRESOURCE(OBM_CHECK)));
SetFocus(hBouton1);
UpdateWindow(hWindow);
{La boucle principale}
while GetMessage(TheMessage,0,0,0) do begin
if not IsDialogMessage(hWindow,TheMessage) then begin
TranslateMessage(TheMessage);
DispatchMessage(TheMessage);
end;
end;
end. |
Partager