Kaimberex

Detecting changes in a multiple GUI program

4 posts in this topic

#1 ·  Posted (edited)

Okay so let me try to explain what I am trying to do and my issue. 

I am developing an inhouse program for my job and I am stumped on a particular scenario. Hoping someone can help me accomplish what I am trying to do. I am pretty sure it can be done using OnEvent Mode but I am still kind of new at that part of Autoit. 

I will attach my project here because it has a lot of includes and is using ISN Autoit Studio which saves its code differently.  Documents.zip

The scenario would be if a user sets the options in the settings page and clicks save the save button is greyed out indicating that the settings have been saved. but if a user decides to change a setting and wants to save again they cant because the button is greyed out until you open the settings window again. I would like to detect changes either with a loop or a OnEvent function. The DetectSettingsChange() function works by itself but I want it to detect every couple of milliseconds if a change has been made on the window and make the Save button active again. 

Here is my main Script:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#AutoIt3Wrapper_Res_Description=Utility to automatically enter information into New Hire Imaging checklist.
#AutoIt3Wrapper_Res_Fileversion=1.1.4.5
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_LegalCopyright=All Rights Reserved.2016
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;*****************************************
;   AutoIt Version: 3.3.14.1
;   Author:         Eric Behrens
;   IT - Deskside Services
;   Allianz Global Corporate & Specialty AG
;   
;
;
;~  Script Function:
;
;
;*****************************************
#include "Forms\New Hire Imaging Checklist Input Utility.isf"
#include "Forms\Settings.isf"
#include <Misc.au3>
#include <Excel.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#include "Forms\About.isf"
#include <File.au3>
#include <AD.au3>
#include <Date.au3>

;Check if another instance of this application is lready running. If detected, kill new instance and keep original.
If _Singleton("New Hire Imaging Checklist Input Utility", 1) = 0 Then
    MsgBox(16, "Error", "Another instance of this program is already running.")
    Exit
EndIf

#Region Global Variables
Global $oExcelChecklist, $sFilePathChecklist, $workbookChecklist, $oExcelQuickGuide, $sFilePathQuickGuide, $workbookQuickGuide, $LogFileDirChoose, $SelectedPrinter, $IsLoggingEnabled
Global $defPrtNm, $DefaultPrinter, $DocumentsProcessed, $LogDir, $ConfigFile
#EndRegion Global Variables
#Region Declare Variables
$DocumentsProcessed = False
#EndRegion Declare Variables
#Region Config.ini Settings
;Create the .ini file
$ConfigFile = @ScriptDir & "\Config.ini"
If FileExists($ConfigFile) = 0 Then _FileCreate($ConfigFile)
$ConfigFileIsLoggingEnabled = IniRead($ConfigFile, "Logging", "Logging", "Disabled")
$ConfigFileCheckPrinterSelection = IniRead($ConfigFile, "Printers", "Selected Printer", "Microsoft XPS Document Writer")
$ConfigFileCheckLogDir = IniRead($ConfigFile, "Logging", "Log Dir", "")
$ConfigFileNamingUtility = IniRead($ConfigFile, "Integration", "Workstation Naming Utility", "False")
#EndRegion Config.ini Settings

#Region Process Config Paramaters.
GUICtrlSetData($cboxPrinters, $ConfigFileCheckPrinterSelection)
#EndRegion Process Config Paramaters.
GetTechnicianName()
GUICtrlSetState($MenuItemPrint,$GUI_DISABLE)
GUICtrlSetState($MenuItemTransferUtility, $GUI_DISABLE)
GUISetState(@SW_SHOW, $MainGUI)


While 1
    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btnUpdate
            AddToSpreadsheet()
        Case $btnExit
            Exit
        Case $MenuItemPrint
            PrintDocuments()
        Case $MenuItemSettings
            GUISetState(@SW_DISABLE, $MainGUI)
            SettingsGUI()
            GUISetState(@SW_ENABLE, $MainGUI)
        Case $MenuItemExit
            Exit
        Case $MenuItemAbout
            GUISetState(@SW_DISABLE, $MainGUI)
            AboutBox()
            GUISetState(@SW_ENABLE, $MainGUI)
    EndSwitch
WEnd

