Sign in to follow this  
Followers 0
John117

resume while 1 after other while 1 ends . .

6 posts in this topic

#1 ·  Posted (edited)

I have a While 1 statement that controls the button function of a GUI (GUI1)

One of the buttons controlled by While 1 opens a second GUI (GUI2)

The Button functions for that GUI are inside of the first while 1

Ex

build GUI1

While 1

If Button to close then close

if Button to build GUI2 Then

Build GUI2

While 1

If button to do things on GUI2 Then

Do Things

If Button to close on GUI2 Then

Exit Loop

delete GUI2

WEnd

WEnd

This is how I've been getting around' with out errors. Problem is now I want to add double click detection and the only stuff I have is a function.

So if I make it this . . .

build GUI1

While 1

If Button to close then close

if Button to build GUI2 Then

_BuildGUI2()

EndIF

WEnd

;Functions

_BuildGUI2()

Build GUI2

While 1

If button to do things on GUI2 Then

Do Things

If Button to close on GUI2 Then

Exit Loop

delete GUI2

WEnd

Then the problem and point of this post is, I need to reenter the first while 1 loop on GUI 1

But, the loop is closed and buttons no longer work on GUI 1. . . :) Please help! (Parent-Child Relationship)

Edited by Hatcheda

Share this post


Link to post
Share on other sites



I have a While 1 statement that controls the button function of a GUI (GUI1)

One of the buttons controlled by While 1 opens a second GUI (GUI2)

The Button functions for that GUI are inside of the first while 1

; ...

Then the problem and point of this post is, I need to reenter the first while 1 loop on GUI 1

But, the loop is closed and buttons no longer work on GUI 1. . .

Try this:

#include <guiconstants.au3>

$hGUI_1 = GUICreate("Title_1", 200, 200, 100, 100)
$GUI_2_Button = GUICtrlCreateButton("GUI_2", 10, 10)
GUISetState(@SW_SHOW, $hGUI_1)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete($hGUI_1)
            ExitLoop
            
        Case $GUI_2_Button
            $hGUI_2 = GUICreate("Title_2", 200, 200, 200, 200, -1, -1, $hGUI_1)
            $DoSomethingButton = GUICtrlCreateButton("Do_It!", 10, 10)
            GUISetState(@SW_SHOW, $hGUI_2)
            
            While 1
                Switch GUIGetMsg()
                    Case $GUI_EVENT_CLOSE
                        GUIDelete($hGUI_2)
                        ExitLoop
                        
                    Case $DoSomethingButton
                        MsgBox(64, "Done", "Did it.", 1)
                EndSwitch
            WEnd
    EndSwitch
WEnd

:P Please help! (Parent-Child Relationship)

So, tell us about your childhood... how did you get along with your parents... :)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hey, PsaltyDS! thanks for the reply. My parents were very loving, Thanks! :)

This is what I am using now. (my origional/current format, your code) ~same thing

CODE

#include <guiconstants.au3>

$hGUI_1 = GUICreate("Title_1", 200, 200, 100, 100)

$GUI_2_Button = GUICtrlCreateButton("GUI_2", 10, 10)

GUISetState(@SW_SHOW, $hGUI_1)

While 1

$Msg1 = GUIGetMsg()

If $Msg1 = $GUI_EVENT_CLOSE Then

GUIDelete($hGUI_1)

ExitLoop

EndIf

If $Msg1 = $GUI_2_Button Then

$hGUI_2 = GUICreate("Title_2", 200, 200, 200, 200, -1, -1, $hGUI_1)

$DoSomethingButton = GUICtrlCreateButton("Do_It!", 10, 10)

GUISetState(@SW_SHOW, $hGUI_2)

While 1

$Msg2 = GUIGetMsg()

If $Msg2 = $GUI_EVENT_CLOSE Then

GUIDelete($hGUI_2)

ExitLoop

EndIf

If $Msg2 = $DoSomethingButton Then

MsgBox(64, "Done", "Did it.", 1)

EndIf

WEnd

EndIf

WEnd

The problem is I can't get the following code away from a function! ie I want to add it to GUI1 so that on double click it opens GUI2 and GUI2 can close without shuting down GUI1

Then at the end, GUI1 still needs to work :)

If I could get the following working and inserted into the above, that would be great.

single click on GUI1 does anything, double click does anything else :)

CODE
#include <GuiConstants.au3>

