Jump to content

Tooltip wrapper to keep it on screen.


Recommended Posts

I've just given Jon a change to simplify the tooltip code and it also means that tooltip's no longer stay on-screen like they did in recent unstables. Here's a script that wraps ToolTip() to provide that functionality using an all-AutoIt method.

Func _ToolTip($t, $x, $y)
    Local $opt = Opt("WinTitleMatchMode", 4)   ; Store the old setting
    If $__m_hToolTip = "" Then; Create a tooltip to get the HWND
        Local $text = "A line of random text: " & Int(Random(1000, 10000))
        ToolTip($text, 10000, 10000); Create way off screen so it can't be seen.
        $__m_hToolTip = "handle=" & WinGetHandle($text)
    Local $pos = WinGetPos($__m_hToolTip)
    If Not @error Then
        ToolTip($t, $pos[0], $pos[1])   ; This helps cut down on flicker
        Local $width = $pos[2], $height = $pos[3]   ; Convenient names
       ; Adjust the x position if necessary
        If $width >= @DesktopWidth Or $x < 0 Then
            $x = 0
        ElseIf $x + $width > @DesktopWidth Then 
            $x = @DesktopWidth - $width
       ; Adjust the y position if necessary
        If $height >= @DesktopHeight Or $y < 0 Then
            $y = 0
        ElseIf $y + $height > @DesktopHeight Then
            $y = @DesktopHeight - $height
    ToolTip($t, $x, $y)   ; Should be the final display
    Opt("WinTitleMatchMode", $opt)   ; Restore the setting
EndFunc   ; _ToolTip()
Link to comment
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...