在 AutoIt 中使用 switch case 中的循环。

huangapple go评论53阅读模式
英文:

loop use in switch case autoit

问题

我有成千上万个小工具,我试图使用AutoIt创建一个菜单。我必须定义成千上万个函数、案例和变量,如何能够更容易地实现呢?
以下是我的代码,如何使用循环来选择案例并运行 soft.exe。

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("MainMenu", 615, 437, 192, 124)

$Soft1 = GUICtrlCreateButton("Button1", -8, 0, 75, 25)
$Soft2 = GUICtrlCreateButton("Button2", -18, 10, 75, 25)
$Soft3 = GUICtrlCreateButton("Button3", -28, 20, 75, 25)
$Soft4 = GUICtrlCreateButton("Button4", -38, 30, 75, 25)
$Soft5 = GUICtrlCreateButton("Button5", -48, 40, 75, 25)
$Soft6 = GUICtrlCreateButton("Button6", -58, 50, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Soft1
            Startsoft1()
        Case $Soft2
            Startsoft2()
        Case $Soft3
            Startsoft3()
        Case $Soft4
            Startsoft4()
        Case $Soft5
            Startsoft5()
        Case $Soft6
            Startsoft6()
    EndSwitch
WEnd

Func Startsoft1()
    Run('Soft1.exe')
EndFunc

Func Startsoft2()
    Run('Soft2.exe')
EndFunc

Func Startsoft3()
    Run('Soft3.exe')
EndFunc

Func Startsoft4()
    Run('Soft4.exe')
EndFunc

Func Startsoft5()
    Run('Soft5.exe')
EndFunc

我是编程新手,因此正在学习新的东西。

英文:

I have a thousands mini tools, I am trying to create a menu by using Autuit. I have to define thousand functions and case and variable how i can make it easy.
here is my code how can use loop for select case and run soft.exe

#include &lt;ButtonConstants.au3&gt;
#include &lt;GUIConstantsEx.au3&gt;
#include &lt;WindowsConstants.au3&gt;

$Form1 = GUICreate(&quot;MainMenu&quot;, 615, 437, 192, 124)

$Soft1 = GUICtrlCreateButton(&quot;Button1&quot;, -8, 0, 75, 25)
$Soft2 = GUICtrlCreateButton(&quot;Button2&quot;, -18, 10, 75, 25)
$Soft3 = GUICtrlCreateButton(&quot;Button3&quot;, -28, 20, 75, 25)
$Soft4 = GUICtrlCreateButton(&quot;Button4&quot;, -38, 30, 75, 25)
$Soft5 = GUICtrlCreateButton(&quot;Button5&quot;, -48, 40, 75, 25)
$Soft6 = GUICtrlCreateButton(&quot;Button6&quot;, -58, 50, 75, 25)
GUISetState(@SW_SHOW)


While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Soft1
		Startsoft1()

		Case $Soft2
		Startsoft2()

		Case $Soft3
		Startsoft3()

		Case $Soft4
		Startsoft4()

		Case $Soft5
		Startsoft5()

		Case $Soft6
		Startsoft6()
	EndSwitch
WEnd

Func  Startsoft1()
	Run(&#39;Soft1.exe&#39;)
EndFunc

Func  Startsoft2()
	Run(&#39;Soft2.exe&#39;)
EndFunc

Func  Startsoft3()
	Run(&#39;Soft3.exe&#39;)
EndFunc

Func  Startsoft4()
	Run(&#39;Soft4.exe&#39;)
EndFunc

Func  Startsoft5()
	Run(&#39;Soft5.exe&#39;)
EndFunc


iam new in programing there for learning new things

答案1

得分: 1

尝试这样作为一个很好的起点。在StringSplit方法的字符串中放置名称和路径。如果按钮到达GUI宽度末端,GUI按钮会自动放置在新行。

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

main()

Func main()
    Local $gui_width = @DesktopWidth -100, $gui_height = @DesktopHeight - 80
    Local $Form1 = GUICreate("MainMenu", $gui_width, $gui_height, 50, 10)

    Local $exesName_A = StringSplit('a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe,a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe', ',', 2)
    Local $exesPath_A = StringSplit('a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe,a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe', ',', 2)
    Local $height = 45, $width = 125, $y = 0, $x = 0
    Local $button_A[UBound($exesName_A)]

    For $i = 0 To UBound($exesName_A) - 1
        If (8 + ($x + 1) * $width) > $gui_width Then
            $y += 1
            $x = 0
        EndIf

        $button_A[$i] = GUICtrlCreateButton($exesName_A[$i], 8 + $x * $width, 10 + $y * $height, 75, $height)
        GUICtrlSetImage(-1, "shell32.dll", 22+ $i)
        $x += 1
    Next

    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
        EndSwitch
        ; 扫描所有按钮以检查是否有按钮被按下
        For $i = 0 To UBound($button_A) - 1
            If $nMsg = $button_A[$i] Then
                ConsoleWrite('现在运行exe文件' & $exesPath_A[$i] & @CRLF)
                ;~ ShellExecute($exesPath_A[$i], '') ; 取消注释以运行exe文件
            EndIf
        Next
    WEnd
EndFunc   ;==>main
英文:

Try something like this as a good starting point.
Put the names and pathes in the strings of the method StringSplit.
The GUI buttons are automatically placed in a new line if the button reaches the GUI width end.

#include &lt;ButtonConstants.au3&gt;
#include &lt;GUIConstantsEx.au3&gt;
#include &lt;WindowsConstants.au3&gt;

main()

Func main()
	Local $gui_width = @DesktopWidth -100, $gui_height = @DesktopHeight - 80
	Local $Form1 = GUICreate(&quot;MainMenu&quot;, $gui_width, $gui_height, 50, 10)

	Local $exesName_A = StringSplit(&#39;a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe,a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe&#39;, &#39;,&#39;, 2)
	Local $exesPath_A = StringSplit(&#39;a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe,a.exe,b.exe,c.exe,d.exe,e.exe,f.exe,g.exe,h.exe,i.exe,j.exe,k.exe,l.exe,m.exe,n.exe,o.exe&#39;, &#39;,&#39;, 2)
	Local $height = 45, $width = 125, $y = 0, $x = 0
	Local $button_A[UBound($exesName_A)]

	For $i = 0 To UBound($exesName_A) - 1
		If ((8 + ($x + 1) * $width) &gt; $gui_width) Then
			$y += 1
			$x = 0
		EndIf

		$button_A[$i] = GUICtrlCreateButton($exesName_A[$i], 8 + $x * $width, 10 + $y * $height, 75, $height)
		GUICtrlSetImage(-1, &quot;shell32.dll&quot;, 22+ $i)
		$x += 1
	Next

	GUISetState(@SW_SHOW)

	While 1
		$nMsg = GUIGetMsg()
		Switch $nMsg
			Case $GUI_EVENT_CLOSE
				Exit

		EndSwitch
		; scan all buttons to check if one was pressed
		For $i = 0 To UBound($button_A) - 1
			If $nMsg = $button_A[$i] Then
				ConsoleWrite(&#39;Now run the exe&#39; &amp; $exesPath_A[$i] &amp; @CRLF)
;~ 			ShellExecute($exesPath_A[$i], &#39;&#39;) ; uncomment this to run the exe
			EndIf
		Next
	WEnd

EndFunc   ;==&gt;main

huangapple
  • 本文由 发表于 2023年2月7日 01:00:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75364355.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定