Adding tooltips to the status bar

by Richard Russell, January 2007

If your program uses the WINLIB library to create a toolbar then you can easily add tooltips to the toolbar buttons using the PROC_addtooltips function provided. However if you use the same library to create a status bar no built-in method for adding tooltips to it is provided.

Nevertheless it is actually quite easy to add tooltips to a status bar. You should first create the status bar in the usual way, using the FN_createstatusbar function, and divide it up into the wanted number of parts. Next you need a handle to a tooltip control; there are two ways of achieving that, depending on whether or not your program also uses a toolbar.

If you have created a toolbar with tooltips then you can obtain a handle to its tooltip control as follows:

      TB_GETTOOLTIPS = 1059
      SYS "SendMessage", htoolbar%, TB_GETTOOLTIPS, 0, 0 TO htooltip%
Here htoolbar% is the handle of the toolbar, as returned from FN_createtoolbar.

If your program doesn't use a toolbar, you must install the WINLIB5 (or WINLIB5A) library:
      INSTALL @lib$+"WINLIB5"
The tooltip control can now be created as follows:
      TTS_NOPREFIX = 2
      WS_CHILD = &40000000
      WS_VISIBLE = &10000000
      htooltip% = FN_createwindow("tooltips_class32", "", 0, 0, 0, 0, 0, \ 
If instead your program uses the WINLIB5A library then the code must be adapted as follows:
      TTS_NOPREFIX = 2
      WS_CHILD = &40000000
      WS_VISIBLE = &10000000
      htooltip% = FN_createwindow(@hwnd%, "tooltips_class32", "", 0, 0, 0, 0, 0, \ 
It is advisable to create only one tooltip control for your entire program.

Next define a TOOLINFO data structure and initialise a couple of its members:
      DIM ti{cbSize%, uFlags%, hwnd%, uId%, rect{l%,t%,r%,b%}, hinst%, lpszText%}
      TTM_ADDTOOL = 1028
      SB_GETRECT = 1034
      TTF_SUBCLASS = &10
      ti.cbSize% = DIM(ti{})
      ti.uFlags% = TTF_SUBCLASS
      ti.hwnd% = hstatusbar%
Here hstatusbar% is the handle of the status bar, as returned from FN_createstatusbar.

Now we have everything we need to create the tooltips themselves. For each part of the status bar create a tooltip for it as follows:
      tip$ = "Tool tip"+CHR$0
      ti.lpszText% = !^tip$
      SYS "SendMessage", hstatusbar%, SB_GETRECT, part%, ^ti.rect.l%
      SYS "SendMessage", htooltip%, TTM_ADDTOOL, 0, ti{}
Here part% is the status bar part number, starting from 0 for the first (leftmost) part.

Note particularly the important CHR$0 concatenated to the end of the tooltip string (here "Tool tip").