Func AddToSpreadsheet()
    Local $UserID = GUICtrlRead($inputUserID)
    Local $ComputerName = GUICtrlRead($inputComputerName)
    Local $UserName = GUICtrlRead($inputName)
    Local $LotusPW = GUICtrlRead($inputLotusPW)
    Local $PhoneNo = GUICtrlRead($inputPhoneNo)
    Local $PW = GUICtrlRead($inputPW)
    Local $StartDate = GUICtrlRead($inputDate)
    Local $DeskLocation = GUICtrlRead($inputLocation)
    Local $SerialNumber = GUICtrlRead($inputSerialNo)
    Local $Technician = GUICtrlRead($inputTechnician)
    If GUICtrlRead($inputUserID) = "" Then
        MsgBox(16, "Missing info", "Please enter a User ID to continue", 0)
    ElseIf GUICtrlRead($inputComputerName) = "" Then
        MsgBox(16, "Missing info", "Please enter a Computer Name to continue", 0)
    ElseIf GUICtrlRead($inputName) = "" Then
        MsgBox(16, "Missing info", "Please enter a Name to continue", 0)
    ElseIf GUICtrlRead($inputLotusPW) = "" Then
        MsgBox(16, "Missing info", "Please enter a Lotus Notes Password to continue", 0)
    ElseIf GUICtrlRead($inputPhoneNo) = "" Then
        MsgBox(16, "Missing info", "Please enter a Phone Number to continue", 0)
    ElseIf GUICtrlRead($inputPW) = "" Then
        MsgBox(16, "Missing info", "Please enter a Windows Password to continue", 0)
    ElseIf GUICtrlRead($inputLocation) = "" Then
        MsgBox(16, "Missing info", "Please enter a Location to continue", 0)
    ElseIf GUICtrlRead($inputSerialNo) = "" Then
        MsgBox(16, "Missing info", "Please enter a Serial Number to continue", 0)
    Else
        GUICtrlSetState($btnUpdate,$GUI_DISABLE)
        GUICtrlSetState($btnExit,$GUI_DISABLE)
        $oExcelChecklist = _Excel_Open(False)
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        $sFilePathChecklist = @ScriptDir & "\Documents\New Hire Checklist.xlsx"
        $workbookChecklist = _Excel_BookOpen($oExcelChecklist, $sFilePathChecklist)
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $UserName, "D42")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $ComputerName, "E43")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $UserID, "J42")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $LotusPW, "K44")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $PhoneNo, "M42")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $PW, "C44")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $StartDate, "C45")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $DeskLocation, "J45")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $SerialNumber, "K43")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookChecklist, $workbookChecklist.Activesheet, $Technician, "N43")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        Sleep(500)
        $oExcelQuickGuide = _Excel_Open(False)
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        $sFilePathQuickGuide = @ScriptDir & "\Documents\New Hire Quick Guide.xlsx"
        $workbookQuickGuide = _Excel_BookOpen($oExcelQuickGuide, $sFilePathQuickGuide)
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $UserName, "C8")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $UserID, "H15")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $PW, "H17")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $LotusPW, "H19")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        _Excel_RangeWrite($workbookQuickGuide, $workbookQuickGuide.Activesheet, $PhoneNo, "H21")
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error writing to worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        $DocumentsProcessed = True
    EndIf
    PrintDocuments()
    _Excel_BookClose($workbookChecklist, False)
    _Excel_BookClose($workbookQuickGuide, False)
    LoggingToExcel()
    ClearForm()
    GUICtrlSetState($btnUpdate,$GUI_ENABLE)
    GUICtrlSetState($btnExit,$GUI_ENABLE)
EndFunc   ;==>AddToSpreadsheet
Func DefaultPrinterChange()
    
    $sPrinterName = '"\\VUSSLBSRFS1001.agcs.biz\SecureColor"'
    $DefaultPrinter = _GetDefaultPrinter()
    RunWait(@ComSpec & " /c " & 'RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry ' & '/y /n ' & $sPrinterName, "", @SW_HIDE)
    
