【问题标题】:Use AutoIt to call another AutoIt compiled executable with parameters使用 AutoIt 调用另一个带有参数的 AutoIt 编译的可执行文件
【发布时间】:2013-07-25 12:17:10
【问题描述】:

我试图创建一个可以使用多个工具提示的程序,但我遇到了一个问题:我一次只能使用一个,因为在那之后,新的将替换以前的。

我想出了一个解决方案:编译一个创建工具提示的程序,并根据需要尽可能多地使用它。但是还有另一个问题:我希望工具提示位于不同的位置和不同的文本/标题。

为此,我需要使用参数或其他类型的变量来改变工具提示的坐标和文本。

我调用的 exe 会执行一些非常简单的操作,例如:

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

可能有一种更快/更简单的方法。

【问题讨论】:

  • 为什么不创建小 GUI?然后你可以把它们放在你想要的任何地方。

标签: parameters tooltip parameter-passing executable autoit


【解决方案1】:

最简单的方法是使用/AutoIt3ExecuteLine 命令行选项,它允许您从命令行运行1 行代码。在最简单的情况下,您可以像这样实现它:

_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

这里唯一真正的诡计是让工具提示和睡眠在一行上。生成的代码如下所示:

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

根据您的计算机的性能,您可能会看到两个工具提示显示之间存在明显的延迟。如果你想让它们同时显示,那么代码会变得有点复杂:

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

有更好的进程间通信方法,但这个非常简单。

最后,使用 GUITooltip* 函数可能有更好的方法。

【讨论】:

    猜你喜欢
    • 2017-04-06
    • 1970-01-01
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 2016-04-23
    • 2011-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多