Tooltips for controls

Started by Ivan Iraola, November 02, 2009, 09:41:13 PM

Previous topic - Next topic

Ivan Iraola

First of all I'm LOVING the new FF3, I'm porting some old code to FF3 and so far is looking great and easy to convert, however, the GUI designer I have besides FF3, allows to add TOOLTIPS to controls, FF3 doesn't have that capability (only for TOOLBAT buttons).

That would be an excellent addition to the designer.
Android App Developer
http://www.uncledroid.com

Paul Squires

I agree. David Warner already suggested this to me a couple of weeks ago during beta testing. I can certainly see this finding its way into FF3. It would be a very good addition.
Paul Squires
PlanetSquires Software

Robert Eaton

Paul,
Is this still on the list as a possible new feature?

Thanks,
Bob

Paul Squires

Yes, it is still on the list. Won't be there in v3.06 though.
Paul Squires
PlanetSquires Software

Roger Garstang

I believe my most recent function for making tooltips is:


' Major Versions
'3= WinNT 3.51
'4= WinNT 4.0/Win9x-ME
'5= Windows2K/XP/2003
'6= WinLonghorn/Vista

' Minor Versions
'0=  Win95/NT 4.0/2K
'1=  WinXP
'2=  Win2003/WinXP64
'10= Win98
'51= WinNT 3.51
'90= WinME

Function ToolTipSet(ByVal prevTip As Dword, ByVal hWnd As Dword, ByVal hCtrl As Dword, ByVal sText As Asciiz * 80, Optional ByVal BalloonStyle As Dword, Optional ByVal Title As Asciiz * 100, Optional ByVal IconPic As Dword) As Long
Static osi           As OSVERSIONINFOEX
Static allowBalloons As Dword ' 1= Balloons Allowed, 2= XP SP2+ (hIcons allowed)
Local  hWnd_ToolTip  As Dword
Local  TI            As TOOLINFO
Local  classname     As Asciiz * 17

   ' prevTip= 0 to create a new tooltip Parent Window, else use prev hWnd from function return
   ' BalloonStyle= 1 for Balloon, 2 for Balloon that Tracks/Stays and is activated by app.
   ' Icons= 1 for Info, 2 for Warning, 3 for Error, SP2 can also be HICON handle...but docs are weird saying you have to clean up the copy it makes???
   
   If IsWindow(prevTip) Then ' If really a tooltip then use it.
      GetClassName(prevTip, classname, 17)
      If classname= "tooltips_class32" Then hWnd_ToolTip= prevTip
   End If

   If BalloonStyle Then
      If hWnd_ToolTip= 0 Then ' If no Previous Tooltip Window.
         If osi.dwOSVersionInfoSize= 0 Then ' If haven't checked Version already.
            osi.dwOSVersionInfoSize= SizeOf(OSVERSIONINFO) ' OSVERSIONINFOEX not supported Pre Win2K
            GetVersionEx(osi)
            Select Case osi.dwMajorVersion
               Case 4
                  If osi.dwMinorVersion= 90 Then allowBalloons= 1 ' WinME
               Case 5
                  Select Case osi.dwMinorVersion
                     Case 0 ' Win2K
                        allowBalloons= 1
                     Case 1 ' WinXP
                        osi.dwOSVersionInfoSize= SizeOf(OSVERSIONINFOEX) ' OSVERSIONINFOEX not supported Pre Win2K
                        GetVersionEx(osi)
                        If osi.wServicePackMajor > 1 Then allowBalloons= 2 Else allowBalloons= 1
                     Case > 1
                        allowBalloons= 2
                  End Select
               Case > 5
                  allowBalloons= 2
            End Select
         End If
         If allowBalloons Then ' Balloon Version Available.
            hWnd_ToolTip= CreateWindowEx(%WS_Ex_Topmost, "tooltips_class32", "", %TTS_BALLOON Or %TTS_NOPREFIX Or %TTS_ALWAYSTIP Or %WS_Ex_ToolWindow, 0,0,0,0,0, ByVal 0, GetModuleHandle(ByVal %Null), ByVal 0)
            If IsWindow(hWnd_ToolTip) Then
                SendMessage(hWnd_ToolTip, %TTM_SETMAXTIPWIDTH, 0, 300)
                If (allowBalloons= 1) And IconPic > 3 Then IconPic= 1 ' If hIcon given and PreXP SP2 then make it Info Icon
                SendMessage(hWnd_ToolTip, %TTM_SETTITLE, IconPic, ByVal VarPtr(Title))
            End If
         End If
      End If
   End If
   
   If hWnd_ToolTip= 0 Then ' No Selected Tooltip Window yet or error making Ballon Style Tooltip.
      hWnd_ToolTip= CreateWindowEx(%WS_Ex_Topmost, "tooltips_class32", "", %TTS_NOPREFIX Or %TTS_ALWAYSTIP, 0,0,0,0,0, ByVal 0, GetModuleHandle(ByVal %Null), ByVal 0)
      If IsWindow(hWnd_ToolTip) Then SendMessage(hWnd_ToolTip, %TTM_SETMAXTIPWIDTH, 0, 300)
   End If

   If hWnd_ToolTip= 0 Then Exit Function

   TI.cbSize= SizeOf(TI)
   TI.hWnd= hWnd
   If hCtrl= 0 Then TI.uId= hWnd Else TI.uId = hCtrl ' If 0 set to Window else set to Control. hCtrl is Handle, not ID of control.
   
   Function= SendMessage(hWnd_ToolTip, %TTM_DELTOOL, 0, ByVal VarPtr(TI))
   If Len(sText) > 0 Then
      If BalloonStyle= 2 Then TI.uFlags= %TTF_IDISHWND Or %TTF_TRACK Or %TTF_ABSOLUTE Or %TTF_TRANSPARENT Else TI.uFlags= %TTF_SUBCLASS Or %TTF_IDISHWND Or %TTF_TRANSPARENT
      TI.lpszText= VarPtr(sText)
      If SendMessage(hWnd_ToolTip, %TTM_ADDTOOL, 0, ByVal VarPtr(TI)) Then Function= hWnd_ToolTip Else Function= 0
   End If
