Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling context menus

Status
Not open for further replies.

jdeejay

Programmer
Oct 5, 2001
44
US
What steps are needed to do a OnContextMenu (dialog app) and have the menu: 1) not appear unless it is over the list control and 2) change according to what is selected on the list control? Por ejemplo, in Outlook, the context menu is different when right clicking on the left, shortcuts, pane vs. when you right click in the right, message list, pane. Also, within the message list, the menu changes according to whether the item right clicked has an attachment to view or not.

I can do a simple context menu, but am not sure how you limit/change it on the fly.

TIA for any direction you can give.
 
Instead of trying to handle the context menu from your dialog, you should rather derive from CListBox (or whatever control you want to intercept rightclicks) and subclass the controls. Then override the WM_RBUTTONUP (as shown):

// in declaration for CBlahDialog
[tt]class CBlahDialog : public CDialog
{
/* ... */
public:
CMyList m_ctlList;
}[/tt]

// Somewhere in CBlahDialog::OnInitDialog...
[tt]m_ctlList.SubclassDlgItem(IDC_MYLIST,this);[/tt]

// Somewhere in CMyList::OnRButtonUp
[tt]TrackPopupMenu( /* ... */ );[/tt]
 
Thanks for the response. I see the reason to subclass the control, but I haven't been able to implement it properly. I can't seem to add the control variable in the declaration for the dialog class without error. Keep getting compile errors 2146 and 2501 about missing ';' before identifier 'xxx' and missing storage-class or type specifiers. I am following the method suggested above.

I have created a class MyList that derives from CListCtrl, but when I try to add a control variable to the dialog class, I get errors. I have added the .h file as well. Probably something silly, but I don't see it.

thanks.
 
Uuuuhhh, duh, it *was* silly. Added the .h file in the wrong place.

Thanks apatterno for your help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top