Jump to content

Closing a gui with same variable name


Recommended Posts

Hey people!! How you all doing??

Ive looked around, but didnt find an answer to my "horrible" dilemma (is that written corectly??)

I have this gui with a button (WOW!!), and the button creates another gui and shows it. If i click the "close" button (the X on the top) in this secondary gui, I want it to close only the secondary gui, therefore, It calls a function that makes

"guidelete($gui2)"

however, if before closing the second gui. i press the button on the first gui again, it creates another gui, with the same Variable name ($gui2). now, if i press the xlose button, in either of the $gui2's, it will close the last one created. The problem is that i now cannot close the first one created. help plz.

#include<guiconstants.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

opt("guioneventmode",1)

global $gui2

$maingui = GUICreate("Gui1", 400,400,-1,-1,$WS_MAXIMIZEBOX + $WS_MINIMIZEBOX)
GUISetOnEvent($gui_event_close, "bye")

;~ guiseticon 
$mainfileMenu = GUICtrlCreateMenu("File")
GUICtrlCreateMenuItem("Close", $mainfileMenu)
guictrlsetonevent(-1, "bye")

GUICtrlCreateLabel("Good Morning/afternoon!!", 30,30)


$generate = GUICtrlCreateButton("Big Button!!", 50, 150, 200, 100, $BS_DEFPUSHBUTTON + $BS_MULTILINE + $BS_CENTER)
GUICtrlSetOnEvent($generate, "generate")

guisetstate()

func generate()
        $gui2 = GUICreate("gui2",-1,-1,-1,-1,$WS_MAXIMIZEBOX + $WS_MINIMIZEBOX)
        GUISetOnEvent($gui_event_close, "closewindow")  
        guisetstate()
endfunc
    
func closewindow()
    GUIdelete($gui2)
endfunc

func bye()
    Exit
endfunc

while 1
    sleep(100)
wend

My own pocket emo http://www.mindistortion.net/pocketemo/?da...1-7-2-0-0-1-0-0LOL[quote name='beerman' post='399180' date='Sep 6 2007, 08:45 AM']I have learned, never think inside the box. The moment you have a bright idea, and stand up to quickly exclaiming, "Eureka, I have it!". You will knock yourself out, from bashing your head on the inside of the box as you stand... So in conclusion it is always safer to think outside the box. :)[/quote]

Link to comment
Share on other sites

Hi,

#include<guiconstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

opt("guioneventmode",1)

$maingui = GUICreate("Gui1", 400,400,-1,-1,$WS_MAXIMIZEBOX + $WS_MINIMIZEBOX)
GUISetOnEvent($gui_event_close, "bye")

;~ guiseticon
$mainfileMenu = GUICtrlCreateMenu("File")
GUICtrlCreateMenuItem("Close", $mainfileMenu)
guictrlsetonevent(-1, "bye")

GUICtrlCreateLabel("Good Morning/afternoon!!", 30,30)


$generate = GUICtrlCreateButton("Big Button!!", 50, 150, 200, 100, $BS_DEFPUSHBUTTON + $BS_MULTILINE + $BS_CENTER)
GUICtrlSetOnEvent($generate, "generate")

guisetstate()

func generate()
    GUICreate("gui2",-1,-1,-1,-1,$WS_MAXIMIZEBOX + $WS_MINIMIZEBOX)
    GUISetOnEvent($gui_event_close, "closewindow")    
    guisetstate()
endfunc
    
func closewindow()
    GUIdelete(@GUI_WinHandle)
endfunc

func bye()
    Exit
endfunc

while 1
    sleep(100)
wend

Cheers

Link to comment
Share on other sites

Thanks a million!

My own pocket emo http://www.mindistortion.net/pocketemo/?da...1-7-2-0-0-1-0-0LOL[quote name='beerman' post='399180' date='Sep 6 2007, 08:45 AM']I have learned, never think inside the box. The moment you have a bright idea, and stand up to quickly exclaiming, "Eureka, I have it!". You will knock yourself out, from bashing your head on the inside of the box as you stand... So in conclusion it is always safer to think outside the box. :)[/quote]

Link to comment
Share on other sites

Ok, new problem.

How do i make it so that, when all gui's are deleted, the program ends. Is there a way to do that?

My own pocket emo http://www.mindistortion.net/pocketemo/?da...1-7-2-0-0-1-0-0LOL[quote name='beerman' post='399180' date='Sep 6 2007, 08:45 AM']I have learned, never think inside the box. The moment you have a bright idea, and stand up to quickly exclaiming, "Eureka, I have it!". You will knock yourself out, from bashing your head on the inside of the box as you stand... So in conclusion it is always safer to think outside the box. :)[/quote]

Link to comment
Share on other sites

anyone??

My own pocket emo http://www.mindistortion.net/pocketemo/?da...1-7-2-0-0-1-0-0LOL[quote name='beerman' post='399180' date='Sep 6 2007, 08:45 AM']I have learned, never think inside the box. The moment you have a bright idea, and stand up to quickly exclaiming, "Eureka, I have it!". You will knock yourself out, from bashing your head on the inside of the box as you stand... So in conclusion it is always safer to think outside the box. :)[/quote]

Link to comment
Share on other sites

Hi,

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

opt("guioneventmode",1)

Global $sHGui

$maingui = GUICreate("Gui1", 400,400, 0, 0, BitOr($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX))
GUISetOnEvent($gui_event_close, "bye")
$mainfileMenu = GUICtrlCreateMenu("File")
GUICtrlCreateMenuItem("Close", $mainfileMenu)
GUICtrlSetOnEvent(-1, "bye")
GUICtrlCreateLabel("Good Morning/afternoon!!", 30,30)
$generate = GUICtrlCreateButton("Big Button!!", 50, 150, 200, 100, BitOr($BS_DEFPUSHBUTTON,$BS_MULTILINE,$BS_CENTER))
GUICtrlSetOnEvent($generate, "generate")
GUISetState(@SW_SHOW, $maingui)

