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 » Customization and menu command items Collapse All
Subject Author Date
Roberto Manes Feb 20, 2007 - 8:32 AM

I’m running a MDI application supporting customization. It happens that every time I create a popup menu dynamically containing a command item which was not declared neither in any menu nor any toolbar of the application the next time I restart it I get the debug assertion failure at ExtCmdManager.cpp line 1862 and the system crashes.
If I remove from the registry the key named MyApplicationName->Prof-UIS260->Profiles->MyApplicationName->CommandManager the application restarts.

Here follows the code I wrote to get the popup menu

    if( !menu.LoadMenu(nMyMenuID) )
    {
        ASSERT( FALSE );
        return;
    }

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

    CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd;
    VERIFY( pPopup->UpdateFromMenu( hWnd, &menu ) );
    ClientToScreen(&point);
    VERIFY(
        pPopup->TrackPopupMenu( TPMX_OWNERDRAW_FIXED, point.x, point.y )
        );

NOTE: if I call pPopup->UpdateFromMenu(hWnd, &menu, true,true, true) I do not get such a problem.
Do I have to call the UpdateFromMenu() method as explained above everytime I need a popup menu ?

Suhai Gyorgy Feb 21, 2007 - 3:27 AM

Fifth and last parameter of CExtPopupMenuWnd::UpdateFromMenu is bNoRefToCmdMngr, which is false by default. Help says, this parameter "Specifies that the command items in Prof-UIS pop-up menu is not be based on the command descriptions stored in the command manager if this argument is true." So if you use the default parameter, UpdateFromMenu will load the commands of the popup menu into the command manager, which will save information about these commands in registry when you close the application, and tries to load them at next start-up. But this loading fails, as there are no commands like those in any of your menus or toolbars at start-up. This causes the assert. So if you use UpdateFromMenu(hWnd, &menu, true, true, true);, these commands will not have any relation with command manager, thus resolving the assert-problem.

Different topic, relating your code: You can eliminate usage of CMenu, if you use

	CExtPopupMenuWnd * pPopup = new CExtPopupMenuWnd;
	pPopup->CreatePopupMenu(hWnd);
	pPopup->LoadMenu(hWnd, nMyMenuID, true, true);
	ClientToScreen(&point);
	...