Sign in to follow this  
Followers 0
chie

How to close only GUI 2

28 posts in this topic

& As always help file was no good to solve this problem....Well atleast I was unable to figure out how can I close only GUI 2 & let GUI 1 open. this is simplest sample of my code, since its too long to post the whole thing hire. Any sugesstions?

#include <GUIConstants.au3>
GUICreate("My GUI Rater")  
$mainwindow = GUICreate("Rater", 300, 100)      ; GUI 1
$OK = GUICtrlCreateButton("Show GUI2", 110, 60, 75, 23)
GUISetState () 

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    
    Switch $msg
        Case $OK
    
            $Window_Search_options = GUICreate("Search Options", 400, 100) ; GUI 2
            GUISetState(@SW_SHOW)
    
        Case Else
        
    EndSwitch
WEndoÝ÷ Ø    l¡©ò×¢~)ëazÚÚÊg§ºØ^MúBTCS³Ëh¦Ì(®H§«­¢+Ø¥¹±Õ±ÐíU%
½¹ÍѹÑ̹ÔÌÐì)U%
ÉÑ ÅÕ½Ðí5äU$IÑÈÅÕ½Ðì¤)=ÁÐ ÅÕ½ÐíQÉå5¹Õ5½ÅÕ½Ðì°Ä¤ìÕ±ÐÑÉ䵹ԥѵ̡MÉ¥ÁÐAÕͽá¥Ð¤Ý¥±°¹½ÐÍ¡½Ý¸¸(ÀÌØíµ¥¹Ý¥¹½ÜôU%
ÉÑ ÅÕ½ÐíIÑÈÅÕ½Ðì°ÌÀÀ°ÄÀÀ¤$$ìU$Ä(ÀÌØí=,ôU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½ÐíM¡½ÜU$ÈÅÕ½Ðì°ÄÄÀ°ØÀ°ÜÔ°È̤()U%MÑMÑÑ ¤()]¡¥±Ä($ÀÌØíµÍôU%Ñ5Í ¤($(%%ÀÌØíµÍôÀÌØíU%}Y9Q}
1=MQ¡¸á¥Ñ1½½À($(%MÝ¥Ñ ÀÌØíµÍ($%
ÍÀÌØí=,($($$$ÀÌØí]¥¹½Ý}MÉ¡}½ÁÑ¥½¹ÌôU%
ÉÑ ÅÕ½ÐíMÉ =ÁÑ¥½¹ÌÅÕ½Ðì°ÐÀÀ°ÄÀÀ¤ìU$È($$%U%MÑMÑÑ¡M]}M!=¤($($%
ͱÍ($$(¹MÝ¥Ñ )]¹((íøQÉäµ¹ÔMQIP(íø´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´(ÀÌØíá¥Ñ¥Ñ´ôQÉå
ÉÑ%Ñ´ ÅÕ½Ðíá¥ÐÅÕ½Ðì¤)QÉåMÑMÑÑ ¤()]¡¥±Ä(ÀÌØíµÍôQÉåÑ5Í ¤(M±Ð(
ÍÀÌØíµÍôÀ(
½¹Ñ¥¹Õ1½½À(
ÍÀÌØíµÍôÀÌØíá¥Ñ¥Ñ´(á¥Ñ1½½À(¹M±Ð)]¹)á¥Ð(íø´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´(íøQÉäµ¹Ô9

Share this post


Link to post
Share on other sites



I would not have posted this unless I have already searched the forum.! Yes there were some ecamples but I found none that chould help me with this case thing since I cant use gui1() & gui2() & functions hire

Share this post


Link to post
Share on other sites

You know you could do some of the job yourselfe. I dont meen to be mean, but you know all you have to do is to make a few searches and study what comes up.

Search for: GuiSwitch, GuiDelete or "multiple forms"

I did a search for +$msg1 +$msg2 and this came up.

Share this post


Link to post
Share on other sites

I told you already I cant use functions nor Opt('GUIOnEventMode', 1) if I do this, Buttons stop working!

Share this post


Link to post
Share on other sites

Explain why you cnat use any of those?

Or GuiGetMsg in advanced mode for that sake? Its like RTFM you know!

$array[0]= 0 or Event ID or Control ID

$array[1] = The window handle the event is from

$array[2] = The control handle the event is from (if applicable)

$array[3] = The current X position of the mouse cursor (relative to the GUI window)

$array[4] = The current Y position of the mouse cursor (relative to the GUI window)

Share this post


Link to post
Share on other sites

Take a look at the GUISwitch() examples in the help file.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

This might be what your after if I'm understanding correctly:

#include <guiconstants.au3>
GUICreate("My GUI Rater") 
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.
$mainwindow = GUICreate("Rater", 300, 100)   ; GUI 1
$OK = GUICtrlCreateButton("Show GUI2", 110, 60, 75, 23)
$Window_Search_options = GUICreate("Search Options", 400, 100) ; GUI 2
GUISetState(@SW_SHOW, $mainwindow)
GUISetState(@SW_HIDE, $Window_Search_options)

While 1
    $msg = GUIGetMsg(1)
    Select
        Case $msg[0] = -3 And $msg[1] = $mainwindow
            ExitLoop
        Case $msg[0] = -3 And $msg[1] = $Window_Search_options
            GUISetState(@SW_HIDE, $Window_Search_options)
        Case $msg[0] = $OK
            GUISetState(@SW_SHOW, $Window_Search_options)
    EndSelect
WEnd


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Your way to kind SmOke_N :whistle:

hmm, and I'm probably way to rude at the moment ;)

Nah... I don't even think my solution is right, I think it should be GUISwitch(), but I was messing around with something else and came up with that or
#include <guiconstants.au3>
GUICreate("My GUI Rater") 
Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.
$mainwindow = GUICreate("Rater", 300, 100)   ; GUI 1
$OK = GUICtrlCreateButton("Show GUI2", 110, 60, 75, 23)
$Window_Search_options = GUICreate("Search Options", 400, 100) ; GUI 2
GUISetState(@SW_SHOW, $mainwindow)
GUISetState(@SW_HIDE, $Window_Search_options)

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case -3
            If $msg[1] = $mainwindow Then ExitLoop
            GUISetState(@SW_HIDE, $Window_Search_options)
        Case $OK
            GUISetState(@SW_SHOW, $Window_Search_options)
    EndSwitch
WEnd
this.

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Edit nothing interesting hire

Edited by chie

Share this post


Link to post
Share on other sites

Aww no edit button.... eathe way thank you. I need to analyse this now.

Share this post


Link to post
Share on other sites

It looks more like you should just put the 2nd GUI in it's own function, and call it from there, letting it have it's own loop and conditional statements.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

& As always help file was no good to solve this problem....Well atleast I was unable to figure out how can I close only GUI 2 & let GUI 1 open. this is simplest sample of my code, since its too long to post the whole thing hire. Any sugesstions?

#include <GUIConstants.au3>
GUICreate("My GUI Rater")  
$mainwindow = GUICreate("Rater", 300, 100)      ; GUI 1
$OK = GUICtrlCreateButton("Show GUI2", 110, 60, 75, 23)
GUISetState () 

While 1
    $msg = GUIGetMsg()
    
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    
    Switch $msg
        Case $OK
    
            $Window_Search_options = GUICreate("Search Options", 400, 100) ; GUI 2
            GUISetState(@SW_SHOW)
    
        Case Else
        
    EndSwitch
WEndoÝ÷ Ø    l¡©ò×¢~)ëazÚÚÊg§ºØ^MúBTCS³Ëh¦Ì(®H§«­¢+Ø¥¹±Õ±ÐíU%
½¹ÍѹÑ̹ÔÌÐì)U%
ÉÑ ÅÕ½Ðí5äU$IÑÈÅÕ½Ðì¤)=ÁÐ ÅÕ½ÐíQÉå5¹Õ5½ÅÕ½Ðì°Ä¤ìÕ±ÐÑÉ䵹ԥѵ̡MÉ¥ÁÐAÕͽá¥Ð¤Ý¥±°¹½ÐÍ¡½Ý¸¸(ÀÌØíµ¥¹Ý¥¹½ÜôU%
ÉÑ ÅÕ½ÐíIÑÈÅÕ½Ðì°ÌÀÀ°ÄÀÀ¤$$ìU$Ä(ÀÌØí=,ôU%
Ñɱ
ÉÑ    ÕÑѽ¸ ÅÕ½ÐíM¡½ÜU$ÈÅÕ½Ðì°ÄÄÀ°ØÀ°ÜÔ°È̤()U%MÑMÑÑ ¤()]¡¥±Ä($ÀÌØíµÍôU%Ñ5Í ¤($(%%ÀÌØíµÍôÀÌØíU%}Y9Q}
1=MQ¡¸á¥Ñ1½½À($(%MÝ¥Ñ ÀÌØíµÍ($%
ÍÀÌØí=,($($$$ÀÌØí]¥¹½Ý}MÉ¡}½ÁÑ¥½¹ÌôU%
ÉÑ ÅÕ½ÐíMÉ =ÁÑ¥½¹ÌÅÕ½Ðì°ÐÀÀ°ÄÀÀ¤ìU$È($$%U%MÑMÑÑ¡M]}M!=¤($($%
ͱÍ($$(¹MÝ¥Ñ )]¹((íøQÉäµ¹ÔMQIP(íø´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´(ÀÌØíá¥Ñ¥Ñ´ôQÉå
ÉÑ%Ñ´ ÅÕ½Ðíá¥ÐÅÕ½Ðì¤)QÉåMÑMÑÑ ¤()]¡¥±Ä(ÀÌØíµÍôQÉåÑ5Í ¤(M±Ð(
ÍÀÌØíµÍôÀ(
½¹Ñ¥¹Õ1½½À(
ÍÀÌØíµÍôÀÌØíá¥Ñ¥Ñ´(á¥Ñ1½½À(¹M±Ð)]¹)á¥Ð(íø´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´´(íøQÉäµ¹Ô9
At first glance it looks to me like your primary problem is declaring $Msg twice.

I don't do the tray controled GUISwitch but I do Use multiple GUI's in the same script and have no prblems with it.

Using $Msg = GUIGetMsg()

I just put each GUI in a function and then

If (Or Case) $Msg = MenuItem1 Then Another_GUI()

The other GUI is created as any other but after the GUISetState() you have to be sure to use something like

While 1

$Msg = GUIGetMsg()

If $Msg = -3 OR $Msg = $Btn_Cancel Then

GUIDelete()

GUISwitch($MainGUI)

GUISetState

Return

Wend

(All this is from memory because I don't have the code I use in front of me I migt not have the Return statement in the actual code)

I think that you will also have to use $Msg2 = TrayGetMsg()

and then use that to control your GUIDelete(), GUISwitch(), and GUISetState() Calls

So it would be somthing along the line of

GUISetState()

While 1

$Msg = GUIGetMsg()

$Msg2 = TrayGetMsg()

Switch

Case $Msg = -3 Or $Msg2 = $TrayItem_CloseGUI

GUIDelete()

GUISwitch($MainGUI)

GUISetState ;; required to turn control back to the main GUI so the controls on there will work again.

Return

EndSwitch

Wend

EndSwitch


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

It looks more like you should just put the 2nd GUI in it's own function, and call it from there, letting it have it's own loop and conditional statements.

Solved hire is final code if someone is interestad & About founctions, In my code where I want to use it I have already 200 lines of code & to rewrite all this would be realy bothersome..this why i was looking for a weay to do it with case...

#include <guiconstants.au3>
GUICreate("My GUI Rater") 
;~ Opt("TrayMenuMode",1)   ; Default tray menu items (Script Paused/Exit) will not be shown.
$mainwindow = GUICreate("Rater", 300, 100)   ; GUI 1
$Paa_change_options = GUICreate("pass change options", 400, 100) ; GUI 3
$Window_Search_options = GUICreate("Search Options", 400, 100) ; GUI 2

;Show Main window & Fail meny on main window
GUISetState(@SW_SHOW, $mainwindow)
$filemenu = GUICtrlCreateMenu ("&File")
$pass_options_item= GUICtrlCreateMenuitem ("pass options",$filemenu)
$Search_options_Item= GUICtrlCreateMenuitem ("search options",$filemenu)

GUISetState(@SW_HIDE, $Window_Search_options)
GUISetState(@SW_HIDE, $Paa_change_options)

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[0]
        Case -3
            If $msg[1] = $mainwindow Then ExitLoop
            GUISetState(@SW_HIDE, $Window_Search_options)
            GUISetState(@SW_HIDE, $Paa_change_options)
        Case $pass_options_item
            GUISetState(@SW_SHOW, $Paa_change_options)
        Case $Search_options_Item
            GUISetState(@SW_SHOW, $Window_Search_options)

    EndSwitch
WEndoÝ÷ Ø{¦Éëºw^®ËZÖ(ºxk¢±«lµªíjjl0éçyç^"¯{d.zËb¢{zÛ,ºh±â0YfjG¦j|º+âuëazdáÌ"Yj{az¢±ªÞr·µç[ºÙè¶ÈhÂx­Â)ew+y«jZ-õ.±¨{aDZäbZ®zËb¢}­êÞÍm)à!Ú'¶éÝz»-jwb¶Å¡È&¬{u¡j×hzÀ±íæy©Ú7êk ÕhZµªÞ¶²~â²Øb²Ê&zH§vÚ®¶²¶§«­¢+Ø
Í´Ì(%ÀÌØíµÍlÅtôÀÌØíµ¥¹Ý¥¹½ÜQ¡¸á¥Ñ1½½À
Edited by chie

Share this post


Link to post
Share on other sites

How odd, someone has asked the exact same question as you has @chie.

Close 2nd GUI without closing 1st GUI.

And uhh, you don't use arrays because you don't understand them? But you expect to be able to handel multiple GUI's?

Yeah I know, I'm in the bully corner at the moment. :whistle:

PS: When I do a search I always try with the "search titles only" option selected. Tend to get better hits then.

Since I have been such a bully let's see if I can help you out.

#include <GUIConstants.au3>
MultipleWindows()
Exit
Func MultipleWindows()
    ;;#include <GUIConstants.au3>
    HotKeySet("{ESC}", "MultipleWindowsTerminate")
    ;Create tray items
    Local $settingsitem = TrayCreateMenu("Settings")
    LOcal $displayitem = TrayCreateItem("Display", $settingsitem)
    Local $printeritem = TrayCreateItem("Printer", $settingsitem)
    TrayCreateItem("")
    Local $aboutitem = TrayCreateItem("About")
    TrayCreateItem("")
    Local $trayExit  = TrayCreateItem("Exit")

    TraySetState()
    ; Create GUIs
    Local $MAX = 5
    Local $guis[$MAX + 1] ;BitOr(-1, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CLIPCHILDREN), $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_POPUP,, $WS_CLIPSIBLINGS
    Local $mainGui = GUICreate("GUI: Main", 500, 400); $WS_MAXIMIZE + , $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX, $WS_CLIPCHILDREN
    $guis[0] = HWnd($mainGui)
    GUISetState(@SW_SHOW)


    For $i = 1 To $MAX
        $guis[$i] = GUICreate("GUI: " & $i, 150, 100, $i * 10, $i * 10, BitOR(-1, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_CLIPCHILDREN, $WS_CHILD), BitOR($WS_EX_MDICHILD, $WS_EX_APPWINDOW, $WS_EX_LEFTSCROLLBAR, $WS_EX_OVERLAPPEDWINDOW, $WS_EX_CLIENTEDGE), HWnd($mainGui)) ; ,BitOR($WS_EX_MDICHILD, $WS_EX_APPWINDOW, $WS_EX_LEFTSCROLLBAR, $WS_EX_OVERLAPPEDWINDOW, $WS_EX_CLIENTEDGE))
        GUISetBkColor(555, HWnd($guis[$i]))
        ;SetParent(Hwnd($mainGui) , hwnd($guis[$i]))
        GUISetState(@SW_SHOW)
    Next
    GUISetState(@SW_SHOW, HWnd($mainGui)) ; Switch focus to main gui
    ; Monitor events
    Local $msg = GUIGetMsg(1) ;NOTE: Read the help file on GUIGetMsg
    While 1
        $msg = GUIGetMsg(1)
        ConsoleWrite(">Window switch" & @LF)
        Switch $msg[0]
            Case 0
                Sleep(100) ;Slepping will reduce CPU load
            Case - 11 ;Dont care about mouse movements
            Case  -3  
               If $msg[1] = $guis[0] Then 
                  ExitLoop
               Else 
                  GUIDelete($msg[1])
                  GUISwitch($guis[0])
               EndIf 
            Case Else
                ConsoleWrite("Control or event ID:=" & $msg[0] & ", hwnd:=" & $msg[1] & ", main:=" & $guis[0] & @LF)
        EndSwitch
        ;NOTE: You need to handel tray msgs in the active msg loop
        ConsoleWrite("Tray switch" & @LF)
        Switch TrayGetMsg()
            Case $trayExit
               ConsoleWrite("+++Tray exit" & @LF)
                Exit
        EndSwitch
    WEnd
    ConsoleWrite("---End of loop, returning from func" & @LF)
    ;At this point we will terminate
    Return 1
EndFunc   ;==>MultipleWindows

OK, I'm a tad late with this one several posts inbetween

Hum yes I understand You hide Gui-s at start & show when needed But I have 2 Questions. Lets suppose I will make many Guis & Hide them ( This will mean the guis are created but not shown ) it will increase alot CPU usage in this case Right ?

Not nescesarely when they are hiden the will not produce much.

& question 2 there is 1 thing I dont understand , its Why Case -3 ? What does Case -3 mean? & $msg[1] What are they for? is this some kind of array thing?

-3 = $GUI_EVENT_CLOSE

You can use -3 to avoid the overhead of including guiconstants.au3

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Func MultipleWindowsTerminate()
    ;Used by hotkeyset
    Exit
EndFunc   ;==>MultipleWindowsTerminate

Edited by Uten

Share this post


Link to post
Share on other sites

Hum yes I understand You hide Gui-s at start & show when needed But I have 2 Questions. Lets suppose I will make many Guis & Hide them ( This will mean the guis are created but not shown ) it will increase alot CPU usage in this case Right ?

& question 2 there is 1 thing I dont understand , its Why Case -3 ? What does Case -3 mean? & $msg[1] What are they for? is this some kind of array thing?

Case -3
            If $msg[1] = $mainwindow Then ExitLoop
In the first case if you aren't closing the GUI's then you can bet you will increase CPU usage!!

The second question is already answered but I'll clarify it. -3 is the control identifier for the little red X in the top right of the GUI. I rarely #iinclude files so I don't remember what the AutoIt constants are. As a matter of fact I have a script that I run against functions in the Functions in the UDF files that removes the AutoIt constants. BTW if anyone is interested I do have a constants file Which contains ALL of the constants including those that were extracted from the UDF files.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

In the first case if you aren't closing the GUI's then you can bet you will increase CPU usage!!

By the magnitude of?

-3 is the control identifier for the little red X in the top right of the GUI.

Dont think so, you get the same message if you don't have that X.

The event -3 ($GUI_EVENT_CLOSE) will be created with ALT+F4 in this code.

Local $gui = GUICreate(@ScriptName, 135, 0, @DesktopWidth - 135 - 65, _
             -4, $WS_DLGFRAME, _
            $WS_EX_TOPMOST);$WS_DLGFRAME; + $WS_EX_TOOLWINDOW
    GUISetState(@SW_SHOW)
while 1
    switch GuiGetMsg()
        case 0
            sleep(0) ;give up your cpu time slot
        case -3 ;Your asked to close your window/application
            exit
    endswitch
wend

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