Solved

multi line tool tips

Posted on 2000-03-27
4
338 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Running shell command from Access 3 72
Get filename and folder into excel 7 74
Tab names are off by one 5 54
Change owner from userA to server Local Administrators 7 62
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

776 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