Is it possible to add a custom tooltip on a CMFCToolBarComboBoxButton in a CMFCToolbar ?
I can now use the "default" tooltip text as defined in the resource file, but I cannot find the way to be able to dynamically change the tooltip text on the combobox in the toolbar.
Resources :
IDR_TOOLBAR1 TOOLBAR 16, 15
BEGIN
BUTTON ID_BUTTON32771
BUTTON ID_BUTTON32772
BUTTON ID_BUTTON32773
END
STRINGTABLE
BEGIN
ID_BUTTON32771 "Button 1\nButton 1"
ID_BUTTON32772 "Button 2\nButton 2"
ID_BUTTON32773 "Button 3\nButton 3"
END
Toolbar is created normally and is showing up nicely; I "replace" the button with a CMFCToolBarComboBoxButtoncsCombo in OnToolbarReset (handler of AFX_WM_RESETTOOLBAR )
LRESULT CMainFrame::OnToolbarReset(WPARAM wp,LPARAM)
{
UINT uiToolBarId = (UINT) wp;
if (uiToolBarId == IDR_TOOLBAR1 )
{
CMFCToolBarComboBoxButtoncsCombo(ID_BUTTON32772, GetCmdMgr()->GetCmdImage(ID_BUTTON32772, FALSE), CBS_DROPDOWNLIST);
m_MyToolbar.ReplaceButton(ID_BUTTON32772, csCombo);
m_MyToolbar.AddItem( _T("un") );
m_MyToolbar.AddItem( _T("deux") );
m_MyToolbar.AddItem( _T("trois") );
}
return 0;
}
This work fine, the button is replaced with the combobox and the default tooltip text is displayed.
Now, I want to be able to have the tooltip text changed dynamically.
I tried to handler TTN_NEEDTEXT (and TTN_NEEDTEXTA and TTN_NEEDTEXTW) in the main frame (and even in my derived toolbar class), but it is not called for the toolbars.
I tried deriving my own CMFCToolBarComboBoxButton class and override the 2 virtual methods I could find that should be doing what I expected :
class MyComboBox : public CMFCToolBarComboBoxButton
{
public:
MyComboBox ();
MyComboBox (UINT uiID, int iImage, DWORD dwStyle = CBS_DROPDOWNLIST, int iWidth = 0);
virtual BOOL OnGetCustomToolTipText(CString& );
virtual BOOL OnUpdateToolTip(CWnd* , int , CToolTipCtrl& , CString& );
virtual ~MyComboBox ();
DECLARE_SERIAL(MyComboBox )
};
and
IMPLEMENT_SERIAL(MyComboBox , CMFCToolBarComboBoxButton,0)
MyComboBox ::MyComboBox (UINT uiID, int iImage, DWORD dwStyle , int iWidth ) : CMFCToolBarComboBoxButton(uiID, iImage,dwStyle, iWidth )
{
}
MyComboBox ::MyComboBox ()
{
}
MyComboBox ::~MyComboBox ()
{
}
BOOL MyComboBox ::OnGetCustomToolTipText(CString& strToolTip)
{
strToolTip = "bonjour";
return TRUE;
}
BOOL MyComboBox ::OnUpdateToolTip(CWnd* /*pWndParent*/, int /*iButtonIndex*/, CToolTipCtrl& /*wndToolTip*/, CString& str)
{
str = "allo";
return TRUE;
}
The 2 virtual methods are never called; well, they are called when opening the application and when closing the application; but never when the application is running normally when the user move/hover the mouse on top of the combobox in the toolbar.
I tried looking into the tooltip manager (CTooltipManager) and enable or not the tooltip manager by calling or not InitTooltipManager.
( I quickly tried this with VS2012 and I get the same "not-working" results).
Are there some steps I am missing to be able to do that ?
Thanks.
Max.