Jump to content

Multiple GUI windows......unloading individual forms?


hogfan
 Share

Recommended Posts

I've done some reading, but still can't achieve what I'm trying to do here. Within my application, the user can launch additional forms from several buttons. I have setup each additional form/GUI with it's own while statement because I want to allow the user to keep several of these open until the choose to close them.

So an example is, from within my main GUI the user clicks a button which calls a function to launch this secondary GUI:

Func _MyFunction2()
$currentTool = "MyVariable"
$ClipCurrent = ClipGet()
$frmScript = GUICreate( "Script On Clipboard", 388, 204, 335, 237, -1, -1, $Form1_1_1)
$edtCurrentScript = GUICtrlCreateEdit("", 0, 0, 385, 201, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, $ClipCurrent)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "_QuitScriptWindow")

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit

EndSwitch
Sleep(100)
WEnd
EndFunc

The referenced _QuitScriptWindow function basically calls "Exit", but I believe this will completely exit the app. Is there a way that within these additional functions/GUI's I can allow the user to basically just unload that form when they click the "X" button on it? I don't want to exit the main GUI, only that specific window. Any help is extremely appreciated. Coming from a Visual Basic background, this is confusing me in AutoIt since there is nothing similar to a unload form event.

-hogfan

Link to comment
Share on other sites

Check out this Wiki Tutorial that should help answer that question.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Looking through that WIKI article I see how to do this with two static GUI windows open. However, I have the possibility of about 9 popup informational windows that I need to keep track of.......Is there a better way of doing this? Other than naming each of the 9 guis differently? Because basically all I'm doing is popping up a window for the user with an edit box that contains some text.....However the text is dynamic based on which button they clicked to launch the this second Gui window. The other caveat is that i need to allow the user to leave several of these open at once and close them out individually.

-hogfan

Link to comment
Share on other sites

  • Moderators

hogfan,

Just save the handles of the GUIs you create and have more cases in here:

$aMsg = GUIGetMsg(1) ; Use advanced parameter to get an array returned
Switch $aMsg[1] ; First check which GUI sent the message
    Case $hGUI1
        Switch $aMsg[0] ; Now check for the messages sent from $hGUI1

to deal with them. Not very difficult. :D

But make sure you declare the GUI handle variables initially or you will get error messages. :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

hogfan,

And here is how you might do it: :oops:

#include <GUIConstantsEx.au3>

Global $aButton[9], $aGUI[9]

$hGUI = GUICreate("Test", 500, 500)
For $i = 0 To 8
    $aButton[$i] = GUICtrlCreateButton("GUI " & $i, 10, 10 + (50 * $i), 80, 30)
Next
GUISetState()

For $i = 0 To 8
    $aGUI[$i] = GUICreate("GUI " & $i, 200, 200, 100 + (100 * $i), 100 + (50 * $i), -1, -1, $hGUI)
    GUISetState(@SW_HIDE, $aGUI[$i])
Next

GUISwitch($hGUI)

While 1

    $aMsg = GUIGetMsg(1)
    Switch $aMsg[1]
        Case $hGUI
            Switch $aMsg[0]
                Case $GUI_EVENT_CLOSE
                    Exit
                Case Else
                    For $i = 0 To 8
                        If $aMsg[0] = $aButton[$i] Then
                            GUICtrlSetState($aButton, $GUI_DISABLE)
                            GUISetState(@SW_SHOW, $aGUI[$i])
                            ExitLoop
                        EndIf
                    Next
            EndSwitch
        Case Else
            For $i = 0 To 8
                If $aMsg[1] = $aGUI[$i] Then
                    Switch $aMsg[0]
                        Case $GUI_EVENT_CLOSE
                            GUICtrlSetState($aButton, $GUI_ENABLE)
                            GUISetState(@SW_HIDE, $aGUI[$i])
                            ExitLoop
                    EndSwitch
                EndIf
            Next
    EndSwitch

WEnd

Ask if you do not follow the code. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

So from what I can tell, this is initially creating all the GUIs when the script is executed and then just hiding them all? The clicking the buttons is just showing the that GUI. The While loop determines the GUI you clicked the X in and just rehides it? Am I following? Thanks.

-hogfan

Link to comment
Share on other sites

  • Moderators

hogfan,

You have it! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

ok, but is this possible? Each of my additional GUIs is launched when it is needed by the user clicking on a image which call a function like the one it my initial post, minus the While loop portion.

Func _MyFunction2() $currentTool = "MyVariable" $ClipCurrent = ClipGet()
$frmMyScript1 = GUICreate( "Current Script", 388, 204, 335, 237, -1, -1, $Form1_1_1)
$edtCurrentScript = GUICtrlCreateEdit("", 0, 0, 385, 201,BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, $ClipCurrent) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE, "_QuitScriptWindow")
EndFunc

Each GuiCreate function has it's own unique handle (ie. $frmMyScript1). So is there a way to check that window handle within the While loop and close the specific window based on that handle?

-hogfan

Edited by hogfan
Link to comment
Share on other sites

  • Moderators

hogfan,

So you insist on creating them as required and you want to use OnEvent mode...OK. :D

Take a look at this:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Opt("GUIOnEventMode", 1)

Global $aButton[9], $aGUI[9]

$hGUI = GUICreate("Test", 500, 500)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_Exit")

For $i = 0 To 8
    $aButton[$i] = GUICtrlCreateButton("GUI " & $i, 10, 10 + (50 * $i), 80, 30)
    GUICtrlSetOnEvent(-1, "Button_Press")
Next

GUISetState()

While 1
    Sleep(10)
WEnd

Func GUI_Exit()

    Switch @GUI_WINHANDLE
        Case $hGUI
            Exit
        Case Else
            For $i = 0 To 9
                If @GUI_WINHANDLE = $aGUI[$i] Then
                    GUICtrlSetState($aButton[$i], $GUI_ENABLE)
                    GUIDelete($aGUI[$i])
                    ExitLoop
                EndIf
            Next
    EndSwitch

EndFunc

