One more request :D
I would like the ability to add tool tips to some or all controls.
Thanks!
John
Function ToolTipSet(ByVal hWnd As Dword, ByVal hCtrl As Dword, ByVal sText As String) As Long
Static hWnd_ToolTip As Dword
Local TI As TOOLINFO
If Len(sText)= 0 Then Exit Function
If IsWindow(hWnd_ToolTip) = 0 Then
hWnd_ToolTip = CreateWindowEx(0, "tooltips_class32", "", %TTS_NOPREFIX Or %TTS_ALWAYSTIP, 0,0,0,0,0, ByVal 0, App.hInstance, ByVal 0)
SendMessage(hWnd_ToolTip, %TTM_SETMAXTIPWIDTH, 0, 300)
SendMessage(hWnd_ToolTip, %TTM_SETDELAYTIME, %TTDT_INITIAL, 800)
SendMessage(hWnd_ToolTip, %TTM_SETDELAYTIME, %TTDT_AUTOPOP, 5000)
SendMessage(hWnd_ToolTip, %TTM_SETDELAYTIME, %TTDT_RESHOW, 400)
End If
If hWnd_ToolTip = 0 Then Exit Function
TI.cbSize = SizeOf(TI)
TI.uFlags = %TTF_SUBCLASS Or %TTF_IDISHWND
TI.uId = hCtrl
TI.hWnd = hWnd
If SendMessage(hWnd_ToolTip, %TTM_GETTOOLINFO, 0, ByVal VarPtr(TI)) Then 'remove old tip first?
Call SendMessage(hWnd_ToolTip, %TTM_DELTOOL, 0, ByVal VarPtr(TI))
End If
TI.lpszText = StrPtr(sText)
Function = SendMessage(hWnd_ToolTip, %TTM_ADDTOOL, 0, ByVal VarPtr(TI))
End Function
Thanks Roger! That's perfect. John
Roger,
I implemented the code you supplied and it works great. I have one problem though, and I am not familiar enough with tooltips to know how to make it do what I want (or if that is even possible).
When you have a tooltip on a button, you can hover the mouse over the button to see the tooltip. However, once you click the button, you have to hover over (you don't have to wait for the tooltip to appear) another button with a tooltip before the first tooltip will reactivate. (I also tried this with listboxes and comboboxes, and got the same results.)
I saw this same behavior in other applications, as well. For instance, in FireFly v1.07, I noticed this behavior with tooltips on the toolbar. But, when I checked toolbars in applications created by FireFly, the problem didn't exist.
I would imagine that the thought is once a user clicks a button, they know what it does, so it won't reactivate and show the tooltip again, but I would like to show it anyways, or, if possible, show it after a longer delay.
Is this possible?
Thanks!
John
The %TTM_SETDELAYTIME messages in the code setup the delays. I played with them for a while to get them to work they way I wanted. Sometimes they just don't work as expected though, but %TTDT_INITIAL is supposed to be the wait when first hovered over, %TTDT_AUTOPOP is how long it waits before "popping", and %TTDT_RESHOW is the wait before reshowed if focus is lost, etc. They are somewhat linked though and the control avegerages out the times like if the values would overlap, etc. You just have to play with them to get the desired effect.
You may also want to read up on tooltips and remove the %TTF_SUBCLASS flag which lets you pass messages to it with %TTM_RELAYEVENT. Maybe then you could send it mousemove messages and such and thus allow you into tricking it into thinking the mouse is still hovered over the button, etc.
Roger
How do you this implemented in the FF Designer
- I put an Button and Copy this function in the codeeditor of the button.
Is that correct?
Please give me the right solution?
Thanks
Stephane
Looks that is my code :)
Beste Edwin
Leg eens uit hoe je dat schrijft in de code editor?
Met vriendelijke groeten
Stephane
Ps: Edwin kan jij low level programmeren ik heb een bibliotheek nodig voor mijn elektronica schakelingen te besturen met de pc.
Ik zou graag de geluidskaart aansturen en de timer IC onder Win2k maar is dat mogelijk met de WinAPI met PBWin of C code?
Loose translation:
Quote from: StephaneDear Edwin,
That once writes editor to leg from how you in the code?
With pleasant groeten,
Stephane.
PS: Edwin can program you low level I need a library for my elektronica control schakelingen with the pc.
I gladly the sound card head and the timer IC under Win2k but are that possibly with the WinAPI with PBWin or c code?
Is it just me or does Stephane make a lot of requests?
:P
--Bob
Quote from: Edwin KnoppertLooks that is my code :)
No telling where I got the code from. But, even when I get code I modify it and it isn't exactly the same. If I recall I found code in two places and combined them because they were pretty much the same.
Hopefully Paul will modify FF to have tooltips and use something like this. Only flaw I've found so far is this doesn't check for other existing tooltip classes, and when things like Trackbar/Sliders have their own tooltip there are multiple tooltip classes with the app.
Stephane,
Just pretend it is an FF_Function after pasting it to the general section, then give it your form's hWnd and the hWnd of the control...and the text of course, and that's it.
Roger
I just implemented the FF_Function pasting it to the general section, but how give it your hWnd and the hWnd of the control?
How does it work
Can you please give me an short example?
Kind regards
Stephane
Stephane,
Just pretend it is an FF_Function after pasting it to the general section, then give it your form's hWnd and the hWnd of the control...and the text of course, and that's it.[/quote]
No worries, simply had fun in replying..
:)
Edwin
You hate me, is it true but I'm good buyer for you PwrDev and PwrStatic
When comes there an update or upgrade of PwrDev?
Let me know when it's comes
Thanks
Stephane
Old code...New Version-
'------------------------------------------------------------------------------------------------------------------------
' 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
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
Hi Roger,
In your earlier version of ToolTipsSet the hWnd_ToolTip Dword variable is declared Static, therefore once implemented remains the same for all subsequent calls to the ToolTipSet function.
In the latest version of ToolTipsSet the hWnd_ToolTip Dword variable is not Static but can be set by PrevTip to be the same value as an earlier call to the function or can be (0) new.
Could you please explain the rational behind this change and the reasons or advantages obtained.
Regards
Gian Young
Less memory/resources used if reusing the same tooltip parent. Also in Balloon tooltips any icons/titles set are linked with the parent, so all have the same icon/title in previous version.