user180574
user180574

Reputation: 6084

MFC: how to fix redraw properly for inherited CDialogBar?

I make an inherited class from CDialogBar.

class CMyDialogBar : public CDialogBar
{
    DECLARE_DYNAMIC(CMyDialogBar)

    // Implementation
public:
    BOOL Create(CWnd * pParentWnd, UINT nIDTemplate, UINT nStyle, UINT nID);
    BOOL Create(CWnd * pParentWnd, LPCTSTR lpszTemplateName, UINT nStyle, UINT nID);

protected:
    virtual void DoDataExchange(CDataExchange* pDX) { return CDialogBar::DoDataExchange(pDX); }
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    DECLARE_MESSAGE_MAP()
};

The only big change is the function OnEraseBkgnd() because I like the background to be white.

BOOL CMyDialogBar::OnEraseBkgnd(CDC* pDC)
{
    return TRUE;
}

It works OK. However, when I move the rebar around it doesn't redraw correctly as shown in the figure below.

enter image description here

The source code can be downloaded here: https://138.197.210.223/test/My.zip.

Upvotes: 2

Views: 102

Answers (1)

Adrian Mole
Adrian Mole

Reputation: 51825

You need your OnEraseBkgnd override to actually erase the background! For example, to set the entire client rectangle to white, you could do this:

BOOL CMyDialogBar::OnEraseBkgnd(CDC *pDC)
{
    RECT wr; GetClientRect(&wr);
    pDC->FillSolidRect(&wr, RGB(255,255,255));
    return TRUE;
}

EDIT: Maybe you already have this, but also be sure to add ON_WM_ERASEBKGND to your message map:

BEGIN_MESSAGE_MAP(CMyDialogBar, CDialogBar)
    // ... (other message handlers, if any) ...
    ON_WM_ERASEBKGND()
END_MESSAGE_MAP()

Upvotes: 1

Related Questions