End Function 

Roger Garstang

What I call Balloon style 2 is a little more advanced with the ability to keep it open till clicked and add a close button, etc.  Other things can be added like TTS_CLOSE and TTF_PARSELINKS, etc.  If I recall though there is a weird issue when turning on the Close button where you have to enable it in the Tooltip's Main Window otherwise it shows disabled...I think the WS_Ex_ToolWindow I add does this.  Been a while since I used that style though.  Regular tip or Balloon style 1 are usually what most need.

Robert Eaton

Roger,
That works great!

Thanks,
Bob

Roger Garstang

Cool.  Just dug a little more on MSDN.  Looks like they took out the comment about cleaning up the copied hicon...user note below the help has a comment that probably did it.  You do have to cleanup your own icon that you give it to copy though which is a given anyway.  Looks like Vista+ adds icons 4,5,and 6 for large versions of the first 3 icons too...this should work fine since my check that makes > 3 ignored only applies to allowBalloons being 1 which is XP SP1 and before.

Andrew Lindsay

Paul,

Is there any update on Toolips for all other controls in the Designer?

Best regards

Andrew Lindsay

Paul Squires

Hi Andrew,

It's still in the New Features Requested section of my bug tracker. It will get in FF at some point. It is too good a feature not to have in FF.
Paul Squires
PlanetSquires Software

Robert Eaton

Either I'm implementing it incorrectly ::), or there is a small bug in the code that Roger posted.
(I'm setting the tooltip text in WM_CREATE.)

If you let your mouse hover over a control until the tooltip disappears, it stops working for that control until you restart the program.

Anyone else see that?

Rudolf Furstauer

Hi Robert,

your observation is correct, there is an bug in the program behavior.
But until now I could not determine where the bug is.  :(

The error occurs only in the combination of OS-XP and XP themes are on.
If XP themes is turned off, the tip is displayed again.
Under W7 the tip reappears correctly.

Eddy Van Esch

Paul,

When you are implementing tooltips in FF3, would you consider adding the possibility to set the %TTM_SETMAXTIPWIDTH parameter?
That would allow us to set the max. width of the tooltip and also would allow multi-line tooltips.

Kind regards
Eddy

Roger Garstang

#13
Sounds good. I think my 300 max above was just trial and error with a good setting that aligned to the screen or something...been a while since I first created it.  The 80 char limit on the text I put in because NMTTDISPINFO limits it and if people set the style for TTN_GETDISPINFO to be used then the limit was needed.  It would be cool if this was in the properties for each control like VS does it, but maybe a dropdown textarea then you can type multiple lines and maybe FF sets it up to wrap by what you type.

As for the redraw, XP has a lot of issues drawing tooltips.  I tried playing with all the tooltip time settings, but nothing worked any better. Being able to select timeouts or leaving it default would be a plus though...If I remember right there are different limits per OS on them though and in some cases you can't make it stay open too long.  Nero usually has huge tooltips that stay as long as you hold the mouse on the control...that option would be cool too, but I think you will have to manually show the tip and hide it to do it. %TTF_TRANSPARENT is an important flag in XP, otherwise when on a button or other object that paints mouseover focus you get flicker.  XP itself has issues with tips too if you set a textbox to password or numeric only and the balloon tip comes up that warns you Caps lock is on or if you didn't type numeric...depending on the styles, when it closes it usually erases all your frame controls.