;Opt("MustDeclareVars", 1)

Global Const $WM_COMMAND = 0x0111

Global $Edit1

$Form2 = GUICreate("Test Button For Double Click", 716, 561, 155, 134)

$Edit1 = GUICtrlCreateEdit("Type Message Here", 10, 30, 230, 60, $ES_WANTRETURN)

$Button = GUICtrlCreateButton("Button Test", 10, 100, 89, 41, $BS_NOTIFY)

GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

GUISetState(@SW_SHOW)

While 1

$msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

ExitLoop

EndSelect

WEnd

Func _LoWord($x)

Return BitAND($x, 0xFFFF)

EndFunc ;==>_LoWord

Func _HiWord($x)

Return BitShift($x, 16)

EndFunc ;==>_HiWord

Func MY_WM_COMMAND($hWnd, $msg, $wParam)

Local Const $BN_CLICKED = 0;

Local Const $BN_DBLCLICKED = 5;

Local $nID = _LoWord($wParam)

Local $nNotifyCode = _HiWord($wParam)

If $nID <> 2 Then

Switch $nNotifyCode

Case $BN_CLICKED

GUICtrlSetData($Edit1, (GUICtrlRead($Edit1)+1))

Case $BN_DBLCLICKED

MsgBox(0, "Double", "Click")

;GUICreate("Update Profile", 100, 100)

;GUISetState()

EndSwitch

EndIf

Return $GUI_RUNDEFMSG

EndFunc ;==>MY_WM_COMMAND

The problem: I can make the function build the GUI2 and control it. Even close it and keep GUI1 open, but then I am out of the loop. Or I can stay in the loop and not get the function of the doubleclick :P

Edited by Hatcheda

Share this post


Link to post
Share on other sites

*bump* :)

Share this post


Link to post
Share on other sites

I much prefer GuiOnEventMode for this:

#include <GuiConstants.au3>

Opt("GuiOnEventMode", 1)

Global Const $WM_COMMAND = 0x0111
Global Const $BN_CLICKED = 0;
Global Const $BN_DBLCLICKED = 5;
Global $hParent, $Edit1, $Edit1Data, $hChild

$hParent = GUICreate("Test Button For Double Click", 716, 561, 155, 134)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit", $hParent)
$Edit1 = GUICtrlCreateEdit("Type Message Here", 10, 30, 230, 60, $ES_WANTRETURN)
$Button = GUICtrlCreateButton("Button Test", 10, 100, 89, 41, $BS_NOTIFY)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")
GUISetState(@SW_SHOW)

While 1
    Sleep(20)
WEnd

Func MY_WM_COMMAND($hWnd, $msg, $wParam)
    Local $nID = BitAND($wParam, 0xFFFF)
    Local $nNotifyCode = BitShift($wParam, 16)
    If $hWnd = $hParent And $nID <> 2 Then
        Switch $nNotifyCode
            Case $BN_DBLCLICKED
                _ChildGUI()
            Case $BN_CLICKED
                $Edit1Data = GUICtrlRead($Edit1) + 1
                GUICtrlSetData($Edit1, $Edit1Data)
        EndSwitch
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_COMMAND

Func _ChildGUI()
    $hChild = GUICreate("Child GUI", 200, 200, 400, 400, -1, -1, $hParent)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseChild", $hChild)
    $ChildButton = GUICtrlCreateButton("Double", 10, 10, 100, 30)
    GUICtrlSetOnEvent(-1, "_ShowDouble")
    GUISetState(@SW_SHOW, $hChild)
EndFunc   ;==>_ChildGUI

Func _ShowDouble()
    MsgBox(64, "Double", "Double " & $Edit1Data & " = " & $Edit1Data * 2)
EndFunc   ;==>_ShowDouble

Func _CloseChild()
    GUIDelete($hChild)
EndFunc   ;==>_CloseChild

Func _Quit()
    Exit
EndFunc   ;==>_Quit

Note the changes to MY_WM_COMMAND():

1. Integrated the on-liner subfunctions.

2. Added the check for the parent GUI being the source of the button hit, or it will get hits from the child GUI too.

3. Tested for double-click BEFORE testing for single-click, otherwise you get BOTH on a double-click.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

You know, this works. will be interesting to adapt all my other code, but will be much easier to read! Thanks! :)

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
Sign in to follow this  
Followers 0