Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > General Discussion
  New Posts New Posts RSS Feed - User info. on menu items? Help!!
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

User info. on menu items? Help!!

 Post Reply Post Reply
Author
Message
cjsoft View Drop Down
Newbie
Newbie


Joined: 20 January 2004
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote cjsoft Quote  Post ReplyReply Direct Link To This Post Topic: User info. on menu items? Help!!
    Posted: 20 January 2004 at 8:47am

I have an application that generates at runtime a rather large popup menu (on right click). The user action to perform (when selected) on every item is the same, just the information associated with each item is different. So rather than define a command id for every item (there are potentially thousands), I want to use the same command id for each item, but just set user info. to each menu item.

This I have achieved (I think) by using 'SetMenuItemInfo', but I can't find out how to retrieve this information once a menu item has been selected by the user - obviusly when the routed command hits my window, the menu has already been destroyed, and I'm not sure how to retrieve it anyway. The windows message 'WM_MENUCOMMAND' seems to indicate it might do what I want, but I can't work out how to integrate this into the my class.

This is driving me nuts!!! Any ideas anyone?

Thanks,

Colin



Edited by cjsoft
Back to Top
vladsch View Drop Down
Newbie
Newbie


Joined: 04 February 2004
Location: Canada
Status: Offline
Points: 30
Post Options Post Options   Thanks (0) Thanks(0)   Quote vladsch Quote  Post ReplyReply Direct Link To This Post Posted: 04 February 2004 at 9:46pm

This is from MSDN:

The WM_MENUCOMMAND message is sent only for menus that are defined with the MNS_NOTIFYBYPOS flag set in the dwStyle member of the MENUINFO structure.

If you have that covered then add the following to your message map for the window:

    ON_MESSAGE(WM_MENUCOMMAND, OnMenuCommand)

define in your window class header for the window:

    afx_msg long OnMenuCommand(WPARAM wParam, LPARAM lParam);

And add the function (assuming CMainFrame is your window class name):

afx_msg long CMainFrame::OnMenuCommand(WPARAM wParam, LPARAM lParam)
{
   HMENU hMenu = (HMENU)lParam;
   CMenu menu;
   MENUITEMINFO miInfo;

   menu.Attach(hMenu);
   menu.GetMenuItemInfo(wParam, &miInfo, TRUE);

   // use the miInfo to extract the info you want and store relevant data  in a member variable

   // of your class,  retrieve that variable value when trackpopupmenu call returns so you'll

   // know which item was selected

   . . .

   menu.Detach();

   return 0L;
}

I did not test this code because in my app I don't have any bypos menu items.

 

Back to Top
SuperMario View Drop Down
Admin Group
Admin Group
Avatar

Joined: 14 February 2004
Status: Offline
Points: 18057
Post Options Post Options   Thanks (0) Thanks(0)   Quote SuperMario Quote  Post ReplyReply Direct Link To This Post Posted: 20 October 2004 at 11:04am
Maybe you could look at the DynamicPopus sample.  This might illustrate the functionality you are looking for.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.172 seconds.