-1

我正在努力寻找一个地方

$Password = GUICtrlRead($PasswordInput)

代替

Func BeginningGUI()
   #Region ### START Koda GUI section ### Form=
   $Form1 = GUICreate("Stronghold Kingdoms", 248, 95, -1, -1)
   $PasswordInput = GUICtrlCreateInput("Password", 8, 32, 233, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
   $ButtonOk = GUICtrlCreateButton("OK", 86, 64, 75, 25, $BS_NOTIFY)
   $ButtonCancel = GUICtrlCreateButton("Cancel", 167, 64, 75, 25, $BS_NOTIFY)
   $EnterPassLabel = GUICtrlCreateLabel("Please Enter Your Stronghold Kingdoms Password", 0, 12, 241, 17, 0)
   GUISetState(@SW_SHOW)
   #EndRegion ### END Koda GUI section ###

   While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
     Case $GUI_EVENT_CLOSE
        Exit
     Case $ButtonCancel
        Exit
     Case $ButtonOk
        OpenSHK()
        Exit
  EndSwitch
   WEnd
EndFunc

Func OpenSHK()
   Run("C:\Program Files (x86)\Firefly Studios\Stronghold Kingdoms\StrongholdKingdoms.exe")
   WinWaitActive("Stronghold Kingdoms")
   Sleep(5000)
   Send($Password)
   MouseClick("left",927,163)
   Sleep(5000)
   MouseClick("left",1112,371)
   WinWaitActive("Stronghold Kingdoms - World 8")
   sleep(10000)
EndFunc

我只需要将他们输入的内容声明为 $Password 以供以后使用。

我尝试将它放在 Case $ButtonOk 下面,但它给出了关于未声明变量的错误。

4

1 回答 1

0

在单击 $ButtonOK 之后,在调用之前将其放置OpenSHK()

Func BeginningGUI()
  GLOBAL $Password
  ...
  $nMsg = GUIGetMsg()
  Switch $nMsg
     Case $GUI_EVENT_CLOSE
        Exit
     Case $ButtonCancel
        Exit
     Case $ButtonOk
        $Password = GUICtrlRead($PasswordInput)            
        OpenSHK()
        Exit
  EndSwitch
   WEnd
EndFunc

您需要首先声明$Password变量(就像我GLOBAL在函数代码开头所做的那样),或者修改您的OpenSHK()函数以将其作为参数接受,如OpenSHK($Password). 在第二种情况下,您可以简单地LOCAL $Passenger在函数的开头添加BeginningGUI而不是GLOBAL.

Func BeginningGUI()
  LOCAL $Password
  ...
  $nMsg = GUIGetMsg()
  Switch $nMsg
     Case $GUI_EVENT_CLOSE
        Exit
     Case $ButtonCancel
        Exit
     Case $ButtonOk
        $Password = GUICtrlRead($PasswordInput)            
        OpenSHK($Password)
        Exit
  EndSwitch
   WEnd
EndFunc

Func OpenSHK($Password)
   Run("C:\Program Files (x86)\Firefly Studios\Stronghold Kingdoms\StrongholdKingdoms.exe")
   WinWaitActive("Stronghold Kingdoms")
   Sleep(5000)
   Send($Password)
   MouseClick("left",927,163)
   Sleep(5000)
   MouseClick("left",1112,371)
   WinWaitActive("Stronghold Kingdoms - World 8")
   sleep(10000)
EndFunc
于 2013-05-25T22:58:31.590 回答