Jump to content

Second GUI not calling functions


Recommended Posts

Hi all,

I'm sure the solution is obvious, but after my Helpfile-fu, Google-fu, Forum-fu and FAQ-fu failed me and hours of fiddling, I need a fresh pair of eyes to help.

The first GUI in this script loads, and when you press on the first button loads another GUI in the function Autobench. But this second GUI doesn't respond to any button presses. Any pointers to getting the buttons to respond would be greatly appreciated.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)
#RequireAdmin

$MachineField = 0

$FormMainGUI = GUICreate("Benchmarks", 450, 150, (@Desktopwidth/2)-225, (@DesktopHeight/2)-250)
$btnAutomated = GuiCtrlCreateButton("Deploy and run automated benchmarks",75,40,300,41)
$btnExitGui = GUICtrlCreateButton("Exit", 186, 100, 75, 25, 0)

GUISetState(@SW_SHOW,$FormMainGUI)

GUISetOnEvent($GUI_EVENT_CLOSE,"CloseGui",$FormMainGUI)
GUICtrlSetOnEvent($btnExitGui,"CloseGui")
GUICtrlSetOnEvent($btnAutomated,"AutoBench")

WinWaitClose("Benchmarks")


;**************************************************
;Functions

Func AutoBench()
    GUIDelete($FormMainGUI)

    $MachineNameGUI = GUICreate("Machine name",450,150,(@DesktopWidth/2)-225, (@DesktopHeight/2)-150)
    $MachineFieldlbl = GUICtrlCreateLabel("Please enter the machine name (brand/model, e.g. Apple MacBook Pro 13",10,10)
    $MachineField = GUICtrlCreateInput("",10,30)
    $MachineSaveBtn = GUICtrlCreateButton("Save",10,55,100,20)

    GuiSetState(@SW_SHOW,$MachineNameGUI)

    GUISetOnEvent($GUI_EVENT_CLOSE,"CloseGui",$MachineNameGUI)
    GUICtrlSetOnEvent($MachineSaveBtn,"MachineSaveBtn")

    WinWaitClose("Machine name")
EndFunc

Func MachineSaveBtn()
    GUICtrlRead($MachineField)
    MsgBox(0,"",$MachineField)
EndFunc


Func CloseGui()
    Exit
EndFunc

Much thanks!

Link to comment
Share on other sites

  • Moderators

unexpectedpanda,

You need to have an idle loop in the main portion of the script where it can wait for you to action the controls. At the moment you are just waiting at the WinWaitClose("Machine name") line and, as you are still in a function, AutoIt just queues any further events - hence no reaction to them.

Remove the 2 WinWaitClose lines and substitute this for the WinWaitClose("Benchmarks") line:

While 1
    Sleep(10)
WEnd

Now the script will return to the main portion of the script after creating the second GUI and be waiting for you to action its controls. :P

Please ask if anything is unclear. :x

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Ah, so because it's in a function it's treated differently. Interesting! I look forward to playing around a bit more :x

Thanks so much for your kindness Melba23 -- I'd also like to thank you for all your other responses on this forum, they've saved me and no doubt many others a few times now.

Edited by unexpectedpanda
Link to comment
Share on other sites

  • Moderators

unexpectedpanda,

Thanks for the compliments. :x

You may find the Interrupting a running function and Managing Multiple GUIs tutorials in the Wiki of interest if you want to learn a little more about such things. :P

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...