Link to home
Start Free TrialLog in
Avatar of TomBock2004
TomBock2004

asked on

Multi-line tool tip

During a search on "multi-line tool tips", I came across an accepted answer that was provided by webbingxia

I am not sure as to how I should implement this code (below "char szLongMessage[] =").   Do I create a module and then call the function from the  Other Tab, Control Tip Text line?   Can anyone help?  

Tom




==========================================================
Multiline Tooltips
Multiline tooltips allow text to be displayed on more than one line. They are supported by version 4.70 and later of the common controls. 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 accommodate only 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.
}
==========================================================
Avatar of Jokra_the_Barbarian
Jokra_the_Barbarian
Flag of United States of America image

Are you talking about the tooltips that appear when you mouse over a form control? If so, all you have to do is include a vbcrlf in the string. You can set a control tip text on form load if you want:

    Me.Control1.ControlTipText = "Hello." & vbCrLf & "Not much to see here."
ASKER CERTIFIED SOLUTION
Avatar of shanesuebsahakarn
shanesuebsahakarn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial