Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How can I check a context menu item in a dialog application? (newbie)

45 views
Skip to first unread message

George Sgouros

unread,
Apr 26, 1999, 3:00:00 AM4/26/99
to
Environment: VC6 SP2 , Win 95

Greetings

My aim is to show a context menu in a dialog app and check/uncheck its only
menu item.

To achieve that , I did the following:

1. Created a dialog app using appwizard
2. Added a handler for the WM_RBUTTONUP message in my dialog class which
shows a context menu:
(something like the following)

void CMyDlg::OnRButtonUp(UINT nFlags, CPoint point)
{

// Create the context menu
CMenu MyContextMenu;

// Load the menu
MyContextMenu.LoadMenu(IDR_MY_MENU);

// Show the menu
ClientToScreen(&point);
MyContextMenu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN| TPM_RIGHTBUTTON
,point.x,point.y,this);

}

As I said earlier, my menu only has an item which I want to check or
uncheck.

So I added an UPDATE_COMMAND_UI handler for my menu item like this:


void CMyDlg::OnUpdate MyMenuMyItem(CCmdUI* pCmdUI)
{

pCmdUI->SetCheck();

}

What's the problem?
Nothing happens!
When I step inside SetCheck() in debug mode, I see this function:

void CTestCmdUI::SetCheck(int)
{
// do nothing -- just want to know about calls to Enable
!!!!!!!!!!! )
}

This situation is quite frustrating.What am I doing wrong?
I would be gratefull to anyone who could provide me with an answer and
(hopefully) a solution.

Thanks in advance

George Sgouros


Gautam N. Lad

unread,
Apr 26, 1999, 3:00:00 AM4/26/99
to

Hi,
I think the problem is the menu object, MyContextMenu. You are loading a
new menu all the time, so the one you check gets destroyed, when the
MyContextMenu objects gets destroyed.
Try this instead. Create a CMenu member in the class. THen, somewhere in the
dialog's init. fuctnion (or the constructor) load the menu .

Hope this helps!
Bye!


- Gautam N. Lad / Vimal N. Lad
http://www.geocities.com/SiliconValley/Heights/1107

Mike F.

unread,
Apr 26, 1999, 3:00:00 AM4/26/99
to
On Mon, 26 Apr 1999 15:44:29 GMT, vn...@myna.com (Gautam N. Lad)
wrote:

Dialogs have a different command-routing scheme. OnUpdateXxxx doesn't
get called.


Read MS Knowledge Base article:
Article ID: Q139469

This will give the skinny on command routing for dialogs, popups, and
popups in dialogs

Mike

yannick sustrac

unread,
Apr 28, 1999, 3:00:00 AM4/28/99
to
Try this example which works for me:
for check & enable/disable
Y.

----------------------------------------------------------------
CMenu menu;
VERIFY(menu.LoadMenu(CG_IDR_POPUP_HEX_EDIT));

CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);

pPopup->EnableMenuItem(ID_EDIT_UNDO, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
pPopup->CheckMenuItem(ID_POPUP_AUTOMATICREFRESH, m_bAutomaticRefresh?
MF_CHECKED : MF_UNCHECKED );
if(!IsSelected())
{
pPopup->EnableMenuItem(ID_POPUP_SHOWGRAPH,
MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
pPopup->EnableMenuItem(ID_EDIT_CLEAR,
MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
pPopup->EnableMenuItem(ID_EDIT_CUT, MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
pPopup->EnableMenuItem(ID_EDIT_COPY,
MF_GRAYED|MF_DISABLED|MF_BYCOMMAND);
}
----------------------------------------------------------------


0 new messages