CMFCMenuButton does not close

I have CDialogwith CFMCMenuButton. when I open it, everything looks fine:

CDialog with menu button

The problem occurs when I click on another place to close the menu. The menu seems to be open if the user does not select its option. And if I press Escape on the keyboard, the dialog closes, which is too much; I really would like it to close only the menu.

I know that I can solve this by setting its "OS Menu" property in the resource file to True (or, equivalently, assigning it to a property m_bOSMenu= TRUE). And I would get:

CDialog with a menu button having an OS menu property, set to TRUE

As you can see in the image, the consequences are as follows:

  • I am losing badges (not very important)
  • (), OnInitMenuPopup ( : OnInitMenuPopup, , ). , , .

?

+1
1

MFC.

afxmenubutton.cpp CMFCMenuButton::OnShowMenu CDialogEx CDialog:

#ifdef _DEBUG
    if ((pParent->IsKindOf(RUNTIME_CLASS(CDialog))) && (!pParent->IsKindOf(RUNTIME_CLASS(CDialogEx))))
    {
        TRACE(_T("CMFCMenuButton parent is CDialog, should be CDialogEx for popup menu handling to work correctly.\n"));
    }
#endif

CDialogEx, ! " OS" "False", , !

: https://msdn.microsoft.com/en-us/library/Bb983913.aspx

+1

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


All Articles