Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

a problem with OwnerDraw button

12 views
Skip to first unread message

yitche

unread,
May 2, 2003, 10:50:01 AM5/2/03
to
I have a MyButton class derived from Cbutton and I
overload its DrawItem and in Create method I put
BS_OWNERDRAW. The button should change the color on the
click so I overload onClicked method and set the color
there and call Invalidate.
The functionality works exactly once. When I click on the
button the second time the OnClicked simply does not get
invoked as if I did not click on the button. There is the
code:

void MyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)

{
// TODO: Add your code to draw the specified item
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
CRect rc;
rc=lpDrawItemStruct->rcItem ;
COLORREF BgColor;
if(m_color_flag)
BgColor=RGB(255,0,0);
else
BgColor=RGB(0,255,0);
dc.FillSolidRect (rc,BgColor);
UINT state=lpDrawItemStruct->itemState;
if((state&ODS_SELECTED))
dc.DrawEdge (rc,EDGE_SUNKEN, BF_RECT);
else
dc.DrawEdge (rc, EDGE_RAISED, BF_RECT);
dc.SetTextColor(RGB(0,0,0));
CString temp;
GetWindowText(temp);
dc.DrawText(temp,rc,
DT_CENTER|DT_VCENTER|DT_SINGLELINE);
if((state&ODS_FOCUS))
{
int ichange=2;
rc.bottom-=ichange;
rc.top+=ichange;
rc.left+=ichange;
rc.right-=ichange;
dc.DrawFocusRect(rc);
}
dc.Detach();

}

void MyButton::OnClicked()
{
// TODO: Add your control notification handler
code here
if(m_color_flag)
m_color_flag=false;
Invalidate(); //Redraw the button immediately
}
Please advise,
Yitche

yitche

unread,
May 2, 2003, 12:22:47 PM5/2/03
to
I actually found the answer: I called Create method with
BS_PUSHBUTTON|BS_OWNERDRAW and this what is wrong. The
pushbutton flag can't be together with the BS_OWNERDRAW

>.
>

0 new messages