Func Button_Press()

    For $i = 0 To 9
        If @GUI_CTRLID = $aButton[$i] Then
            GUICtrlSetState($aButton[$i], $GUI_DISABLE)
            $currentTool = "MyVariable"
            $ClipCurrent = ClipGet()
            $aGUI[$i] = GUICreate( "Current Script", 388, 204, 335, 237, -1, -1, $hGUI)
            GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_Exit")
            $edtCurrentScript = GUICtrlCreateEdit("", 0, 0, 385, 201,BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
            GUICtrlSetData(-1, $ClipCurrent)
            GUISetState(@SW_SHOW)
            ExitLoop
        EndIf
    Next

EndFunc

And I know you need no encouragement to ask if you do not understand! :oops:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • 2 weeks later...

OK, believe I have structured my code properly now, but my additional GUIs are still not responding when the X button is clicked. Clicking on the X in the main GUI window does exit the application so my _Quit function appears to be working.

The below code is executed to create one of the additional GUIs when the user clicks a button. The window handle as you can see is $FRMScript.

Func _FRMSCRIPT()
$currentTool = "MYTOOL"

If $MyAction = "" Then
$TOOLCurrent = "You have not selected a script yet!"
Else
$TOOLCurrent = $MyAction
EndIf

$FRMScript = GUICreate($currentTool & " - Current Script", 388, 204, 335, 237, -1, -1)
$edtCurrentScript = GUICtrlCreateEdit("", 0, 0, 385, 201, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, $TOOLCurrent)
GUISetState(@SW_SHOW)
EndFunc

I also have this code that calls my _Quit function on $GUI_EVENT_CLOSE:

;Make Window X button call the Exit Function
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

And here is the code for my _Quit function:

Func _Quit()
Switch @GUI_WINHANDLE
Case $FRMScript
GUIDelete($FRMScript)

Case Else
   Exit
EndSwitch
EndFunc

I don't see what I am doing wrong now to keep the additional GUI from exiting when the X is clicked.

-hogfan

Link to comment
Share on other sites

  • Moderators

hogfan,

Your posted snippets show that you are using the same variable ($FRMScript) each time you create an additional GUI - so you are overwriting the variable each time you create a new GUI. When you click on the [X] of one of the additional GUIs and look at @GUI_WINHANDLE, your Switch structure can only compare that value to the handle of the last created GUI. If you click on the [X] of a previously created GUI, it will not match and so you fire the Case Else and Exit. :oops:

The script I posted above stores the handles of the additional GUIs in an array and the Switch structure checks to see which one of the additional GUIs has sent the CLOSE message and then closes that particular GUI. The Switch only fires Exit if the message came from the parent GUI.

Does that explain why your code is not working as you wish? :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Well actually, that was just a simple example. I am not re-creating the same form multiple times. I have several buttons that launch a "script viewing" window for different tools in my application. So the example GUI with $FRMScript handle is just one of those from. Any additional GUIs will not have same window handle as this one. The GUI handles will always remain static. So I am not sure why if this is the only instance of this GUI open, why my _Quit function is not finding the window handle and deleting that GUI. Does what I am saying make a bit more sense now? Thanks.

-hogfan

Link to comment
Share on other sites

  • Moderators

hogfan,

The GUI handles will always remain static

If you are creating and destroying GUIs this is certainly not true. :oops:

You will have to post a simple working reproducer script which shows the problem if you want more help - trying to debug from small snippets of code and hints such as the erronous statement quoted above never works. :D

I suggest a parent GUI with a couple of buttons which produce misbehaving additional GUIs. Then we can try to determine the structural problem within your code. :rip:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

ok, here is a quick example I put together. All 3 additional GUIs need the ability to be open simutaneously until the user closes each one. Please let me know if you have additional questions. I appreciated the assistance.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GUIComboBox.au3>
#include <myfunctions.au3>
#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <TabConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <Misc.au3>

Opt("GUIOnEventMode", 1)


#Region ### START Koda GUI section ### Form=C:Program FilesAutoIt3SciTEKodaFormsmulti_gui_test.kxf
$Form1 = GUICreate("Form1", 408, 313, 192, 114)
$Group1 = GUICtrlCreateGroup("Tool 1:", 8, 8, 185, 137)
$inptScript1 = GUICtrlCreateInput("", 24, 40, 121, 21)
$cmdPreview1 = GUICtrlCreateButton("Preview 1", 32, 80, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Tool 2:", 205, 8, 185, 137)
$inptScript2 = GUICtrlCreateInput("", 242, 40, 121, 21)
$cmdPreview2 = GUICtrlCreateButton("Preview 2", 244, 79, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Tool 3:", 8, 158, 185, 137)
$inptScript3 = GUICtrlCreateInput("", 29, 180, 121, 21)
$cmdPreview3 = GUICtrlCreateButton("Preview 3", 31, 225, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


;Make Window X button call the Exit Function
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")


While 1
Sleep (100)
WEnd

;Define events for Preview button clicks to launch the appropriate function to display the Script Preview GUI.
GUICtrlSetOnEvent($cmdPreview1, "_PreviewTool1")
GUICtrlSetOnEvent($cmdPreview2, "_PreviewTool2")
GUICtrlSetOnEvent($cmdPreview3, "_PreviewTool3")




;Function to check which X was clicked and exit that specific GUI
Func _Quit()
Switch @GUI_WINHANDLE
Case $frmPrevTool1
GUIDelete($frmPrevTool1)

Case $frmPrevTool2
GUIDelete($frmPrevTool2)

Case $frmPrevTool3
GUIDelete($frmPrevTool3)

Case Else
   Exit
EndSwitch
EndFunc


;Function for launching Script Preview GUI for Tool #1
Func _PreviewTool1()
$currentScript = GUICtrlRead($inptScript1)

;Create the pop-up GUI window for viewing and editing the script
$frmPrevTool1 = GUICreate("Tool 1 Script Preview", 388, 204, 335, 237, -1, -1)
$edtCurrentScript = GUICtrlCreateEdit("", 0, 0, 385, 201, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, $currentScript)
GUISetState(@SW_SHOW)
EndFunc


;Function for launching Script Preview GUI for Tool #2
Func _PreviewTool2()
$currentScript = GUICtrlRead($inptScript2)

;Create the pop-up GUI window for viewing and editing the script
$frmPrevTool2 = GUICreate("Tool 2 Script Preview", 388, 204, 335, 237, -1, -1)
$edtCurrentScript = GUICtrlCreateEdit("", 0, 0, 385, 201, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, $currentScript)
GUISetState(@SW_SHOW)
EndFunc

;Function for launching Script Preview GUI for Tool #3
Func _PreviewTool3()
$currentScript = GUICtrlRead($inptScript3)

;Create the pop-up GUI window for viewing and editing the script
$frmPrevTool3 = GUICreate("Tool 1 Script Preview", 388, 204, 335, 237, -1, -1)
$edtCurrentScript = GUICtrlCreateEdit("", 0, 0, 385, 201, BitOR($ES_AUTOVSCROLL,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
GUICtrlSetData(-1, $currentScript)
GUISetState(@SW_SHOW)
EndFunc

-hogfan

Edited by hogfan
Link to comment
Share on other sites

  • Moderators

hogfan,

That was exactly what was needed! :D

4 points on the code you posted:

- 1. You have no GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") lines for the additional GUIs - I presume this was a simple oversight.

- 2. You need to declare the variables to hold the additional GUI handles at the top of the script - at least you do if you want to avoid Au3Check errors. :)

- 3. You do not need to use GUICtrlCreateGroup("", -99, -99, 1, 1) between groups - just at the end of all the groups.

- 4. And the BIG one to finish with! You need to define the GUICtrlOnEvent functions before you use GUISetState! That is the structural error we needed to see. Just move the GUICtrlSetOnEvent($cmdPreview#, "_PreviewTool#") lines before the GUISetState line and all works as you wish: :oops:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <GUIComboBox.au3>
;#include <myfunctions.au3>
#include <GUIConstants.au3>
#include <GUIListBox.au3>
#include <TabConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Opt("GUIOnEventMode", 1)

Global $frmPrevTool1, $frmPrevTool2, $frmPrevTool3

$Form1 = GUICreate("Form1", 408, 313, 192, 114)
$Group1 = GUICtrlCreateGroup("Tool 1:", 8, 8, 185, 137)
$inptScript1 = GUICtrlCreateInput("", 24, 40, 121, 21)
$cmdPreview1 = GUICtrlCreateButton("Preview 1", 32, 80, 75, 25)
;GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Tool 2:", 205, 8, 185, 137)
$inptScript2 = GUICtrlCreateInput("", 242, 40, 121, 21)
$cmdPreview2 = GUICtrlCreateButton("Preview 2", 244, 79, 75, 25)
;GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Tool 3:", 8, 158, 185, 137)
$inptScript3 = GUICtrlCreateInput("", 29, 180, 121, 21)
$cmdPreview3 = GUICtrlCreateButton("Preview 3", 31, 225, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)

;Define events for Preview button clicks to launch the appropriate function to display the Script Preview GUI.
GUICtrlSetOnEvent($cmdPreview1, "_PreviewTool1")
GUICtrlSetOnEvent($cmdPreview2, "_PreviewTool2")
GUICtrlSetOnEvent($cmdPreview3, "_PreviewTool3")

GUISetState(@SW_SHOW)

;Make Window X button call the Exit Function
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")

While 1
    Sleep(100)
WEnd

;Function to check which X was clicked and exit that specific GUI
Func _Quit()

    ConsoleWrite(@GUI_WinHandle & @CRLF)

    Switch @GUI_WinHandle
        Case $frmPrevTool1
            GUIDelete($frmPrevTool1)
        Case $frmPrevTool2
            GUIDelete($frmPrevTool2)
        Case $frmPrevTool3
            GUIDelete($frmPrevTool3)
        Case Else
            Exit
    EndSwitch
EndFunc   ;==>_Quit

;Function for launching Script Preview GUI for Tool #1
Func _PreviewTool1()
    $currentScript = GUICtrlRead($inptScript1)

    ;Create the pop-up GUI window for viewing and editing the script
    $frmPrevTool1 = GUICreate("Tool 1 Script Preview", 388, 204, 335, 237, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
    $edtCurrentScript = GUICtrlCreateEdit("", 0, 0, 385, 201, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL))
    GUICtrlSetData(-1, $currentScript)
    GUISetState(@SW_SHOW)
EndFunc   ;==>_PreviewTool1

;Function for launching Script Preview GUI for Tool #2
Func _PreviewTool2()
    $currentScript = GUICtrlRead($inptScript2)

    ;Create the pop-up GUI window for viewing and editing the script
    $frmPrevTool2 = GUICreate("Tool 2 Script Preview", 388, 204, 335, 237, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
    $edtCurrentScript = GUICtrlCreateEdit("", 0, 0, 385, 201, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL))
    GUICtrlSetData(-1, $currentScript)
    GUISetState(@SW_SHOW)
EndFunc   ;==>_PreviewTool2

;Function for launching Script Preview GUI for Tool #3
Func _PreviewTool3()
    $currentScript = GUICtrlRead($inptScript3)

    ;Create the pop-up GUI window for viewing and editing the script
    $frmPrevTool3 = GUICreate("Tool 1 Script Preview", 388, 204, 335, 237, -1, -1)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
    $edtCurrentScript = GUICtrlCreateEdit("", 0, 0, 385, 201, BitOR($ES_AUTOVSCROLL, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL))
    GUICtrlSetData(-1, $currentScript)
    GUISetState(@SW_SHOW)
EndFunc   ;==>_PreviewTool3

However, I would suggest you look in detail at the script I posted in #9 above - using arrays would allow you to have a single function in place of the 3 separate additional GUI functions you use at the moment. What you have is perfectly sound, but not very elegant. :D

All clear? :rip:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

hogfan,

My pleasure - you know where I am if you run into any more difficulties. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...