2017-09-02 51 views
-1

一直試圖做一個GUI。我無法啓動GUI。它打開,但不會運行案件$Start啓動GUI

#include <ButtonConstants.au3> 
#include <EditConstants.au3> 
#include <GUIConstantsEx.au3> 
#include <StaticConstants.au3> 
#include <WindowsConstants.au3> 
#Region ### START Koda GUI section ### 
$Form1_1 = GUICreate("rss send", 274, 394, -1, -1) 
$Food = GUICtrlCreateInput("", 24, 88, 225, 21) 
$Marketmax = GUICtrlCreateLabel("Marketplace maximum", 24, 8, 109, 17) 
$Marketplace = GUICtrlCreateInput("", 24, 32, 225, 21) 
$Foodtext = GUICtrlCreateLabel("Food", 24, 64, 28, 17) 
$Woodtext = GUICtrlCreateLabel("Wood", 24, 120, 33, 17) 
$Wood = GUICtrlCreateInput("", 24, 144, 225, 21) 
$Irontext = GUICtrlCreateLabel("Iron", 24, 176, 22, 17) 
$Iron = GUICtrlCreateInput("", 24, 200, 225, 21) 
$Stonetext = GUICtrlCreateLabel("Stone", 24, 232, 32, 17) 
$Stone = GUICtrlCreateInput("", 24, 256, 225, 21) 
$Silvertext = GUICtrlCreateLabel("Silver", 24, 288, 30, 17) 
$Silver = GUICtrlCreateInput("", 24, 312, 225, 21) 
$Start = GUICtrlCreateButton("Start", 24, 344, 89, 33) 
$Exit = GUICtrlCreateButton("Exit", 152, 344, 89, 33) 
GUISetState(@SW_SHOW) 
#EndRegion ### END Koda GUI section ### 

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

     Case $Exit 
      Exit 

     Case $Start 
      func start() 
       for $1 = 1 to $Food/$Marketplace 
        MouseClickDrag("left",731,228,891,228,10) 
        sleep(2000) 
        MouseClick("left",1011,882) 
        sleep(2000) 
       next 
      EndFunc 
    EndSwitch 
WEnd 

回答

0

您可以使用GUISetOnEventHere是描述和示例。

你的情況:

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

Opt("GUIOnEventMode", 1) 

#Region ### START Koda GUI section ### Form=c:\users\regin\desktop\auto it\rss send.kxf 
$Form1_1 = GUICreate("rss send", 274, 394, -1, -1) 
GUISetOnEvent($GUI_EVENT_CLOSE, "Close") 
$Food = GUICtrlCreateInput("", 24, 88, 225, 21) 
$Marketmax = GUICtrlCreateLabel("Marketplace maximum", 24, 8, 109, 17) 
$Marketplace = GUICtrlCreateInput("", 24, 32, 225, 21) 
$Foodtext = GUICtrlCreateLabel("Food", 24, 64, 28, 17) 
$Woodtext = GUICtrlCreateLabel("Wood", 24, 120, 33, 17) 
$Wood = GUICtrlCreateInput("", 24, 144, 225, 21) 
$Irontext = GUICtrlCreateLabel("Iron", 24, 176, 22, 17) 
$Iron = GUICtrlCreateInput("", 24, 200, 225, 21) 
$Stonetext = GUICtrlCreateLabel("Stone", 24, 232, 32, 17) 
$Stone = GUICtrlCreateInput("", 24, 256, 225, 21) 
$Silvertext = GUICtrlCreateLabel("Silver", 24, 288, 30, 17) 
$Silver = GUICtrlCreateInput("", 24, 312, 225, 21) 
$Start = GUICtrlCreateButton("Start", 24, 344, 89, 33) 
GUICtrlSetOnEvent(-1, "Start") 
$Exit = GUICtrlCreateButton("Exit", 152, 344, 89, 33) 
GUICtrlSetOnEvent(-1, "Close") 
GUISetState(@SW_SHOW) 
#EndRegion ### END Koda GUI section ### 

While 1 
    sleep(100) 
WEnd 

Func Start() 
    consolewrite("Start Function" & @CRLF) 
    for $1 = 1 to $Food/$Marketplace 
     MouseClickDrag("left",731,228,891,228,10) 
     sleep(2000) 
     MouseClick("left",1011,882) 
     sleep(2000) 
    next 
EndFunc 

Func Close() 
    exit 
EndFunc 
+0

不錯。我改變了這個問題,所以現在所有的代碼都在那裏。 在代碼中我有一個開始按鈕,但我不能將你的代碼實現到我的,你能幫助嗎? – Lazybutcrazy

+0

你只需要從你的每個'case'語句中創建函數。看到我的答案。 – matrix

+0

在啓動功能中也會出現問題:如果您想使用輸入內容,您需要使用'GUICtrlRead'來讀取它。例如:$ Food_val = GuiCtrlRead($ Food)。在Start函數中使用$ Food_val。 – matrix

0

試試看吧。你不能在while循環中聲明函數。

#include <ButtonConstants.au3> 
#include <EditConstants.au3> 
#include <GUIConstantsEx.au3> 
#include <StaticConstants.au3> 
#include <WindowsConstants.au3> 
#Region ### START Koda GUI section ### 
$Form1_1 = GUICreate("rss send", 274, 394, -1, -1) 
$Food = GUICtrlCreateInput("", 24, 88, 225, 21) 
$Marketmax = GUICtrlCreateLabel("Marketplace maximum", 24, 8, 109, 17) 
$Marketplace = GUICtrlCreateInput("", 24, 32, 225, 21) 
$Foodtext = GUICtrlCreateLabel("Food", 24, 64, 28, 17) 
$Woodtext = GUICtrlCreateLabel("Wood", 24, 120, 33, 17) 
$Wood = GUICtrlCreateInput("", 24, 144, 225, 21) 
$Irontext = GUICtrlCreateLabel("Iron", 24, 176, 22, 17) 
$Iron = GUICtrlCreateInput("", 24, 200, 225, 21) 
$Stonetext = GUICtrlCreateLabel("Stone", 24, 232, 32, 17) 
$Stone = GUICtrlCreateInput("", 24, 256, 225, 21) 
$Silvertext = GUICtrlCreateLabel("Silver", 24, 288, 30, 17) 
$Silver = GUICtrlCreateInput("", 24, 312, 225, 21) 
$Start = GUICtrlCreateButton("Start", 24, 344, 89, 33) 
$Exit = GUICtrlCreateButton("Exit", 152, 344, 89, 33) 
GUISetState(@SW_SHOW) 
#EndRegion ### END Koda GUI section ### 

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

     Case $Exit 
      Exit 

     Case $Start 
      start() 

    EndSwitch 
WEnd 

Func start() 
    MsgBox(64, 'YES', 'JIHAA') 
;~     for $1 = 1 to $Food/$Marketplace 
;~      MouseClickDrag("left",731,228,891,228,10) 
;~      sleep(2000) 
;~      MouseClick("left",1011,882) 
;~      sleep(2000) 
;~ Next ;==>start 
EndFunc ;==>start