CMFCMenuButton redraws incorrectly when switching high contrast mode

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

When I switch the high contrast mode , the button is incorrectly repainted (for comparison, the usual button is displayed):

broken repaint of CMFCMenuButton after toggling high contrast mode

Call Invalidate() or ShowWindow(SW_HIDE);ShowWindow(SW_SHOW); It seems ineffective - even minimizing the dialogue does not cause the correct redrawing. How to make the button repaint the updated color of the system?

Update. Forcing colors after switching the contrast mode only makes the button text visible, but the button itself, the border, is not visible.

 m_ctrlOkButton.SetFaceColor(::GetSysColor(COLOR_BTNFACE)); m_ctrlOkButton.SetTextColor(::GetSysColor(COLOR_BTNTEXT)); 
+5
source share
1 answer

Took me a little, but I was able to solve it. I inherit from the CMFCMenuButton class CMFCMenuButton that I can handle some events:

  • Get the color on the button to the right:
    Handle the WM_SYSCOLORCHANGE event and call GetGlobalData()->UpdateSysColors(); (make sure it propagates to our parent before, for example, __super::OnSysColorChange(); )

  • Get the border and background right:
    Refer to the WM_THEMECHANGED event and call CMFCVisualManager::GetInstance()->DestroyInstance(); to close all open data descriptors .

+3
source

Source: https://habr.com/ru/post/1258437/


All Articles