Programowanie nie musi być trudne!
A więc nasze GUI już istnieje lecz przyciski nie działają rada na to jest bardzo łatwa Nasz cały skrypt wygląda tak:
#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 447, 175, 305, 200) GUICtrlCreateLabel("To moje pierwsze GUI!", 160, 32, 111, 17) $Button1 = GUICtrlCreateButton("Czekaj 10 sekund", 0, 112, 99, 25) $Button2 = GUICtrlCreateButton("Czekaj 20 sekund", 144, 112, 99, 25) $Button3 = GUICtrlCreateButton("Wyłącz", 312, 112, 115, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
Ale nam będzie w tym przypadku chodziło tylko i wyłącznie o skrypt na samym dole. Właśnie o ten:
While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
My musimy to po prostu mówiąc rozbudować.
Ten fragment oznacza przycisk "X" na pasku u góry programu:
Case $GUI_EVENT_CLOSE
Natomiast to jest czynność jaką ma wykonać:
Exit
Tak więc ten cały fragment musimy rozbudować o czekanie kolejno 10 sekund, 20 sekund i wyłączenie.
Tak więc ten fragment z funkcją przycisku "Zaczekaj 10 sekund" będzie wyglądał tak:
While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Sleep(10000) Exit EndSwitch WEnd
A dodane zostało:
Case $Button1 Sleep(10000) Exit
Case $Button1 - oznacza wybrany przycisk w tej chwili od 1 do 3
Sleep(10000) - oznacza to poprostu "Poczekaj 10 sekund" (czas w nawiasie w minisekundach)
Exit - wyłącz
Teraz wiecie już wszystko. Na sam koniec daje pełen skrypt ze wszystkimi działającymi przyciskami:).
#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 447, 175, 305, 200) GUICtrlCreateLabel("To moje pierwsze GUI!", 160, 32, 111, 17) $Button1 = GUICtrlCreateButton("Czekaj 10 sekund", 0, 112, 99, 25) $Button2 = GUICtrlCreateButton("Czekaj 20 sekund", 144, 112, 99, 25) $Button3 = GUICtrlCreateButton("Wyłącz", 312, 112, 115, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 Sleep(10000) Exit Case $Button2 Sleep(20000) Exit Case $Button3 Exit EndSwitch WEnd
Offline