Share via

Adding dark mode to dynamically added sub-menus

ChuckieAJ 391 Reputation points
2025-02-11T21:06:58.2866667+00:00

I have a CMFCMenuButton on my dialog which is set to the DarkMode_Explorer theme.

Therefore, when the dropdown menu part is display it is correctly showing with dark backgrounds.

The only caveat is that there is one instance where I load another menu resource and append it to my buttons' menu.

Code snippets:

  • I load the menu that I want to dynamically add like this:
CMenu menuManageSpeakers;
menuManageSpeakers.LoadMenu(IDR_MENU_POPUP_MANAGE);
  • I populate that menu's submenus dynamically (they show fine in dark mode). Then, I insert the menu to my menu button menu:
const CMenu* pSubMenu = menuManageSpeakers.GetSubMenu(0);
if (pSubMenu)
{
	pMnuPopup->InsertMenu(-1,
		MF_BYPOSITION | MF_POPUP,
		reinterpret_cast<UINT_PTR>(pSubMenu->GetSafeHmenu()), subMenuText);
}

Here you can see the problem:

Image

It is odd that the sub-menus (level 3) are dark. But not this middle menu.

Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.

0 comments No comments

Answer accepted by question author

Minxin Yu 13,516 Reputation points Microsoft External Staff
2025-02-12T02:00:12.1666667+00:00

Hi,

I am able to reproduce the problem.
User's image

Declaring CMenu menuManageSpeakers as a class member or in the heap area work for me.

CMenu* menuManageSpeakers=new CMenu();
User's image

Best regards,

Minxin Yu


If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.