Manipulating Pop-Up Menus

If I define a certain menu or submenu as pop-up, it automatically loses its ID number/name. Thus, I cannot manipulate it from within the program (show/hide and enable/disable). How do I get over this obstacle?
LVL 1
LeschaAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Gus012498Connect With a Mentor Commented:
Tnx
0
 
Gus012498Commented:
You can create your popupmenu dynamicly.

CMenu m_menu;
m_menu.CreatePopupMenu();
m_menu.AppendMenu(flags,id,text);
..
m_menu.AppendMenu(MF_SEPARATOR);
..
m_menu.TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,this);


Regards,

Gus

0
 
LeschaAuthor Commented:
Gus,

this is not what I asked.

I asked how can I enable/disable an item in the menu that has been declared as "pop-up". The function EnableMenuItem (or something like it) requires an ID which pop-up menus do not have.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
pfauxCommented:
if you are using Dev Studio, you can use class wizard to create an update handler (or if you know how to do this by hand go ahead) for the menu item,  and use the

Myhandler(CCmdUI *pCmdUI)
{
   if (whatever)
      pCmdUI->Enable(FALSE);
   else
      pCmdUI->Enable(TRUE);
}

hope this helps
0
 
Gus012498Commented:
The EnableMenuItem function needs the ID of your menu item or the position.
You have to specify the MF_BYPOSITION flag in your call.
0
 
pfauxCommented:
it should still have an ID by the way...
0
 
pfauxCommented:
now if you are trying to enable or disable the POPUP Menu itself, you need to do something like this in OnContextMenu(CWnd*,CPoint point)
{
   if (we want the menu)
       menu.LoadMenu(CG_IDR_POPUP)
   else
       don't load
}

that's the basic idea of what we are doing, we move different popups in and out depending on where we are at in the program...
0
 
LeschaAuthor Commented:
Using MF_BYPOSITION works, but only for the top-level menus. How do I get around to the submenus?

I use the command

CMenu *mnu=GetMenu() to get the top-level menu of my dialog, but how do I get lower?
0
 
Gus012498Commented:
Use
CMenu* mnu->GetSubMenu( int nPos )
0
 
LeschaAuthor Commented:
Using MF_BYPOSITION works, but only for the top-level menus. How do I get around to the submenus?

I use the command

CMenu *mnu=GetMenu() to get the top-level menu of my dialog, but how do I get lower?
0
 
LeschaAuthor Commented:
Almost done!

One more sub-question left:

when I use EnableMenuItem to manipulate the top-level menus, they do not change the color ("enabled" to "grayed") until I click the mouse button on them. I tried to put UpdateWindow() immediately after but it doesn't help.
0
 
Gus012498Commented:
void UpdateWindow( );

Remarks

Updates the client area by sending aWM_PAINT message if the update region is not empty. The UpdateWindow member function sends a WM_PAINT message directly, bypassing the application queue. If the update region is empty, WM_PAINT is not sent.

Look at CWnd::RedrawWindow.
Could you please reject pfaux's answer so that i can post you an answer next time?
0
 
Gus012498Commented:
Sorry, but here is the correct answer from Microsoft:

To redraw the menu bar after a menu bar has been modified, use the DrawMenuBar function. Otherwise, the modifications will not appear until the system redraws the owner window.

0
 
pfauxCommented:
yeah reject my answer.
0
 
LeschaAuthor Commented:
Thanks, two both of you!

Gus - please lock the answer.
0
 
Gus012498Commented:
Tnx
0
 
LeschaAuthor Commented:
Thanks, two both of you!

Gus - please lock the answer.
0
All Courses

From novice to tech pro — start learning today.