我创建了一个 cwnd 类,它显示了一个带有按钮的 retangle,但我不想自己绘制一个按钮,而是委托给按钮组件。
原样....
class ExampleControl : public CWnd
{
void ExampleControl::OnPaint()
{
CPaintDC dc(this);
CRect rc(this);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
m_bmpCache.DeleteObject();
m_bmpCache.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
OnDraw(&memDC);
}
void ExampleControl::OnDraw(CDC* pDC)
{
CRect rcClient(this);
// draw background
pDC->FillSolidRect(rcClient, GetSysColor(COLOR_WINDOW));
// draw border
COLORREF borderColor = RGB(0,0,255);
pDC->Draw3dRect(0, 0, rcClient.Width(), rcClient.Height(), borderColor, borderColor);
**//draw button
//OK this draw a button ... but I would like to write
//CRect rect(10,10,25,15);
//pDC->DrawFrameControl(rect, DFC_BUTTON, DFCS_BUTTONPUSH);**
}
}
正如我想成为的那样......
class ExampleControl : public CWnd
{
//instantiate and call myButton.Create(...)
CButton myButton;
void ExampleControl::OnPaint()
{
CPaintDC dc(this);
CRect rc(this);
CDC memDC;
memDC.CreateCompatibleDC(&dc);
m_bmpCache.DeleteObject();
m_bmpCache.CreateCompatibleBitmap(&dc, rc.Width(), rc.Height());
OnDraw(&memDC);
}
void ExampleControl::OnDraw(CDC* pDC)
{
CRect rcClient(this);
// draw background
pDC->FillSolidRect(rcClient, GetSysColor(COLOR_WINDOW));
// draw border
COLORREF borderColor = RGB(0,0,255);
pDC->Draw3dRect(0, 0, rcClient.Width(), rcClient.Height(), borderColor, borderColor);
//draw button, using the mfc component
//!!!! myButton.OnPaint() !!!!!!!
}
}
请问,我该怎么办?
Ps.:不幸的是,我不能使用 Dialog 类