EndFunc   ;==>DefaultPrinterChange
Func DisableLoggingEnableButton()
    $IsLoggingEnabled = 1
    GUICtrlSetState($btnSettingsLoggingEnabled, $GUI_DISABLE)
    GUICtrlSetState($btnSettingsLoggingDisabled, $GUI_ENABLE)
    GUICtrlSetState($inputSettingsLogDir, $GUI_ENABLE)
    GUICtrlSetState($btnSettingsChooseLogDir, $GUI_ENABLE)
    GUICtrlSetState($btnSettingsOpenLog, $GUI_ENABLE)
EndFunc   ;==>DisableLoggingEnableButton
Func DisableLoggingDisableButton()
    $IsLoggingEnabled = 0
    GUICtrlSetState($btnSettingsLoggingDisabled, $GUI_DISABLE)
    GUICtrlSetState($btnSettingsLoggingEnabled, $GUI_ENABLE)
    GUICtrlSetState($inputSettingsLogDir, $GUI_DISABLE)
    GUICtrlSetState($btnSettingsChooseLogDir, $GUI_DISABLE)
    GUICtrlSetState($btnSettingsOpenLog, $GUI_DISABLE)
EndFunc   ;==>DisableLoggingDisableButton
Func SettingsGUI()
;~  Opt("GUIOnEventMode", 1) ; Change to OnEvent mode
    GUICtrlSetState($btnSettingsSave, $GUI_ENABLE)
    Switch $ConfigFileIsLoggingEnabled
        Case "Enabled"
            GUICtrlSetState($btnSettingsLoggingEnabled, $GUI_DISABLE)
            GUICtrlSetState($inputSettingsLogDir, $GUI_ENABLE)
            GUICtrlSetState($btnSettingsChooseLogDir, $GUI_ENABLE)
            GUICtrlSetState($btnSettingsOpenLog, $GUI_ENABLE)
        Case "Disabled"
            GUICtrlSetState($btnSettingsLoggingDisabled, $GUI_DISABLE)
            GUICtrlSetState($inputSettingsLogDir, $GUI_DISABLE)
            GUICtrlSetState($btnSettingsChooseLogDir, $GUI_DISABLE)
            GUICtrlSetState($btnSettingsOpenLog, $GUI_DISABLE)
    EndSwitch


    EnumeratePrinterList()
    GUICtrlSetData($cboxPrinters, $ConfigFileCheckPrinterSelection)
    GUICtrlSetData($inputSettingsLogDir, $ConfigFileCheckLogDir)
    _GUICtrlEdit_SetSel($inputSettingsLogDir, 1, 1)
    GUISetState(@SW_SHOW, $Settings)
    
    While 1
        DetectSettingsChanges()
        $msg = GUIGetMsg(1)
        Switch $msg[0]
            Case $GUI_EVENT_CLOSE
                GUISetState(@SW_HIDE, $Settings)
                GUISetState(@SW_SHOW, $MainGUI)
                ExitLoop
            Case $btnSettingsOK
;~              DetectSettingsChanges()
                GUISetState(@SW_HIDE, $Settings)
                GUISetState(@SW_SHOW, $MainGUI)
                ExitLoop
            Case $btnSettingsSave
                GUICtrlSetState($btnSettingsOK,$GUI_DISABLE)
                Sleep(250)
                WriteSettingsToFile()
                GUICtrlSetState($btnSettingsSave, $GUI_DISABLE)
                Sleep(250)
                GUICtrlSetState($btnSettingsOK, $GUI_ENABLE)
            Case $btnSettingsLoggingEnabled
                DisableLoggingEnableButton()
            Case $btnSettingsLoggingDisabled
                DisableLoggingDisableButton()
            Case $btnSettingsChooseLogDir
                SelectLogDir()
            Case $btnSettingsOpenLog
;~              DetectSettingsChanges() 
                
                
        EndSwitch



    WEnd
EndFunc   ;==>SettingsGUI
Func EnumeratePrinterList()
    $wbemFlagReturnImmediately = "&h10"
    $wbemFlagForwardOnly = "&h20"

    $WMI = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
    $aItems = $WMI.ExecQuery("SELECT * FROM Win32_Printer", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)

    For $printer In $aItems
        GUICtrlSetData($cboxPrinters, $printer.Name)
    Next
    
EndFunc   ;==>EnumeratePrinterList

