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 General Discussion » CExtPopupMenuWnd::UpdateFromMenu() doesn't seem to be working Collapse All
Subject Author Date
Dylan da Silva Apr 28, 2010 - 9:59 AM

We are in the process of updating our context menus with prof-UIS but we can’t seem to get them working at all.  The following code shows what I mean (taken from DrawCLI sample application):



CMenu menu;
    /*if( !menu.LoadMenu(ID_POPUP_MENU) )
    {
        ASSERT( FALSE );
        return;
    }*/
    menu.CreatePopupMenu();
    menu.AppendMenu(MF_STRING,ID_EDIT_CUT,"Cut");

HWND hWnd = AfxGetMainWnd()->GetSafeHwnd();
    ASSERT( hWnd != NULL );
    ASSERT( ::IsWindow( hWnd ) );

CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd;
    VERIFY( pPopup->UpdateFromMenu( hWnd, &menu ) ); <--- fails here

    VERIFY(
        pPopup->TrackPopupMenu(
            TPMX_OWNERDRAW_FIXED|TPMX_HIDE_KEYBOARD_ACCELERATORS,
            point.x,
            point.y
            )
        );

Technical Support Apr 29, 2010 - 6:31 AM

Then you don’t need the command manager. Just invoke the CExtPopupMenuWnd::UpdateFromMenu() method with the bNoRefToCmdMngr parameter set to true.

Dylan da Silva Apr 29, 2010 - 7:36 AM

So I changed the line with the error to:



VERIFY( pPopup->UpdateFromMenu( hWnd, &menu, true, true, true ) );

I get the same error as before.  I’m not understanding what’s wrong here.  After the AppendMenu() call, I can call TrackPopupMenu() and see a non-Prof-UIS menu, but Prof-UIS doesn’t seem to like that same menu object when it’s passed to UpdateFromMenu().  BTW, stepping back through the call stack when the VERIFY fails shows that the variable m_bTopLevel is false when we specifically set it to true.  There has to be an extra step or something that’s missing.

Technical Support May 3, 2010 - 8:21 AM

There are two types of menu resources:

1) Simple menu resources which typically used for the standard window menu line implemented as a window non-client area near the window caption.

2) Popup menu resources which are used for Win32 context menus only. These menu resources have only one popup menu item at the top level.

Please specify the correct flag value in the bPopupMenu parameter of the CExtPopupMenuWnd::UpdateFromMenu() method:

BOOL CExtPopupMenuWnd::UpdateFromMenu( 
            HWND hWndCmdRecv,
            CMenu * pBuildMenu,
            bool bPopupMenu, // = true
            bool bTopLevel, // = true
            bool bNoRefToCmdMngr // = false
            )

Technical Support Apr 28, 2010 - 12:43 PM

There are two types of menu items:

1) The menu items which are based on the command manager and updated via the MFC’s command updating mechanism. This is the default menu item type. Such menu items appear in the CExtPopupMenuWnd popup menu when the CExtPopupMenuWnd::ItemInsert() method is invoked or when the CExtPopupMenuWnd::LoadMenu() / CExtPopupMenuWnd::UpdateFromMenu() methods are invoked with the bNoRefToCmdMngr parameter set to false. These menu items use the command manager for retrieving menu item text and icon. That’s why the icons appear in menu command items automatically. But such UI design of popup menu window requires the command manager updating from all the menu resources used in your application.

2) The menu items which are NOT based on the command manager and NOT updated via the MFC’s command updating mechanism. Such menu items appear in the CExtPopupMenuWnd popup menu when the CExtPopupMenuWnd::ItemInsertCommand() method is invoked or when the CExtPopupMenuWnd::LoadMenu() / CExtPopupMenuWnd::UpdateFromMenu() methods are invoked with the bNoRefToCmdMngr parameter set to true. This not the default case. But such menu items are very handy for constructing dynamic popup menus containing dynamic menu item counts.

You should choose which menu items do you need? Whether you should simply update the command manager from all the menu resources or whether you need fully dynamic context menus?

Dylan da Silva Apr 28, 2010 - 1:39 PM

Thank you for your response.  However, if you look at the code I pasted originally I need THAT to work.  All of our context menus are dynamically created like in the example there.  From what you have told me I would need to add every single pop-up menu Command ID to the Command Manager to get it working the way we want it to?