Solved

Creating Popup on the fly but item is always disabled.

Posted on 2004-08-13
2
477 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

948 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

21 Experts available now in Live!

Get 1:1 Help Now