Jump to content

re-use gui


nobby
 Share

Recommended Posts

Hey,

I am trying to get a few check boxes to do things for me and after having done them, I'd love the gui to remain open so I can do things again.

I have tried to load the GUI within a fuction and recall the function like this

;Script generated by AutoBuilder 0.4

$run = 0
GUI()

Func GUI()
$run = 0
Opt("GUICoordMode", 1)
Opt("GUINotifyMode", 1)
GuiCreate("TESTING", 348,230,(@DesktopHeight-348)/2, (@DesktopHeight-230)/2 , 0x04CF0000)

$button_1 = GUISetControl("button", "DO IT", 20, 180, 120, 30)
$checkbox_1 = GUISetControl("checkbox", "A", 50, 40, 80, 20)
$checkbox_2 = GUISetControl("checkbox", "B", 50, 60, 90, 20)
$checkbox_3 = GUISetControl("checkbox", "C", 50, 80, 170, 20)
$checkbox_4 = GUISetControl("checkbox", "D", 50, 100, 160, 20)
$button_2 = GUISetControl("button", "Cancel", 210, 180, 110, 30)

GuiShow()
While 1
    sleep(100)
    $msg = GuiMsg(0)

    Select
    Case $msg = -3
        Exit
    Case $msg = 2
     ;;;
    Case $msg = $button_1
       ;;;
    ExitLoop
    Case $msg = $checkbox_1
       ;;;
    $run = $run + 1 
    Case $msg = $checkbox_2
       ;;;
    $run = $run + 10
    Case $msg = $checkbox_3
       ;;;
    $run = $run + 100
    Case $msg = $checkbox_4
       ;;;
    $run = $run + 1000
    Case $msg = $button_2
       ;;;
    Exit
    EndSelect
WEnd

endfunc

If $run = 1 then
a()
elseif $run = 10 then
b()
elseif $run = 100 then
c()
elseif $run = 1000 then
d()
ENDIF

Func A()
msgbox(0,"TEST", "FUNC A")
GUI()
endfunc

Func B()
msgbox(0,"TEST", "FUNC B")
GUI()
endfunc

Func C()
msgbox(0,"TEST", "FUNC C")
GUI()
endfunc

Func D()
msgbox(0,"TEST", "FUNC D")
GUI()
endfunc

exit

The form remains open but on the second pass, when clicking the DO IT button, the GUI closes, no message boxes.

Could you please help?

Cheers

Nobby :D

CheersNobby

Link to comment
Share on other sites

Wow, that's a really interesting way of coding that. Unfortunately, it's a strategy that will run into problems:

1) Calling a function from GUI() that in turn calls GUI() is not a good idea. (Infinite recursion could lead to a crash.)

2) Instead of setting a variable each time a checkbox is checked, use GuiRead to get the checkbox state.

A better approach can be found here: http://www.autoitscript.com/forum/index.php?showtopic=3496

Edit: Fixed link.

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

Incidentally, your way of thinking is probably the fault of AutoBuilder automatically generating the Select Case block with all the $msg = $checkbox_n statements.

You very rarely need to use $msg = $checkbox_n. The only exception I've run into is when you want a checkbox to immediately gray out other checkboxes when chosen.

The main processing for a checkbox-GUI should come almost entirely under

Case $msg = $button_n
     ;;;...
   GuiRead($checkbox_1) ...
  ;;;...
  EndSelect
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
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...