• Advertisement

Archived

This topic is now archived and is closed to further replies.

MFC & Menu

This topic is 5751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello everyone, i''ve make a menu that appear when i right click (i call it "right clicked menu") but i don''t know how to check when a user click on an item and on which item he has click. I''m using this menu in a view and not in a dialog box. thx for your help

Share this post


Link to post
Share on other sites
Advertisement
It''s late so I''ll try to keep this brief and leave most of it up to you to research.

1. Create a Popup Menu in your resources file (you say MFC so you can use the resource editor to do this)

2. In your CView class, override the OnRButtonDown function.

3. Inside this function define a CMenu object and load it using the resource ID you gave your popup menu.

4. After its loaded call its TrackPopupMenu function passing along arguements as to how you want the menu positioned and how you want to recieve input from this menu.

5. There is a flag you can set to have the TrackPopupMenu function return the item number that the user clicked OR you can set a flag that will have your view get sent a message after the user clicks on an item.

You can use the classwizard to generate individual functions that will coorespond to each menu item or you can handle them in your views'' OnCommand function.

good luck!

Share this post


Link to post
Share on other sites
Okay thx !! i''ll try it tonight (i''m at work now )

Good night

Share this post


Link to post
Share on other sites
Okay i try it but TrackPopupMenu return always 65535 even if i click on differents items.

Do you know why ?

Share this post


Link to post
Share on other sites
I forgot to give you my code maybe it can help you :

CMenu menu;
CMenu* pPopup;
menu.LoadMenu( IDR_MENU_CONTEXTUEL );
pPopup = menu.GetSubMenu(0);
CPoint point = _point ;
ClientToScreen ( & point ) ;
pPopup->CheckMenuItem(1,MF_CHECKED|MF_BYPOSITION);
//pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, AfxGetMainWnd());
fprintf(fileErreur,"%d\n", TrackPopupMenu(GetSubMenu(menu,0), TPM_NONOTIFY | TPM_RETURNCMD | TPM_LEFTALIGN | TPM_LEFTBUTTON, point.x, point.y, 0, m_hWnd, NULL));

Share this post


Link to post
Share on other sites
Yes i know, I put it, look the code in the fprintf ...
The first call of TrackPopupMenu is in commentary ...

Share this post


Link to post
Share on other sites

  • Advertisement