Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

How to do tooltip for CBitmapButton in CView

Posted on 1998-05-30
7
Medium Priority
?
669 Views
Last Modified: 2013-11-20
I have an MDI app with child windows derived from CView. In a child windows I have a couple of buttons of class CBitmapButton. What do I have to do to get the tooltips to show for these buttons?
0
Comment
Question by:gates
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1315781
EnableToolTips(true) for your view and supply a handler for the TTN_NEEDTEXT message.  This handler will look at the TOOLTIPTEXT structure passed and determine which control the mouse was over and set the tooltip text appropriately.
 

0
 

Author Comment

by:gates
ID: 1315782
I tried all this before posting the question. The problem I encountered was: only the toolbar buttons's tooltip activate the TTN_NEEDTEXT handler. When the mouse was over the CBitmapButton child windows in the CView window, TTN_NEEDTEXT handler was not called. I also tried creating a CTooltipCtr and AddTool with the CBitmapButton as argument but without success.
I need the exact code that works, because I already read the document as well as the MSJ 4/97 article on tooltips.
0
 
LVL 3

Accepted Solution

by:
tma050898 earned 800 total points
ID: 1315783
Answer on the way...
0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 3

Expert Comment

by:tma050898
ID: 1315784
gates,

While this code was originally written for controls on a dialog, I just tested it for a CBitmapButton control that is dynamically created on a view and it works without any problem.

To use this class simply add a member variable of type CToolTip to the view, call the tool tip's Create function in the view's OnInitialUpdate function and call any of the three overloaded AddWindowTool functions for each control you wish to have a tooltip.

class CToolTip : public CToolTipCtrl
{
public:
 BOOL AddWindowTool(UINT uiControlId);
 BOOL AddWindowTool(UINT uiControlId, UINT uiStringId);
 BOOL AddWindowTool(UINT uiControlId, LPCTSTR pszText);

protected:
 BOOL AddRectTool(CWnd* pWnd, LPCTSTR pszText,
  LPCRECT lpRect, UINT nIDTool);
};

BOOL CToolTip::AddWindowTool(UINT uiControlId) // assumes control id = string id
{
 return AddWindowTool(uiControlId, uiControlId);
}

BOOL CToolTip::AddWindowTool(UINT uiControlId, UINT uiStringId)
{
 CString strText;
 VERIFY(strText.LoadString(uiStringId));
 return (AddWindowTool(uiControlId, strText));
}

BOOL CToolTip::AddWindowTool(UINT uiControlId, LPCTSTR pszText)
{
 BOOL bSuccess = FALSE;

 CWnd* pParentWnd = GetOwner();
 ASSERT(pParentWnd); // did you call create first?
 if (pParentWnd)
 {
  CWnd* pWnd = pParentWnd->GetDlgItem(uiControlId);
  ASSERT(pWnd);
  if (pWnd)
  {
   TOOLINFO ti;
   ti.cbSize = sizeof (TOOLINFO);
   ti.uFlags = TTF_IDISHWND | TTF_SUBCLASS;
   ti.hwnd = pWnd->GetParent()->GetSafeHwnd();
   ti.uId = (UINT) pWnd->GetSafeHwnd();
   ti.hinst = AfxGetInstanceHandle();
   ti.lpszText = (LPTSTR) pszText;
   SendMessage( TTM_DELTOOL, 0, (LPARAM) &ti );
   bSuccess = (BOOL) SendMessage( TTM_ADDTOOL, 0, (LPARAM) &ti );
  }
 }

 return bSuccess;
}

BOOL CToolTip::AddRectTool(CWnd* pWnd, LPCTSTR pszText,LPCRECT lpRect, UINT nIDTool)
{
TOOLINFO ti;
ti.cbSize = sizeof (TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = pWnd->GetSafeHwnd();
ti.uId = nIDTool;
ti.hinst = AfxGetInstanceHandle();
ti.lpszText = (LPTSTR) pszText;
::CopyRect( &ti.rect, lpRect );
return (BOOL) SendMessage( TTM_ADDTOOL, 0, (LPARAM) &ti );
}

Here's an example of the how to use the different CToolTip AddWindowTool functions. As you can see, there are three overloaded functions to pick from depending on how and where you are storing the tooltip text for the controls.

void CYourView::OnInitialUpdate()
{
 ...
 // creation of your CBitmapButton

 m_tooltip.Create(this);

 m_tooltip.AddWindowTool(ID_YOUR_BUTTON, "OK"); // hard coded tooltip

 m_tooltip.AddWindowTool(ID_YOUR_BUTTON); // string id = control id

 m_tooltip.AddWindowTool(ID_YOUR_BUTTON, IDS_YOUR_BUTTON); // string id != control id
 
 ...
}

IMPORTANT!!!
As I wouldn't want other people taking credit for my work, so I want to mention that Ian (the only name I have) wrote this class. I simply added the 2 overloaded AddWindowTool functions so that string resource ids could be used. His email is ianm@iexplorers.com if you want to thank him for providing this code for everyone.

Tom

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1315785
That answer looks familiar, tom :-)

Anyway, gates (bill?) .. did you EnableToolTips(true) first?  I am surprised it did not wark .. and that your views tooltip text handler got called for a tooblar button .. are you sure you put the handler in the correct place?

In my view class, I create a tooltip member for the view class

In my mouse move I detect the item under the mouse (and remember if) and activate the tooltip.  Then in my
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT,0,0xFFFF,OnToolTipNeedText)
handler I check if there is an item that requires a tooltip, and if so I set the text appropriately

I can supply code if you want.

0
 
LVL 3

Expert Comment

by:tma050898
ID: 1315786
RONSLOW,

>>>That answer looks familiar, tom :-)
LOL ! It's the staple of an OOP...code reuse! Looks like we get to rekindle that argument over which class works best ;)

Tom


0
 

Author Comment

by:gates
ID: 1315787
TMA,
Your answer gave me enough hint to fix my problem even though most of the code is from another developer and even though I don't use the code in my work. It's the result that counts so I grade your help Excellent. The key hint is the use of CTooltipCtrl. (Ronslow: I don't use the NeedText handler approach). Many thanks, both, for your help.
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

647 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question