Solved

multi line tool tips

Posted on 2000-03-27
4
340 Views
Last Modified: 2013-11-20
Using tool tips code (TipText "here is what to do"), how would I make the tool tip multi line. If I put \n\r I get a bar in the program. If I just type in a long tool tip then the progam crashes. This should be fairly easy to answer. I am using Visual C++ 6
Thanks
Louise
0
Comment
Question by:c_louise
  • 2
  • 2
4 Comments
 
LVL 1

Accepted Solution

by:
derekcmartin earned 50 total points
ID: 2661666
THIS WAS TAKEN FROM MSDN LIBRARY

Multiline Tooltips
Multiline tooltip support allows text to be displayed on more than one line. This feature is useful if your message is too lengthy to be easily read as a single line of text. The following example shows a multiline tooltip that is displayed when the cursor hovers over the Internet Explorer icon on the desktop.

 
Creating Multiline Tooltips
Your application creates a multiline tooltip by responding to a TTN_GETDISPINFO notification message. To force the tooltip control to use multiple lines, send a TTM_SETMAXTIPWIDTH message, specifying the width of the display rectangle. Text that exceeds this width will wrap to the next line rather than widening the display region. The rectangle height will be increased as needed to accommodate the additional lines. The tooltip control will wrap the lines automatically, or you can use a carriage return/line feed combination, "\r\n", to force line breaks at particular locations.

Note that the text buffer specified by the szText member of the NMTTDISPINFO structure can only accommodate 80 characters. If you need to use a longer string, point the lpszText member of NMTTDISPINFO to a buffer containing the desired text.

The following code fragment is an example of a simple TTN_GETDISPINFO notification handler. It creates a multiline tooltip by setting the display rectangle to 300 pixels and setting the lpszText member of NMTTDISPINFO to point to a buffer with the desired text.

char szLongMessage[] =
"This is a long message for the tooltip, which will automatically "
"be wrapped when it exceeds the maximum tip width.  "
"Alternatively, you can use a \r\n"
"carriage return/line feed combination\r\n"
"to force line breaks at specific\r\n"
"locations.";

switch (lpnmhdr->code) {
  case TTN_GETDISPINFO:
    lpttd = (LPNMTTDISPINFO)lpnmhdr;
    SendMessage(lpnmhdr->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 300);
    lpttd->lpszText = szLongMessage;
    return 0;
      
      ...
 //Other notification handlers go here, as needed.
}
0
 

Author Comment

by:c_louise
ID: 2663970
I still need more explanation on how to get it to work with my code. Here is a piece of code from my program.TOOLTIPTEXT *TipText = ( TOOLTIPTEXT * ) pNMHDR;
            UINT nID = pNMHDR->idFrom;

      if ( TipText->uFlags & TTF_IDISHWND )
      {
      nID = ::GetDlgCtrlID((HWND)nID);
      switch( nID )
      {
      case IDC_BADDNAME:
            strcpy(TipText->szText,"Click to Add new addresses");
            break;
      case IDC_ADDRESSDELETE:
            strcpy(TipText->szText,"Deletes the highlighted names");
            break;
      case IDC_BSTOP:
            strcpy(TipText->szText, "Click to exit the screen");
            break;
Where would I put the code for the multiline tip.

Thanks
Louise
0
 
LVL 1

Expert Comment

by:derekcmartin
ID: 2664141
Louise,
     Try this:

char szLongMessage[] =
"This is a long message for the tooltip, which will automatically " 
"be wrapped when it exceeds the maximum tip width.  "
"Alternatively, you can use a \r\n"
"carriage return/line feed combination\r\n"
"to force line breaks at specific\r\n"
"locations.";


TOOLTIPTEXT *TipText = ( TOOLTIPTEXT * ) pNMHDR;
UINT nID = pNMHDR->idFrom;

if ( TipText->uFlags & TTF_IDISHWND )
{
nID = ::GetDlgCtrlID((HWND)nID);
switch( nID )
{
case IDC_BADDNAME:
strcpy(TipText->szText,"Click to Add new addresses");
break;
case IDC_ADDRESSDELETE:
strcpy(TipText->szText,"Deletes the highlighted names");
break;
case IDC_BSTOP:
strcpy(TipText->szText, "Click to exit the screen");
default:
    lpttd = (LPNMTTDISPINFO)lpnmhdr;
    SendMessage(lpnmhdr->hwndFrom, TTM_SETMAXTIPWIDTH, 0, 300);
    lpttd->lpszText = szLongMessage;
break;

0
 

Author Comment

by:c_louise
ID: 2664299
I changed a few things to better suit my code, because I was getting errors, when it could not find lpttd and lpnmhdr, I made the default like this

default:
            TipText = (LPNMTTDISPINFO)pNMHDR;            
            SendMessage(pNMHDR->idFrom, TTM_SETMAXTIPWIDTH, 300);             
            TipText->lpszText = szLongMessage;
      break;

But when I gave one of the tips a long line it still threw me out of the program when I tried to run it.
Louise
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
isEverywhere  challenge 19 82
matchUp  challenge 6 68
Dell Alienware Graphics Amplifier Driver for non-Alienware systems 18 336
mapAB Challlenge 35 155
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. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.

790 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