I want to change the background ground color of CButton, i dont want to change it to CMFCButton and than use SetFaceColor() .For changing background color of CButton my code is as follows:
MyDialog.h
Code:
afx_msg void onDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
MyDialog.cpp
Code:
BEGIN_MESSAGE_MAP (MyDialog, CDialog)
ON_WM_DRAWITEM()
END_MESSAGE_MAP
void MyDialog :: OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
{
If(nIDCtl == IDOK)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
RECT rect;
rect = lpDrawItemStruct->rcItem;
dc.FillSolidRect(&rect,RGB(0,255,0));
UINT state=lpDrawItemStruct->itemState;
if((state & ODS_SELECTED))
{
dc.DrawEdge(&rect,EDGE_SUNKEN,BF_RECT);
}
else
{
dc.DrawEdge(&rect,EDGE_RAISED,BF_RECT);
}
dc.SetBkColor(RGB(100,100,255));
dc.SetTextColor(RGB(255,0,0));
dc.SetBkMode( TRANSPARENT );
TCHAR buffer[MAX_PATH];
ZeroMemory(buffer,MAX_PATH );
::GetWindowText(lpDrawItemStruct->hwndItem,buffer,MAX_PATH);
dc.DrawText(buffer,&rect,DT_CENTER|DT_VCENTER|DT_SINGLELINE);
dc.Detach();
}
CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
}
MyDialog.rc
DEFPUSHBUTTON "OK" IDOK,10,200,60,18 | BS_OWNERDRAW