?
Solved

How can I update right-click context menus? (pCmdUI)

Posted on 2000-02-13
7
Medium Priority
?
442 Views
Last Modified: 2013-11-20
I have some context menus that popup when the user right clicks on various things. I would like to update this menu (set check marks,
 etc) before it pops up, but I can't seem to get it to work. Does anyone know how to do this?
0
Comment
Question by:Bill Nolan
  • 3
  • 3
7 Comments
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2516309
Hi,

I suppose, there r 3 menu items as
ID_ONE  = one
ID_TWO = Two
ID_SIX   = Six

Then popup the context menu as U do normally using TrackPopupMenu(...)
Have a variable say m_Checkit for that class and use it as
m_Checkit = 0 => check first menu option ID_ONE
m_Checkit = 1 => check second menu option ID_TWO
m_Checkit = 2 => check third menu option ID_SIX
U can set those values as U already know which one set and when to set.

Then map the UPDATE_COMMAND_UI functions for all menu items and do as
...::OnUpdateOne(CCmdUI* pCmdUI)
{
if(m_Checkit == 0)
pCmdUI->SetCheck(TRUE);
else
pCmdUI->SetCheck(FALSE);
}

llly for second
...::OnUpdateOne(CCmdUI* pCmdUI)
{
if(m_Checkit == 1)
pCmdUI->SetCheck(TRUE);
else
pCmdUI->SetCheck(FALSE);
}

llly for third.

Thats it. Hope this helps.
VinExpert
0
 
LVL 7

Author Comment

by:Bill Nolan
ID: 2517297
I'm not sure if I get you on this one.  Are you saying to do this stuff in OnUpdate function?  Because this is my problem- for right click context menus this function is not getting called.  I don't know why.
0
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2517573
HI,

It may be becuase of the IDs. The ID values which r there in Ur pop up menu should be mapped. Then it will work.

R U doing GetSubMenu(0); of some menu or u r creating it?. Post the related code so that I can help U.

VinExpert
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 7

Author Comment

by:Bill Nolan
ID: 2517678
Here is the code.  Note that the function OnCommwObserve() DOES get called, and OnUpdateCommwObserve() DOES NOT get called. There is NO difference in my implementation of these two, only the fact that the UI message is never processed.

In .h file:

afx_msg void OnUpdateCommwObserve(CCmdUI* pCmdUI);
afx_msg void OnCommwObserve();
      In cpp file:

ON_UPDATE_COMMAND_UI(ID_COMMW_OBSERVE, OnUpdateCommwObserve)
ON_COMMAND(ID_COMMW_OBSERVE, OnCommwObserve)

And in the OnRButtonDown() handler:

CMenu aMenu;
aMenu.LoadMenu(IDR_COMMW_CONTEXT_MENU);
ClientToScreen(&point);                  
// Display popup at cursor position
aMenu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,      point.x, point.y, this);


And then I have the functions for each message.
0
 
LVL 3

Accepted Solution

by:
V_Bapat earned 150 total points
ID: 2517778
You can check/uncheck the menu items before you call TrackPopupMenu(...).
Suppose the ID of the menu items are ID_ITEM_ONE, ID_ITEM_TWO and ID_ITEM_THREE, you can check/uncheck these items like this:

aMenu.CheckMenuItem(ID_ITEM_ONE, MF_CHECKED);
aMenu.CheckMenuItem(ID_ITEM_TWO, MF_UNCHECKED);
aMenu.CheckMenuItem(ID_ITEM_THREE, MF_CHECKED);

aMenu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this);

This will check item 1 & 3 and uncheck menu item 2.
That's all to it.

You can also enable/disable the items here. Look in MSDN for CMenu.

Vicky
0
 
LVL 8

Expert Comment

by:Vinayak Kumbar
ID: 2517838
Hi,

Instead of RBUTTONDOWN message handler u r suposed to use the WM_CONTEXT menu as
void CContextvanishView::OnContextMenu(CWnd* pWnd, CPoint point)
{

      CMenu menu;
      menu.LoadMenu(IDR_MAINFRAME);
      m_pPopUp = menu.GetSubMenu(0);

      m_pPopUp->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON,
                point.x, point.y,
                  AfxGetMainWnd());

      
}

Try it. I will try and send u the sample for it.
VinExpert
0
 
LVL 7

Author Comment

by:Bill Nolan
ID: 2518062
Thank you for your help VinExpert, and I learned a couple things.  However, I have to give the points to V Bapat because he (sort of) answered my immediate question (i.e. how to modify the menus).  The OnContextMenu function was useful to know, but it did not help me to change the menus.
Anyway, I needed to change the text in these menus, and it seems I can do so through CMenu.ModifyMenu(), just so you guys know.

I am still unsure why the standard ON_UPDATE_COMMAND_UI messages do not work for context menus.  If anyone knows, I would be happy to hear it.

Thanks again.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The video provides a quick and easy steps to migrate MBOX file to well known Outlook PST and Office 365. Besides this, it also supports and migrates more than 20 email clients of MBOX which include AppleMail, Opera, Thunderbird and SeaMonkey effortl…

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question