CCoolMenuManager - MDI Child Window Menu

In an MDI Application, a child window's system menu is not being handled properly, resulting in disabled menu items "disappearing" entirely. It appears that Windows is passing empty strings to the CCoolMenuManager for this menu. The fix is simple. In the 'ConvertMenu' member function, add the statement:

if (!info.cch) {

CMTRACE(_T("CCoolMenuManager: ignoring empty menu item\n"));

continue; // don't do for system menu commands

}

Before the following if statement:

if (bSysMenu && (info.wID >= 0xF000)) {

CMTRACE(_T("CCoolMenuManager: ignoring sys menu item\n"));

continue; // don't do for system menu commands

}

This seems to work nicely... Now I have to figure out why the m_bAutoAccel=TRUE condition causes memory leaks in an MDI application. If you know why, send me a note, I'd appreciate any help I can get!
[980 byte] By [Andres Cubero] at [2007-11-15 22:06:06]
# 1 Re: CCoolMenuManager - MDI Child Window Menu
I had a similar problem when running the application under Windows 98 - but a different solution.

The situation is worse on Windows 98, because Windows 98 will display small icons to the left of the minimize, maximize/restore, and close command.

Now, bSysMenu is only TRUE for the system menu of the main MDI frame - not for maximized MDI child windows. My solution was to remove the bSysMenu condition from the if statement above:

if (info.wID >= 0xF000) {

CMTRACE(_T("CCoolMenuManager: ignoring sys menu item\n"));

continue; // don't do for system menu commands

}

For my applications this works just fine, since the command range above 0xf000 is reserved for Windows (I think).
Arasch Honarbacht at 2007-11-10 3:08:02 >
# 2 Re: CCoolMenuManager - MDI Child Window Menu
Sorry folks!

found that popup-menus and the commands in the MDI-Window menu will not work correctly. So here is another fix that I

have tested under Windows NT 4.0 and Windows 98:

Keep the original code and add the following block, like this:

void CCoolMenuManager::ConvertMenu(CMenu* pMenu,

UINT nIndex, BOOL bSysMenu, BOOL bShowButtons)

{

ASSERT_VALID(pMenu);

CString sItemName;

// BLOCK: bugfix

if (m_pFrame->IsKindOf(RUNTIME_CLASS(CMDIFrameWnd)))

{

// Arasch Honarbacht 10/98:

// bSysMenu is true for the frame window's system menu only. A maximized child

// window in a MDI-frame will have bSysMenu set to FALSE causing ugly painting

// problems in Windows 98. This block will set bSysMenu to TRUE when it detects

// the MDI child's system menu

CMDIChildWnd *pActiveFrame = static_cast<CMDIFrameWnd *>(m_pFrame)->MDIGetActive();

if (pActiveFrame)

{

CMenu *pSysMenu = pActiveFrame->GetSystemMenu (FALSE);

ASSERT_VALID(pSysMenu);

if (pMenu == pSysMenu)

{

CMTRACE ("CCoolMenuManager: found menu to be active MDI child's system menu. Ignoring it...\n");

bSysMenu = TRUE;

}

}

}

UINT nItem = pMenu->GetMenuItemCount();

for (UINT i = 0; i < nItem; i++) { // loop over each item in menu
Arasch Honarbacht at 2007-11-10 3:09:02 >