While 1
    Sleep(100)
WEnd

Func generate()
    Local $hGui, $aHGui, $Offset
    $aHGui = StringSplit($sHGui, "|")
    $Offset = 10 * $aHGui[0]
    $hGui = GUICreate("gui " & $aHGui[0], -1, -1, $Offset + 390, $Offset - 10, BitOr($WS_MAXIMIZEBOX,$WS_MINIMIZEBOX))
    GUISetOnEvent($gui_event_close, "closewindow")   
    GUISetState(@SW_SHOW, $hGui)
    $sHGui &= $hGui & "|"
EndFunc
   
Func closewindow()
    $sHGui = StringReplace($sHGui, @GUI_WinHandle & "|", "")
    GUIdelete(@GUI_WinHandle)
    If $sHGui = "" Then bye()
EndFunc

Func bye()
    Exit
EndFunc

Cheers

Edited by smashly
Link to comment
Share on other sites

umh, your code is closing all windows. It's just like the bye function.

My own pocket emo http://www.mindistortion.net/pocketemo/?da...1-7-2-0-0-1-0-0LOL[quote name='beerman' post='399180' date='Sep 6 2007, 08:45 AM']I have learned, never think inside the box. The moment you have a bright idea, and stand up to quickly exclaiming, "Eureka, I have it!". You will knock yourself out, from bashing your head on the inside of the box as you stand... So in conclusion it is always safer to think outside the box. :)[/quote]

Link to comment
Share on other sites

I have a question for this, I want my 2nd gui to have 2 buttons (a close and a cancel) but the buttons are unresponsive. I have a feeling its something small I'm missing, I just can't figure it out.

#include<guiconstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>

opt("guioneventmode",1)

$maingui = GUICreate("What would you like to do?", 500, 500)
GUISetOnEvent($gui_event_close, "areyousure")

;~ guiseticon
GUICtrlCreateLabel("New or Edit?", 10, 10)
$neworedit = GUICtrlCreateCombo("", 10, 50)
GUICtrlSetData(-1, "New|Edit", "Edit") 
GUICtrlCreateLabel("Which Database?", 10, 90)
$database = GUICtrlCreateCombo("", 10, 130)
GUICtrlSetData(-1, "Package|Import|Mold", "Package") 


$gobutton = GUICtrlCreateButton("Go", 150, 450, 60)
GUICtrlSetOnEvent($gobutton, "gobutton")
$searchbutton = GUICtrlCreateButton("search", 250, 450, 60)
GUICtrlSetOnEvent($searchbutton, "searchbutton")

guisetstate()

func gobutton()
    If GUICtrlRead($neworedit) = "New" and GUICtrlRead($database) = "import" Then
      MsgBox(0, "include", "replace with include to new imports")
      GUIdelete(@maingui)
      ElseIf GUICtrlRead($neworedit) = "New" and GUICtrlRead($database) = "package" Then
      MsgBox(0, "include", "replace with include to new package")
      GUIdelete(@maingui)
  Else
      If GUICtrlRead($neworedit) = "New" and GUICtrlRead($database) = "mold" Then
      MsgBox(0, "include", "replace with include to new mold")
      GUIdelete(@maingui)
      ElseIf GUICtrlRead($neworedit) = "edit" and GUICtrlRead($database) = "import" Then
      MsgBox(0, "include", "replace with include to edit import")
      GUIdelete(@maingui)
  Else
      if GUICtrlRead($neworedit) = "edit" and GUICtrlRead($database) = "package" Then
      MsgBox(0, "include", "replace with include to edit package")
      GUIdelete(@maingui)
      ElseIf  GUICtrlRead($neworedit) = "edit" and GUICtrlRead($database) = "mold" Then
      MsgBox(0, "include", "replace with include to edit mold")
      GUIdelete(@maingui)
  Else
      MsgBox(0, "incorrect", "incorrect input")
  EndIf
  EndIf
  EndIf
  EndFunc
  Func areyousure()
      $gui = GUICreate("Exiting", 300, 100)
      GUISetOnEvent($gui_event_close, "closewindow")
    GUICtrlCreateLabel("Are You Sure", 10, 10)
          $closebutton = GUICtrlCreateButton("Yes", 10, 50, 60)
          GUISetOnEvent($closebutton, "bye")
          $canclebutton = GUICtrlCreateButton("No", 100, 50, 60)
    GUISetOnEvent($canclebutton, "closewindow")   
    
    guisetstate()
endfunc
Func searchbutton()
    MsgBox(0, "future", "file search")
    GUIdelete(@maingui)
    EndFunc

func closewindow()
    GUIdelete(@GUI_WinHandle)
endfunc

func bye()
    Exit
endfunc

while 1
    sleep(100)
wend

Giggity

Link to comment
Share on other sites

umh, your code is closing all windows. It's just like the bye function.

Umm No, it's closing the original first window with the "Big Button!!" if there are no newly created windows left.

eg: Run script, hit the "Big Button!!" 5 times, now close 4 of the new windows. Is there not 2 windows left?

Close the last new window, and both the original window and last new window close.

It's sorta hard to know what you want by your description

Ok, new problem.

How do i make it so that, when all gui's are deleted, the program ends. Is there a way to do that?

Going bye that description, the only GUI windows that are being deleted in your code are the newly created windows by the "Big Button!!" that are closed.

More clarity in your case would yield better results in help.

Cheers

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