?
Solved

Creating Popup on the fly but item is always disabled.

Posted on 2004-08-13
2
Medium Priority
?
483 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 375 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

801 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