Jump to content

First time GUI Problem


Recommended Posts

Hi,

I'm new to Autoit, and I'm trying to create a GUI.

The main have 2 buttons (CTE and EXIT). The Exit will works at that point.

If I click on the CTE button, a new GUI "Enter Data" will open with 4 inputs. At that point all the buttons will stop working (OK, Cancel, and the EXIT)

See code below. Any help from you guys will be more then appreciate. Thank you in advance

#include <GUIConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Opt("GUIOnEventMode", 1)

Global $g_idExit

_Main()

FUNC _Main()

 Global $GUI1 = GUICreate("Template", 450, 150, 1300, 900)
 $idPM11031 = GUICtrlCreateButton("CTE", 10, 30, 100, 30)
 GUICtrlSetOnEvent($idPM11031, "PM11031")
 $g_idExit = GUICtrlCreateButton("Exit", 120, 90, 100, 30)
 GUICtrlSetOnEvent($g_idExit, "OnExit")
 GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")
 GUISetState() ; display the GUI


 While 1
  Sleep(1000)
 WEnd
 
Exit 

EndFunc   ;==>_Main


Func PM11031()
 $UserData=_InputBox("Enter Data")
 Run("notepad.exe")
 WinWaitActive("Untitled - Notepad")
 Send("data 1 is: " & $UserData[0] & "data 2 is: " & $UserData[1] & "data 3 is: " & $UserData[2] & "data 4 is: " & $UserData[3]  & ".")
 Send("{ENTER}")
EndFunc;


Func _InputBox($Title)
  Dim $data[4]
  Local $GUI2 = GUICreate($Title, 256, 509, 314, 374)
  Local $Input1 = GUICtrlCreateInput("", 19, 40, 213, 21)
  Local $Input2 = GUICtrlCreateInput("", 19, 102, 213, 21)
  Local $Input3 = GUICtrlCreateInput("", 19, 164, 213, 21)
  Local $Input4 = GUICtrlCreateInput("", 19, 228, 213, 21)
  GUICtrlCreateLabel("Data1", 18, 18, 180, 17)
  GUICtrlCreateLabel("Data2", 20, 80, 150, 17)
  GUICtrlCreateLabel("Data3", 20, 142, 150, 17)
  GUICtrlCreateLabel("Data4 ", 20, 204, 200, 17)
  $Button1 = GUICtrlCreateButton("OK", 18, 458, 101, 29, $BS_DEFPUSHBUTTON)
  $Button2 = GUICtrlCreateButton("Cancel", 126, 458, 101, 29, 0)
  GUISetState(@SW_SHOW)
  
   While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
     Case $GUI_EVENT_CLOSE
      Exit
      ;SetError(1)
      ExitLoop
     Case $Button1
      $data[0]=GUICtrlRead($Input1)
      $data[1]=GUICtrlRead($Input2)
      $data[2]=GUICtrlRead($Input3)
      $data[3]=GUICtrlRead($Input4)
      ExitLoop       
     Case $Button2
      Exit
      ;SetError(1)
      ExitLoop
    EndSwitch
   WEnd
   GUIDelete()
   If not @error Then Return $data

EndFunc
 


Func OnExit()
 Exit
EndFunc

 

Edited by JLogan3o13
Link to comment
Share on other sites

  • Moderators

@Fadi please create your own posts if you have a question, rather than commandeering someone else's.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

So why would you post this same question a second time?? Stick to one thread per topic please.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

This is your thread, I split it from the other one. Stick to this thread to get your question answered...

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

You can't use GuiGetMsg when you're using OnEvent mode, just use Event handlers for the new GUI, or turn off OnEvent mode going into the function, and turning it back on after you're done in it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

@Fadi we have a great Wiki. This entry will show you the difference between MessageLoop and OnEventMode. I would suggest you do some reading.

https://www.autoitscript.com/wiki/Managing_Multiple_GUIs

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Something like this is how I'd do it.

#include <GUIConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Opt("GUIOnEventMode", 1)

Global $g_idExit

_Main()

Func _Main()

     Global $GUI1 = GUICreate("Template", 450, 150)
     $idPM11031 = GUICtrlCreateButton("CTE", 10, 30, 100, 30)
     GUICtrlSetOnEvent($idPM11031, "PM11031")
     $g_idExit = GUICtrlCreateButton("Exit", 120, 90, 100, 30)
     GUICtrlSetOnEvent($g_idExit, "OnExit")
     GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")
     GUISetState() ; display the GUI


     While 1
          Sleep(10)
     WEnd

     Exit

EndFunc   ;==>_Main


Func PM11031()
     $UserData = _InputBox("Enter Data")
     Run("notepad.exe")
     WinWaitActive("Untitled - Notepad")
     Send("data 1 is: " & $UserData[0] & "data 2 is: " & $UserData[1] & "data 3 is: " & $UserData[2] & "data 4 is: " & $UserData[3] & ".")
     Send("{ENTER}")
EndFunc   ;==>PM11031