Func SelectLogDir()

    $LogFileDirChoose = FileSaveDialog("Choose a location to save the log file", @ScriptDir, "Excel Files(*.xls)", $FD_PATHMUSTEXIST, "New Hire Log.xls", $Settings)
    GUICtrlSetData($inputSettingsLogDir, $LogFileDirChoose)
    _GUICtrlEdit_SetSel($inputSettingsLogDir, 1, 1)
    
;~  MsgBox(0,"", $LogFileDirChoose)
EndFunc   ;==>SelectLogDir

Func WriteSettingsToFile()
    $sFilePathLogFile = $ConfigFileCheckLogDir
    $Logging = ""
    $SelectedPrinter = GUICtrlRead($cboxPrinters)
    $LogDir = GUICtrlRead($inputSettingsLogDir)
    ;If log file does bot exist then create a new blank log file.
    If $ConfigFileIsLoggingEnabled = "Enabled" Or $IsLoggingEnabled = 1 Then
        If Not FileExists($LogDir) Then
            $oExcelLogFile = _Excel_Open(False)
            If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
            $sFilePathLogFile = $ConfigFileCheckLogDir
            $CreateNewLogDirBook = _Excel_BookNew($oExcelLogFile)
            If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error creating workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
            _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Date", "A1")
            _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Build Technician", "B1")
            _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "User ID", "C1")
            _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "User Name", "D1")
            _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Computer Name", "E1")
            _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Serial Number", "F1")
            _Excel_RangeWrite($CreateNewLogDirBook, $CreateNewLogDirBook.Activesheet, "Start Date", "G1")
            $oExcelLogFile.ActiveSheet.Columns(1).AutoFit
            $oExcelLogFile.ActiveSheet.Columns(2).AutoFit
            $oExcelLogFile.ActiveSheet.Columns(3).AutoFit
            $oExcelLogFile.ActiveSheet.Columns(4).AutoFit
            $oExcelLogFile.ActiveSheet.Columns(5).AutoFit
            $oExcelLogFile.ActiveSheet.Columns(6).AutoFit
            $oExcelLogFile.ActiveSheet.Columns(7).AutoFit
            If $ConfigFileCheckLogDir = "" Then $sFilePathLogFile = $LogFileDirChoose
            _Excel_BookSaveAs($CreateNewLogDirBook, $sFilePathLogFile, $xlExcel8, True)
            If @error Then
                MsgBox($MB_SYSTEMMODAL, "Error", "Error saving workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
                _Excel_Close($oExcelLogFile)
                Exit
            EndIf
            _Excel_Close($oExcelLogFile)
        EndIf
    EndIf
    If $IsLoggingEnabled = 0 Then $Logging = "Disabled"
    If $IsLoggingEnabled = 1 Then $Logging = "Enabled"
    If GUICtrlRead($cbSettingsIntegrateNamingUtility) = 1 Then $Integration = "True"
    If GUICtrlRead($cbSettingsIntegrateNamingUtility) = 4 Then $Integration = "False"
    IniWrite($ConfigFile, "Integration", "Workstation Naming Utility", $Integration)
    IniWrite($ConfigFile, "Logging", "Logging", $Logging)
    IniWrite($ConfigFile, "Printers", "Selected Printer", $SelectedPrinter)
    IniWrite($ConfigFile, "Logging", "Log Dir", $LogDir)
    
EndFunc   ;==>WriteSettingsToFile
Func _GetDefaultPrinter() ; CyberSlug - 18 Nov 2004
    Local $key, $default
    If @OSType = "WIN32_WINDOWS" Then
        $key = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers"
        $defPrtNm = RegRead("HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Printers", "Default")
    Else ;WIN_NT type
        $key = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers"
        $default = RegRead("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows", "Device")
        $defPrtNm = StringLeft($default, StringInStr($default, ",") - 1)
        Return $defPrtNm
    EndIf
EndFunc   ;==>_GetDefaultPrinter

Func _PrintMgr_SetDefaultPrinter($sPrinterName)
    Local $iRet = 1
    Local $oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    If Not IsObj($oWMIService) Then Return SetError(1, 0, 0)
    Local $oPrinters = $oWMIService.ExecQuery("Select * from Win32_Printer where DeviceID = '" & $sPrinterName & "'")
    If Not IsObj($oPrinters) Then Return SetError(1, 0, 0)

    For $oPrinter In $oPrinters
        $iRet = $oPrinter.SetDefaultPrinter()
    Next
    Return ($iRet = 0 ? 1 : SetError($iRet, 0, 0))
EndFunc   ;==>_PrintMgr_SetDefaultPrinter
Func PrintDocuments()
    If $DocumentsProcessed = False Then
        MsgBox(16, "Print Error", "No Data has been entered into Excel documents. Please update form and click Process before printing. ", 0, $MainGUI)
    Else
        $ConfigFileCheckPrinterSelection = IniRead($ConfigFile, "Printers", "Selected Printer", "") ;Check printer selected in settings menu.
        $DefaultPrinter = _GetDefaultPrinter() ;Retrieve Default Printer.Returns FQDN
        $SearchForSecureColor = StringMid($ConfigFileCheckPrinterSelection, 27) ;Check if SecureColor exists in selected Printer
        $SearchForSecureBnW = StringMid($ConfigFileCheckPrinterSelection, 27) ;Check if SecureB&W exists in Selected Printer.
        Local $sPrinterName = ""
        Local $sSubKey = ""
        For $i = 1 To 10
            $sSubKey = RegEnumKey("HKCU\Printers\Connections", $i) ;Find Keys for Printer Connections
            If @error Then ExitLoop
            $PrinterServer = StringMid($sSubKey, 3, 14) ;Trim values to only aquire server name.
            If StringInStr($sSubKey, "SecureColor") > 0 Then $sPrinterNameColor = "\\" & $PrinterServer & ".agcs.biz\SecureColor"
            If StringInStr($sSubKey, "SecureB&W") > 0 Then $sPrinterNameBnW = "\\" & $PrinterServer & ".agcs.biz\SecureB&W" ;Convert to string for default printer change command.
        Next
;~      $msgboxPrint = MsgBox(36, "Print", "Would you like to print the Quick Guide and Checklist?", 0)
;~      Switch $msgboxPrint
;~          Case 6 ;YES
        If $SearchForSecureColor = "SecureColor" Then ;If Secure Color is selected then
            $sPrinterNameColor = """\\" & $PrinterServer & ".agcs.biz\SecureColor"""
            RunWait(@ComSpec & " /c " & 'RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry ' & '/y /n ' & $sPrinterNameColor, "", @SW_HIDE) ;Set SecureColor as Default printer.
            ;Print Stuff from Excel
            _Excel_Print($oExcelChecklist, $workbookChecklist.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default)
            If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
            MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Checklist successfully printed.")
            _Excel_Print($oExcelQuickGuide, $workbookQuickGuide.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default)
            If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
            MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Quick Guide successfully printed.")
            ;Print Stuff from excel
            If $DefaultPrinter = "\\" & $PrinterServer & ".agcs.biz\SecureB&W" Then ;If the default OS printer was SecureB&W then
                $sPrinterName = '"\\' & $PrinterServer & '.agcs.biz\SecureB&W"'
                RunWait(@ComSpec & " /c " & 'RUNDLL32.EXE PRINTUI.DLL,PrintUIEntry ' & '/y /n ' & $sPrinterName, "", @SW_HIDE) ;this command must be passed for a network printer because PrintMGRUDF does not support network printers at this time.
            Else ;If a local printer was the default then use built it PrintMGR function _PrintMgr_SetDefaultPrinter($DefaultPrinter)
                _PrintMgr_SetDefaultPrinter($DefaultPrinter)
            EndIf
        Else
            _Excel_Print($oExcelChecklist, $workbookChecklist.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default)
            If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
            MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Checklist successfully printed.")
            _Excel_Print($oExcelQuickGuide, $workbookQuickGuide.Activesheet, Default, $ConfigFileCheckPrinterSelection, Default, Default, Default, Default, Default)
            If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Printing Error", "Error printing worksheet." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
            MsgBox($MB_SYSTEMMODAL, "Print Success", "New Hire Quick Guide successfully printed.")
        EndIf
;~          Case 7 ;NO
;~      EndSwitch
    EndIf
EndFunc   ;==>PrintDocuments
Func AboutBox()
    $FileVersion = FileGetVersion(@ScriptFullPath)
    GUICtrlSetData($lblAboutVersion, $FileVersion)
    GUISetState(@SW_SHOW, $About)
    
    While 1
        $msg = GUIGetMsg(1)
        Switch $msg[0]
            Case $GUI_EVENT_CLOSE
                GUISetState(@SW_HIDE, $About)
                GUISetState(@SW_SHOW, $MainGUI)
                ExitLoop
            Case $btnAboutClose
                GUISetState(@SW_HIDE, $About)
                GUISetState(@SW_SHOW, $MainGUI)
                ExitLoop
                
                
        EndSwitch



    WEnd

EndFunc   ;==>AboutBox

Func GetTechnicianName()
    _AD_Open()
    $TechName = @UserName
    $TechFQDN = _AD_SamAccountNameToFQDN($TechName)
    $TechDisplayName = _AD_FQDNToDisplayname($TechFQDN)
    GUICtrlSetData($inputTechnician, $TechDisplayName)
EndFunc   ;==>GetTechnicianName

Func LoggingToExcel()
    Local $UserID = GUICtrlRead($inputUserID)
    Local $ComputerName = GUICtrlRead($inputComputerName)
    Local $UserName = GUICtrlRead($inputName)
    Local $StartDate = GUICtrlRead($inputDate)
    Local $SerialNumber = GUICtrlRead($inputSerialNo)
    Local $TechName = GUICtrlRead($inputTechnician)
    Local $TodaysDate = _Date_Time_GetLocalTime()
    If $ConfigFileIsLoggingEnabled = "Enabled" Or $IsLoggingEnabled = 1 Then
        $oExcelLogFile = _Excel_Open(False)
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error starting Excel." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        $sFilePathLogFile = $ConfigFileCheckLogDir
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error creating workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        $workbookLogFile = _Excel_BookOpen($oExcelLogFile, $sFilePathLogFile)
        If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Error", "Error opening to workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        $oRange = $workbookLogFile.ActiveSheet.UsedRange.SpecialCells($xlCellTypeLastCell)
        _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, _Date_Time_SystemTimeToDateTimeStr($TodaysDate), "A" & $oRange.row + 1)
        _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $TechName, "B" & $oRange.row + 1)
        _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $UserID, "C" & $oRange.row + 1)
        _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $UserName, "D" & $oRange.row + 1)
        _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $ComputerName, "E" & $oRange.row + 1)
        _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $SerialNumber, "F" & $oRange.row + 1)
        _Excel_RangeWrite($workbookLogFile, $workbookLogFile.Activesheet, $StartDate, "G" & $oRange.row + 1)
        
        ;Auto Fit column width
        $oExcelLogFile.ActiveSheet.Columns(1).AutoFit
        $oExcelLogFile.ActiveSheet.Columns(2).AutoFit
        $oExcelLogFile.ActiveSheet.Columns(3).AutoFit
        $oExcelLogFile.ActiveSheet.Columns(4).AutoFit
        $oExcelLogFile.ActiveSheet.Columns(5).AutoFit
        $oExcelLogFile.ActiveSheet.Columns(6).AutoFit
        $oExcelLogFile.ActiveSheet.Columns(7).AutoFit
        _Excel_Close($oExcelLogFile, True)
    EndIf
    
    


    
