Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » InsertMenu for inserting a toplevel popup menu into an unknown (unmodificable) menu Collapse All
Subject Author Date
Wilhelm Falkner Jan 28, 2008 - 8:57 AM

Hello,

I want to insert a toplevel popup menu into any existing menu. Using a MFC-Application without Prof-UIS the code:
CMenu* pMenu    = AfxGetMainWnd()->GetMenu();
if (pMenu != NULL) {
CMenu    cmInsert;
                if (cmInsert.LoadMenu(IDR_INSERT_4_DB)) {
/*
                CMenu*    pSubMenu = cmInsert.GetSubMenu(0);
                UINT    nFlags = MF_BYPOSITION | MF_POPUP;
                nFlags = MF_BYPOSITION;
                nFlags = MF_POPUP;
                nFlags = MF_BYPOSITION | MF_POPUP;
                pMenu->InsertMenu(1, nFlags, (UINT_PTR)pSubMenu->m_hMenu);
*/
                CMenu* pPopupMenu = cmInsert.GetSubMenu(0);
                // get its string - *ˆ&) Windows can’t figure it out for itself
                CString strMenuItem;
                cmInsert.GetMenuString(0, strMenuItem, MF_BYPOSITION);

                // Add it
                VERIFY(pMenu->InsertMenu(1, MF_BYPOSITION | MF_POPUP,
                    (UINT)pPopupMenu->GetSafeHmenu(), strMenuItem));
                // remove from the other menu!
                cmInsert.RemoveMenu(0, MF_BYPOSITION);


                DrawMenuBar();
//                    pMenu->InsertMenu(1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)cmInsert.m_hMenu);
                }
            }
        }

Technical Support Jan 29, 2008 - 3:01 AM

The CExtMenuControlBar class kills main frame’s menus and completely monitors menu changing in MDI main frames. It keeps current the main frame’s menu handle internally and uses it for building its toolbar buttons. So the top menu level is ab array of toolbar buttons in the menu bar. You can override the CExtMenuControlBar::_UpdateMenuBar() internal virtual method which builds toolbar buttons. Your method should be similar to the original one except it should insert the additional top level buttons like you need. You should invoke the following code from outside the menu bar to make it rebuild and update its content:

CExtMenuControlBar * pBar = . . .
      pBar->UpdateMenuBar();
      pBar->GetParentFrame()->RecalcLayout();

Wilhelm Falkner Jan 28, 2008 - 9:03 AM

Contine:

But working with PROF-UIS and CExtMenuControlBar, I’m without success.
In your article "Constructing Menus Dynamically at Run Time" you work with items to replace. This works fine (I use it at other locations), but in this case, I can not replace any Item, I have to insert a new popup menu.
How can I do this?

TIA
Willi