Click to See Complete Forum and Search --> : Popup Menu in a CListCtrl


Angie
May 18th, 1999, 12:26 PM
I was able to get the popupmenu on a clistctrl. Now the problems is executing the options on the popupmenu. I have a dialog box that I have attached a menu(idr_menu1) to. This is not a dialog box app. This is just an app displaying a dialog box with a menu attached with several options on it and the dialog box contains a clistctrl that when you right click on it, a popupmenu will come up and display some of the options that are in the main menu. I gave these options the same id as the ones in the main menu. If i go under an option under the main menu(idr_menu1) the appropriate actions take place. If I go under the popup menu and choose the same option(idr_menu2) which have the same id nothing happens. I just assumed if they had the same id and were mapped to the same function it would work. If this makes any sense and someone has come across this, please help.

Thanks,
Angie.

Dan O'Brien
May 18th, 1999, 12:43 PM
Angie, I believe what's happening is the comman message from the popup is being sent to the control, and the control is not sending it on to its parent. One way to do this is subclass the list control and have the new control route the command messages to the handlers in the dialog. You can do this in a number of ways, one of which is to repackage the message and send it (with SendMessage()) to the control's parent.

chhean
May 19th, 1999, 11:23 AM
Angie,

You have to map the message.
For example:
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_BN_CLICKED(ID_MENU_OPTION1, OnMenuOption1)
ON_BN_CLICKED(ID_MENU_OPTION2, OnMenuOption2)
END_MESSAGE_MAP()

where OnMenuOption1 and OnMenuOption2 are functions to be called when respectively the MENU_OPTION1 and MENU_OPTION2 is selected.

Regards

BrianOG
May 20th, 1999, 05:22 AM
Are you using TrackPopupMenu to launch the popup menu?

The CWnd pointer (or HWND) that is passed to TrackPopupMenu should be that of the window that catches the messages.

srini_raghav
May 20th, 1999, 08:53 AM
The code shd go like this for ur case.
TrackPopupMenu
This will popup the menu.
when u click any menuitem in the menu or in the popupmenu.. it will send WM_COMMAND to the parent window, I mean to ur dialog. Check this in the defwindowproc of dialog. In that wparam will be having the menuid....
Check it and let me know... It worked fine to me...
Thanks lot,
Srini