Jump to content

Recommended Posts

Posted

I have been having significant issues showing tooltips on toolbar buttons. For example, if I run the _GUICtrlToolbar_SetToolTips example 10 times, the tooltips work maybe 1 or 2 times out of 10 runs.

  • Sometimes no tooltips show at all
  • Sometimes the tooltips show blank
  • Sometimes the tooltips only show a border
  • Sometimes the tooltips text shows but off-center on the tooltip
  • Sometimes (rarely) the tooltips show properly

I have tried responding to $TTN_GETDISPINFOW (like the help file example) and I've also tried $TBN_GETINFOTIPW which also works but suffers the same failure rate.

Some online help suggests "Stack-Allocated Buffer Lifetime" and memory related issues for the tooltip text but that is all beyond my understanding.

I've also tried forcing AutoIt to run as x86 hoping that it might narrow down the issue but it also failed in the same way.

Does anyone know more about why this only works 10-20% of the time?

Thank you. :)

 

  • Solution
Posted

There is many issues within the code of the example you cited.
Let start with the trivial (no impact) ones :

; Set ANSI format
;~     _GUICtrlToolbar_SetUnicodeFormat($hToolbar, False)

 You cannot use ANSI characters since _WinAPI_CreateWindowEx uses "wstr", so even if this part is commented, it is misleading

; Add standard system bitmaps
    Switch _GUICtrlToolbar_GetBitmapFlags($hToolbar)
        Case 0
            _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_SMALL_COLOR)
        Case 2
            _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)
    EndSwitch

The only valid returned values of this function is 0 or 1.  2 is not possible.

MsgBox($MB_SYSTEMMODAL, "Information", "ToolTip handle .: 0x" & Hex(_GUICtrlToolbar_GetToolTips($hToolbar)))

As you can notice, the returned value of the function is sometimes 0 (no tooltip).

Now the most important part is that when you manually create a separate tooltip control via tooltips_class32, the toolbar doesn't correctly wire up its button notifications.  So you should let the toolbar manage itself its tooltips by specifying the style $TBSTYLE_TOOLTIPS.

This example works flawlessly (at least for me)...

; From Nine

#include <GUIConstantsEx.au3>
#include <GuiToolbar.au3>
#include <GuiToolTip.au3>
#include <WinAPIConstants.au3>
#include <WinAPIConstants.au3>
#include <WindowsNotifsConstants.au3>

Opt("MustDeclareVars", True)

Global Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idHelp

Example()

Func Example()
  Local $hGUI = GUICreate("Toolbar Get/Set ToolTips (v" & @AutoItVersion & ")", 400, 300)
  Local $hToolbar = _GUICtrlToolbar_Create($hGUI, $TBSTYLE_FLAT + $TBSTYLE_TOOLTIPS)
  GUISetState()

  Local $hToolTip = _GUICtrlToolbar_GetToolTips($hToolbar)
  ConsoleWrite("Tooltip " & $hToolTip & @CRLF)

  Switch _GUICtrlToolbar_GetBitmapFlags($hToolbar)
    Case 0
      _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_SMALL_COLOR)
    Case 1
      _GUICtrlToolbar_AddBitmap($hToolbar, 1, -1, $IDB_STD_LARGE_COLOR)
  EndSwitch

  _GUICtrlToolbar_AddButton($hToolbar, $e_idNew, $STD_FILENEW)
  _GUICtrlToolbar_AddButton($hToolbar, $e_idOpen, $STD_FILEOPEN)
  _GUICtrlToolbar_AddButton($hToolbar, $e_idSave, $STD_FILESAVE)
  _GUICtrlToolbar_AddButtonSep($hToolbar)
  _GUICtrlToolbar_AddButton($hToolbar, $e_idHelp, $STD_HELP)

  GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY)

  Do
  Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

; Handle WM_NOTIFY messages
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
  Local $tInfo = DllStructCreate($tagNMTTDISPINFO, $lParam)
  If $tInfo.Code = $TTN_GETDISPINFOW Then
    Switch $tInfo.IDFrom
      Case $e_idNew
        $tInfo.aText = "New"
      Case $e_idOpen
        $tInfo.aText = "Open"
      Case $e_idSave
        $tInfo.aText = "Save"
      Case $e_idHelp
        $tInfo.aText = "Help"
    EndSwitch
  EndIf
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Posted
1 hour ago, Nine said:

Now the most important part is that when you manually create a separate tooltip control via tooltips_class32, the toolbar doesn't correctly wire up its button notifications.  So you should let the toolbar manage itself its tooltips by specifying the style $TBSTYLE_TOOLTIPS.

Excellent point. Your suggestion makes perfect sense.

1 hour ago, Nine said:

This example works flawlessly (at least for me)...

I can confirm this as well. It works consistently and properly every time. Your method also allows me to successfully apply dark theme to the tooltips. Some of the other methods for toolbar tooltips did not allow the dark theme to stay applied.

Thank you for being gracious with your time and sharing your knowledge. I always appreciate it. 

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
×
×
  • Create New...