sawer
2009-07-19 08:56:01 UTC
Hi
I'm tring to make owner draw round button.
1-)void CMyButton::PreSubclassWindow()
{
CRect rc;
GetClientRect( &rc );
CRgn Region;
Region.CreateRoundRectRgn(rc.left,rc.top,rc.right,rc.bottom,50,50);
SetWindowRgn(Region,TRUE);
CButton::PreSubclassWindow();
}
I searched and find out that SetWindowrgn function is used in
PreSubclassWindow handler. Is that a choice or rule for owner drawing?
2-) If i set owner-darw button to TRUE, i must write DrawItem method of my
custom class. I tried this:
void CMyButton::DrawItem(LPDRAWITEMSTRUCT dis)
{
CDC * dc = CDC::FromHandle(dis->hDC);
CRect r;
GetClientRect(&r);
int save = dc->SaveDC();
COLORREF color;
color = dis->itemState & ODS_SELECTED ? RGB(0,255,0) : RGB(255, 0, 0);
CBrush br(color);
dc->SelectObject(&br);
dc->SelectClipPath(RGN_COPY);
dc->PatBlt(0, 0, r.Width(), r.Height(), PATCOPY);
dc->StrokePath();
dc->RestoreDC(save);
}
But it didn't draw round button. What must be written to DrawItem function?
Thanks.
I'm tring to make owner draw round button.
1-)void CMyButton::PreSubclassWindow()
{
CRect rc;
GetClientRect( &rc );
CRgn Region;
Region.CreateRoundRectRgn(rc.left,rc.top,rc.right,rc.bottom,50,50);
SetWindowRgn(Region,TRUE);
CButton::PreSubclassWindow();
}
I searched and find out that SetWindowrgn function is used in
PreSubclassWindow handler. Is that a choice or rule for owner drawing?
2-) If i set owner-darw button to TRUE, i must write DrawItem method of my
custom class. I tried this:
void CMyButton::DrawItem(LPDRAWITEMSTRUCT dis)
{
CDC * dc = CDC::FromHandle(dis->hDC);
CRect r;
GetClientRect(&r);
int save = dc->SaveDC();
COLORREF color;
color = dis->itemState & ODS_SELECTED ? RGB(0,255,0) : RGB(255, 0, 0);
CBrush br(color);
dc->SelectObject(&br);
dc->SelectClipPath(RGN_COPY);
dc->PatBlt(0, 0, r.Width(), r.Height(), PATCOPY);
dc->StrokePath();
dc->RestoreDC(save);
}
But it didn't draw round button. What must be written to DrawItem function?
Thanks.