Accueil > > > COULEURS ET TRANSPARENCE DES CONTROLES (API)
COULEURS ET TRANSPARENCE DES CONTROLES (API)
Information sur la source
Description
Suite aux nombreuses questions dans le forum sur la transparence des STATICs et l'utilisation des couleurs dans les contrôles, je me suis dit qu'il serait utile de proposer un petit code source dans lequel je rassemble tout ce que je sais à ce sujet. Tout réside dans le traitement des messages suivants: WM_CTLCOLORSTATIC: pour définir la couleur et la transparence d'un STATIC, CHECKBOX ou bouton radio. WM_CTLCOLOREDIT: pour définir la couleur du texte et de fond d'un EDIT. WM_CTLCOLORLISTBOX: pour définir la couleur du texte et de fond d'une LISTBOX. WM_CTLCOLORSCROLLBAR: pour définir la couleur de fond d'une SCROLLBAR. WM_CTLCOLORDLG: pour définir la couleur de fond d'une boite de dialogue. WM_DRAWITEM: pour définir la couleur du texte et de fond d'un bouton créé avec le style BS_OWNERDRAW. En cliquant sur un contôle de la boite de dialogue, ce programme change la couleur, choisie au hasard, d'un STATIC en affichant sa valeur héxadécimale. Ce source n'utilise pas les ressources. Il suffit de le copier puis le coller dans un nouveau projet WIN32. Il a été fait sous Visual C++ 6.
Source
- #include <windows.h>
-
- /******************************************************************/
- /************* Fonction de dessin des boutons *************/
- /******************************************************************/
- void DessinerBouton(LPDRAWITEMSTRUCT lpds,LPCTSTR texte,COLORREF couleurtexte,COLORREF couleurfond)
- {
- //Déclarations:
- SIZE dims;
- char nom[50];
- //Définir le texte du bouton:
- strcpy(nom, texte);
- //Déterminer les dimensions du texte:
- GetTextExtentPoint32(lpds->hDC, nom, strlen(nom), &dims);
- //Définir la couleur du texte:
- SetTextColor(lpds->hDC, couleurtexte);
- //Définir la couleur du fond:
- SetBkColor(lpds->hDC, couleurfond);
- //Déterminer l'état du bouton:
- BOOL etat=lpds->itemState & ODS_SELECTED;
- //Déterminer la largeur et la hauteur du bouton:
- int largeur=lpds->rcItem.right-lpds->rcItem.left;
- int hauteur=lpds->rcItem.bottom-lpds->rcItem.top;
- //Ecrire le texte sur le bouton:
- ExtTextOut(lpds->hDC,(largeur-dims.cx)/2+etat, (hauteur-dims.cy)/2+etat, ETO_OPAQUE | ETO_CLIPPED, &lpds->rcItem, nom, strlen(nom), NULL);
- //Dessiner le cadre du bouton selon son état:
- DrawEdge(lpds->hDC, &lpds->rcItem,(etat ? EDGE_SUNKEN : EDGE_RAISED ), BF_RECT);
- //Retour:
- return;
- }
- /******************************************************************/
-
- /******************************************************************/
- /************** Procédure de la boite de dialogue ***********/
- /******************************************************************/
- BOOL CALLBACK DialogProc( HWND hDlg, UINT message, WPARAM wParam,LPARAM lParam )
- {
- //Déclarer et définir les couleurs de fond de certains contrôles:
- static HBRUSH hbDialog = CreateSolidBrush(RGB(200,175,100));
- static HBRUSH hbEdit= CreateSolidBrush(RGB(210,200,150));
- static HBRUSH hbScrollh= CreateSolidBrush(RGB(60,250,240));
- static HBRUSH hbScrollv= CreateSolidBrush(RGB(250,160,230));
- static HBRUSH hbList= CreateSolidBrush(RGB(120,170,130));
- //Déclarer et définir notre police:
- static HFONT hPolice=CreateFont(32,0,0,0,400,0,0,0,0,0,0,0,0,"Arial");
- //Déclaration de nos contrôles:
- static HWND hBouton1,hBouton2,hBouton3,hBouton4,hBouton5,hBouton6,hEdit;
- static HWND hCheckbox1,hCheckbox2,hRadio1,hRadio2,hScrollh,hScrollv,hList,hQuitter;
- static HWND hStatic1,hStatic2,hStatic3,hStatic4,hStatic5,hRadios,hChecks,hCadre;
-
- switch (message)
- {
- case WM_INITDIALOG://Initialisation de notre boite de dialogue
- {
- //Ecrire le titre de la boite de dialogue:
- SetWindowText(hDlg,"Couleurs et transparence");
- //Création de nos contrôles:
- hBouton1=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,20,30,80,24,hDlg,0,0,0);
- hBouton2=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,20,70,80,24,hDlg,0,0,0);
- hBouton3=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,20,110,80,24,hDlg,0,0,0);
- hBouton4=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,20,150,80,24,hDlg,0,0,0);
- hBouton5=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,20,190,80,24,hDlg,0,0,0);
- hBouton6=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,20,230,80,24,hDlg,0,0,0);
- hQuitter=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,310,230,80,24,hDlg,0,0,0);
- hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT",0,WS_CHILD | WS_VISIBLE,130,233,150,20,hDlg,0,0,0);
- hCheckbox1=CreateWindow("BUTTON","Check 1",WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX ,308,167,100,16,hDlg,0,0,0);
- hCheckbox2=CreateWindow("BUTTON","Check 2",WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX ,308,187,100,16,hDlg,0,0,0);
- hRadio1=CreateWindow("BUTTON","Radio 1",WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON ,305,106,100,16,hDlg,0,0,0);
- hRadio2=CreateWindow("BUTTON","Radio 2",WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON ,305,126,100,16,hDlg,0,0,0);
- hScrollh=CreateWindow("SCROLLBAR",0,WS_CHILD | WS_VISIBLE | SBS_HORZ,20,270,400,20,hDlg,0,0,0);
- hScrollv=CreateWindow("SCROLLBAR",0,WS_CHILD | WS_VISIBLE | SBS_VERT,420,30,20,240,hDlg,0,0,0);
- hList=CreateWindowEx(WS_EX_CLIENTEDGE,"LISTBOX",0,WS_CHILD | WS_VISIBLE,130,110,150,104,hDlg,0,0,0);
- hRadios=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_GROUPBOX,300,91,90,56,hDlg,0,0,0);
- hChecks=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_GROUPBOX,300,151,90,59,hDlg,0,0,0);
- hCadre=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_GROUPBOX,130,39,260,48,hDlg,0,0,0);
- hStatic1=CreateWindow("STATIC","Edit :",WS_CHILD | WS_VISIBLE ,130,216,80,16,hDlg,0,0,0);
- hStatic2=CreateWindow("STATIC","ListBox :",WS_CHILD | WS_VISIBLE ,130,93,80,16,hDlg,0,0,0);
- hStatic3=CreateWindow("STATIC","www.cppfrance.com",WS_CHILD | WS_VISIBLE | SS_CENTER,132,49,256,36,hDlg,0,0,0);
- hStatic4=CreateWindow("STATIC","Static :",WS_CHILD | WS_VISIBLE ,130,30,80,16,hDlg,0,0,0);
- //Ajouter deux éléments dans la LISTBOX:
- SendMessage(hList,LB_ADDSTRING,0,(LPARAM)"Premier élément");
- SendMessage(hList,LB_ADDSTRING,0,(LPARAM)"Deuxième élément");
- //Changer la police de notre STATIC principal:
- SendMessage(hStatic3,WM_SETFONT,(WPARAM)hPolice,1);
- //Donner le focus à notre EDIT:
- SetFocus(hEdit);
- return 0;
- }
-
- case WM_CLOSE://Fermeture
- //Suppression des objets créés:
- DeleteObject(hbDialog);
- DeleteObject(hbEdit);
- DeleteObject(hbScrollh);
- DeleteObject(hbScrollv);
- DeleteObject(hbList);
- DeleteObject(hPolice);
- //Fermeture de la Boite de dialogue:
- EndDialog(hDlg,0);
- return 0;
-
- case WM_CTLCOLORDLG://Couleur de fond de la boite de dialogue
- return (INT_PTR)hbDialog;
-
- case WM_DRAWITEM://Dessin des boutons
- {
- LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
-
- if (lpdis->hwndItem==hBouton1)//Bouton jaune
- {
- DessinerBouton(lpdis,"Jaune",RGB(0,0,255),RGB(255,255,0));
- return TRUE;
- }
-
- if (lpdis->hwndItem==hBouton2)//Bouton vert
- {
- DessinerBouton(lpdis,"Vert",RGB(114,95,42),RGB(0,255,0));
- return TRUE;
- }
-
- if (lpdis->hwndItem==hBouton3)//Bouton bleu
- {
- DessinerBouton(lpdis,"Bleu",RGB(255,255,0),RGB(0,0,255));
- return TRUE;
- }
-
- if (lpdis->hwndItem==hBouton4)//Bouton rouge
- {
- DessinerBouton(lpdis,"Rouge",RGB(255,255,255),RGB(255,0,0));
- return TRUE;
- }
-
- if (lpdis->hwndItem==hBouton5)//Bouton blanc
- {
- DessinerBouton(lpdis,"Blanc",RGB(255,0,0),RGB(255,255,255));
- return TRUE;
- }
-
- if (lpdis->hwndItem==hBouton6)//Bouton noir
- {
- DessinerBouton(lpdis,"Noir",RGB(0,255,255),RGB(0,0,0));
- return TRUE;
- }
-
- if (lpdis->hwndItem==hQuitter)//Bouton Quitter
- {
- DessinerBouton(lpdis,"Quitter",RGB(255,255,0),RGB(114,95,42));
- return TRUE;
- }
- break;
- }
-
- case WM_CTLCOLORSTATIC://Dessin des STATICs, RADIOs et CHECKBOXes
- {
- if ((HWND)lParam==hCheckbox1)
- {
- SetTextColor((HDC)wParam,RGB(0,0,255));
- SetBkMode((HDC)wParam, TRANSPARENT);
- return (BOOL)GetStockObject(NULL_BRUSH);
- }
-
- if ((HWND)lParam==hCheckbox2)
- {
- SetTextColor((HDC)wParam,RGB(0,0,255));
- SetBkMode((HDC)wParam, TRANSPARENT);
- return (BOOL)GetStockObject(NULL_BRUSH);
- }
-
- if ((HWND)lParam==hRadio1)
- {
- SetTextColor((HDC)wParam,RGB(255,0,0));
- SetBkMode((HDC)wParam, TRANSPARENT);
- return (BOOL)GetStockObject(NULL_BRUSH);
- }
-
- if ((HWND)lParam==hRadio2)
- {
- SetTextColor((HDC)wParam,RGB(255,0,0));
- SetBkMode((HDC)wParam, TRANSPARENT);
- return (BOOL)GetStockObject(NULL_BRUSH);
- }
-
- if ((HWND)lParam==hStatic1)
- {
- SetTextColor((HDC)wParam,RGB(255,255,255));
- SetBkMode((HDC)wParam, TRANSPARENT);
- return (BOOL)GetStockObject(NULL_BRUSH);
- }
-
- if ((HWND)lParam==hStatic2)
- {
- SetTextColor((HDC)wParam,RGB(255,255,255));
- SetBkMode((HDC)wParam, TRANSPARENT);
- return (BOOL)GetStockObject(NULL_BRUSH);
- }
-
- if ((HWND)lParam==hStatic3)
- {
- SetTextColor((HDC)wParam,RGB(170,200,175));
- SetBkMode((HDC)wParam, TRANSPARENT);
- return (BOOL)GetStockObject(NULL_BRUSH);
- }
-
- if ((HWND)lParam==hStatic4)
- {
- SetTextColor((HDC)wParam,RGB(255,255,255));
- SetBkMode((HDC)wParam, TRANSPARENT);
- return (BOOL)GetStockObject(NULL_BRUSH);
- }
- return 0;
- }
-
- case WM_CTLCOLOREDIT://Dessin du contrôle EDIT
- {
- if ((HWND)lParam==hEdit)
- {
- SetTextColor((HDC)wParam,RGB(70,110,60));
- SetBkColor((HDC)wParam,RGB(210,200,150));
- return (BOOL) hbEdit;
- }
- return 0;
- }
-
- case WM_CTLCOLORSCROLLBAR://Dessin des SCROLLBARs
- {
- if ((HWND)lParam==hScrollh) return (BOOL) hbScrollh;
- if ((HWND)lParam==hScrollv) return (BOOL) hbScrollv;
- return 0;
- }
-
- case WM_CTLCOLORLISTBOX://Dessin de la LISTBOX
- {
- if ((HWND)lParam==hList)
- {
- SetTextColor((HDC)wParam,RGB(255,255,0));
- SetBkColor((HDC)wParam,RGB(120,170,130));
- return (BOOL) hbList;
- }
- return 0;
- }
-
- case WM_COMMAND://Clic sur un contrôle
- {
- //Obtenir le device contexte du STATIC principal:
- HDC hdc=GetDC(hStatic3);
- //Déterminer la zone dessinable:
- RECT rect;
- GetClientRect(hStatic3,&rect);
- //Effacer contenu du STATIC:
- FillRect(hdc,&rect,hbDialog);
- //Choisir une couleur au hasard:
- int couleur=rand()%256*0x10000+rand()%256*0x100+rand()%256;
- //Définir la couleur du texte:
- SetTextColor(hdc,couleur);
- //Rendre le Static transparent:
- SetBkMode(hdc,TRANSPARENT);
- //Choisir notre police:
- HFONT hOrigi=(HFONT)SelectObject(hdc,hPolice);
- //Convertir la couleur en valeur héxadécimale:
- char valeurhexa[6];
- itoa(couleur,valeurhexa,16);
- //Ecrire la valeur dans le STATIC
- DrawText( hdc, valeurhexa, -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
- //Restaurer la police originale:
- SelectObject(hdc,hOrigi);
- //Libérer le device context:
- ReleaseDC(hStatic3,hdc);
-
- if ((HWND)lParam==hQuitter)//clic sur Quitter
- {
- //Envoi du message de fermeture
- SendMessage(hDlg,WM_CLOSE,0,0);
- break;
- }
-
- }
- }
- //Retour:
- return 0;
- }
- /******************************************************************/
-
- /******************************************************************/
- /***************** Fonction WinMain *****************************/
- /******************************************************************/
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
- {
- //Allouer de la mémoire pour notre dialog template:
- LPDLGTEMPLATE lpdt = ( LPDLGTEMPLATE) GlobalAlloc(GPTR, 512);
- if (!lpdt) return 1;
- // Définir les propriétés de la boite de dialogue:
- lpdt->style = DS_CENTER | WS_POPUP | WS_MINIMIZEBOX| WS_SYSMENU | DS_MODALFRAME | WS_CAPTION;
- lpdt->x = lpdt->y = 0; lpdt->cx = 230; lpdt->cy = 155;
- //Lancer la boite de dialogue
- DialogBoxIndirect(hInstance,lpdt,NULL,(DLGPROC)DialogProc);
- //Libération de la mémoire allouée:
- GlobalFree((HGLOBAL)lpdt);
- //Retour:
- return 0;
- }
- /******************************************************************/
#include <windows.h>
/******************************************************************/
/************* Fonction de dessin des boutons *************/
/******************************************************************/
void DessinerBouton(LPDRAWITEMSTRUCT lpds,LPCTSTR texte,COLORREF couleurtexte,COLORREF couleurfond)
{
//Déclarations:
SIZE dims;
char nom[50];
//Définir le texte du bouton:
strcpy(nom, texte);
//Déterminer les dimensions du texte:
GetTextExtentPoint32(lpds->hDC, nom, strlen(nom), &dims);
//Définir la couleur du texte:
SetTextColor(lpds->hDC, couleurtexte);
//Définir la couleur du fond:
SetBkColor(lpds->hDC, couleurfond);
//Déterminer l'état du bouton:
BOOL etat=lpds->itemState & ODS_SELECTED;
//Déterminer la largeur et la hauteur du bouton:
int largeur=lpds->rcItem.right-lpds->rcItem.left;
int hauteur=lpds->rcItem.bottom-lpds->rcItem.top;
//Ecrire le texte sur le bouton:
ExtTextOut(lpds->hDC,(largeur-dims.cx)/2+etat, (hauteur-dims.cy)/2+etat, ETO_OPAQUE | ETO_CLIPPED, &lpds->rcItem, nom, strlen(nom), NULL);
//Dessiner le cadre du bouton selon son état:
DrawEdge(lpds->hDC, &lpds->rcItem,(etat ? EDGE_SUNKEN : EDGE_RAISED ), BF_RECT);
//Retour:
return;
}
/******************************************************************/
/******************************************************************/
/************** Procédure de la boite de dialogue ***********/
/******************************************************************/
BOOL CALLBACK DialogProc( HWND hDlg, UINT message, WPARAM wParam,LPARAM lParam )
{
//Déclarer et définir les couleurs de fond de certains contrôles:
static HBRUSH hbDialog = CreateSolidBrush(RGB(200,175,100));
static HBRUSH hbEdit= CreateSolidBrush(RGB(210,200,150));
static HBRUSH hbScrollh= CreateSolidBrush(RGB(60,250,240));
static HBRUSH hbScrollv= CreateSolidBrush(RGB(250,160,230));
static HBRUSH hbList= CreateSolidBrush(RGB(120,170,130));
//Déclarer et définir notre police:
static HFONT hPolice=CreateFont(32,0,0,0,400,0,0,0,0,0,0,0,0,"Arial");
//Déclaration de nos contrôles:
static HWND hBouton1,hBouton2,hBouton3,hBouton4,hBouton5,hBouton6,hEdit;
static HWND hCheckbox1,hCheckbox2,hRadio1,hRadio2,hScrollh,hScrollv,hList,hQuitter;
static HWND hStatic1,hStatic2,hStatic3,hStatic4,hStatic5,hRadios,hChecks,hCadre;
switch (message)
{
case WM_INITDIALOG://Initialisation de notre boite de dialogue
{
//Ecrire le titre de la boite de dialogue:
SetWindowText(hDlg,"Couleurs et transparence");
//Création de nos contrôles:
hBouton1=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,20,30,80,24,hDlg,0,0,0);
hBouton2=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,20,70,80,24,hDlg,0,0,0);
hBouton3=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,20,110,80,24,hDlg,0,0,0);
hBouton4=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,20,150,80,24,hDlg,0,0,0);
hBouton5=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,20,190,80,24,hDlg,0,0,0);
hBouton6=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,20,230,80,24,hDlg,0,0,0);
hQuitter=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_OWNERDRAW,310,230,80,24,hDlg,0,0,0);
hEdit=CreateWindowEx(WS_EX_CLIENTEDGE,"EDIT",0,WS_CHILD | WS_VISIBLE,130,233,150,20,hDlg,0,0,0);
hCheckbox1=CreateWindow("BUTTON","Check 1",WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX ,308,167,100,16,hDlg,0,0,0);
hCheckbox2=CreateWindow("BUTTON","Check 2",WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX ,308,187,100,16,hDlg,0,0,0);
hRadio1=CreateWindow("BUTTON","Radio 1",WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON ,305,106,100,16,hDlg,0,0,0);
hRadio2=CreateWindow("BUTTON","Radio 2",WS_CHILD | WS_VISIBLE | BS_AUTORADIOBUTTON ,305,126,100,16,hDlg,0,0,0);
hScrollh=CreateWindow("SCROLLBAR",0,WS_CHILD | WS_VISIBLE | SBS_HORZ,20,270,400,20,hDlg,0,0,0);
hScrollv=CreateWindow("SCROLLBAR",0,WS_CHILD | WS_VISIBLE | SBS_VERT,420,30,20,240,hDlg,0,0,0);
hList=CreateWindowEx(WS_EX_CLIENTEDGE,"LISTBOX",0,WS_CHILD | WS_VISIBLE,130,110,150,104,hDlg,0,0,0);
hRadios=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_GROUPBOX,300,91,90,56,hDlg,0,0,0);
hChecks=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_GROUPBOX,300,151,90,59,hDlg,0,0,0);
hCadre=CreateWindow("BUTTON",0,WS_CHILD | WS_VISIBLE | BS_GROUPBOX,130,39,260,48,hDlg,0,0,0);
hStatic1=CreateWindow("STATIC","Edit :",WS_CHILD | WS_VISIBLE ,130,216,80,16,hDlg,0,0,0);
hStatic2=CreateWindow("STATIC","ListBox :",WS_CHILD | WS_VISIBLE ,130,93,80,16,hDlg,0,0,0);
hStatic3=CreateWindow("STATIC","www.cppfrance.com",WS_CHILD | WS_VISIBLE | SS_CENTER,132,49,256,36,hDlg,0,0,0);
hStatic4=CreateWindow("STATIC","Static :",WS_CHILD | WS_VISIBLE ,130,30,80,16,hDlg,0,0,0);
//Ajouter deux éléments dans la LISTBOX:
SendMessage(hList,LB_ADDSTRING,0,(LPARAM)"Premier élément");
SendMessage(hList,LB_ADDSTRING,0,(LPARAM)"Deuxième élément");
//Changer la police de notre STATIC principal:
SendMessage(hStatic3,WM_SETFONT,(WPARAM)hPolice,1);
//Donner le focus à notre EDIT:
SetFocus(hEdit);
return 0;
}
case WM_CLOSE://Fermeture
//Suppression des objets créés:
DeleteObject(hbDialog);
DeleteObject(hbEdit);
DeleteObject(hbScrollh);
DeleteObject(hbScrollv);
DeleteObject(hbList);
DeleteObject(hPolice);
//Fermeture de la Boite de dialogue:
EndDialog(hDlg,0);
return 0;
case WM_CTLCOLORDLG://Couleur de fond de la boite de dialogue
return (INT_PTR)hbDialog;
case WM_DRAWITEM://Dessin des boutons
{
LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam;
if (lpdis->hwndItem==hBouton1)//Bouton jaune
{
DessinerBouton(lpdis,"Jaune",RGB(0,0,255),RGB(255,255,0));
return TRUE;
}
if (lpdis->hwndItem==hBouton2)//Bouton vert
{
DessinerBouton(lpdis,"Vert",RGB(114,95,42),RGB(0,255,0));
return TRUE;
}
if (lpdis->hwndItem==hBouton3)//Bouton bleu
{
DessinerBouton(lpdis,"Bleu",RGB(255,255,0),RGB(0,0,255));
return TRUE;
}
if (lpdis->hwndItem==hBouton4)//Bouton rouge
{
DessinerBouton(lpdis,"Rouge",RGB(255,255,255),RGB(255,0,0));
return TRUE;
}
if (lpdis->hwndItem==hBouton5)//Bouton blanc
{
DessinerBouton(lpdis,"Blanc",RGB(255,0,0),RGB(255,255,255));
return TRUE;
}
if (lpdis->hwndItem==hBouton6)//Bouton noir
{
DessinerBouton(lpdis,"Noir",RGB(0,255,255),RGB(0,0,0));
return TRUE;
}
if (lpdis->hwndItem==hQuitter)//Bouton Quitter
{
DessinerBouton(lpdis,"Quitter",RGB(255,255,0),RGB(114,95,42));
return TRUE;
}
break;
}
case WM_CTLCOLORSTATIC://Dessin des STATICs, RADIOs et CHECKBOXes
{
if ((HWND)lParam==hCheckbox1)
{
SetTextColor((HDC)wParam,RGB(0,0,255));
SetBkMode((HDC)wParam, TRANSPARENT);
return (BOOL)GetStockObject(NULL_BRUSH);
}
if ((HWND)lParam==hCheckbox2)
{
SetTextColor((HDC)wParam,RGB(0,0,255));
SetBkMode((HDC)wParam, TRANSPARENT);
return (BOOL)GetStockObject(NULL_BRUSH);
}
if ((HWND)lParam==hRadio1)
{
SetTextColor((HDC)wParam,RGB(255,0,0));
SetBkMode((HDC)wParam, TRANSPARENT);
return (BOOL)GetStockObject(NULL_BRUSH);
}
if ((HWND)lParam==hRadio2)
{
SetTextColor((HDC)wParam,RGB(255,0,0));
SetBkMode((HDC)wParam, TRANSPARENT);
return (BOOL)GetStockObject(NULL_BRUSH);
}
if ((HWND)lParam==hStatic1)
{
SetTextColor((HDC)wParam,RGB(255,255,255));
SetBkMode((HDC)wParam, TRANSPARENT);
return (BOOL)GetStockObject(NULL_BRUSH);
}
if ((HWND)lParam==hStatic2)
{
SetTextColor((HDC)wParam,RGB(255,255,255));
SetBkMode((HDC)wParam, TRANSPARENT);
return (BOOL)GetStockObject(NULL_BRUSH);
}
if ((HWND)lParam==hStatic3)
{
SetTextColor((HDC)wParam,RGB(170,200,175));
SetBkMode((HDC)wParam, TRANSPARENT);
return (BOOL)GetStockObject(NULL_BRUSH);
}
if ((HWND)lParam==hStatic4)
{
SetTextColor((HDC)wParam,RGB(255,255,255));
SetBkMode((HDC)wParam, TRANSPARENT);
return (BOOL)GetStockObject(NULL_BRUSH);
}
return 0;
}
case WM_CTLCOLOREDIT://Dessin du contrôle EDIT
{
if ((HWND)lParam==hEdit)
{
SetTextColor((HDC)wParam,RGB(70,110,60));
SetBkColor((HDC)wParam,RGB(210,200,150));
return (BOOL) hbEdit;
}
return 0;
}
case WM_CTLCOLORSCROLLBAR://Dessin des SCROLLBARs
{
if ((HWND)lParam==hScrollh) return (BOOL) hbScrollh;
if ((HWND)lParam==hScrollv) return (BOOL) hbScrollv;
return 0;
}
case WM_CTLCOLORLISTBOX://Dessin de la LISTBOX
{
if ((HWND)lParam==hList)
{
SetTextColor((HDC)wParam,RGB(255,255,0));
SetBkColor((HDC)wParam,RGB(120,170,130));
return (BOOL) hbList;
}
return 0;
}
case WM_COMMAND://Clic sur un contrôle
{
//Obtenir le device contexte du STATIC principal:
HDC hdc=GetDC(hStatic3);
//Déterminer la zone dessinable:
RECT rect;
GetClientRect(hStatic3,&rect);
//Effacer contenu du STATIC:
FillRect(hdc,&rect,hbDialog);
//Choisir une couleur au hasard:
int couleur=rand()%256*0x10000+rand()%256*0x100+rand()%256;
//Définir la couleur du texte:
SetTextColor(hdc,couleur);
//Rendre le Static transparent:
SetBkMode(hdc,TRANSPARENT);
//Choisir notre police:
HFONT hOrigi=(HFONT)SelectObject(hdc,hPolice);
//Convertir la couleur en valeur héxadécimale:
char valeurhexa[6];
itoa(couleur,valeurhexa,16);
//Ecrire la valeur dans le STATIC
DrawText( hdc, valeurhexa, -1, &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE );
//Restaurer la police originale:
SelectObject(hdc,hOrigi);
//Libérer le device context:
ReleaseDC(hStatic3,hdc);
if ((HWND)lParam==hQuitter)//clic sur Quitter
{
//Envoi du message de fermeture
SendMessage(hDlg,WM_CLOSE,0,0);
break;
}
}
}
//Retour:
return 0;
}
/******************************************************************/
/******************************************************************/
/***************** Fonction WinMain *****************************/
/******************************************************************/
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
//Allouer de la mémoire pour notre dialog template:
LPDLGTEMPLATE lpdt = ( LPDLGTEMPLATE) GlobalAlloc(GPTR, 512);
if (!lpdt) return 1;
// Définir les propriétés de la boite de dialogue:
lpdt->style = DS_CENTER | WS_POPUP | WS_MINIMIZEBOX| WS_SYSMENU | DS_MODALFRAME | WS_CAPTION;
lpdt->x = lpdt->y = 0; lpdt->cx = 230; lpdt->cy = 155;
//Lancer la boite de dialogue
DialogBoxIndirect(hInstance,lpdt,NULL,(DLGPROC)DialogProc);
//Libération de la mémoire allouée:
GlobalFree((HGLOBAL)lpdt);
//Retour:
return 0;
}
/******************************************************************/
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[WP7] DYNAMICALLY CHANGE STARTUP PAGE[WP7] DYNAMICALLY CHANGE STARTUP PAGE par KooKiz
Let's say that you want to allow the user to customize the startup page of your application. You can easily change the startup page by editing the 'NavigationPage' attribute in the manifest file. But the manifest cannot be modified once the applicatio...
Cliquez pour lire la suite de l'article par KooKiz SESSION SILVERLIGHT 5 3D : SLIDES ET DEMOSSESSION SILVERLIGHT 5 3D : SLIDES ET DEMOS par Groc
Durant les techdays, j'ai eu le plaisir d'animer une session sur Silverlight 5 et la 3D avec Simon Ferquel. Comme promis, voici nos slides et mes démos (celles avec le viper BSG) ici et là. Pour mémoire, les démos utilisent toutes le viper BSG...
Cliquez pour lire la suite de l'article par Groc [TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES[TECHDAYS 2012] SESSION WEBMATRIX 2 : LE COUTEAU SUISSE GRATUIT POUR VOS DéVELOPPEMENTS WEB - SLIDES par gpommier
Suite à la session que j'ai présenté sur WebMatrix 2, vous pouvez trouver les slides ici, ainsi que les démos en packages nuget : démos1 et démos2 J'en profite pour remercier chaleureusement tous ceux qui sont venus très nombreux à cette sess...
Cliquez pour lire la suite de l'article par gpommier [SHAREPOINT] LES SESSIONS TECHDAYS 2012.[SHAREPOINT] LES SESSIONS TECHDAYS 2012. par Patrick Guimonet
Voici donc pour ceux qui n'ont pas pu venir, ou ceux qui n'ont pas pu toutes les suivre la liste des sessions SharePoint aux TechDays 2012, que je mettrais à jour dès que les liens des vidéo seront disponibles. Ou ici : http...
Cliquez pour lire la suite de l'article par Patrick Guimonet TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3TECHDAYS PARIS 2012 : SESSION PLEINIèRE JOUR 3 par ROMELARD Fabrice
Speaker: Bernard Ourghanlian Cette session est comme chaque jour transmise en live par BrainSonic, et j'ai donc suivi cette troisième pleinière par ce moyen sur mon iPad . Elle est dédiée comme chaque année à la mise en perspective de l'é...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Logiciels
Tribler (2012)TRIBLER (2012)Tribler est un client pair à pair (P2P/Peer-to-Peer) open source avec la capacité de regarder des... Cliquez pour télécharger Tribler OneSwarm (2012)ONESWARM (2012)Le peer-to-peer qui protège votre vie privée, c'est OneSwarm.
Ce logiciel de peer-to-peer crypté... Cliquez pour télécharger OneSwarm PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V8.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning
|