2016-11-09 8 views
0

私は、ボタンが内部にあるリトグラフを表示するcwndクラスを作成しますが、自分でボタンを描くのではなく、ボタンコンポーネントに委託したいと思います。私はなりたいとしてそのままmwc内のコンポーネントを塗りつぶす

....

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の:私は残念ながら

答えて

0

あなたはボタンのpaintメソッドを呼び出す必要はありません]ダイアログクラスを使用することはできません。

、明らかにキャプションを変更...]ボタンを作成し、あなたのOnCreateイベントハンドラで(...、OnCreate関数(LPCREATESTRUCTのLPCをを)ON_WM_CREATE())

BEGIN_MESSAGE_MAP(CExampleControl, CWnd) // in your .cpp implementation file 
// ... other handlers 
    ON_WM_CREATE() 
END_MESSAGE_MAP() 

int CExampleControl::OnCreate(LPCREATESTRUCT lpcs) 
{ 
    __super::OnCreate(lpcs); 
    myButton.Create(_T("My caption"), WS_CHILD|WS_VISIBLE, CRect(0, 0, 100, 100), this, 101); 
    return 0; 
} 

をWM_CREATEのハンドラを作成します。座標、およびボタンのIDが表示されます。

その後、何もする必要はありません。ボタンは親ウィンドウの子として自身を描画します。

関連する問題