gymsam
asked on
Popup menu
I have a popup menu.This popupmenu popup when toolbar button is clicked.The listing is as follows
CMenu *pM = m_Menu.GetSubMenu(nCategor y);
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,M F_DISABLED |MF_GRAYED );
}
Iam able to get the ID of each submenu items , but iam not able to disable menuitem with ID 35551.Why?
CMenu *pM = m_Menu.GetSubMenu(nCategor
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,M
}
Iam able to get the ID of each submenu items , but iam not able to disable menuitem with ID 35551.Why?
try MF_DISABLED|MF_GRAYED|MF_B YCOMMAND
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,M F_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
MF_BYCOMMAND is "always on by default" After all, it is defined as 0x00000000
gymsam:
Check the return code:
int nRet= pM->EnableMenuItem(35551,M
If it is -1, then there is something wrong. But most likely, the automatic Command updating is reenabling it, as described by Zoppo.
-- Dan
ASKER
Dan
i checked like this
if(pM->EnableMenuItem(3555 1,MF_DISAB LED|MF_GRA YED))
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?
i checked like this
if(pM->EnableMenuItem(3555
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?
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
-- Dan
ASKER
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,M F_DISABLED |MF_GRAYED );
the EnableMenuItem returns +ve number but not disabling why?
as you know in this case
if(pM->GetMenuItemID(i) == 35551)
pM->EnableMenuItem(35551,M
the EnableMenuItem returns +ve number but not disabling why?
ASKER
35551 is the ID of this sub menu item
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
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
ASKER
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.
for gymsam,
Do you have any additional questions? Do any comments need clarification?
-- Dan
Do you have any additional questions? Do any comments need clarification?
-- Dan
ASKER
I have created an menu handler for the submenuitem and solved my problem.Thank you for participating.
>>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
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
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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