Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC menu issues

MFC menu issues

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++debugging
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LighthouseJ
    wrote on last edited by
    #1

    I have a simple menu written out, it has 5 options on the main menu bar, and under the 4th menu, I have 3 menu items. I'm trying to check or uncheck the last item under the 4th menu option, it is identified as ID_ACTION_FIT. Here is the code I have so far to check the item: CMenu * MainMenu = GetMenu(); CMenu * ActionMenu = MainMenu->GetSubMenu(3); ActionMenu->CheckMenuItem (ID_ACTION_FIT, MF_BYCOMMAND); That code is inside the event handler for the item I'm trying to check. I have done this before once with no problems but it's not working now. When it reaches the second line quoted and attempts to get the submenu, it fails a debug assertion. I don't have the code for GetSubMenu so I don't know what is actually being tested. The MainMenu pointer is valid. I don't know what's wrong but I think I have an error that's too obvious to see. Does anyone have an idea of what is the problem?

    B B J 3 Replies Last reply
    0
    • L LighthouseJ

      I have a simple menu written out, it has 5 options on the main menu bar, and under the 4th menu, I have 3 menu items. I'm trying to check or uncheck the last item under the 4th menu option, it is identified as ID_ACTION_FIT. Here is the code I have so far to check the item: CMenu * MainMenu = GetMenu(); CMenu * ActionMenu = MainMenu->GetSubMenu(3); ActionMenu->CheckMenuItem (ID_ACTION_FIT, MF_BYCOMMAND); That code is inside the event handler for the item I'm trying to check. I have done this before once with no problems but it's not working now. When it reaches the second line quoted and attempts to get the submenu, it fails a debug assertion. I don't have the code for GetSubMenu so I don't know what is actually being tested. The MainMenu pointer is valid. I don't know what's wrong but I think I have an error that's too obvious to see. Does anyone have an idea of what is the problem?

      B Offline
      B Offline
      Bob Stanneveld
      wrote on last edited by
      #2

      Hello, What does the assertion dialog say? You do have the source code for CMenu::GetSubMenu() since it's MFC. You didn't delete the implementation files did you? Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

      L 2 Replies Last reply
      0
      • B Bob Stanneveld

        Hello, What does the assertion dialog say? You do have the source code for CMenu::GetSubMenu() since it's MFC. You didn't delete the implementation files did you? Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

        L Offline
        L Offline
        LighthouseJ
        wrote on last edited by
        #3

        All it says is:

        Debug assertion failed!
        Program: C:\...path\to\program.exe
        File: f:\vs70builds\9955\vc\MFCATL\ship\atlmfc\include\afxwin1.inl
        Line: 875

        For information on assertions...

        (Press Retry to debug the application

        [Abort] [Retry] [Ignore]

        If I press Retry, it tells me Unhandled exception at some address. If I press Break, and go to the call stack and double click the CMenu::GetSubMenu() item on top of the stack, I get a box that says "There is no source code available for the current location." and I can see the disassembly if I want. I never deleted any implementation files but if I do have the source code for that function, VS .NET cannot find it and I don't know how to tell it where it is.

        1 Reply Last reply
        0
        • B Bob Stanneveld

          Hello, What does the assertion dialog say? You do have the source code for CMenu::GetSubMenu() since it's MFC. You didn't delete the implementation files did you? Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

          L Offline
          L Offline
          LighthouseJ
          wrote on last edited by
          #4

          I added a "MainMenu->AssertValid();" after I get the main menu pointer but before I get the submenu. I get another assertion but this time I got the source code for that function. The assertion line is "ASSERT(m_hMenu == NULL || ::IsMenu(m_hNull);". m_hNull looks valid, on this particular run of the program, it is 0x0000e900 which is not NULL. I don't see how this assertion is triggered, nothing about the menu data looks suspicious.

          1 Reply Last reply
          0
          • L LighthouseJ

            I have a simple menu written out, it has 5 options on the main menu bar, and under the 4th menu, I have 3 menu items. I'm trying to check or uncheck the last item under the 4th menu option, it is identified as ID_ACTION_FIT. Here is the code I have so far to check the item: CMenu * MainMenu = GetMenu(); CMenu * ActionMenu = MainMenu->GetSubMenu(3); ActionMenu->CheckMenuItem (ID_ACTION_FIT, MF_BYCOMMAND); That code is inside the event handler for the item I'm trying to check. I have done this before once with no problems but it's not working now. When it reaches the second line quoted and attempts to get the submenu, it fails a debug assertion. I don't have the code for GetSubMenu so I don't know what is actually being tested. The MainMenu pointer is valid. I don't know what's wrong but I think I have an error that's too obvious to see. Does anyone have an idea of what is the problem?

            B Offline
            B Offline
            Bartosz Bien
            wrote on last edited by
            #5

            The assertion in CMenu::GetSubMenu is ASSERT(::IsMenu(m_hMenu));, so the main menu handle seems to be invalid. Where (in which class and function) do you call this code? Regards, BB http://spin.bartoszbien.com

            L 1 Reply Last reply
            0
            • B Bartosz Bien

              The assertion in CMenu::GetSubMenu is ASSERT(::IsMenu(m_hMenu));, so the main menu handle seems to be invalid. Where (in which class and function) do you call this code? Regards, BB http://spin.bartoszbien.com

              L Offline
              L Offline
              LighthouseJ
              wrote on last edited by
              #6

              I'm calling it in my CChildView class, in the event handler for the menu item I'm trying to toggle. When you said that, I realized that the CChildView only corresponds to the view itself, not the entire app, at least as far high as the menu exists. I changed the code to get the menu like this: CWnd * pParent = ::AfxGetMainWnd(); CMenu * MainMenu = pParent->GetMenu(); CMenu * ActionMenu = MainMenu->GetSubMenu(3); Which looks like it's picking up the right things when debugging, I won't be sure it's right until I write more code, but thanks for helping me point that out.

              1 Reply Last reply
              0
              • L LighthouseJ

                I have a simple menu written out, it has 5 options on the main menu bar, and under the 4th menu, I have 3 menu items. I'm trying to check or uncheck the last item under the 4th menu option, it is identified as ID_ACTION_FIT. Here is the code I have so far to check the item: CMenu * MainMenu = GetMenu(); CMenu * ActionMenu = MainMenu->GetSubMenu(3); ActionMenu->CheckMenuItem (ID_ACTION_FIT, MF_BYCOMMAND); That code is inside the event handler for the item I'm trying to check. I have done this before once with no problems but it's not working now. When it reaches the second line quoted and attempts to get the submenu, it fails a debug assertion. I don't have the code for GetSubMenu so I don't know what is actually being tested. The MainMenu pointer is valid. I don't know what's wrong but I think I have an error that's too obvious to see. Does anyone have an idea of what is the problem?

                J Offline
                J Offline
                Jose Lamas Rios
                wrote on last edited by
                #7

                According to CMenu's documentation, "[t]he return value is undefined if CWnd is a child window". Try changing the first line to:

                CMenu* MainMenu = AfxGetMainWnd()->GetMenu();

                [UPDATE]: After posting this I noticed you had already found the problem. Sorry. -- jlr http://jlamas.blogspot.com/[^] -- modified at 0:36 Thursday 6th October, 2005

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups