i'm owner draw some controls.
here what i use for a button:
case WM_DRAWITEM:
{
DRAWITEMSTRUCT *test=(DRAWITEMSTRUCT*) lParam;
HIMAGELIST imlIcon=ImageList_Create(inst->imgtest.width(),inst->imgtest.height(),ILC_COLOR,1,1);
ImageList_Add(imlIcon,inst->imgtest,NULL);
HTHEME hTheme = OpenThemeData(inst->hwnd, L"BUTTON");
//fill the background with button face color
FillRect(test->hDC, &test->rcItem,(HBRUSH) GetSysColor(COLOR_BTNFACE));
if ( test->itemState & ODS_SELECTED) // If it is pressed
{
DrawEdge(test->hDC,&test->rcItem,EDGE_SUNKEN,BF_RECT); // Draw a sunken face
}
else if ( test->itemState & ODS_DISABLED)
{
DrawThemeBackground(hTheme, test->hDC, BP_PUSHBUTTON, PBS_DISABLED, &test->rcItem, 0);
}
else
{
DrawEdge(test->hDC, &test->rcItem,EDGE_RAISED,BF_RECT); // Draw a raised face
}
//add the transparent image to the button
if ( test->itemState & ODS_DISABLED)
{
DrawThemeIcon(hTheme, test->hDC, BP_PUSHBUTTON, PBS_DISABLED,&test->rcItem,imlIcon,0);
DrawThemeText(hTheme, test->hDC, BP_PUSHBUTTON, PBS_DISABLED,(LPCWSTR) inst->strCaption.c_str(),-1,DT_LEFT|DT_HIDEPREFIX,0,&test->rcItem);
}
else
{
TransparentBlt(test->hDC,0,0,inst->imgtest.width(),inst->imgtest.height(),inst->imgtest,0,0,inst->imgtest.width(),inst->imgtest.height(),GetPixel(inst->imgtest,0,0));
SetTextColor(test->hDC,inst->clrTextColor);
SetBkMode(test->hDC,TRANSPARENT);//text background transparent
DrawText(test->hDC,inst->strCaption.c_str(),-1,&test->rcItem,DT_LEFT);
}
//draw the caption
//draw the focus rectangle
HPEN pen = CreatePen(PS_DOT,1,RGB(0,0,0));//these is the must close to the rectangle focus style
SelectObject(test->hDC,pen);
SelectObject(test->hDC,GetStockObject(NULL_BRUSH));//the rectangle will be transparent
if ( (test->itemState & ODS_FOCUS )) // If the button is focused
{
int iChange = 3;
test->rcItem.top += iChange;
test->rcItem.left += iChange;
test->rcItem.right -= iChange;
test->rcItem.bottom -= iChange;
Rectangle(test->hDC, test->rcItem.left, test->rcItem.top, test->rcItem.right, test->rcItem.bottom);
}
CloseThemeData(hTheme);
ImageList_Destroy(imlIcon);
}
break;
i see 1 problem with these 2 lines:
DrawThemeIcon(hTheme, test->hDC, BP_PUSHBUTTON, PBS_DISABLED,&test->rcItem,imlIcon,0);
DrawThemeText(hTheme, test->hDC, BP_PUSHBUTTON, PBS_DISABLED,(LPCWSTR) inst->strCaption.c_str(),-1,DT_LEFT|DT_HIDEPREFIX,0,&test->rcItem);
1 - the icon isn't drawed black and white. i only see a black rectangle with control size;
2 - the text is drawed, but why i see chinese characteres?