5

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));
MrTux
  • 32,350
  • 30
  • 109
  • 146
  • 1
    CMFCMenuButton is owner draw. It apperas the control doesn't detect the change to the UI color scheme, so you may need to detect the contrast mode change and change the colors of the button to get it to show. – 1201ProgramAlarm Oct 19 '16 at 00:32
  • @1201ProgramAlarm Thanks for the hint, in was able to solve this in the meantime... – MrTux Oct 19 '16 at 01:50

1 Answers1

3

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.

MrTux
  • 32,350
  • 30
  • 109
  • 146