Jump to content

Button control inactive in a child window


Raja
 Share

Recommended Posts

Hi

Can anyone please look at the the code below and provide some pointers to fix it and any advice on if it should have been written differently based on best practices for such requirements.

What is expected:

Parent window provides 2 buttons (Accept and Decline).

On clicking Accept a set of commands is run and program Exits.

On clicking Decline, a child window is launced with a progress bar and a Cancel button, which gives user 30 seconds to review his selction before he is logged off.

The problem:

The Cancel button does not respond and as a result user does not get the Parent window back again.

Many thanks in advance!

Raja

#include <GuiConstants.au3>
Opt("GUIOnEventMode", 1)
$objMainGUI = GuiCreate("Parent", 200, 130, -1, -1)

; Create Accept button
$objButton_1 = GuiCtrlCreateButton("&Accept", 20, 40, 70, 30, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent(-1, "Accept") 

; Create Decline button
$objButton_2 = GuiCtrlCreateButton("&Decline", 110, 40, 70, 30)
GUICtrlSetOnEvent(-1, "Decline")

GUISetState()
While 1
    Sleep(100)
WEnd


Func Accept()
    GUIDelete() 
    Msgbox(0, "", "Accepted")
    Exit
EndFunc
        
Func Decline()
    GUIDelete()
    Progress()
EndFunc

Func Progress()
    $objChildGUI = GUICreate("Review selection",350,125, -1,-1)
    $objLabel_5 = GuiCtrlCreateLabel('Your login will terminate in 30 seconds. If you wish to review your selection,' & _
                                                                'then please click on Cancel.', 20, 20, 325, 50, $SS_LEFT)
    $objProgress = GUICtrlCreateProgress (20,85,100,20)
    $objButton_3 = GUICtrlCreateButton ("Cancel",250,75,80,30)
    GUICtrlSetOnEvent($objButton_3, "Cancel")   
    GUISetState()
    While 1
        For $i = 0 To 100
            GUICtrlSetData ($objProgress,$i)
            Sleep(300)
        Next
    WEnd
EndFunc
    
Func Cancel()
    GUIDelete()
    Msgbox (0, "", "Cancelled")
    GUISetState(@SW_SHOW, $objMainGUI)
EndFunc
Link to comment
Share on other sites

Maybe....

#include <GuiConstants.au3>
Global $objChildGUI, $Counter=0, $objProgress
Opt("GUIOnEventMode", 1)
$objMainGUI = GuiCreate("Parent", 200, 130, -1, -1)

; Create Accept button
$objButton_1 = GuiCtrlCreateButton("&Accept", 20, 40, 70, 30, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent(-1, "Accept")    

; Create Decline button
$objButton_2 = GuiCtrlCreateButton("&Decline", 110, 40, 70, 30)
GUICtrlSetOnEvent(-1, "Decline")

GUISetState()
While 1
    Sleep(100)
WEnd


Func Accept()
    GUIDelete($objMainGUI)    
    Msgbox(0, "", "Accepted",3)
    Exit
EndFunc
        
Func Decline()
    GUISetState(@SW_HIDE,$objMainGUI)
    Progress()
EndFunc

Func Progress()
    $objChildGUI = GUICreate("Review selection",350,125, -1,-1)
    $objLabel_5 = GuiCtrlCreateLabel('Your login will terminate in 30 seconds. If you wish to review your selection,' & _
                                                                'then please click on Cancel.',    20, 20, 325, 50, $SS_LEFT)
    $objProgress = GUICtrlCreateProgress (20,85,100,20)
    $objButton_3 = GUICtrlCreateButton ("Cancel",250,75,80,30)
    GUICtrlSetOnEvent($objButton_3, "Cancel")    
    GUISetState()
    GUICtrlSetData ($objProgress,$Counter)
    AdlibEnable("Enable",300)
EndFunc
    
Func Cancel()
    AdlibDisable()
    $Counter=0
    GUIDelete($objChildGUI)
    Msgbox (0, "", "Cancelled",3)
    GUISetState(@SW_SHOW, $objMainGUI)
EndFunc
Func Enable()
    GUICtrlSetData ($objProgress,$Counter)
    $Counter+=1
EndFunc
Link to comment
Share on other sites

Thanks Generator!

It does work, had to add the loop to exit after 30 seconds.

With due regards, is this a work around OR this is how such requirements are coded?

Cheers

Raja

Anyone else out there who would like to contribute there experience please? :)

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