On Draw buttons
Posted: Wed Oct 30, 2002 1:41 pm
In a SDI C View app, lets say I put a button there and make it on draw, How would I make it look like a oval?
Code: Select all
void COvalButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
// do oval drawing stuff here
dc.Detach();
}
Code: Select all
ok I did mean that but when I compile this:
class CMyBtn : CButton
{
public:
void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
};
BOOL CAboutDlg::PreCreateWindow(CREATESTRUCT& cs)
{
CMyBtn btnmy;
CRect rct( 80, 80, 120, 120 );
CWnd* pWnd;
btnmy.Create( _T("Hello"), BS_DEFPUSHBUTTON | BS_OWNERDRAW | WS_VISIBLE, rct, pWnd, IDC_BUTTON1 );
return CDialog::PreCreateWindow(cs);
}
void CMyBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
COLORREF clrBlue = RGB( 0, 0, 255 );
CBrush brBlue( clrBlue );
dc.SelectObject( brBlue );
dc.Rectangle( 85, 85, 115, 115 );
dc.Detach();
}
I get this error:
Compiling...
C:\PROGRAM FILES\DEVSTUDIO\MyProjects\Btn\Btn.cpp(169) : error C2248:
Code: Select all
class CMyBtn : public CButton
Code: Select all
void CMyBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
COLORREF clrBlue = RGB( 0, 0, 255 );
COLORREF clrOld;
CBrush brBlue( clrBlue );
CBrush* pbrOld;
pbrOld = dc.SelectObject(&brBlue );
// dc.Rectangle( 85, 85, 115, 115 );
RECT rect;
GetClientRect(&rect);
dc.Rectangle(0, 0, rect.right, rect.bottom);
clrOld = dc.SetBkColor(clrBlue);
dc.DrawText(_T("Hello"), &rect, DT_SINGLELINE | DT_VCENTER | DT_CENTER);
dc.SetBkColor(clrOld);
dc.SelectObject(pbrOld);
dc.Detach();
}