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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

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
Gus012498Commented:
Tnx
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Internet Marketing

From novice to tech pro — start learning today.