Jump to content

How do you check a GUI for a change before closing it?


M4M
 Share

Recommended Posts

I am not all to sure on how to word this but here it goes....

I have a gui that has a few options (about 5 checkboxes, a drop-down list, 2 search fields and 2 radio buttons). How can I script it so that if a change was made and if the user tried to close the gui, A warning would pop-up saying that changes where made...yada, yada, yada.....you get the idea.

I know how to script everything else, its just the detection of the changes is what is giving me trouble.

Just to let ya know, all the options are saved in an ini file. I had an idea of this: when the user clicks on the close button, have it save the gui to a temp ini file, and have the script look at the temp ini and compare it with the origional ini, and if a different setting was found, it would warn the user, and at the end of it all, have it delete the temp ini file. Would this work? Would there be an easier way? :whistle:

Link to comment
Share on other sites

ummmmm, yea, I did read the help file and seen this also...and from what I understand, this command just checks the current state of the control in question. how can this be used to compare from what the state of a control is to the state of the control when the user tries to close the gui?

I.E. when the gui first opens, a checkbox is checked. the user unchecked the checkbox and then closes the gui. how can I script it so the script sees the change made and warns the user of the change before closing the gui?

I guess what I am saying is this..... If this is what you would use, how would you use it to detect the change, and not just report the current state of the control?

Link to comment
Share on other sites

I would think something along these lines would be used.

Global Const $Start[x] ;x is the number of controls
For $z = 1 To x
     $Start[$z] = guictrlread($control_ID[$z])
Next
Opt("OnExitFunc", "Func_Name")
;Your Code Here
Func Func_Name()
     For $z = 1 To x
            If $Start[$z] <> guictrlread($control_ID[$z]) Then
                 ;The "changes have been made" message or whatever
            EndIf
     Next
EndFunc
Link to comment
Share on other sites

Paulie: is this what you had in mind? If so I am a moron for not seeing it earlier... :whistle:

#include <GUIConstants.au3>

$Form1 = GUICreate("AForm1", 361, 207, 193, 112)
$Checkbox1 = GUICtrlCreateCheckbox("ACheckbox1", 56, 40, 137, 49)
GUICtrlSetState(-1,$GUI_CHECKED)
$before = GUICtrlRead($Checkbox1)
$Button1 = GUICtrlCreateButton("close", 56, 144, 89, 33, 0)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $Button1
            $after = GUICtrlRead($Checkbox1)
            If $before = $after Then
                msgbox(0,"no change","the checkbox did not change")
                Exit
            Else
                MsgBox(0,"changed","the checkbox changed")
                Exit
            EndIf
    EndSelect
WEnd

crzftx: heh, that is still a weeeeee bit over my head at this point. I have yet to play with global constraints yet. besides, would that work with a mixture of controls (checkboxes, radio, dropdown lists)?

Link to comment
Share on other sites

Just compare everything to the INI file when it closes.

due to the amount of controls, I figured that would be easier to script in one big IF statement then to have about 15 "$var = GUICtrlRead($control) AND to have them all checked in an IF statement.

I.E: IF GUICtrlRead($Checkbox1) = iniread(this.ini,"do","re","me") AND GUICtrlRead($Checkbox2) = iniread(this.ini,"heh","lol","wtf") and ect,ect,ect

or is there an easer way to lump all of the controls into one var. so I dont have to have a mile-long IF statement? OR would my origional idea be better (create a temp ini and compare the two)?

heh, OR am I just making it way harder then it really is? Please keep in mind, I havent had much time to fully explore autoit, so I am still unfamiliar on how flexable the commands are.

Edited by M4M
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...