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 » Menu dynamic update Collapse All
Subject Author Date
Roberto Manes Jan 17, 2007 - 4:35 AM

Dear Sirs

I would appreciate if you could help me to understand where the Drawcli application updates the "Window" menu with the document name of the opened document. The matter is that when I run my mdi application, I open one document, I click onto the "Window" menu and from the OnExtMenuPrepare() method declared in the CMainframe class I can’t get any item having the command ID number __ID_MDIWNDLIST_FIRST. Do you have any idea ? Thanks in advance for your help.

Technical Support Jan 17, 2007 - 10:27 AM

There is the following code in the CMainFrame::OnExtMenuPrepare() method in the DrawCli sample:

int nMaxCmdID = 0;
for( int nCmdID = __ID_MDIWNDLIST_FIRST; nCmdID <= __ID_MDIWNDLIST_LAST; nCmdID++ )
{
    nItemPos = pPopup->ItemFindPosForCmdID( nCmdID );
    if( nItemPos > 0 )
    {
        if( nCmdID > nMaxCmdID )
        {
            nMaxCmdID = nCmdID;
            nNewPos = nItemPos;
        }
    }
}
This code is looking for the menu items which correspond to the mdi child windows. You can see how these items are constructed in the CExtPopupMenuWnd::UpdateMdiWindowsMenu() method.

Roberto Manes Jan 19, 2007 - 11:09 AM

Everything seems to be clear to me, but probably I’m still missing something because I wrote the following code in the OnCreate() method of the mainframe

    VERIFY(
        CExtCustomizeSite::MenuInfoAdd(
            this,
            _T("Default"),
            IDR_MAINFRAME,
            true,
            false,
            RUNTIME_CLASS( CMainFrame )
            )
        );

    VERIFY(
        CExtCustomizeSite::MenuInfoAdd(
            this,
            _T("Document"),
            IDR_SmartColorTYPE,
            false,
            false,
            RUNTIME_CLASS( CMDIChildWnd ),
            RUNTIME_CLASS( CView ),
            RUNTIME_CLASS( CDocument )
            )
        );
    VERIFY(
        CExtCustomizeSite::MenuInfoLoadAccelTable(
            _T("Default"),
            IDR_MAINFRAME
            )
        );
    VERIFY(
        CExtCustomizeSite::MenuInfoLoadAccelTable(
            _T("Document"),
            IDR_SmartColorTYPE
            )
        );
    CExtCustomizeSite::MenuInfoGetByName( _T("Document") )
        -> GetNode( true )
            -> SearchNodeElement( _T("&Window"), 1 )
                -> ModifyFlags( __ECTN_TBB_APPEND_MDI_MENU );
    
    if( !CExtCustomizeSite::EnableCustomization( this ) )
    {
        ASSERT( FALSE );
        return -1;
    }

As you can see in the menu named _T("Document") I modified the style of the element named _T("&Window"), this way I think that when I click onto the menu "Window" automatically it should be updated depending on the opened documents. Also if the language would be italian
I suppose that the SearchNodeElement( _T("&Window"), 1 ) method should become SearchNodeElement( _T("&Finestre"), 1 ), that is with the right name of the voice properly translated, is it ?



Technical Support Jan 21, 2007 - 3:34 AM

Yes, that’s correct. You should use different menu item names for both languages or, alternatively you should use menu item indixes.

Roberto Manes Jan 22, 2007 - 1:42 AM

Apparently I did follow correctly the example available by the Drawcli application, but I still can’t see my "Window" menu updated. Would it be necessary to have a look of my application or you can suggest to check something else ?

Technical Support Jan 22, 2007 - 12:19 PM

Did you remove the application state data from the system registry or did you try to reset the menu bar in the Customize dialog? Of course you can send us a project that shows what’s wrong so we can find out what’s wrong.

Roberto Manes Jan 26, 2007 - 7:36 AM

I prepared the project for you. It’s a very simple MDI project which is very similar to your MDI sample application. The funny thing is that now with this simplyfied project when I ckick onto the New Document button I get the document opened but the menu is not updated. I checked in my ChildFrame class and it seems to be ok. Please have a look to my project to understand what I’m missing. Note: I sent the project to your email support@prof-uis.com. Thanks

Technical Support Jan 27, 2007 - 11:15 AM

To fix the problem with menu, please update the source code for the following method in your project:

void CSmartColorApp::OnFileNew()
{
    CWinApp::OnFileNew();
}


Roberto Manes Jan 29, 2007 - 1:33 AM

I know that if I do not ovverride the OnFileNew() method it works, but I do not understand yet why your MDI application sample provided with your Prof-UIS code is working and my application it doesn’t, that is your MDI application updates the menu depending on the document created (by overriding the OnFileNew() method and using the CreateNewChild() method) and also the "window" menu is updated with the names of new documents. Did you have a look of my source code (CWinApp derived class and CMDIChildFrm derived class) ?

Technical Support Jan 29, 2007 - 11:59 AM

The OnFileNew() method’s code should be different for two types of MDI projects: when the MFC document/view architecture is used and when it not. In the first case, a document, a child frame and a view object should be created using a registered document template object and all three objects should be connected with each other. The previous version of the OnFileNew() method in your project will work if the document/view architecture is not used (it simply creates the MDI child frame window and its child view window).

Roberto Manes Jan 30, 2007 - 2:27 AM

Yes I did note the difference between my application and the MDI application sample but anyway my "Window" menu is not updated yet with the list of opened or created documents...