Solved

multi line tool tips

Posted on 2000-03-27
4
333 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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. …
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now