Solved

Popup menu

Posted on 2001-06-22
14
385 Views
Last Modified: 2013-11-20
I have a popup menu.This popupmenu popup when toolbar button is clicked.The listing is as follows

CMenu *pM = m_Menu.GetSubMenu(nCategory);

               for(int i =0;i < pM->GetMenuItemCount();i++)
               {
                    str.Format("index %d MenuItem ID %d",i,pM->GetMenuItemID(i));
                    AfxMessageBox(str);
                    if(pM->GetMenuItemID(i) == 35551)
                         pM->EnableMenuItem(35551,MF_DISABLED|MF_GRAYED);
               }

Iam able to get the ID of each submenu items , but iam not able to disable menuitem with ID 35551.Why?
0
Comment
Question by:gymsam
14 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 6217901
Hi gymsam,

I guess you have implemented a command message handler for that ID...

you'll have to implement also an update command UI message handler 'OnUpdateXY'
coz MFC's framework automatically enables menu items with IDs for which a handler
exists.

hope that helps,

ZOPPO
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6217984
try MF_DISABLED|MF_GRAYED|MF_BYCOMMAND
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6220295
ShaunWilde:
MF_BYCOMMAND is "always on by default"  After all, it is defined as 0x00000000

gymsam:
Check the return code:

  int nRet= pM->EnableMenuItem(35551,MF_DISABLED|MF_GRAYED);
             
If it is -1, then there is something wrong.  But most likely, the automatic Command updating is reenabling it, as described by Zoppo.

-- Dan
0
 

Author Comment

by:gymsam
ID: 6220573
Dan

i checked like this

if(pM->EnableMenuItem(35551,MF_DISABLED|MF_GRAYED))
   AfxMessageBox("Success");
else
   AfxMessageBox("Failed");

I got the message "Success".I my project non of the menu items have handlers,infact we have CMenuEx which has been derived from CMenu and it has been overiden.Do u need any thing more?
             
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6221132
The "Enabling/disabling handlers" would not be part of anything to do with the CMenu-derived object.  It would be an OnXxxxxXxxxx function, most likely in your CMainFrame or a view class.

-- Dan
0
 

Author Comment

by:gymsam
ID: 6223094
I don't have any OnXxxxx function associated for an subitem in this popupmenu.Now i have got valid pointer to the SubMenuItem how do i enable or disable an subitem in this popup menu?

as you know in this case

if(pM->GetMenuItemID(i) == 35551)
                        pM->EnableMenuItem(35551,MF_DISABLED|MF_GRAYED);
             
the EnableMenuItem returns +ve number but not disabling why?
0
 

Author Comment

by:gymsam
ID: 6223098
35551 is the ID of this sub menu item
0
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.

 
LVL 49

Expert Comment

by:DanRollins
ID: 6223483
Try using a different number, say 20000.  MFC take some liberties with high ID soe its own internal enabling.

Anyway, does 35551 not coorespond to a command ID in your program?  It would be in your Resource.h file (just open it and search for 35551).

If it does not correspond to a command, then what good will it do?  If the user selects it, nothing will happen!  So why is it in the menu if it doesn't do anything and you don't want it there, and you don't want the user to click it?  It all seems strange.

-- Dan

0
 

Author Comment

by:gymsam
ID: 6225948
My project handlers message routing with out having handlers, its very tricker iam also wondering about that.But now i have created a handler for this sub menu item and iam able to enable and disable it.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6307046
for gymsam,
Do you have any additional questions?  Do any comments need clarification?

-- Dan
0
 

Author Comment

by:gymsam
ID: 6307113
I have created an menu handler for the submenuitem and solved my problem.Thank you for participating.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 6307235
>>I have created an menu handler for the submenuitem and solved my problem.

Is there any chance that my comment -- in which I suggested that you create a menu handler for the submenu item -- helped lead you toward that solution?

Just curious.

-- Dan
0
 

Author Comment

by:gymsam
ID: 6307303
Not Exactly,but i want to find a shortcut solution faster and solve.Any how you followed my comments and participated well,so i can reward you.
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 50 total points
ID: 6352587
>>you followed my comments and participated well,so i can reward you.

Awaiting the reward.

-- Dan
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

Title # Comments Views Activity
Unix / Linux grid computing 5 149
Add content to output file 4 62
tripleUp challenge 7 74
NotAlone Challenge 20 80
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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…
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

895 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

11 Experts available now in Live!

Get 1:1 Help Now