-
September 15th, 2014, 02:51 PM
#16
Re: How to Enable/Disable Menu Item 2 in OnUpdate Handler of Menu Item 1?
Originally Posted by VictorN
Please, explain more clear what you need!
Originally Posted by sunnysky
I have two menu items. When item 1 is updated, I want item 2 to be enabled/disabled. In the OnUpdate handler of menu item 1, I have tried to use "t_pMenu = pCmdUI->m_pMenu;", "t_pMenu = pCmdUI->m_pSubMenu;" and "t_pMenu = pCmdUI->m_pParentMenu;" but I always get NULL t_pMenu. How can I achieve this purpose?
Code:
void CDummyView::OnUpdateMenuItem1(CCmdUI* pCmdUI)
{
if(m_bShowMenuItem1)
{
pCmdUI->SetText("Hide Features")
CMenu * t_pMenu = pCmdUI->m_pSubMenu;
if(t_pMenu != NULL)
t_pMenu->EnableMenuItem(ID_MENU_ITEM2, MF_ENABLED);
}
else
{
pCmdUI->SetText("Show Features")
CMenu * t_pMenu = pCmdUI->m_pParentMenu;
if(t_pMenu != NULL)
t_pMenu->EnableMenuItem(ID_MENU_ITEM2, MF_GRAYED);
}
}
void CDummyView::OnUpdateMenuItem2(CCmdUI* pCmdUI)
{
...
}
I asked you for more clear explanation of your problem, not just copy/paste of your OP!
How could we help you if you didn't explain your problem?
Victor Nijegorodov
-
September 15th, 2014, 03:04 PM
#17
Re: How to Enable/Disable Menu Item 2 in OnUpdate Handler of Menu Item 1?
Hi GCDEF,
I don't get method 1 using same handler. Menu item 1 is clicked, so OnUpdateMenu1() is called. But when I click menu item 2, I don't want OnUpdateMenu1() to be called. I don't understand the purpose here.
Now method 2 using state variable. I updated the state variable m_bShowFeatures in the OnMenuItem1, but OnUpdateMenuItem2 still doesn't get called.
Basically, what we want is that when Menu 1 is set to be "Show Features", Menu 2 is completely disabled. When Menu 1 is set to be "Hide Features", Menu 2 can be set to be "Show..." or "Hide..." itself.
Below is more code. I hope this provides more context. Thanks a lot.
Code:
void CDummyView::OnMenuItem1()
{
m_bShowFeatures = !m_bShowFeatures;
m_pDoc->UpdateAllViews(NULL, SHOW_HIDE_ALL_FEATURES);
}
void CDummyView::OnUpdateMenuItem1(CCmdUI* pCmdUI)
{
if(m_bShowFeatures)
{
pCmdUI->SetText("Hide Features")
CMenu * t_pMenu = pCmdUI->m_pSubMenu;
if(t_pMenu != NULL)
t_pMenu->EnableMenuItem(ID_MENU_ITEM2, MF_ENABLED);
}
else
{
pCmdUI->SetText("Show Features")
CMenu * t_pMenu = pCmdUI->m_pParentMenu;
if(t_pMenu != NULL)
t_pMenu->EnableMenuItem(ID_MENU_ITEM2, MF_GRAYED);
}
}
void CDummyView::OnMenuItem2()
{
m_bShowSmallFetures= !m_bShowSmallFetures;
m_pDoc->UpdateAllViews(NULL, SHOW_HIDE_SMALL_FEATURES);
}
void CDummyView::OnUpdateMenuItem2(CCmdUI* pCmdUI)
{
if(m_bShowSmallFetures)
pCmdUI->SetText("Hide Small Features")
else
pCmdUI->SetText("Show Small Features")
}
-
September 15th, 2014, 03:04 PM
#18
Re: How to Enable/Disable Menu Item 2 in OnUpdate Handler of Menu Item 1?
-
September 15th, 2014, 03:06 PM
#19
Re: How to Enable/Disable Menu Item 2 in OnUpdate Handler of Menu Item 1?
It's not a copy/paste. I made it clearer in the next post.
-
September 15th, 2014, 03:17 PM
#20
Re: How to Enable/Disable Menu Item 2 in OnUpdate Handler of Menu Item 1?
Originally Posted by sunnysky
Hi GCDEF,
I don't get method 1 using same handler. Menu item 1 is clicked, so OnUpdateMenu1() is called. But when I click menu item 2, I don't want OnUpdateMenu1() to be called. I don't understand the purpose here.
Now method 2 using state variable. I updated the state variable m_bShowFeatures in the OnMenuItem1, but OnUpdateMenuItem2 still doesn't get called.
Basically, what we want is that when Menu 1 is set to be "Show Features", Menu 2 is completely disabled. When Menu 1 is set to be "Hide Features", Menu 2 can be set to be "Show..." or "Hide..." itself.
Below is more code. I hope this provides more context. Thanks a lot.
Code:
void CDummyView::OnMenuItem1()
{
m_bShowFeatures = !m_bShowFeatures;
m_pDoc->UpdateAllViews(NULL, SHOW_HIDE_ALL_FEATURES);
}
void CDummyView::OnUpdateMenuItem1(CCmdUI* pCmdUI)
{
if(m_bShowFeatures)
{
pCmdUI->SetText("Hide Features")
}
else
{
pCmdUI->SetText("Show Features")
}
}
void CDummyView::OnUpdateMenuItem2()
{
m_bShowSmallFetures= !m_bShowSmallFetures;
m_pDoc->UpdateAllViews(NULL, SHOW_HIDE_SMALL_FEATURES);
}
void CDummyView::OnUpdateMenuItem2(CCmdUI* pCmdUI)
{
if(m_bShowSmallFetures)
pCmdUI->SetText("Hide Small Features")
else
pCmdUI->SetText("Show Small Features")
}
Wouldn't this do what you want?
Code:
void CDummyView::OnMenuItem1()
{
m_bShowFeatures = !m_bShowFeatures;
m_pDoc->UpdateAllViews(NULL, SHOW_HIDE_ALL_FEATURES);
}
void CDummyView::OnUpdateMenuItem1(CCmdUI* pCmdUI)
{
if(m_bShowFeatures)
{
pCmdUI->SetText("Hide Features")
}
else
{
pCmdUI->SetText("Show Features")
}
}
void CDummyView::OnUpdateMenuItem2(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_bShowSmallFetures)
}
-
September 15th, 2014, 03:36 PM
#21
Re: How to Enable/Disable Menu Item 2 in OnUpdate Handler of Menu Item 1?
Originally Posted by GCDEF
Wouldn't this do what you want?
Code:
void CDummyView::OnMenuItem1()
{
m_bShowFeatures = !m_bShowFeatures;
m_pDoc->UpdateAllViews(NULL, SHOW_HIDE_ALL_FEATURES);
}
void CDummyView::OnUpdateMenuItem1(CCmdUI* pCmdUI)
{
if(m_bShowFeatures)
{
pCmdUI->SetText("Hide Features")
}
else
{
pCmdUI->SetText("Show Features")
}
}
void CDummyView::OnUpdateMenuItem2(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_bShowSmallFetures)
}
Thanks.
But this probably doesn't work. In this case, when Menu Item 2 is grayed, it cannot be enabled again.
-
September 15th, 2014, 03:38 PM
#22
Re: How to Enable/Disable Menu Item 2 in OnUpdate Handler of Menu Item 1?
Originally Posted by sunnysky
Thanks.
But this probably doesn't work. In this case, when Menu Item 2 is grayed, it cannot be enabled again.
Did you try it? When you call menu1 again, m_bShowFeatures will be set to the opposite value, and menu 2 will be enabled again. Menu item 2 is grayed out or not based on the value of m_bShowFeatures.
-
September 15th, 2014, 05:01 PM
#23
Re: How to Enable/Disable Menu Item 2 in OnUpdate Handler of Menu Item 1?
Originally Posted by sunnysky
Thanks.
But this probably doesn't work. In this case, when Menu Item 2 is grayed, it cannot be enabled again.
How about debug it?
For example, put a breakpoint on the Enable call.
Code:
void CDummyView::OnUpdateMenuItem2(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!m_bShowSmallFetures)
}
Then as a test, replace
Code:
pCmdUI->Enable(!m_bShowSmallFetures);
with
Code:
pCmdUI->Enable(TRUE);
That way, you can see whether it's a command UI issue or because m_ShowSmallFetures isn't getting set properly.
-
September 16th, 2014, 09:34 AM
#24
Re: How to Enable/Disable Menu Item 2 in OnUpdate Handler of Menu Item 1?
Sorry for the mistake in the previous post and this repost. I can't edit my posts.
I got it work. Below is the code I tried. Two flag variables m_bShowFeatures and m_bShowSmallFetures are initialized to be TRUE.
Code:
void CDummyView::OnMenuItem1()
{
m_bShowFeatures = !m_bShowFeatures;
m_pDoc->UpdateAllViews(NULL, SHOW_HIDE_ALL_FEATURES);
}
void CDummyView::OnUpdateMenuItem1(CCmdUI* pCmdUI)
{
if(m_bShowFeatures)
pCmdUI->SetText("Hide Features")
else
pCmdUI->SetText("Show Features")
}
void CDummyView::OnMenuItem2()
{
m_bShowSmallFetures= !m_bShowSmallFetures;
m_pDoc->UpdateAllViews(NULL, SHOW_HIDE_SMALL_FEATURES);
}
void CDummyView::OnUpdateMenuItem2(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bShowFetures)
if(m_bShowSmallFetures)
pCmdUI->SetText("Hide Small Features")
else
pCmdUI->SetText("Show Small Features")
}
So OnUpdateMenuItem2() does get invoked after OnMenuItem1() is called when Menu Item 1 is clicked. I didn't expect this.
-
September 16th, 2014, 10:12 AM
#25
Re: How to Enable/Disable Menu Item 2 in OnUpdate Handler of Menu Item 1?
Originally Posted by sunnysky
Sorry for the mistake in the previous post and this repost. I can't edit my posts.
I guess it is because you logged in as a Guest rather than a registered CG user.
Victor Nijegorodov
-
September 16th, 2014, 11:28 AM
#26
Re: How to Enable/Disable Menu Item 2 in OnUpdate Handler of Menu Item 1?
In "My Profile", I am shown as a member. But I don't know why I am a "Guest" when posting.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|