Sign in to follow this  
Followers 0
qwert

Strange behavior using GUIToolTip.au3

7 posts in this topic

I've isolated a rather strange behavior with GUIToolTip.au3.  Custom tooltips are erratic in certain circumstances, as I indicated in a previous thread.

 

My initial assessment was somewhat correct:

tooltips can be “flitty” ... they can flash on/off two or three times while the cursor is settling into a control

As it turns out, "settling" doesn't seem to be involved.  Oddly, it's the direction of the cursor movement into the control

Here is an example that demonstrates the problem:

;
;       Demonstration of Custom Tooltips ... mainly of font size function
;
#include <GUIConstantsEx.au3>
#include <GUIToolTip.au3>
#include <WinAPI.au3>
#include <FontConstants.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $hGUI = GUICreate(StringTrimRight(@ScriptName, 4), 350, 200, 700, 200)
    Local $iAdd = GUICtrlCreateButton("Button ToolTip", 30, 32, 130, 28)
    GUICtrlSetTip(-1, "This is a standard tooltip" & @CRLF & "It is created with GUICtrlSetTip()")
    Local $hAdd = GUICtrlGetHandle($iAdd)
    ; Create a tooltip control
    Local $hToolTip = _GUIToolTip_Create($hGUI, $TTS_BALLOON)    ; Balloon
;   Local $hToolTip = _GUIToolTip_Create($hGUI, $TTS_CLOSE)       ; Normal, $TTS_CLOSE << didn't work
; If using a Windows theme setting, this will disable it for the tooltip displayed, so you can color it
; it has to be placed before you try to actually set the colors, doing it after will reset the colors.
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", $hToolTip, "wstr", 0, "wstr", 0)            ;<<<< DISABLE THEME is necessary
; The color value used in the _GUIToolTip_SetTipBkColor function is an RGB value            << INCORRECT
    _GUIToolTip_SetTipBkColor($hToolTip, 0xFFFFF4) ; FFFFEE is blue ... EEFFFF is yellow
; The color value used in the _GUIToolTip_SetTipTextColor function is an BGR value
    _GUIToolTip_SetTipTextColor($hToolTip, 0x444444)
    _GUIToolTip_SetMaxTipWidth($hToolTip, 600)          ; 600 pixels
; add a tool to the tooltip control
    _GUIToolTip_AddTool($hToolTip, 0, "This is a balloon tip that's created with _GUIToolTip_Create" & @CRLF & "It can easily be made to contain multiple lines.", $hAdd)
    _SetFont_hWnd($hToolTip, 14)
    GUISetState()

    While 1
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
; Destroy the tooltip control (not required upon normal exit)
    _GUIToolTip_Destroy($hToolTip)
    GUIDelete($hGUI)
EndFunc   ;==>Example

;~ http://www.autoitscript.com/forum/topic/57419-deleting-listviewitem-leaves-a-black-space/?p=441871
;==========================================================
Func _SetFont_hWnd($hwnd, $size = 8.5, $weight = 400, $attr = 0, $fontname = "Tahoma")                  ; specify FONT
    Local $_tagfont = DllStructCreate($tagLOGFONT)
    Local $hDC = _WinAPI_GetDC($hwnd)
    ; lfHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72)
    Local $lf_height = -($size * _WinAPI_GetDeviceCaps($hDC, $LOGPIXELSY)) / 72
    _WinAPI_ReleaseDC($hwnd, $hDC)
    DllStructSetData($_tagfont, 'Height', $lf_height);
    DllStructSetData($_tagfont, 'Width', 0);
    DllStructSetData($_tagfont, 'Escapement', 0);
    DllStructSetData($_tagfont, 'Orientation', 0);
    DllStructSetData($_tagfont, 'Weight', $weight);
    DllStructSetData($_tagfont, 'Italic', BitAND($attr, 0x2))
    DllStructSetData($_tagfont, 'Underline', BitAND($attr, 0x4))
    DllStructSetData($_tagfont, 'StrikeOut', BitAND($attr, 0x8))
    DllStructSetData($_tagfont, 'CharSet', 0); 0 = ANSI_CHARSET
    DllStructSetData($_tagfont, 'OutPrecision', 0); 0 = OUT_DEFAULT_PRECIS
    DllStructSetData($_tagfont, 'ClipPrecision', 0); 0 = CLIP_DEFAULT_PRECIS
    DllStructSetData($_tagfont, 'Quality', 0); 0 = DEFAULT_QUALITY
    ; 0 = DEFAULT_PITCH, 1 = FIXED_PITCH, 2 = VARIABLE_PITCH
    ; $FF_DONTCARE = 0 (FF_ROMAN = 16, FF_SWISS = 32, FF_MODERN = 48, FF_SCRIPT = 64, FF_DECORATIVE = 80)
    DllStructSetData($_tagfont, 'PitchAndFamily', BitOR(0, $FF_DONTCARE))
    DllStructSetData($_tagfont, 'FaceName', $fontname);
    Local $h_font = _WinAPI_CreateFontIndirect($_tagfont)
    _SendMessage($hwnd, $WM_SETFONT, $h_font, True)
EndFunc   ;==>_SetFont_hWnd

When a control is approached from below or from either side, the custom tooltip is rock solid. But when approached from the top, the custom tip blinks on, then off, then back on about 90% of the time. Before I increased the timer parameters, it flashed multiple times.

 

