CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Jun 2010
    Posts
    72

    Unhappy On menu item again

    I am stuck at how to access the menu item

    My menu has 5 items, the first one will have 5 subitems, and I am unable to access the subitems

    CMenu* submenu=menu.GetSubMenu(0);
    ASSERT(submenu->GetSafeHMenu()); // This line throws exception

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: On menu item again

    1. What exception?
    2. Where is this code called from?
    3. If your CMenu class is a MFC one, then you should probably have posted this question in the Visual C++ Programming Forum
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2010
    Posts
    72

    Re: On menu item again

    somebody please help me


    here is the code
    Code:
    CString OnGetClick()
    {
      CMenu* submenu=menu.GetSubMenu(0);
      ASSERT(submenu);
      ASSERT(::ismenu(submenu->GetSafeHMenu()); // This line throws exception 
      CString str;
      submenu->GetMenuString(1,str,NF_BYPOSITION);
      return str;
    }

  4. #4
    Join Date
    Jun 2010
    Posts
    72

    Re: On menu item again

    Quote Originally Posted by VictorN View Post
    1. What exception?
    2. Where is this code called from?
    3. If your CMenu class is a MFC one, then you should probably have posted this question in the Visual C++ Programming Forum
    1.2.The value in submenu looks valid, something like 0x0182981 but I don't know why the second assert validate its handle to false
    3. Yes, but I posted it here I can't move it there to repeat the post

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: On menu item again

    Quote Originally Posted by Turingmachine View Post
    Code:
    CString OnGetClick()
    {
      CMenu* submenu=menu.GetSubMenu(0);
      ASSERT(submenu);
      ASSERT(::ismenu(submenu->GetSafeHMenu()); // This line throws exception 
      CString str;
      submenu->GetMenuString(1,str,NF_BYPOSITION);
      return str;
    }
    1. What is this ismenu function?
    2. Where is this code called from?
    Victor Nijegorodov

  6. #6
    Join Date
    Jun 2010
    Posts
    72

    Re: On menu item again

    1.It is IsMenu Api function
    2.that code is actually from a on-command-range message map function
    Code:
     
    void OnPickItem(UINT nItem)
    {
       CMenu* submenu=menu.GetSubMenu(0);
      ASSERT(submenu);
      ASSERT(::IsMenu(submenu->GetSafeHMenu()); // This line throws exception 
      submenu->CheckMenuRadioItem(ID_APP1, ID_APP7, nItem, MF_BYCOMMAND);
    
    }

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: On menu item again

    Quote Originally Posted by Turingmachine View Post
    1.It is IsMenu Api function
    2.that code is actually from a on-command-range message map function
    1. What command and what range?
    2. Can't you debug?
    3. You'll never get any useful help unless you provide a useful info about your problem.
    Victor Nijegorodov

  8. #8
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: On menu item again

    [ moved thread ]
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  9. #9
    Join Date
    Jun 2010
    Posts
    72

    Re: On menu item again

    I just redo an old program for fun,

    I have a dialog, that when rightclicking on it will show me a popup menu, which includes

    File
    ..Click File 1
    ..Click File 2
    ..Click File 3
    ..Click File 4
    ..Click File 5
    Exit

    Each of the |Click File i" Is defined as ID_APP1,....ID_APP5
    in the message map, there I define
    ON_COMMAND-RANGE(ID_APP1, ID_APP5, &Func)

    and there I use the above function but when I run the application, I got an assertion failure right at that line during the debugging,
    That isn't a valid menu handle while the previous line passes the ASSERT.

  10. #10
    Join Date
    Jun 2010
    Posts
    72

    Re: On menu item again

    Please help me till the end, I don't want to stop it right now, very urgent help SMS SMS SMS

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: On menu item again

    Quote Originally Posted by Turingmachine View Post
    ... when I run the application, I got an assertion failure right at that line during the debugging,
    That isn't a valid menu handle while the previous line passes the ASSERT.
    Yes, it looks like "menu handle isn't valid".

    You again ignored to supply enough info.
    What is this "menu" object? Where is it come from? How could we know it was correctly loaded/created?
    Victor Nijegorodov

  12. #12
    Join Date
    Jun 2010
    Posts
    72

    Re: On menu item again

    Exception only shows up after I pick one of those "Click File i", this means menu is valid

    If I eliminate that OnPickItem from the program, things are fine

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: On menu item again

    Quote Originally Posted by Turingmachine View Post
    Quote Originally Posted by VictorN View Post
    ... You again ignored to supply enough info.
    What is this "menu" object? Where is it come from? How could we know it was correctly loaded/created?
    Exception only shows up after I pick one of those "Click File i", this means menu is valid

    If I eliminate that OnPickItem from the program, things are fine
    So, you are still avoiding to answer my questions to make your problem clear...
    OK!
    I'll give up
    and
    Good luck.
    Victor Nijegorodov

  14. #14
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: On menu item again

    TuringMachine. I have to tell you it's frustrating for the 'regular' folks here that do most of the answering, that when they ask direct questions the original poster doesn't answer them.

    It would make it much easier for us to help you, if you answered the questions that are asked. Sometimes, the questions make not seem to be related, but the person trying to help usually asks them to help narrow down the problem.

    Also, when ask to post the code - post the code. Giving a description of what you think the code is isn't going to help us (help you). We want to see the actual code.

    At any rate, why do you need to get the submenu? You generally should be able to do what you need with OnCommandRange or OnUpdateCommandUI.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured