Jump to content

GUI buttons not working with GUIOnEventMode = 1


Go to solution Solved by 68ponyGT,

Recommended Posts

Posted (edited)

I am writing AutoIt scripts to automate software installation. I am having problems with my GUI Buttons not working when GUIOnEventMode is set to 1.

This test code works fine. While in the _WinWaitActivate function I can click the cancel button and the function is interrupted.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1)

Global $Interrupt = False

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$hButton1 = GUICtrlCreateButton("Cancel", 10, 10, 80, 30)
GUICtrlSetOnEvent($hButton1, "_CancelFunc")
GUISetState(@SW_SHOW, $hGUI)

_WinWaitActivate("Untitled - Notepad")

Func _CancelFunc()
$Interrupt = True
EndFunc   ;==>_CancelFunc

Func _Exit()
Exit
EndFunc   ;==>_Exit

Func _WinWaitActivate($title, $text = "", $timeout = 10800)
MsgBox(0, "", "Waiting On Notepad")
While $timeout And Not WinExists($title, $text)
$timeout -= .5
Sleep(500)
If $Interrupt Then
MsgBox(0, "", "Installation Cancelled")
Return False
EndIf
WEnd
Local $Return = WinActivate($title, $text)
Return $Return
EndFunc   ;==>_WinWaitActivate

This is my script with the GUI code. The $btnCancel will not set the $Interrupt variable to true while in the _WinWaitActivate function. Also the $GUI_EVENT_CLOSE does not work either. The _WinWaitActivate function which is exactly the same as in the test code above. I have only posted the code I think is relevant due to the size of the application, I can post more if needed. Any help would be greatly appreciated.

#include <ME_Globals_Constants.au3>
#include <ME_Core_Functions.au3>
#include <ME_Utility_Functions.au3>
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <TreeViewConstants.au3>

Opt("GUIOnEventMode", 1)

; -------------------- Installation Status Window ------------------------------
Func CreateInstallStatus_GUI($varTitle)
Local $wintop = $arrScreenSize[3] - 425
Global $frmInstallStatus = GUICreate($varTitle, 797, 339, 5, $wintop, BitOR($GUI_SS_DEFAULT_GUI, $DS_MODALFRAME, $DS_SETFOREGROUND))
GUISetBkColor(0xA6CAF0)
Global $lblHeading = GUICtrlCreateLabel("MBUSI ME Software Installation", 8, 8, 332, 33)
GUICtrlSetFont($lblHeading, 18, 800, 0, "Calibri")
Global $lblSoftwareName = GUICtrlCreateLabel("Software Name", 11, 79, 780, 30)
GUICtrlSetFont($lblSoftwareName, 20, 800, 0, "Calibri")
GUICtrlSetColor($lblSoftwareName, 0x800000)
Global $progInstallProgress = GUICtrlCreateProgress(0, 309, 796, 29)
Global $btnPause = GUICtrlCreateButton("&Pause", 536, 8, 97, 33)
GUICtrlSetFont($btnPause, 10, 400, 0, "MS Sans Serif")
Global $btnCancel = GUICtrlCreateButton("&Cancel", 643, 7, 97, 33)
GUICtrlSetFont($btnCancel, 10, 400, 0, "MS Sans Serif")
;Global $lstStatus = GUICtrlCreateList("", 0, 114, 796, 200, BitOR($LBS_NOTIFY, $WS_VSCROLL, $WS_BORDER))
Global $lstStatus = GUICtrlCreateList("", 0, 114, 796, 229, BitOR($LBS_NOTIFY, $WS_VSCROLL, $WS_BORDER))
GUICtrlSetFont($lstStatus, 10, 400, 0, "MS Sans Serif")
;GUICtrlSetColor($lstStatus, 0xFFFFFF)
;GUICtrlSetBkColor($lstStatus, 0xFFFFFF)
Global $lblInstallType = GUICtrlCreateLabel("Installation Type", 11, 39, 350, 46)
GUICtrlSetFont($lblInstallType, 26, 800, 0, "Calibri")
GUICtrlSetColor($lblInstallType, 0x800000)

#region ### frmInstallStatus OnEvents ###
GUICtrlSetOnEvent($btnPause, "_TogglePause")
GUICtrlSetOnEvent($btnCancel, "btnCancelInstallClick")
GUISetOnEvent($GUI_EVENT_CLOSE, "_MyExit")
#endregion ### frmInstallStatus OnEvents ###

EndFunc   ;==>CreateInstallStatus_GUI

Func btnCancelInstallClick()
$Interrupt = True
EndFunc   ;==>btnCancelInstallClick

Func _WinWaitActivate($title, $text = "", $timeout = 10800)
MsgBox(0, "", "Waiting On Notepad")
While $timeout And Not WinExists($title, $text)
$timeout -= .5
Sleep(500)
If $Interrupt Then
MsgBox(0, "", "Installation Cancelled")
Return False
EndIf
WEnd
Local $Return = WinActivate($title, $text)
Return $Return
EndFunc   ;==>_WinWaitActivate

 

I have used AutoIt Debugger and can see my code looping through _WinWaitActivate function but no GUI buttons are working.

 

Thanks in advance

Edited by 68ponyGT
Posted

You can't manually enter them, you have to use the code button ("<>") on the toolbar. New forum software, mentioned several times so far today.

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!

  Reveal hidden contents

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

Posted

This is my function to begin installation, once I start this function, all GUI buttons stop working

Func BeginInstall()

    $SplashTxt = "ME Software Installation" & @LF & "Operating System: " & @OSVersion & @LF & "Do Not Use Mouse or Keyboard During Installation."
    SplashTextOn($ME_AppTitle, $SplashTxt, 400, 100, -1, -1, 6, "", 12)
    Sleep(3000)
    SplashOff()

    $count = _GUICtrlListBox_GetCount($lstSelectedSoftware)
    If $count = 0 Then
        MsgBox(16, $ME_AppTitle, "No Applications Selected.")
        Exit
    EndIf

    GUISetState(@SW_SHOW, $frmInstallStatus)

    $varInstallType = GUICtrlRead($cmbInstallType)
    If Not StringInStr($varInstallType, " Installation") Then $varInstallType = $varInstallType & " Installation"
    GUICtrlSetData($lblInstallType, $varInstallType)

    ; Prompt the user to run the script - use a Yes/No prompt (4 - see help file)
    Local $answer = MsgBox(52, $ME_AppTitle, "This script will install ME Software. Continue?", 5)
    ; Check the user's answer to the prompt (see the help file for MsgBox return values)
    ; If "No" was clicked (7) then exit the script
    If $answer = 7 Then
        _LogStatus("Installation Cancelled by user")
        _ErrorMsg("Installation Cancelled")
        Exit
    EndIf

    _LogStatus("Beginning " & $varInstallType & ". Press PAUSE Key to Pause Script or Ctrl+Alt+X to Exit.")

    ; Prompt user for Manual Install.
    Local $answer = MsgBox(4, $ME_AppTitle, "Perform Automatic Installation?" & @LF & "Click No to Install Manually.", 5)
    If $answer = 7 Then
        $varInstallMode = "Manual"
    Else
        $varInstallMode = "Auto"
    EndIf
    _LogStatus($varInstallMode & " Install Mode Selected")
    GUICtrlSetData($lblSoftwareName, $varInstallMode & " Installation Mode")

    ; Map Network Drive
    _LogStatus("Mapping Network Drive ...")
    Global $MapDrive = DriveMapAdd("*", $NetShare, 0, $NetUser, $NetPassword)
    If $MapDrive = "" Then
        _LogStatus("Error Mapping Network Drive. ERROR: " & @error & ". Error Code Extended: " & @extended)
        _ErrorMsg("Error Mapping Network Drive. " & @CRLF & "ERROR: " & @error & ". Error Code Extended: " & @extended)
        Exit
    Else
        _LogStatus("Installation Drive Mapped Successfully.")
    EndIf

    For $index = 0 To _GUICtrlListBox_GetCount($lstSelectedSoftware) - 1
        $Result = _GUICtrlListBox_GetText($lstSelectedSoftware, $index)
        ;MsgBox(0, "Result", $Result)
        _LogStatus("Retrieving Selected Software List")
        For $index1 = 0 To UBound($Application) - 1
            If $Application[$index1][0] = $Result Then
                GUICtrlSetData($lblSoftwareName, $Result)
                Local $varApplication = $Application[$index1][2]
                Call($varApplication, $MapDrive, $varInstallMode)
                ;MsgBox(0, "Result", $varApplication)
            EndIf
        Next
    Next
    ; Delete Mapped Drive
    _LogStatus("Deleting Mapped Drive ...")
    If DriveMapDel($MapDrive) Then _LogStatus("Mapped Drive Deleted Successfully")

    GUISetState(@SW_HIDE, $frmInstallStatus)
    ProgramLoop()

EndFunc   ;==>BeginInstall
Posted

There's no way for that section to be interrupted by your controls, so it's going to keep running until it hits the end or a Return.

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!

  Reveal hidden contents

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

  • Solution
Posted

After more testing I see the issue. I am calling BeginInstall function using a button. Apparently no other events are captured until the initial event is complete.

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
  • Recently Browsing   0 members

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