I took a look at the UDF and could only speculate that it might be something in the HitTest logic, but I couldn’t see anything obvious. But the fact that the standard tooltip is also affected makes it possible that it could be outside of the UDF.

 

If someone knowledgeable could take a look, the cause might be obvious.  And if it’s only a result one of my settings, please let me know which. I made changes to them, but wasn’t able to get around this effect.

 

Thanks in advance for any help resolving this.

Share this post


Link to post
Share on other sites



I noticed that it only happens when the tip is using the balloon style of tooltip, if you change it to the standard style the flickering doesn't happen. Even the GUICtrlSetTip will flicker if you use the balloon style with it just by itself without the UDF created tip.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Thanks for your response.

I hadn't noticed that case, which seems to rule out the UDF as a cause.  But that brings two questions:

1.  What could possibly be behind the difference in the direction the cursor moves?

2.  Could the UDF be changed in some way to counteract the behavior?  ... like inject a delay ... or adjust the initial cursor position.

It would be great if there was a solution.  It will be a shame if large-font, balloon-style tips are marred by this behavior. 

Share this post


Link to post
Share on other sites

Further investigation (on the 'net) indicates that this is a known problem.  This "solution" may help shed some light:

Balloon style ToolTips may flicker if the mouse moves over the little pointed corner of the balloon. This is because the mouse is no longer hovering over the main window - it is hovering over the ToolTip itself. To prevent this behavior, you can use the TTF_TRANSPARENT flag in the uFlags parameter of the TOOLINFO structure. This flag will cause mouse events to be passed to the underlaying window as if the ToolTip was transparent.

... and from msdn:

TTF_TRANSPARENT

Causes the tooltip control to forward mouse event messages to the parent window. This is limited to mouse events that occur within the bounds of the tooltip window.

This would seem to mean a change in _GUIToolTip_SetToolInfo().  But exactly what is beyond me.  (I don't see a reference to uFlags.)

Any ideas?

 

Share this post


Link to post
Share on other sites

One more thing to add:

I tried a simple modification to _GUIToolTip_SetToolInfo ... but then realized 1) I'm not calling it, 2) it's not called internally, and 3) there is no usage defined in the UDF.

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......:
; ===============================================================================================================================
Func _GUIToolTip_SetToolInfo($hWnd, $sText, $iID = 0, $iLeft = 0, $iTop = 0, $iRight = 0, $iBottom = 0, $iFlags = $TTF_TRANSPARENT, $iParam = 0) ; Default

How should it be used?

Share this post


Link to post
Share on other sites

I never could figure out how that function is used, from everything I read about tooltips when I rewrote the UDF, whatever that function was supposed to do it was doing it wrong. I left it as is though because I didn't know how to correct it, and no one used it anyways, and because I didn't know enough about the function and how it worked I didn't want to say that it was written wrong. I figured if anyone found a way that worked they'd let us know. ;)

BTW, I wouldn't use that to fix the issue with the flickering tooltips, I'd used $TTF_Transparent in the _GUITooltip_AddTool function when the tools are added, which is where you'd find that variable name.

#include <GUIConstantsEx.au3>
#include <GUIToolTip.au3>

Example()

Func Example()
    Local $hGUI = GUICreate(StringTrimRight(@ScriptName, 4), 350, 200)

    Local $iAdd = GUICtrlCreateButton("Button ToolTip", 30, 32, 130, 28)
    Local $hAdd = GUICtrlGetHandle($iAdd)
    ; create a tooltip control using default settings
    Local $hToolTip = _GUIToolTip_Create(0, BitOR($_TT_ghTTDefaultStyle, $TTS_BALlOON))

    ; add a tool to the tooltip control
    _GUIToolTip_AddTool($hToolTip, 0, "This is a ToolTip", $hAdd, 0, 0, 0, 0, BitOR($TTF_SUBCLASS, $TTF_IDISHWND, $TTF_TRANSPARENT))
    GUISetState()

    While 1
        If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop
    WEnd
    ; Destroy the tooltip control
    _GUIToolTip_Destroy($hToolTip)
    GUIDelete($hGUI)
EndFunc   ;==>Example

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Solved!

BrewManNH, you've done it!

I went into my local copy of ToolTips.au3 and made this addition:

; #FUNCTION# ====================================================================================================================
; Author ........: Paul Campbell (PaulIA)
; Modified.......: Bob Marotte (BrewManNH)
; ===============================================================================================================================
Func _GUIToolTip_AddTool($hTool, $hWnd, $sText, $iID = 0, $iLeft = 0, $iTop = 0, $iRight = 0, $iBottom = 0, $iFlags = Default, $iParam = 0)
    Local $iBuffer, $tBuffer, $pBuffer
    If $iFlags = Default Then $iFlags = BitOR($TTF_SUBCLASS, $TTF_IDISHWND, $TTF_TRANSPARENT) ;<<<< $TTF_TRANSPARENT added to stop flicker

Now every bubble tip is rock solid. 

I figured this was a better way that adding 50+ characters to a dozen AddTool function calls.  Plus, I don't see why this shouldn't be changed in the UDF to make it the standard.  Is anyone using different settings for those flags?  (meaning: other than Default)

Thanks very much for sticking with this.  I hope people will find this trail of crumbs ... because everyone should try these styled-text balloon tips!

 

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0