EndFunc   ;==>LoggingToExcel
Func ClearForm()
    GUiCtrlSetData($inputUserID,"")
    GUiCtrlSetData($inputComputerName,"")
    GUiCtrlSetData($inputName,"")
    GUiCtrlSetData($inputLotusPW,"")
    GUiCtrlSetData($inputPhoneNo,"")
    GUiCtrlSetData($inputPW,"")
    GUiCtrlSetData($inputDate,"")
    GUiCtrlSetData($inputLocation,"")
    GUiCtrlSetData($inputSerialNo,"")
    $DocumentsProcessed = False
EndFunc

Func DetectSettingsChanges()
;~  Sleep(1000)
    $DetectPrinterChange = GUICtrlRead($cboxPrinters)
    $DetectLogDirChange = GUICtrlRead($inputSettingsLogDir)
    $DetectLogEnabledChange = GUICtrlGetState($btnSettingsLoggingEnabled)
    If $DetectPrinterChange not = $ConfigFileCheckPrinterSelection Then 
        Sleep(100)
    Else
        GUICtrlSetState($btnSettingsSave, $GUI_ENABLE)  
    EndIf
    If $DetectLogDirChange Not  = $ConfigFileCheckLogDir Then
        Sleep(100)
    Else
        GUICtrlSetState($btnSettingsSave, $GUI_ENABLE)  
    EndIf
