How to Handle Menu event?

A

Ahmad Jalil Qarshi

hi!

I have Added a new CommandBarControl of type msoControlButton in the Menu
"Inline Picture" (which is displayed when you right click on some picture or
some OleObject in MS Word Document). I have also run some VBA macros on
click event at this new inserted menu Item by specifying them into
PutOnAction function. But now i want to call some functions of my ActiveX
control's class on click event at this new inserted menu. Is it possible if
so then please help me. i am using ATL in VC6

Thanks

Ahmad Jalil Qarshi
 
F

Fuzzier

Your class must implement IDTCommandTarget interface (typelib: Program
File\Common Files\Microsoft Shared\MSEnv\dte.olb).
Exec() and QueryStatus() will pass in 'cmdName', which is the full qualified
command name of a command -- "Addins.%progid%.%name%" (e.g.
progid:"MyAddin", name:"MyCmd", full name: "Addins.MyAddin.MyCmd").
You should check this name by comparing it with supported commands, then do
anything you like.
 
F

Fuzzier

1. If you want to handle event from a Word button, you must implement
_CommandBarButtonEvents as ICommandBarButtonEvents.
------------------------------------------------
// sample code VC++:
class ATL_NO_VTABLE CEventSink :
public CComObjectRootEx<CComSingleThreadModel>,
public IDispatchImpl<ICommandBarButtonEvents,
&__uuidof(ICommandBarButtonEvents), &LIBID_Office, /*wMajor =*/ 2, /*wMinor
=*/ 3> // 2.3 = office 11.0
{
....
BEGIN_COM_MAP(CEventSink)
COM_INTERFACE_ENTRY_IID(__uuidof(_CommandBarButtonEvents),
ICommandBarButtonEvents)
END_COM_MAP()
....
STDMETHOD_(void, Click)(_CommandBarButton *Ctrl, VARIANT_BOOL
*CancelDefault);
};

------------------------------------------------
Then advise the event sink for the button (e.g. inside
_IDTExtensibility2::OnConnection()).

2. I think the problem is a custom button in a popup menu doesn't raise
events when it's clicked (bug?). The function _CommandBarButton::Execute()
will raise the event, however.
I created a word document and added a button to the "Inline Picture" popup
menu, and I created a VBA class to handle the 'click' event of the button
which simply shows a msgbox. The instance of the class is created during
document loading. But sadly, the event was not raised when I clicked the
button. Instead, I had a macro to invoke the 'Execute' method of the button,
the event is raised. I also tried to handle events from the build-in
"Cut(&T)" buttons, and the event was raised when it was clicked.
 

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