[RESOLVED] Trouble with MDI GetSubMenu - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20

Thread: [RESOLVED] Trouble with MDI GetSubMenu

  1. #16
    Join Date
    Jan 2011
    Posts
    15

    Re: Trouble with MDI GetSubMenu

    Quote Originally Posted by VictorN View Post
    Perhaps, because the 2nd document uses another menu?
    Since I'm getting a pointer for the main window at the beginning...
    Code:
    CMenu	*pMenu = AfxGetApp()->m_pMainWnd->GetMenu()
    I would imagine that this means I'm re-using the same menu. Either way, I don't see why I can sometimes access the submenu of a submenu... but other times I cannot.

  2. #17
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,013

    Re: Trouble with MDI GetSubMenu

    The mainframe menu is usually reloaded by change the document.
    Victor Nijegorodov

  3. #18
    Join Date
    Jan 2011
    Posts
    15

    Re: Trouble with MDI GetSubMenu

    For what it's worth... to anyone else who runs into this problem...

    This issue is when I try to access the submenus using MF_BYPOSITION. The cause of this problem is that when any MDI child window was created, I do NOT have the icon to the left of the "File" menu. However, one I open a 2nd child window and navigate between the 2... now both documents have the icon to the left of the "File" menu.

    This icon is what allows me to select things like minimize, maximize and move.

    By putting in a simple line to check to see if submenu #0 has a string value or is an icon, I know if I need to treat the "File" menu as submenu #0 or #1.

    Easy fix, hard to find.

    Code:
    int	nOffset = 0;
    CString szTemp;
    
    GetMenuString(0, szTemp, MF_BYPOSITION);
    if (szTemp.IsEmpty())
    	nOffset++;
    
    CMenu* pSubMenu = GetSubMenu(0 + nOffset); // this should ALWAYS get me to the "File" menu

  4. #19
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,013

    Re: [RESOLVED] Trouble with MDI GetSubMenu

    This way is not good.
    1. you should check whether the child window is maximized (then the first menu item is an "icon") or not.
    2. You should not hard code the menu item strings, i.e. you should not expect that the first menu would be "File", the second - "Edit" and so on. The better way - to find the menu that corresponds to "File" using some menu item IDs that are always included in that menu (like ID_FILE_OPEN, ID_FILE_CLOSE and so on). A good example is the MFC CMDIFrameWnd::GetWindowMenuPopup method.
    Victor Nijegorodov

  5. #20
    Join Date
    Jan 2011
    Posts
    15

    Re: [RESOLVED] Trouble with MDI GetSubMenu

    I do see the merit in what you are suggesting, but in my case - the menu arrangement is static. I don't need to worry about the "File" menu being 1st or 3rd. My only requirement is that I'm doing a real-time substitution of text in the menu dependent on the operator specific language. So using code that returns the location of the "File" menu as 1 doesn't really help me any more than knowing that it is in location 0 + 1 if the item in location 0 has a string length of 0.

    And in terms of sub-menus, this solution would not work if the only items in a sub-menu are also sub-menus. Granted... once you know the index location of "File", the sub-menu of sub-menu issue is irrelevant because you know have the index of that original sub-menu from doing the lookup function.

    Anyway... for my purposes, this option is more than what I need... but thank you for your suggestions.

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center