;~  If $DetectLogEnabledChange = 144 Then
;~      MsgBox(0,"","You cannot press Enabled")
;~  ElseIf  $DetectLogEnabledChange = 80 Then
;~      MsgBox(0,"","You can press Enabled")
;~  EndIf
    
;~  ConsoleWrite($test1 & @CRLF)
;~  $test2 = GUICtrlGetState($btnSettingsLoggingDisabled)
;~  ConsoleWrite($test2 & @CRLF)
EndFunc

Here are the forms in au3 format in case you dont have ISN AutoIt Studio. 

New Hire Imaging Checklist Input Utility.au3

Settings.au3

Edited by Kaimberex
full script was missing. Added full script

Share this post


Link to post
Share on other sites



Kaimberex,

And what is this "scenario" that is causing you a problem - or are we supposed to guess?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

Share this post


Link to post
Share on other sites
35 minutes ago, Melba23 said:

Kaimberex,

And what is this "scenario" that is causing you a problem - or are we supposed to guess?

M23

Sorry long day, The scenario would be if a user sets the options in the settings page and clicks save the save button is greyed out indicating that the settings have been saved. but if a user decides to change a setting and wants to save again they cant because the button is greyed out until you open the settings window again. I would like to detect changes either with a loop or a OnEvent function. The DetectSettingsChange() function works by itself but I want it to detect every couple of milliseconds if a change has been made on the window and make the Save button active again. 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I think the easiest would be to use a global variable: set to True or False depending on actions taken by the user.

