0

I was trying to create a program that would use multiple tooltips, but I came across a problem: I can only use one at a time, because after that, the new one will replace the previous.

I came up with a solution: Compile a program that creates a tooltip and use it as much as needed. But then there is another problem: I want the tooltips in different positions and with different texts/titles.

To do that I need to use parameters or other types of variables that would change the coordinates and text of the tooltip.

My called exe would perform something very simple like:

ToolTip($text, $x, $y, $title, 0, 1 + 4)
Sleep(10000)

There is probably a quicker/easier way to do it.

1
  • Why not creating little GUIs? Then you can place them wherever you want them. Commented Jul 25, 2013 at 14:37

1 Answer 1

2

The easiest way to do this is to make use of the /AutoIt3ExecuteLine command line option, which allows you to run 1 line of code from the command line. At its simplest you could implement it like this:

_ShowAnotherTooltip(1000, "Hello", 100, 100)
_ShowAnotherTooltip(1000, "World", 200, 200)


Func _ShowAnotherTooltip($time, $text, $x = Default, $y = Default, $title = "", $icon = Default, $options = Default)
    Local $cmd = StringFormat("ToolTip(%s,%s,%s,%s,%s)", "'" & $text & "'", $x, $y, "'" & $title & "'", $icon, $options)

    Run("""" & @AutoItExe & """ /AutoIt3ExecuteLine ""Sleep(" & $cmd & "*0+" & $time & ")""")
EndFunc   ;==>_ShowAnotherTooltip

Only real trickery here is getting the tooltip and sleep on one line. The code generated will look something like:

Sleep(ToolTip('Hello', 100, 100, '', Default, Default)*0+1000)

Depending on how good your computer is, you will probably see a noticeable delay between the two tooltips showing. If you want to have them all show at the same time then the code gets a bit more complicated:

If $CmdLine[0] And $CmdLine[1] = "/ExecuteLine" Then
    ; This is the child script

    ; Wait for the window to appear
    WinWait($CmdLine[2])

    ; Then execute the line.
    Execute($CmdLine[3])

    Exit
EndIf

_AddAnotherTooltip(1000, "Hello", 100, 100)
_AddAnotherTooltip(1000, "World", 200, 200)

_ShowTheTooltips()



Func _ShowTheTooltips()
    GUICreate("ShowThoseTooltipsNow")
    Sleep(1000)
EndFunc   ;==>_ShowTheTooltips

Func _AddAnotherTooltip($time, $text, $x = Default, $y = Default, $title = "", $icon = Default, $options = Default)
    Local $cmd = StringFormat("ToolTip(%s,%s,%s,%s,%s)", "'" & $text & "'", $x, $y, "'" & $title & "'", $icon, $options)

    Local $iPid
    If @Compiled Then
        $iPid = Run("""" & @AutoItExe & """ /ExecuteLine ShowThoseTooltipsNow ""Sleep(" & $cmd & "*0+" & $time & ")""")
    Else
        $iPid = Run("""" & @AutoItExe & """ """ & @ScriptFullPath & """ /ExecuteLine ShowThoseTooltipsNow ""Sleep(" & $cmd & "*0+" & $time & ")""")
    EndIf

    ProcessWait($iPid)
EndFunc   ;==>_AddAnotherTooltip

There are better methods of interprocess communication but this one is very simple.

Finally, there is probably a better way to do it using the GUITooltip* functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.