Print Page | Close Window

User info. on menu items? Help!!

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: General Discussion
Forum Description: Topics Related to Visual C++ MFC Development in General
URL: http://forum.codejock.com/forum_posts.asp?TID=371
Printed Date: 11 May 2024 at 6:58am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: User info. on menu items? Help!!
Posted By: cjsoft
Subject: User info. on menu items? Help!!
Date 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




Replies:
Posted By: vladsch
Date 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.

 



Posted By: SuperMario
Date Posted: 20 October 2004 at 11:04am
Maybe you could look at the DynamicPopus sample.  This might illustrate the functionality you are looking for.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net