#include <GUIConstants.au3>

Global $g__bEnable = False ; keep track of control status (also works with menu items)

Example()

Func Example()
    Local $hGUI = GUICreate("Example", 190, 100)
    Local $hAction = GUICtrlCreateButton("Enable", 10, 10, 80, 20)
    Local $hDisable = GUICtrlCreateButton("Disable", 100, 10, 80, 20)
    GUICtrlSetState(-1, $GUI_DISABLE) ; disable the last control created

    GUISetState(@SW_SHOW)

    Local $msg
    While 1
        $msg = GUIGetMsg()

        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hAction
                If Not $g__bEnable Then GUICtrlSetState($hDisable, $GUI_ENABLE) ; check status (simple condition)
                $g__bEnable = True ; set to True
            Case $hDisable
                GUICtrlSetState($hDisable, $GUI_DISABLE) ; here we already know the control is active
                $g__bEnable = False ; set to False
        EndSwitch
    WEnd
EndFunc

This method works for other controls, including menu items. For multiple controls you should probably use an array of True and False values. This is just a simple example demonstrating how to monitor user interaction with GUI controls. In a real situation you may have a more complex set of conditions to test before enabling or disabling a control.

Edit1: In addition, you might want to look at AdlibRegister which you could use to test the status of the global variable (or the control) every however many milliseconds.

Edit2: Here's the same code which reads the control status instead of testing a global variable.

#include <GUIConstants.au3>

Example()

Func Example()
    Local $hGUI = GUICreate("Example", 190, 100)
    Local $hAction = GUICtrlCreateButton("Enable", 10, 10, 80, 20)
    Local $hDisable = GUICtrlCreateButton("Disable", 100, 10, 80, 20)
    GUICtrlSetState(-1, $GUI_DISABLE) ; disable the last control created

    GUISetState(@SW_SHOW)

    Local $msg
    While 1
        $msg = GUIGetMsg()

        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $hAction
                If BitAnd(GUICtrlGetState($hDisable), $GUI_DISABLE) == $GUI_DISABLE Then GUICtrlSetState($hDisable, $GUI_ENABLE) ; check status (simple condition)
            Case $hDisable
                GUICtrlSetState($hDisable, $GUI_DISABLE) ; here we already know the control is active
        EndSwitch
    WEnd
EndFunc 

The second method is probably a bit cleaner, but uses more functions. The first method is a bit easier to write and the global can be more easily tested/modified at any time; after any (or all) user actions.

Edited by czardas
1 person likes this

Share this post


Link to post
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