Func _InputBox($Title)
     Dim $data[4]
     Local $GUI2 = GUICreate($Title, 256, 509, 314, 374)
     Local $Input1 = GUICtrlCreateInput("", 19, 40, 213, 21)
     Local $Input2 = GUICtrlCreateInput("", 19, 102, 213, 21)
     Local $Input3 = GUICtrlCreateInput("", 19, 164, 213, 21)
     Local $Input4 = GUICtrlCreateInput("", 19, 228, 213, 21)
     GUICtrlCreateLabel("Data1", 18, 18, 180, 17)
     GUICtrlCreateLabel("Data2", 20, 80, 150, 17)
     GUICtrlCreateLabel("Data3", 20, 142, 150, 17)
     GUICtrlCreateLabel("Data4 ", 20, 204, 200, 17)
     $Button1 = GUICtrlCreateButton("OK", 18, 458, 101, 29, $BS_DEFPUSHBUTTON)
     $Button2 = GUICtrlCreateButton("Cancel", 126, 458, 101, 29, 0)
     GUISetState(@SW_SHOW)
     Opt("GUIOnEventMode", 0)

     While 1
          $nMsg = GUIGetMsg()
          Switch $nMsg
               Case $GUI_EVENT_CLOSE
;~                     Exit
                    ;SetError(1)
                    ExitLoop
               Case $Button1
                    $data[0] = GUICtrlRead($Input1)
                    $data[1] = GUICtrlRead($Input2)
                    $data[2] = GUICtrlRead($Input3)
                    $data[3] = GUICtrlRead($Input4)
                    ExitLoop
               Case $Button2
;~                     Exit
                    ;SetError(1)
                    ExitLoop
          EndSwitch
     WEnd
     Opt("GUIOnEventMode", 1)
     GUIDelete($GUI2)
     If Not @error Then Return $data

EndFunc   ;==>_InputBox



Func OnExit()
     Exit
EndFunc   ;==>OnExit

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Another question:

Now if I hit the cancel on GUI2, it will call the notepad and use and empty data.

How can I do, so if I hit the Cancel on the GUI2, it I will close the Gui2, and don't return the data, and keep the GUI1 open (not closing the script)

 

Link to comment
Share on other sites

You can do it like this, also gives your function some error checking to see why it's coming back blank.

The message boxes are only for demonstration purposes, you can put whatever you'd like in their place.

#include <GUIConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Opt("GUIOnEventMode", 1)

Global $g_idExit

_Main()

Func _Main()

     Global $GUI1 = GUICreate("Template", 450, 150)
     $idPM11031 = GUICtrlCreateButton("CTE", 10, 30, 100, 30)
     GUICtrlSetOnEvent($idPM11031, "PM11031")
     $g_idExit = GUICtrlCreateButton("Exit", 120, 90, 100, 30)
     GUICtrlSetOnEvent($g_idExit, "OnExit")
     GUISetOnEvent($GUI_EVENT_CLOSE, "OnExit")
     GUISetState() ; display the GUI


     While 1
          Sleep(10)
     WEnd

     Exit

EndFunc   ;==>_Main


Func PM11031()
     $UserData = _InputBox("Enter Data")
     Switch @error
          Case 0
               Run("notepad.exe")
               WinWaitActive("Untitled - Notepad")
               Send("data 1 is: " & $UserData[0] & "data 2 is: " & $UserData[1] & "data 3 is: " & $UserData[2] & "data 4 is: " & $UserData[3] & ".")
               Send("{ENTER}")
          Case 1
               MsgBox($MB_SYSTEMMODAL, "Closed", "User closed GUI")
          Case 2
               MsgBox($MB_SYSTEMMODAL, "Cancelled", "User hit Cancel")
     EndSwitch
EndFunc   ;==>PM11031


Func _InputBox($Title)
     Dim $data[4]
     Local $GUI2 = GUICreate($Title, 256, 509, 314, 374)
     Local $Input1 = GUICtrlCreateInput("", 19, 40, 213, 21)
     Local $Input2 = GUICtrlCreateInput("", 19, 102, 213, 21)
     Local $Input3 = GUICtrlCreateInput("", 19, 164, 213, 21)
     Local $Input4 = GUICtrlCreateInput("", 19, 228, 213, 21)
     Local $SetError = 0
     GUICtrlCreateLabel("Data1", 18, 18, 180, 17)
     GUICtrlCreateLabel("Data2", 20, 80, 150, 17)
     GUICtrlCreateLabel("Data3", 20, 142, 150, 17)
     GUICtrlCreateLabel("Data4 ", 20, 204, 200, 17)
     $Button1 = GUICtrlCreateButton("OK", 18, 458, 101, 29, $BS_DEFPUSHBUTTON)
     $Button2 = GUICtrlCreateButton("Cancel", 126, 458, 101, 29, 0)
     GUISetState(@SW_SHOW)
     Opt("GUIOnEventMode", 0)

     While 1
          $nMsg = GUIGetMsg()
          Switch $nMsg
               Case $GUI_EVENT_CLOSE
;~                     Exit
                    $SetError = 1
                    ExitLoop
               Case $Button1
                    $data[0] = GUICtrlRead($Input1)
                    $data[1] = GUICtrlRead($Input2)
                    $data[2] = GUICtrlRead($Input3)
                    $data[3] = GUICtrlRead($Input4)
                    $SetError = 0
                    ExitLoop
               Case $Button2
;~                     Exit
                    $SetError = 2
                    ExitLoop
          EndSwitch
     WEnd
     Opt("GUIOnEventMode", 1)
     GUIDelete($GUI2)
     Return SetError($SetError, 0, $data)
EndFunc   ;==>_InputBox



Func OnExit()
     Exit
EndFunc   ;==>OnExit

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...