Jump to content

GUI window only works the first time.


kyle2727
 Share

Go to solution Solved by Melba23,

Recommended Posts

I'm working on a script that will run as long as someone is logged into the pc. It simply waits for a specific window to become active and then launches a window with several selections to choose from. These will be shortcuts to speed up the most used processes. It works without a problem the first time. After a selection is made the window is closed until that specific window becomes active again. When this happens the window pops up as it should but none of the buttons work, everything is unresponsive. I'm not sure what I'm missing here. 

#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>




Opt("GUIOnEventMode", 1)
AutoItSetOption("TrayIconDebug", 1) 


Global $Initial


Wait()


Func Wait()
   WinWaitActive("The window")
   GUI_1()
EndFunc


Func GUI_1()
   $Initial = GUICreate("", 500, 500)
   GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
   GUICtrlCreateLabel("Would you like to use one of the shortcuts below?", 10, 10)
   $No = GUICtrlCreateButton("No Thanks", 20, 190)
   GUICtrlSetOnEvent($No, "Close")
   guisetstate(@SW_SHOW)
   
   While 1
 sleep(100)
   WEnd
EndFunc


Func Close()
   GUISetState(@SW_HIDE, $Initial)
   WinWaitClose("The Window")
   Sleep(10000)
   Wait()
EndFunc

 

Link to comment
Share on other sites

  • Moderators
  • Solution

kyle2727,

Welcome to the AutoIt forum. :)

That was a fun logic flow to interpret. I think should do what you want - I used the AutoIt Help window as the trigger:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $Initial, $hWinHandle = 0, $fWaiting = True

While 1

    ; Get target window handle
    If $hWinHandle = 0 And WinExists("AutoIt Help") Then
        $hWinHandle = WinGetHandle("AutoIt Help")
    EndIf

    ; If waiting for this window to become active and it becomes active
    If $fWaiting = True And WinActive("AutoIt Help") Then
        ; Create the GUI
        GUI_1()
        ; Clear the flag
        $fWaiting = False
    EndIf

    ; If the flag has been cleared AND the GUI is not active And the window is no longer active
    If $fWaiting = False And Not(WinActive($Initial)) And Not(WinActive("AutoIt Help")) Then
        ; Set the flag to look again
        $fWaiting = True
    EndIf
WEnd

Func GUI_1()
    $Initial = GUICreate("", 500, 500)
    WinSetOnTop($Initial, "", 1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
    GUICtrlCreateLabel("Would you like to use one of the shortcuts below?", 10, 10)
    $No = GUICtrlCreateButton("No Thanks", 20, 190)
    GUICtrlSetOnEvent($No, "Close")
    GUISetState(@SW_SHOW)
EndFunc   ;==>GUI_1

Func Close()
    GUIDelete($Initial)
    WinActivate($hWinHandle)
EndFunc   ;==>Close
I hope the comments are clear enough - please ask if not. :)

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

  • Moderators

kyle2727,

Glad I could help. :)

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