Search the Community
Showing results for tags 'gui onevent for-loop'.
-
Is there a way to create a GUI in a for-loop? As in: I have a program which asks the user for passwords if the email is unknown. For each account that is not known, I want a GUI to be created that prompts the user for the password. After user clicks the 'OK' button on the GUI, the password is written to a file, and program continues with the next account. Something like this (I AM aware that code below doesn't work): #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1) Global $accounts_file = "accountz.ini" Global $gui_pw, $label_pw, $input_pw, $button_pw_enter Func _GUIAskPasswordButtonClick() Local $password = GUICtrlRead($input_pw) Switch @GUI_CtrlId Case $button_pw_enter If ($password <> "") Then IniWrite($accounts_file, GUICtrlRead($label_pw), "Password", $password) GUIDelete($gui_pw) Else MsgBox(16, "Error", "Please type password:") GUICtrlSetData($input_pw, "") GUICtrlSetState($input_pw, $GUI_FOCUS) EndIf EndSwitch EndFunc Func _Exit() Exit EndFunc Func GUIAskPassword($login) $gui_pw = GUICreate("Account unknown", 395, 180) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUICtrlCreateGroup("", 70, 50, 300, 80) GUICtrlCreateLabel("Login:", 85, 70, 75, 20) $label_pw = GUICtrlCreateLabel($login, 170, 70, 175, 20) GUICtrlCreateLabel("Password:", 85, 95, 75, 20) $input_pw = GUICtrlCreateInput("", 170, 95, 175, 20, $ES_PASSWORD) GUICtrlSetState(-1, $GUI_FOCUS) $button_pw_enter = GUICtrlCreateButton("&OK", 163, 145, 75, 25, $BS_DEFPUSHBUTTON) GUICtrlSetOnEvent(-1, "_GUIAskPasswordButtonClick") GUISetState(@SW_SHOW, $gui_pw) EndFunc Dim $accounts[3] = ["first@email.com", "second@email.com", "third@email.com"] For $i = 0 To Ubound($accounts) - 1 GUIAskPassword($accounts[$i]) Next While 1 Sleep(10) WEnd This piece of code is simplified. In my program this GUI is a child window and the number of accounts can vary. ONEVEnt mode is obligatory My script doesn't work because it puts all 3 GUI's in the same variable $gui_pw, so things are messed up big time: the first GUIs can't be closed. How do I wait until the user has clicked the OK button before creating the next GUI? Is there an easier and better way to do this? The only thing I came up with now, is to switch to messageloop mode and back to onevent mode after completing my function...but that is soooo ugly Any ideas?