0

内部にボタンがある retangle を表示する cwnd クラスを作成しますが、自分でボタンを描画する代わりに、ボタン コンポーネントに委譲したいと考えています。

そのまま ....

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() !!!!!!!

    }
}

どうすればいいですか?

追伸: 残念ながら Dialog クラスは使えません

4

1 に答える 1