?
Solved

Multi-line ToolTips

Posted on 1998-05-20
23
Medium Priority
?
597 Views
Last Modified: 2013-11-20
How does one implement a multi-line tooltip?  I've tried putting various characters (like \r and \n) in the string resource to be display but I always get:

This is line 1|This is line 2

If the line is too long, it gets truncated.
0
Comment
Question by:jhance
[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
23 Comments
 
LVL 4

Expert Comment

by:piano_boxer
ID: 1313304
Microsoft's ToolTip control does NOT currently support multi-line text. You will have to write i your self.
0
 
LVL 32

Author Comment

by:jhance
ID: 1313305
If that is the case, then what method does MS use in IE4.0 for the tooltips which appear on the toolbar icons?  They seem to have the capability of having a multi-line display.  
0
 
LVL 8

Expert Comment

by:gelbert
ID: 1313306
Just use Spy to watch for tooltips and toolbar messages used inside IE 4.0 and make sure that you are using the same common control library as IE 4.0. It gives you list of messages and the rest(what do they mean and how to use them) you will have to figure out yourself.
0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 10

Expert Comment

by:RONSLOW
ID: 1313307
MS does support multi-line tooltips.

You just need to set the width of the tooltip control and it will automatically extend to multiple lines (with word-wrap) to fit the text in.

I can show you code to do this.


0
 
LVL 32

Author Comment

by:jhance
ID: 1313308
RONSLOW,

Some more information on how to do this would help.  I'm not creating a tooltip control explicitly in MFC.  How do you get a handle to it to control it's width?
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1313309
I'll dig it out.  I do this myself because I have long descriptive strings and they look very silly when all one one long skinny tooltip.

Hang on and I'll find my code...

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1313310
you send the control a TTM_SETMAXTIPWIDTH

more digging...

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1313311
BTW: Have a look at "Tiptoe Through the ToolTips With Our All-Encompassing ToolTip Programmer's Guide" in MSJ Apr 97 (also on MSDN).  It uses \n for multi-line tooltips.

0
 
LVL 32

Author Comment

by:jhance
ID: 1313312
Like I said earlier, I tried using "\n" in the ToolTip text but just get a bold "|" in the tip.  I'm not sure how to send a TTM_SETMAXTIPWIDTH to the control since I never created a control.  I'm just calling EnableToolTips() and handling the WM_NEEDTEXT message.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1313313
after enabling your tooltip with EnableToolTips you should be try doing this after EnableToolTips (assuming that is what you are doing)

  CToolTipCtrl* pToolTip = AfxGetThreadState()->m_pToolTip;
  if (pToolTip->GetSafeHwnd() != NULL) {
    pToolTip->SendMessage(TTM_SETMAXTIPWIDTH, 0, 160);
  }

change 160 to whatever size you want (in pixels).

0
 
LVL 32

Author Comment

by:jhance
ID: 1313314
Well, this method does make the tool tip wider but I still am not able to get more than a single line.  Any other ideas?
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 400 total points
ID: 1313315
If you text is longer that required it will wrap.

Set the width to something smaller (eg. 80).

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1313316
I havesample code now that uses EnableToolTips and the SetTipMaxWidth call .. and it works giving multi-line tooltips.

I started with the MSJ March 97 C++ article sample code (Virgil) and modified the OnGetTooltipText by adding the lines for getting the tooltip and setting its width.  NOTE: I couldn't do this at the point of the EnableToolTip's because the enabled tool tip control isn't created until it is first needed.  SO I set the width here instead

void CMainFrame::OnGetTooltipText(NMHDR* pNMHDR, LRESULT* plRes)
{
  CToolTipCtrl* pToolTip = AfxGetThreadState()->m_pToolTip;
  if (pToolTip->GetSafeHwnd() != NULL) {
    pToolTip->SendMessage(TTM_SETMAXTIPWIDTH, 0, 10);
  }
  TOOLTIPTEXT& ttt = *((TOOLTIPTEXT*)pNMHDR);
  strncpy(ttt.szText,
    GetWhoItIs(CPoint (pNMHDR->idFrom)),
    sizeof(ttt.szText));
}

0
 
LVL 32

Author Comment

by:jhance
ID: 1313317
OK, I'll give that a try.  Thanks for hanging with me here.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1313318
S'alright .. that's what I'm here for :-)

0
 
LVL 32

Author Comment

by:jhance
ID: 1313319
That did it, thanks!
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1313320
Still not sure why \n is not allowed in Enable tool tips method .. but seems to work ok in manually created tooltip (I've run the sample code that uses \n in the tooltip and it seems to work fine). But at least you can make your tips look a little nicer now.

0
 
LVL 32

Author Comment

by:jhance
ID: 1313321
I think I graded you too soon.  Or perhaps I wan't complete clear on what I was asking.  Anyway, I'm getting multi-line tooltips but I still only get the first 80 (79 actually) characters displayed regardless of how wide I make the tooltip.  Any other ideas?

Thanks...
0
 
LVL 32

Author Comment

by:jhance
ID: 1313322
Hmmm, poking around in MFC source code produces the following revelation:

typedef struct tagNMTTDISPIFNOA {
    NMHDR hdr;
    LPSTR lpszText;
    char szText[80];
    HINSTANCE hinst;
    UINT uFlags;
    LPARAM lParam;
} NMTTDISPINFOA, FAR *LPNMTTDISPINFOA;

Note that szText is fixed at 80 characters!  Is it possible to provide my own structure instead of this stupid one?
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1313323
There is a limit on the length .. which you have found.  You never said you wanted really long tips, though.

I believe that you can put a pointer to a string into lpszText instead .. I don't think there is a limit if you do it that way .. and I think you CAN use '\n' in that case.


0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1313324
Of course, that string need to not go out of scope after the function returns.  Make it a static (or a member var or whatever) .. as long as it doesn't disappear when the TTN_NEEDTEXT handler returns.

0
 
LVL 32

Author Comment

by:jhance
ID: 1313325
It's interesting.  I _was_ using the lpszText pointer, BUT, I was loading the string from a string table resource instead of just a char *.  If I just point lpszText at a long char * string, I get multi-line AND the \n works.

Go figure.  Thanks again.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1313326
Looks like you've got a few alternatives now and a better understand of the mysteries of tool tips (although some mysteries reamin just that .. like when \n works).

Glad to help.

0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

770 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