Link to home
Start Free TrialLog in
Avatar of David F
David F

asked on

MFC: How do I add ToolTip to a CTabView tab located in a CSplitterWnd?

Hi,

Using MFC, I want to add a tooltip to a tab on a CTabView.  I don't care if it's just the tab itself or the full view.  The particular tab is a CHtmlView and is in one of the panes of a CSplitterWnd.    So I have the CMainFrame that creates a couple CSplitterWnd items on OnCreateClient  where one of those panes uses a CTabView.

I tried using a CToolTipCtrl created in CMainFrame::OnCreateClient after adding the CSplitterWnd for the CTabView since the CTabView::OnCreate adds the tabs but nothing seemed to work.

TIA!!

I implemented the suggestion on page 941-942 in the book Programming Windows with MFC second Edition to derive from CToolTipCtrl and implement new functions that use TTF_SUBCLASS.   I tried it with in the CMyTabView on the client area of the tabs.  It sort of works with the Edit and Rich Views but not HTML view.  By sort of, I mean, it works maybe twice then doesn't come up again.  Here's that part:

    int CMyTabView::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
      if (CTabView::OnCreate(lpCreateStruct) == -1)
        return -1;
    
      AddView(RUNTIME_CLASS(CMyEditView), _T("Tab1"));
      AddView(RUNTIME_CLASS(CMyRichView), _T("Tab2"));
      AddView(RUNTIME_CLASS(CMyHtmlView), _T("Tab3"));
    
      m_ToolTip.Create(this, TTS_ALWAYSTIP);
      
      CMFCTabCtrl &tabctrl=GetTabControl();
      for (int i=0; i < tabctrl.GetTabsNum(); ++i) {
        m_ToolTip.AddWindowTool(tabctrl.GetTabWnd(i), _T("Test Tool Tip"));
      }
      
      return 0;
    }

Open in new window

Not working on the HTML View was fine because I really just want it on the tab.   So I change it up and got rid of the stuff above (except the .Create) and added:

    void CMyTabView::OnInitialUpdate()
    {
      CTabView::OnInitialUpdate();
      
      CMFCTabCtrl &tabctrl=GetTabControl();
      CRect rc;
      tabctrl.GetTabsRect(rc);
      if (!rc.IsRectEmpty()) {
        m_ToolTip.AddRectTool(&tabctrl, _T("test tip"), &rc, (UINT_PTR) tabctrl.GetSafeHwnd());
      }
    }

Open in new window


But that doesn't work.  It tried using `this` as well, still didn't work.  So while something worked, still can't get it to work on the tabs?  Any ideas?
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

https://docs.microsoft.com/en-us/cpp/mfc/reference/ctooltipctrl-class?view=vs-2019#addtool


Basically in the CTabView::OnCreate you have does this work (where your tooltip control is myToolTipCtrl) ?

myToolTipCtrl.AddTool(this, "hello");

Avatar of David F
David F

ASKER

I've tried it on the CMainFrame referencing the CTabView, I've done it on the CHtmlView,  I've done it with the CTabView.  In all cases, no tooltip shows.  Even adding the RelayEvent in  various PreTranslateMessage.   Do you have a more complete example since I must be missing something?

NOTE: I've updated the original question with some code samples.

Can you put a bare bones project together yourself with your customised classes to give the framework (splitter, tab, htmlview...) and post it here.


At one time there were loads of example projects on microsoft about how to use MFC.  I can't find them anymore and I've not actually coded in MFC for numbers of years.

This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.