Re: Context Menu in List Control
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 05 Dec 2006 12:26:30 -0500
See below...
On 4 Dec 2006 22:07:11 -0800, "nandan.mehra@xxxxxxxxx" <nandan.mehra@xxxxxxxxx> wrote:
Hi all,****
I want to create a context menu called by a right mouse click on a
multi-selection List Control in a report mode. So far I've managed to
create the menu by handling NM_RCLICK, like this:
void GetTLETab::OnNMRclickList(NMHDR *pNMHDR, LRESULT *pResult)
{
CMenu menu;
CPoint pt;
::GetCursorPos( &pt);
menu.CreatePopupMenu();
menu.AppendMenu( MF_STRING, 0, _T("Delete this item"));
menu.AppendMenu( MF_STRING, 1, _T("View details"));
This is a Really Bad Idea. You should not put any English-language strings in your source
code. One option is to put those strings in the STRINGTABLE and load them, but a better
idea is to create a menu that has the elements you want already in it.
CMenu menu;
menu.LoadMenu(IDM_LISTCTRL_POPUP);
CMenu * popup = menu.GetSubmenu(0);
****
****
menu.TrackPopupMenu( TPM_LEFTALIGN, pt.x, pt.y, this);
If you use the above technique, this would be
popup->TrackPopupMenu(...);
****
*pResult = 0;****
}
This displays the context menu correctly. Now I need to
1) find which item was clicked and
2) associate actions with the menu items.
Part of the problem is the fact that you are doing all this the hard way. You gave your
menu IDs 0 and 1, both of which are extremely bad choices. Had you created the menu in
the menu editor and used the LoadMenu/GetSubmenu, you would have some nice symbols already
assigned for the menu items, and it would be obvious.
Just use the ClassWizard from the menu editor to "add handler" for the popup menu items.
See: no real work required!
But if you insist on doing this "by hand", the hardest possible way, then you have to
choose IDs that will never conflict with any menu IDs you might ever use (difficult to do
manually) and you will have to manually add, to the message map,
ON_COMMAND(IDM_DELETE_THIS_ITEM, OnDeleteThisItem)
ON_COMMAND(IDM_VIEW_DETAILS, OnViewDetails)
You will have to manually add the handlers to your source code and put their prototypes in
your header file yourself.
Why go through all this work which produces a clumsy, ethnocentric mechanism, when you can
use the tooling to create the menu and its handlers?
joe
*****
Joseph M. Newcomer [MVP]
Unfortunately, I have no idea how and where to do that.
I would appreciate any hints.
nandan
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- Context Menu in List Control
- From: nandan.mehra@xxxxxxxxx
- Context Menu in List Control
- Prev by Date: Re: Function calling when dialog exit
- Next by Date: Re: End of OnSize event
- Previous by thread: Re: Context Menu in List Control
- Next by thread: End of OnSize event
- Index(es):
Relevant Pages
|