Custom button and multiple documents

  • Thread starter Vladimir Chtchetkine
  • Start date
V

Vladimir Chtchetkine

Hi everyone!

Here is a problem. I wrote a simple ATL COM add-in to MS WORD that
adds a toolbar+button to Word's commandbars and now I want to:
1. Enable/disable it depending on a document state.
2. Handle "clicks" in appropriate "document" instance.
Here is how addin is structured:
1. In _IDTExtensibility2::OnConnection I hookup to ApplicationEvents2
receiving "DocumentOpen" and "NewDocument" events.
2. In _IDTExtensibility2::OnStartupComplete I add (if doesn't exist)
my custom toolbar+button to the app's commandbar
3. In DocOpen and NewDoc handlers I create an object that represents
that particular document (lets say MyDoc) In MyDoc initialization
routine I find my custom button (starting with
_Document::GetControlbars()) and hookup it to _CommandbarButtonEvents

So far so good. Button gets added, clicks are coming down the pipe,
button::Enable works like Japanese car's engine, but…

But that's for a single doc environment! If I have two docs opened
button::Enable within one MyDoc's environment enables or disables my
button in another doc too. Same thing with clicks. I'm receiving two
of them, one in each MyDoc instance although I pressed that button
only once and only in one document window.

Can anybody shed some light on what do I do wrong and how to do it
right?

TIA,

Vladimir

P.S. I'm new to Word add-ins so forgive me if I missed something
really obvious :)
 

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