Events for a CommanbarCombobox

A

Ashok Kumar K

Hello,

I have written a COM addin to Microsoft Word 2000 using VC++. In the
OnConnection method of the _IDTExtensibility2 interface, I am creating a
toolbar in which I have some CommandBarButton and a CommandBarComboBox. I am
advising for events sink using the _CommandBarButtonEvents and the
_CommandBarComboBoxEvents interfaces.

When launch word, the toolbar gets created and everything works. I am able
to get the events for the button as well as the combobox change event. When
I open another word document (i.e. a second word document), the toolbar is
displayed in this window, the events for the button click comes, but not the
combo box change event. When I go back to the first document while the
second document is open, everything still works normal, I get both the
events. I noticed this all the subsequent windows as well. Only in the first
document window, the combo box change event comes and the rest of the window
the change event does not fire at all. Whereas the button event comes in all
the windows.

I have tried the same in VB as well. The result is the same. Why does word
behave like this and how do I get the Change event in all the
windows/documents?

Following the sample code that I have written in VB to simulate the problem.
------------------------------------------
'TestAddin.cls
Option Explicit
Private oApp As Word.Application
Private oTBHandler As ToolbarHandler

Implements IDTExtensibility2

Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)

End Sub

Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)

End Sub

Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object,
ByVal ConnectMode As AddInDesignerObjects.ext_ConnectMode, ByVal AddInInst
As Object, custom() As Variant)
Set oApp = Application
Set oTBHandler = New ToolbarHandler
oTBHandler.CreateToolbar oApp
End Sub

Private Sub IDTExtensibility2_OnDisconnection(ByVal RemoveMode As
AddInDesignerObjects.ext_DisconnectMode, custom() As Variant)
oTBHandler.DeleteToolbar
End Sub

Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)

End Sub
-----------------------------------------------------------------
'ToolbarHandler.cls
Option Explicit
Private oApp As Word.Application
Private WithEvents oCmd As Office.CommandBarButton
Private WithEvents ocmb As Office.CommandBarComboBox

Public Sub CreateToolbar(App As Word.Application)
Dim oTB As Office.CommandBar

Set oApp = App
Set oTB = App.CommandBars.Add("Test Addin")
oTB.Visible = True
Set oCmd = oTB.Controls.Add(msoControlButton)
oCmd.Caption = "click me"
oCmd.Tag = "Test_button"
oCmd.Style = msoButtonCaption
Set ocmb = oTB.Controls.Add(msoControlComboBox)
ocmb.Tag = "Test_Combo"
ocmb.AddItem "one"
ocmb.AddItem "two"
ocmb.AddItem "three"

End Sub

Private Sub ocmb_Change(ByVal Ctrl As Office.CommandBarComboBox)
Dim c As CommandBarComboBox
Set c = Ctrl
MsgBox c.Text
End Sub

Private Sub oCmd_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault
As Boolean)
MsgBox "clicked"
End Sub

Public Sub DeleteToolbar()
oApp.CommandBars("Test Addin").Delete
End Sub
 
E

Eugene E. Starostin

Ashok,

There is a problem. Sometime Word releases control connection points.
We have reconnected them on several Word events such as Window.Activate.

Eugene Starostin
 
A

Ashok Kumar K

Hi Peter,

Thanks for your reply. I do use the Tag property in all my controls. I had
noticed this problem with the buttons. After adding the Tag property, I able
to get the button click event in all the windows, but not the Combo box
change event.

Ashok Kumar K
 
P

Peter Huang

Hi Ashok,

Now I am researching the issue and I will update your with new information
ASAP.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang

Hi

Based on my research, for combobox we have t o resink(advise) the handlers
in the DocumentChange event.
You may have a try.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang

Hi,

If you have any more concerns on it, please feel free to post here.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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