Problem with DrawItem
I am trying to change the background color of button and when abutton
is pushed I will let the user know that its pushed .
I am able to change the background color but it does show pushed when
button clicks.
Can anyone fix this?
Problem with my code is
void CFilterBtn::DrawItem(LPDRAWITEMSTRUCT
lpDrawItemStruct/*lpDrawItemStruct*/)
{
CBrush defBrush, selBrush;
COLORREF Orange = RGB(0, 10, 10);
selBrush.CreateSolidBrush(Orange);
UINT uStyle = DFCS_BUTTONPUSH;
// This code only works with buttons.
ASSERT(lpDrawItemStruct->CtlType == ODT_BUTTON);
if(lpDrawItemStruct->itemAction == ODA_SELECT)
uStyle |= DFCS_PUSHED;
// If drawing selected, add the pushed style to DrawFrameControl.
if (lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |= DFCS_PUSHED;
// Draw the button frame.
::DrawFrameControl(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem,
DFC_BUTTON, uStyle);
// Get the button's text.
CString strText;
GetWindowText(strText);
// Draw the button text using the text color red.
FillRect(lpDrawItemStruct->hDC, &lpDrawItemStruct->rcItem,
selBrush);
COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC,
RGB(255,0,0));
::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(),
&lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
::SetBkColor(lpDrawItemStruct->hDC, RGB(0,0,0));
}