Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMFCMenuButton not properly repainting when toggling high contrast mode

In an C++ MFC project I'm using CMFCMenuButton using MSVC 2013.

When I toggle the high contrast mode the button is not properly repainted (for comparison a normal button is displayed):

broken repaint of CMFCMenuButton after toggling high contrast mode

Calling Invalidate() or ShowWindow(SW_HIDE);ShowWindow(SW_SHOW); seem to have no effect - even minimizing the dialog does not cause a proper redraw. How can I force the button to repaint with the updated system color?

Update: Forcing the colors after toggling contrast mode just makes the button text visible, however the button itself, the border, is not visible.

m_ctrlOkButton.SetFaceColor(::GetSysColor(COLOR_BTNFACE));
m_ctrlOkButton.SetTextColor(::GetSysColor(COLOR_BTNTEXT));
like image 270
MrTux Avatar asked Oct 18 '22 00:10

MrTux


1 Answers

Took me a while, but I was able to solve this. I'm inheriting from the CMFCMenuButton class so that I can handle some events:

  1. Get the color on the button right:
    Handle the WM_SYSCOLORCHANGE event and call GetGlobalData()->UpdateSysColors(); (make sure it's propagated to our parent before, e.g., by __super::OnSysColorChange();)

  2. Get the border and background right:
    Handle the WM_THEMECHANGED event and call CMFCVisualManager::GetInstance()->DestroyInstance(); in order to close all opened theme data handles.

like image 88
MrTux Avatar answered Oct 23 '22 11:10

MrTux