Combobox in outlook add ons toolbar not firing event on when window is small RRS feed

  • Question

  • I have a COM based addon toolbar for Outlook. In outlook2007 when resized the outlook window such that some of the addon toolbar controls hide in chevron(drop-down menu of toolbar) and for _CommandBarComboBox when select or change text of combbox and hit enter from that drop-down menu of toolbar, It is not firing change events.However buttons are firing events correctly.I have created this combobox using Office::_CommandBarComboBox and use IDispEventSimpleImpl for adding change events.

    There is a neat problem with above scenario, when the window is smaller, and toolbar is docked so that some buttons will be accessed via a pop-up menu, these do not work, you will not be notified. How come? How to solve this.

    Please help, is there any flags or style type i am missing or any other.

    Thursday, August 23, 2012 9:34 AM

All replies

  • Hi Nikhil_30,

    Thanks for posting in the MSDN Forum.

    Based on your issue, could you please share some snippets here? It's beneficial for us to reproduce the problem and do further research.

    Best Regards,

    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    Friday, August 24, 2012 1:53 AM
  • Hi Leo_Gao,

    I have a class as following for a addin , where i have created two buttons and a combobox on toolbar.

    // Addin.h : Declaration of the CAddin
    #ifndef __ADDIN_H_
    #define __ADDIN_H_
    #include "stdafx.h"
    #include "resource.h"       // main symbols
    #import "C:\Program Files\Common Files\Designer\MSADDNDR.DLL" raw_interfaces_only, raw_native_types, no_namespace, named_guids 
    // CAddin
    extern _ATL_FUNC_INFO OnClickButtonInfo;
    extern _ATL_FUNC_INFO OnComboBoxChangeInfo;
    extern _ATL_FUNC_INFO OnOptionsAddPagesInfo;
    class ATL_NO_VTABLE CAddin : 
    	public CComObjectRootEx<CComSingleThreadModel>,
    	public CComCoClass<CAddin, &CLSID_Addin>,
    	public ISupportErrorInfo,
    	public IDispatchImpl<IAddin, &IID_IAddin, &LIBID_OUTLOOKADDINLib>,
    	public IDispatchImpl<_IDTExtensibility2, &IID__IDTExtensibility2, &LIBID_AddInDesignerObjects>,
    	public IDispEventSimpleImpl<1,CAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
    	public IDispEventSimpleImpl<2,CAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
    	public IDispEventSimpleImpl<3,CAddin,&__uuidof(Office::_CommandBarButtonEvents)>,
    	public IDispEventSimpleImpl<4,CAddin,&__uuidof(Outlook::ApplicationEvents_10)>,
    	public IDispEventSimpleImpl<5,CAddin,&__uuidof(Office::_CommandBarComboBoxEvents)>
    	typedef IDispEventSimpleImpl</*nID =*/ 1,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandButton1Events;
    	typedef IDispEventSimpleImpl</*nID =*/ 2,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandButton2Events;
    	typedef IDispEventSimpleImpl</*nID =*/ 3,CAddin, &__uuidof(Office::_CommandBarButtonEvents)> CommandMenuEvents;
    	typedef IDispEventSimpleImpl</*nID =*/ 4,CAddin, &__uuidof(Outlook::ApplicationEvents_10)> AppEvents;
    	typedef IDispEventSimpleImpl</*nID =*/ 5,CAddin, &__uuidof(Office::_CommandBarComboBoxEvents)> CommandButton3Events;
    	COM_INTERFACE_ENTRY2(IDispatch, IAddin)
    SINK_ENTRY_INFO(1, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickButton, &OnClickButtonInfo)
    SINK_ENTRY_INFO(2, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickButton2, &OnClickButtonInfo)
    SINK_ENTRY_INFO(3, __uuidof(Office::_CommandBarButtonEvents),/*dispid*/ 0x01, OnClickMenu, &OnClickButtonInfo)
    SINK_ENTRY_INFO(5, __uuidof(Office::_CommandBarComboBoxEvents),/*dispid*/ 0x01, OnClickchange, &OnComboBoxChangeInfo)
    // ISupportsErrorInfo
    	STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid);
    	void __stdcall OnClickButton(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
    	void __stdcall OnClickButton2(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
    	void __stdcall OnClickMenu(IDispatch * /*Office::_CommandBarButton**/ Ctrl,VARIANT_BOOL * CancelDefault);
    	void __stdcall OnOptionsAddPages(IDispatch* /*PropertyPages**/ Ctrl);
    	void __stdcall OnClickchange(IUnknown * pCtrl);
    // IAddin
    // _IDTExtensibility2
    	STDMETHOD(OnConnection)(IDispatch * Application, ext_ConnectMode ConnectMode, IDispatch * AddInInst, SAFEARRAY * * custom)
    		CComPtr < Office::_CommandBars> spCmdBars; 
    	CComPtr < Office::CommandBar> spCmdBar;
    	// QI() for _Application
    	CComQIPtr <Outlook::_Application> spApp(Application); 
    	// get the CommandBars interface that represents Outlook's 		//toolbars & menu 
    	m_spApp = spApp;
    	CComPtr<Outlook::_Explorer> spExplorer; 	
    	HRESULT hr = spExplorer->get_CommandBars(&spCmdBars);
    		return hr;
    	// now we add a new toolband to Outlook
    	// to which we'll add 2 buttons
    	CComVariant vName("OutlookAddin");
    	CComVariant vName1("OutlookAddin1");
    	CComPtr <Office::CommandBar> spNewCmdBar;
    	// position it below all toolbands
    	//MsoBar	CComVariant vPos(1); 
    	CComVariant vTemp(VARIANT_TRUE); // menu is temporary		
    	CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);			
    	//Add a new toolband through Add method
    	// vMenuTemp holds an unspecified parameter
    	//spNewCmdBar points to the newly created toolband
    	spNewCmdBar = spCmdBars->Add(vName, vPos, vEmpty, vTemp);
    	//now get the toolband's CommandBarControls
    	CComPtr < Office::CommandBarControls> spBarControls;
    	spBarControls = spNewCmdBar->GetControls();
    	//MsoControlType::msoControlButton = 1
    	CComVariant vToolBarType(1);
    	CComVariant vToolBarComboType(Office::msoControlComboBox);
    	//show the toolbar?
    	CComVariant vShow(VARIANT_TRUE);
    	CComPtr < Office::CommandBarControl> spNewBar; 
    	CComPtr < Office::CommandBarControl> spNewBar2; 
    	CComPtr < Office::CommandBarControl> spNewBar3; 
    	// add first button
    	spNewBar = spBarControls->Add(vToolBarType, vEmpty, vEmpty, vEmpty, vShow); 
    	// add 2nd button
    	spNewBar2 = spBarControls->Add(vToolBarType, vEmpty, vEmpty, vEmpty, vShow);
    	spNewBar3 = spBarControls->Add(vToolBarComboType, vEmpty, vEmpty, vEmpty, vShow);
    	_bstr_t bstrNewCaption(OLESTR("Item1"));
    	_bstr_t bstrTipText(OLESTR("Tooltip for Item1"));
    	// get CommandBarButton interface for each toolbar button
    	// so we can specify button styles and stuff
    	// each button displays a bitmap and caption next to it
    	CComQIPtr < Office::_CommandBarButton> spCmdButton(spNewBar);
    	CComQIPtr < Office::_CommandBarButton> spCmdButton2(spNewBar2);
    	CComQIPtr < Office::_CommandBarComboBox> spCmdButton3(spNewBar3);
    	// to set a bitmap to a button, load a 32x32 bitmap
    	// and copy it to clipboard. Call CommandBarButton's PasteFace()
    	// to copy the bitmap to the button face. to use
    	// Outlook's set of predefined bitmap, set button's FaceId to 	//the
    	// button whose bitmap you want to use
    	HBITMAP hBmp =(HBITMAP)::LoadImage(_Module.GetResourceInstance(),
    	// put bitmap into Clipboard
    	::SetClipboardData(CF_BITMAP, (HANDLE)hBmp);
    	// set style before setting bitmap
    	hr = spCmdButton->PasteFace();
    	if (FAILED(hr))
    		return hr;
    	spCmdButton->PutTooltipText(OLESTR("Tooltip for Item1")); 
    	spCmdButton->PutTag(OLESTR("Tag for Item1")); 
    	//show the toolband
    	//specify predefined bitmap
    	spCmdButton2->PutTooltipText(OLESTR("Tooltip for Item2")); 
    	spCmdButton2->PutTag(OLESTR("Tag for Item2"));
    	spCmdButton3->PutTooltipText(OLESTR("Tooltip for Item3"));	
    	spCmdButton3->PutBeginGroup(VARIANT_TRUE);  // creates a separator
    	spCmdButton3->PutTag(OLESTR("Tag for Item3"));
    	m_spButton = spCmdButton;
    	m_spButton2 = spCmdButton2;
    	m_spComboboxList = spCmdButton3;
    	_bstr_t bstrNewMenuText(OLESTR("New Menu Item"));
    	CComPtr < Office::CommandBarControls> spCmdCtrls;
    	CComPtr < Office::CommandBarControls> spCmdBarCtrls; 
    	CComPtr < Office::CommandBarPopup> spCmdPopup;
    	CComPtr < Office::CommandBarControl> spCmdCtrl;
    	// get CommandBar that is Outlook's main menu
    	hr = spCmdBars->get_ActiveMenuBar(&spCmdBar); 
    	if (FAILED(hr))
    		return hr;
    	// get menu as CommandBarControls 
    	spCmdCtrls = spCmdBar->GetControls(); 
    	// we want to add a menu entry to Outlook's 6th(Tools) menu 	//item
    	CComVariant vItem(5);
    	spCmdCtrl= spCmdCtrls->GetItem(vItem);
    	IDispatchPtr spDisp;
    	spDisp = spCmdCtrl->GetControl(); 
    	// a CommandBarPopup interface is the actual menu item
    	CComQIPtr < Office::CommandBarPopup> ppCmdPopup(spDisp);  
    	spCmdBarCtrls = ppCmdPopup->GetControls();
    	CComVariant vMenuType(1); // type of control - menu
    	CComVariant vMenuPos(6);  
    	CComVariant vMenuEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
    	CComVariant vMenuShow(VARIANT_TRUE); // menu should be visible
    	CComVariant vMenuTemp(VARIANT_TRUE); // menu is temporary		
    	//CComPtr < Office::CommandBarControl> spNewMenu;
    	// now create the actual menu item and add it
    	//spNewMenu = spCmdBarCtrls->Add(vMenuType, vMenuEmpty, vMenuEmpty, vMenuEmpty, vMenuTemp); 
    	//we'd like our new menu item to look cool and display
    	// an icon. Get menu item  as a CommandBarButton
    	//CComQIPtr < Office::_CommandBarButton> spCmdMenuButton(spNewMenu);
    	// we want to use the same toolbar bitmap for menuitem too.
    	// we grab the CommandBarButton interface so we can add
    	// a bitmap to it through PasteFace().
    	// show the menu		
    //	spNewMenu->PutVisible(VARIANT_TRUE); 
    //	m_spMenu = spCmdMenuButton;
    	hr = CommandButton1Events::DispEventAdvise((IDispatch*)m_spButton);
    		return hr;
    	hr = CommandButton2Events::DispEventAdvise((IDispatch*)m_spButton2);
    		return hr;
    	hr = CommandButton3Events::DispEventAdvise(m_spComboboxList);
    		return hr;
    	hr = CommandMenuEvents::DispEventAdvise((IDispatch*)m_spMenu);
    		return hr;
    	hr = AppEvents::DispEventAdvise((IDispatch*)m_spApp,&__uuidof(Outlook::ApplicationEvents_10));
    		ATLTRACE("Failed advising to ApplicationEvents");
    		return hr;
    	bConnected = true;
    	return S_OK;
    	STDMETHOD(OnDisconnection)(ext_DisconnectMode RemoveMode, SAFEARRAY * * custom)
    			HRESULT hr = CommandButton1Events::DispEventUnadvise((IDispatch*)m_spButton);
    				return hr;
    			hr = CommandButton2Events::DispEventUnadvise((IDispatch*)m_spButton2);
    				return hr;
    			hr = CommandButton3Events::DispEventUnadvise((IDispatch*)m_spComboboxList);
    				return hr;
    			hr = CommandMenuEvents::DispEventUnadvise((IDispatch*)m_spMenu);
    				return hr;
    			hr = AppEvents::DispEventUnadvise((IDispatch*)m_spApp);
    				return hr;
    			bConnected = false;
    		return S_OK;
    	STDMETHOD(OnAddInsUpdate)(SAFEARRAY * * custom)
    		return E_NOTIMPL;
    	STDMETHOD(OnStartupComplete)(SAFEARRAY * * custom)
    		return E_NOTIMPL;
    	STDMETHOD(OnBeginShutdown)(SAFEARRAY * * custom)
    		return E_NOTIMPL;
    		CComPtr<Office::_CommandBarButton> m_spButton; 
    		CComPtr<Office::_CommandBarButton> m_spButton2; 
    		CComPtr<Office::_CommandBarButton> m_spMenu; 
    		CComPtr<Office::_CommandBarComboBox> m_spComboboxList;
    		CComPtr<Outlook::_Application> m_spApp;
    		bool bConnected;
    #endif //__ADDIN_H_

    For the every controls i.e. buttons and combobox i have added events as following: 

    void __stdcall CAddin::OnClickButton(IDispatch* /*Office::_CommandBarButton* */ Ctrl,VARIANT_BOOL * CancelDefault)
    	CComQIPtr<Office::_CommandBarButton> pCommandBarButton(Ctrl);
    	//the button that raised the event. Do something with this...
    	MessageBox(NULL, "Clicked Button1", "OnClickButton", MB_OK);
    void __stdcall CAddin::OnClickButton2(IDispatch* /*Office::_CommandBarButton* */ Ctrl,VARIANT_BOOL * CancelDefault)
    	CComQIPtr<Office::_CommandBarButton> pCommandBarButton(Ctrl);
    	//the button that raised the event. Do something with this...
    	MessageBox(NULL, "Clicked Button2", "OnClickButton2", MB_OK);
    void __stdcall CAddin::OnClickchange(IUnknown  * pCtrl )
    	MessageBox(NULL, "Combobox change -1", "OnClickchange", MB_OK);
    	CComQIPtr<Office::_CommandBarComboBox> spCombo = pCtrl;
    	//the button that raised the event. Do something with this...
    	MessageBox(NULL, "Combobox change", "OnClickchange", MB_OK);

    All the click and change events called normally. But when outlook window is small such that ,toolbar is docked so that some buttons will be accessed via a pop-up menu. and at that time if i clicked on buttons from pop-up menu, they will called click events, but for combobox if we enter a text and hit enter change event not called.

    Thanks in advance for your help.....


    Friday, August 24, 2012 5:55 AM
  • Hi,

    I will involve some experts who are familiar with this issue, this may take some time. Much appreciate for your patience and understanding.

    Have a good day.

    Leo_Gao [MSFT]
    MSDN Community Support | Feedback to us

    Monday, August 27, 2012 1:42 AM
  • Hi Leo_Gao,

    I am still looking for your response for this issue.



    Tuesday, September 4, 2012 8:30 AM
  • Hi Nikhil,

    I apologize for the delay in getting back to you on this. Offhand I didn't see any reports of this issue before, so I'll have to do some testing to see if I can reproduce this problem. The one question that would be great to know is whether this issue is specific to Outlook or the control (in other words, does it also happen in other Office applications?). I presume you probably do not know this offhand, but if you do, please let me know.


    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Friday, September 7, 2012 7:13 PM
  • Hi Bill,

    I did not check this with any other office application. Yes this issue is specific to combo box control. Button controls are working fine when accessed via pop-up menu. 

    Please help me!!!



    Monday, September 10, 2012 11:41 AM
  • Nikhil, after looking into this further, I think I'm more confused than when I started :) Would it be possible for you to open a support incident so someone can work directly with you on this?

    Overall, I'm not clear on whether the issue you have having is directly related to the new toolbar you are creating, or the addition to the Tools menu that your code is partially doing (the actual implementation is commented out). I'm also confused about the collapsing menus you are referring to, because those are no longer in Outlook 2007, unless you are referring to the "flyout" menus.

    I set up some relatively simple Outlook VBA code to do the equivalent of what your C++ code is doing with a new toolbar, but when I resize the Outlook 2007 explorer the new toolbar is always the last on the screen as the window is made smaller, but the control events continue to work. If you are familiar with Outlook VBA, this is the code I was using in ThisOutlookSession:

    Public WithEvents spNewBar1 As Office.CommandBarButton
    Public WithEvents spNewBar2 As Office.CommandBarButton
    Public WithEvents spNewBar3 As Office.CommandBarComboBox
    Public WithEvents bars As Office.CommandBars
    Dim bar As Office.CommandBar
    Private Sub Application_Startup()
      Set bars = ActiveExplorer.CommandBars
      Set bar = bars.Add("test", msoBarTop, True)
      bar.Enabled = True
      bar.Visible = True
      Set spNewBar1 = bar.Controls.Add(msoControlButton, , , , True)
      Set spNewBar2 = bar.Controls.Add(msoControlButton, , , , True)
      Set spNewBar3 = bar.Controls.Add(msoControlDropdown, , , , True)
      spNewBar1.Visible = True
      spNewBar1.Enabled = True
      spNewBar1.Caption = "Item1"
      spNewBar1.Tag = "1"
      spNewBar1.TooltipText = "ToolTip for Item1"
      spNewBar2.Visible = True
      spNewBar2.Enabled = True
      spNewBar2.Style = msoButtonIconAndCaption
      spNewBar2.Caption = "Item2"
      spNewBar2.Tag = "2"
      spNewBar2.TooltipText = "ToolTip for Item2"
      spNewBar2.Visible = True
      spNewBar3.Enabled = True
      spNewBar3.Style = msoComboNormal
      spNewBar3.Caption = "Item3"
      spNewBar3.Tag = "3"
      spNewBar1.TooltipText = "ToolTip for Item3"
      spNewBar3.AddItem "item1"
      spNewBar3.AddItem "item2"
      spNewBar3.DropDownLines = 4
      spNewBar3.DropDownWidth = 100
      spNewBar3.ListIndex = 1
    End Sub
    Private Sub spNewBar1_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
      MsgBox "Button1 click"
    End Sub
    Private Sub spNewBar2_Click(ByVal Ctrl As Office.CommandBarButton, CancelDefault As Boolean)
      MsgBox "Button2 click"
    End Sub
    Private Sub spNewBar3_Change(ByVal Ctrl As Office.CommandBarComboBox)
      MsgBox "drop change"
    End Sub

    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Wednesday, September 12, 2012 7:01 PM

    Hi Bill,

    Here is the snapshot of the issue. May be this will help you to understand my issue.

    It is not about tools menu. It is about accessing add in toolbar from drop drown(chevron) menu.

    Waiting for your response. Thanks for your help.

    Issue imageAdd-in Toolbar image



    Tuesday, September 18, 2012 9:06 AM
  • Hi Nikhil,

    Thanks, I see the difference now. In your situation, the toobar is staying on a single line whereas for me it's automatically resizing to multiple lines when the window is made smaller. Do you happen to know how to control this behavior? I did some searching and testing, but can't seem to figure this out.

    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Tuesday, September 18, 2012 8:45 PM
  • Hi Bill,

    I had already done a lot of searching and hit & trial with styles & properties but unable to find any useful information.

    However, if add-in toolbar will automatically re-sized to multiple lines, than if a toolbar having a lot of controls for e.g 25-30, it does not look good and that is why this drop drown(chevron) menu comes in picture.

    Can u now replicate my issue or understand the scenario? Please help me on this .



    Wednesday, September 19, 2012 5:00 AM
  • Hi Bill,

    I am waiting for your response, do you get any information or clue to the issue?



    Friday, October 5, 2012 8:25 AM
  • Hi Nikhil,

    I apologize for the delay. I have been doing some more research, but haven't found out exactly what controls that toolbar behavior. I'm going to add a bunch more controls and see if that makes the behavior change.

    In the meantime, if this is a critical issue for you, I would suggest opening a support incident for this. However, my "educated guess" is that even if this is some form of a bug in Outlook and/or the CommandBars, it is unlikely it would be something that could be fixed at this point in time. So the workaround may be to change the toolbar properties in some way so that it does not collapse down to the state where the chevron appears.

    Bill Jacob - Microsoft Customer Service & Support - Developer Messaging

    Friday, October 5, 2012 7:20 PM