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
|
case WM_DRAWITEM:
// drawing code goes here
//getting the Draw Item structure
LPDRAWITEMSTRUCT b;
b = (LPDRAWITEMSTRUCT) lParam;
//Getting the button visual theme(i get the xp style)
HTHEME hTheme;
hTheme = OpenThemeData(hButton, L"button");
//translate the LPDRAWITEMSTRUCT->itemState to DrawThemeBackground int id state
int c=0;
UINT g=0;
//testing the button state
if(b->itemState & ODS_HOTLIGHT)
{
c=PBS_HOT;
g=DFCS_HOT;
}
else if (b->itemState & ODS_DEFAULT)
{
c=PBS_DEFAULTED;
g=DFC_BUTTON;
}
else if (b->itemState & ODS_DISABLED)
{
c=PBS_DISABLED;
g=DFCS_INACTIVE;
}
else if (b->itemState & ODS_SELECTED)
{
c=PBS_PRESSED;
g=DFCS_PUSHED;
}
else
{
c=PBS_NORMAL;
g=DFC_BUTTON;
}
//draw the button with right state
//the state is what the button action can draw to us(click,disable and others)
//DrawThemeBackground(hTheme, b->hDC, BP_PUSHBUTTON, c, &b->rcItem, 0);
DrawFrameControl(b->hDC, &b->rcItem, DFC_BUTTON |DFCS_ADJUSTRECT, g);
//getting and draw icon
HICON hicon;
hicon=LoadIcon(NULL,IDI_EXCLAMATION);
DrawIcon(b->hDC,5,5, hicon);
SelectObject(b->hDC,CreatePen(PS_DOT,1,GetSysColor(COLOR_3DSHADOW)));
LineTo(b->hDC,100,0);
//before show the text, i need put it transparent(hide the text backcolor)
SetBkMode(b->hDC,TRANSPARENT);
//i can draw the text with prefix('&')
//the DT_EXPANDTABS is for show us the '\t' and others
if(b->itemState & ODS_NOACCEL)//if the menu key is pressed then
DrawText(b->hDC,caption.c_str(),-1,&b->rcItem,DT_EXPANDTABS| DT_CENTER | DT_HIDEPREFIX);
else
DrawText(b->hDC,caption.c_str(),-1,&b->rcItem,DT_EXPANDTABS| DT_CENTER);
return 0;
|