CONTROLES API WINDOWS


Tutorial boutons


Telecharger
bouton et static image


Telecharger
Tutorial listbox


Telecharger
Tutorial combobox


Telecharger
Tutorial timer


Telecharger






CREATION DE CONTROLES API WINDOWS CPP


CREATION D'UN BOUTON
HWND bout;

bout = CreateWindow("button",
"Clic ici", WS_CHILD | WS_VISIBLE ,
20,200,150,30,
hWnd,
(HMENU)IDB_BOUT,
hInst, NULL);

IDB_BOUT Commande du bouton.
WS_VISIBLE Rend la fenêtre visible dés sa création.
WS_CHILD Contrôle enfant. C'est obligatoire si l'on veut qu'il soit à l'intérieur de notre fenêtre.

CREATION D'UN BOUTON RADIO
HWND bout;

bout = CreateWindow("button",
"Bouton radio", WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON,
20,200,150,30,
hWnd,
(HMENU)IDB_BOUT,
hInst, NULL);

IDB_BOUT Commande du bouton.
BS_AUTORADIOBUTTON Signifie que c'est un bouton radio.
WS_VISIBLE Rend la fenêtre visible dés sa création.
WS_CHILD Contrôle enfant. C'est obligatoire si l'on veut qu'il soit à l'intérieur de notre fenêtre.

CREATION D'UN BOUTON CHECKBOX
HWND bout;

bout = CreateWindow("button",
"Bouton checkbox", WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX,
20,200,150,30,
hWnd,
(HMENU)IDB_BOUT,
hInst, NULL);

IDB_BOUT Commande du bouton.
BS_AUTOCHECKBOX Signifie que c'est un bouton checkbox.
WS_VISIBLE Rend la fenêtre visible dés sa création.
WS_CHILD Contrôle enfant. C'est obligatoire si l'on veut qu'il soit à l'intérieur de notre fenêtre.

CREATION D'UN BOUTON GROUPBOX
HWND bout;

bout = CreateWindow("button",
"bouton Group box", WS_CHILD | WS_VISIBLE | BS_GROUPBOX,
10,10,250,150,
hWnd,
0,
hInst, NULL);

BS_GROUPBOX Signifie que c'est un bouton groupbox.
WS_VISIBLE Rend la fenêtre visible dés sa création.
WS_CHILD Contrôle enfant. C'est obligatoire si l'on veut qu'il soit à l'intérieur de notre fenêtre.

CREATION D'UN STATIC
HWND stat;

stat = CreateWindow("static",
"Texte sur le static", WS_CHILD | WS_VISIBLE | WS_BORDER,
10,10,200,20,
hWnd,
0,
hInst, NULL);

WS_BORDER Ajoute une bordure autour du static.
WS_VISIBLE Rend la fenêtre visible dés sa création.
WS_CHILD Contrôle enfant. C'est obligatoire si l'on veut qu'il soit à l'intérieur de notre fenêtre.

CREATION D'UN EDIT TEXTE SIMPLE LIGNE
HWND editbox;

editbox = CreateWindow("edit",
"Texte du edit", WS_CHILD | WS_VISIBLE ,
10,10,150,20,
hWnd,
0,
hInst, NULL);

WS_VISIBLE Rend la fenêtre visible dés sa création.
WS_CHILD Contrôle enfant. C'est obligatoire si l'on veut qu'il soit à l'intérieur de notre fenêtre.

CREATION D'UN EDIT TEXTE MULTILIGNE
HWND editbox;

editbox = CreateWindow("edit",
"Texte du edit", WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_WANTRETURN | WS_VSCROLL,
10,10,300,300,
hWnd,
0,
hInst, NULL);

ES_MULTILINE Possibilité de saisir plusieurs lignes.
ES_WANTRETURN Retour à la ligne automatique.
WS_VSCROLL Mettre un ascenseur vertical.
WS_VISIBLE Rend la fenêtre visible dés sa création.
WS_CHILD Contrôle enfant. C'est obligatoire si l'on veut qu'il soit à l'intérieur de notre fenêtre.

CREATION D'UN LISTBOX
HWND list;

list = CreateWindow("listbox",
"", WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL,
10,10,150,200,
hWnd,
0,
hInst, NULL);

WS_VSCROLL Mettre un ascenseur vertical.
WS_BORDER Ajoute une bordure autour de la listbox.
WS_VISIBLE Rend la fenêtre visible dés sa création.
WS_CHILD Contrôle enfant. C'est obligatoire si l'on veut qu'il soit à l'intérieur de notre fenêtre.

Les messages listbox
SendMessage(list, LB_ADDSTRING, 0,(LPARAM)"texte à inserer"); // Ajoute de texte dans la listbox.
int nsel = SendMessage(list, LB_GETCOUNT, 0, 0); // Permet de savoir combien il y a d'items dans la listbox.

CREATION D'UN COMBOBOX
HWND combo;

combo = CreateWindow("COMBOBOX",
"", WS_CHILD | WS_VISIBLE | WS_BORDER | CBS_DROPDOWNLIST,
10,10,150,200,
hWnd,
0,
hInst, NULL);

WS_BORDER Ajoute une bordure autour du combobox.
WS_VISIBLE Rend la fenêtre visible dés sa création.
WS_CHILD Contrôle enfant. C'est obligatoire si l'on veut qu'il soit à l'intérieur de notre fenêtre.

Les messages combobox
SendMessage(combo, CB_ADDSTRING, 0,(LPARAM)"texte à inserer"); // Ajoute de texte dans le combobox.
SendMessage(combo,CB_RESETCONTENT,(WPARAM)0,(LPARAM)0); // Efface la liste du combo.
int comb1 = SendMessage(combo, CB_GETCURSEL, 0,0); // Permet de savoir quel item est selectionné.

CREATION D'UN TIMER
#define IDT_TIMER1 3000 // A declarer dans le fichier .h

SetTimer(hwnd,
IDT_TIMER3, // pour les fonction du timer
1000, // 1000 pour une seconde
(TIMERPROC) NULL);