Skip to main content
GameDev.net gamedev.net
🔒 Locked

MFC & Menu

Started by Kosov Apr 20, 2002 at 3:47 AM 5 replies 500+ views
Original Post
Kosov
Kosov
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
xtrmntr
xtrmntr
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!
Kosov
Kosov
Okay thx !! i''ll try it tonight (i''m at work now )

Good night
Kosov
Kosov
Okay i try it but TrackPopupMenu return always 65535 even if i click on differents items.

Do you know why ?
Kosov
Kosov
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));
Endurion
Endurion
TPM_RETURNCMD is the magic flag,
that gives you the id of the chosen menu item.
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>
Kosov
Kosov
Yes i know, I put it, look the code in the fprintf ...
The first call of TrackPopupMenu is in commentary ...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.