|
- Programowo http://www.programowo.pun.pl/index.php - Pisanie pierwszych programów http://www.programowo.pun.pl/viewforum.php?id=15 - #Lekcja 3: Działanie przycisków naszego GUI. http://www.programowo.pun.pl/viewtopic.php?id=8 |
| MikiMaJe - 2013-06-13 16:49:57 |
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: Kod:#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
WEndAle nam będzie w tym przypadku chodziło tylko i wyłącznie o skrypt na samym dole. Właśnie o ten: Kod:While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEndMy musimy to po prostu mówiąc rozbudować. Kod:Case $GUI_EVENT_CLOSE Natomiast to jest czynność jaką ma wykonać: Kod:Exit Tak więc ten cały fragment musimy rozbudować o czekanie kolejno 10 sekund, 20 sekund i wyłączenie. Kod:While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Sleep(10000)
Exit
EndSwitch
WEndA dodane zostało: Kod:Case $Button1
Sleep(10000)
ExitCase $Button1 - oznacza wybrany przycisk w tej chwili od 1 do 3 Kod:#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 |