How do I disable a Menu ?

R

Ronnie

when there is no active document, I want to my menu I add disable,
I do it like this
define CComQIPtr < Office::_CommandBarButton> m_spCmdButton
then m_spcmdButton point to my Menu
I use method :m_spCmdButton.PutEnable(false) to disable this menu, but it
will crash visio application
why ?

is there nother way to disable my menu?

any help will be appreciated?
thanks
 
D

David Parker [Visio MVP]

Consider Application events that respond to DocumentClosed event.
If it is the last document, then remove or disable menu.
 
R

Ronnie

I just do it in the DocumentClosed event
but key problem is that a exception occurs when excuting the code
:m_spCmdButton.PutEnable(false)
why?
I can use the same code when Addding my menu, there is no exception.
why is there a exception when using the code in DocumentClosed event.
 
D

David Parker [Visio MVP]

I have found that it is unrewarding to hold a reference to a CommandBar
object becase it is prone to causing exceptions, so I always enumerate the
CommadBars to get the object that I want to get hold of.
 
R

Ronnie

thanks, I got it


David Parker said:
I have found that it is unrewarding to hold a reference to a CommandBar
object becase it is prone to causing exceptions, so I always enumerate the
CommadBars to get the object that I want to get hold of.
 
R

Ronnie

thanks, I do it just like you said
there is no exception but the menu is disappear when disable the menu
I want to make it visible but it is disable, I have put it visible , but it
can not work
is there a method to do it?

thanks,
Ronnie
 
R

Ronnie

I have done it, but there is another problem that PDF icon disappear when I
disable my menu,
why?
I do it like this:

CComQIPtr<Office::CommandBar>spCmdBar;
CComPtr < Office::CommandBarControl> spNewMenu;
hr = spCmdBars->get_Item(vToolName, &spCmdBar);
if(spCmdBar.p != NULL)
{
spNewMenu = spCmdBar->FindControlvtMissing,vtMissing,
vBtnTag,vtMissing,vtMissing);
spNewMenu->PutEnable(VARIANT_FALSE);
}

thanks,
Ronnie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top