Click here to Skip to main content
13,832,051 members
Click here to Skip to main content
Add your own
alternative version

Tagged as


8 bookmarked
Posted 27 Mar 2018
Licenced CPOL

CMFCEditBrowseCtrl Without Flickering

, 15 Apr 2018
Rate this:
Please Sign up or sign in to vote.
Workaround for a bug in the CMFCEditBrowseCtrl that causes heavy flickering (starting with Windows 7)


In this article, I want to show a simple workaround for a bug in the MFC Feature Pack, and explain how I arrived at the solution.


When you open the attached application and move your mouse, you will notice that the folder icon of the first edit control flickers heavily.

demo of the flicker

To find the cause of this problem, I used WinSpector, but Spy++ works as well. Open up Spy++ and show the messages sent to the first edit control. When you move the mouse above the control, you will see many WM_NCPAINT-messages:

So let's look up the MFC source code, to find out what the CMFCEditBrowseCtrl does with the WM_NCPAINT-Message. The code is located in the file afxeditbrowsectrl.cpp.



void CMFCEditBrowseCtrl::OnNcPaint()
    OnDrawBrowseButton(&dc, rect, m_bIsButtonPressed, m_bIsButtonHighlighted);

Stepping further into OnDrawBrowseButton we arive at CMFCVisualManagerWindows::OnDrawBrowseButton (located in afxvisualmanagerwindows.cpp)

BOOL CMFCVisualManagerWindows::OnDrawBrowseButton(...)
    pDC->FillRect(rect, &(GetGlobalData()->brWindow));

So everythime, the button is drawn via WM_NCPAINT, the visualmanager first erases the area, and then redraws everything. This causes the flickering.

Many methods of MFC-Feature Pack classes are declared virtual, so to workaround this issue, we can easily add our own, customized implementation instead.

Using the Code

To remove the flicker, replace the CMFCEditBrowseCtrl with this fixed implementation:

class CMFCEditBrowseCtrlNoFlicker : public CMFCEditBrowseCtrl
  void OnDrawBrowseButton(CDC* pDC, CRect rect, BOOL bIsButtonPressed, BOOL bIsButtonHot) override
    CMemDC dc(*pDC, rect);
    __super::OnDrawBrowseButton(&dc.GetDC(), rect, bIsButtonPressed, bIsButtonHot);

In this implementation, we use a CMemDC, i.e., we buffer all drawing commands. So technically, the button is still erased and redrawn many times, but since only the final result is drawn on the screen, the flickering is gone.


  • 2018-04-03: First version (skip drawing when flags did not change)
  • 2018-04-16: Updated implementation with CMemDC (fixes missing redraw after minimizing the application)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
Austria Austria
No Biography provided

You may also be interested in...


Comments and Discussions

Questionproblem Pin
Michel Wassink7-Apr-18 12:49
memberMichel Wassink7-Apr-18 12:49 
AnswerRe: problem Pin
hofingerandi15-Apr-18 23:27
memberhofingerandi15-Apr-18 23:27 
GeneralRe: problem Pin
Michel Wassink18-Apr-18 10:50
memberMichel Wassink18-Apr-18 10:50 
GeneralA Point of Interest Pin
Rick York27-Mar-18 12:45
mveRick York27-Mar-18 12:45 
Questiongreat Pin
Michel Wassink27-Mar-18 12:12
memberMichel Wassink27-Mar-18 12:12 
QuestionAttached Application? Pin
Rick York27-Mar-18 7:32
mveRick York27-Mar-18 7:32 
AnswerRe: Attached Application? Pin
hofingerandi27-Mar-18 10:58
memberhofingerandi27-Mar-18 10:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web03 | 2.8.190114.1 | Last Updated 16 Apr 2018
Article Copyright 2018 by hofingerandi
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid