Solved

Creating Popup on the fly but item is always disabled.

Posted on 2004-08-13
2
476 Views
Last Modified: 2013-11-20
I'm creating a popup menu on the fly and the menu item is always disabled. I've done this before without a problem, but not in a MDI Window. Do I have to do something different?

Here is what I'm doing:

// Create popup menu
CMenu PopupMenu;
PopupMenu.CreatePopupMenu();
UINT uFlags = (/*put conditional here*/true) ? MF_ENABLED : MF_GRAYED;

PopupMenu.AppendMenu( uFlags, IDS_INSERT,"Insert" );
//Tried this too
//PopupMenu.AppendMenu( MF_BYCOMMAND, IDS_INSERT,"Insert" );
//PopupMenu.EnableMenuItem( IDS_INSERT, uFlags );

// Display popup menu
CMDIFrameWnd *frameWindow = (CMDIFrameWnd*)CMDIFrameWnd::FromHandle(GetForegroundWindow());
CMDIChildWnd *voWindow    = frameWindow->MDIGetActive();
CRect rectGrid;
voWindow->GetWindowRect( rectGrid );
PopupMenu.TrackPopupMenu( TPM_LEFTALIGN | TPM_LEFTBUTTON,
      rectGrid.left + pXY[0],
      rectGrid.bottom - pXY[1], voWindow);
0
Comment
Question by:tcf22
2 Comments
 
LVL 48

Expert Comment

by:AlexFM
ID: 11795465
Do you have IDS_INSERT menu handle in the CMDIFrameWnd  class? Without menu handle item is disabled (see CFrameWnd::m_bAutoMenuEnable member). You can set this member to FALSE or add ON_UPDATE_COMMAND_UI handler and enable menu item explicitly.
0
 
LVL 3

Accepted Solution

by:
jimbucci earned 125 total points
ID: 11809852
A menu item will remain disabled until you have a handler for the menu item

add:  ON_COMMAND(ID_MENUITEM, OnMenuitem)
add:  afx_msg void OnMenuItem() to the .h file
add: void CSomeFrame::OnMenuItem() to the .cpp file.  Your menu items will appear as they are handled.

Jim
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now