Jump to content

Recommended Posts

Posted

Good day,

The following was derived from "Managing Multiple GUIs".

However, I ma having difficulties in navigating from the 1st GUI to the 2nd GUI, and then from the 2nd GUI back to the 1st GUI.

Here is what I have thus far [...employing the "advanced" parameter with GUIGetMsg...]:

; -----------------------------------------------
; a) Disabling _Gui1() when _Gui2() is called
; b) Then enabling _Gui1() when _Gui2() is exited.
; -----------------------------------------------
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $g_h_Gui1, $g_idButton1a, $g_idButton1b, $g_idButton1c, $g_idButton1d, $g_h_Gui2, $g_idButton2a
; -----------------------------------------------
_Main()
; -----------------------------------------------
Func _Main()
    _Gui1()
    Local $aMsg
    ; -----------------------------------------------
    While 1
        $aMsg = GUIGetMsg(1) ; Use advanced parameter to get array
        ; -----------------------------------------------
        If Not IsHWnd($aMsg[1]) Then ContinueLoop ; Preventing subsequent lines from processing when nothing happens
        ; -----------------------------------------------
        Switch $aMsg[1] ; Check which GUI sent the message
            Case $g_h_Gui1
                Switch $aMsg[0] ; Now check for the messages for $g_h_Gui1
                    Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI: $g_h_Gui1 ...
                        ExitLoop ;  ... exit the loop and thus exit the program
                    Case $g_idButton1a
                        _LaunchSAWWMM()
                    Case $g_idButton1b
                        _ExitSAW()
                    Case $g_idButton1d
                        _ExitMe()
                    Case $g_idButton1c
                        GUICtrlSetState($g_idButton1c, $GUI_DISABLE)
                        _Gui2()
                EndSwitch
                ; -----------------------------------------------
            Case $g_h_Gui2
                Switch $aMsg[0] ; Now check for the messages for $g_h_Gui2
                    Case $GUI_EVENT_CLOSE ; If we get the CLOSE message from this GUI : $g_h_Gui2 ...
                        GUIDelete($g_h_Gui2) ; ...then delete the GUI ...
                        GUICtrlSetState($g_idButton1c, $GUI_ENABLE) ; ...and finally enable the button...which previously disabled.
                    Case $g_idButton2a
                        _EnableHotKey()
                EndSwitch
        EndSwitch
    WEnd
EndFunc   ;==>_Main
; -----------------------------------------------
Func _Gui1()
    ;$g_h_Gui1 = GUICreate("GUI 1", 145, 135, 125, 100)
    $g_h_Gui1 = GUICreate("GUI 1", 145, 135)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    $g_idButton1a = GUICtrlCreateButton("Launch SAW", 10, 10, 125, 25)
    $g_idButton1c = GUICtrlCreateButton("Add SoundFile", 10, 40, 125, 25)
    $g_idButton1b = GUICtrlCreateButton("Exit SAW", 10, 70, 125, 25)
    $g_idButton1d = GUICtrlCreateButton("Exit", 10, 100, 125, 25)
    GUISetState()
EndFunc   ;==>_Gui1
; -----------------------------------------------
Func _Gui2()
    ;$g_h_Gui2 = GUICreate("GUI 2", 145, 45, 350, 350)
    $g_h_Gui2 = GUICreate("GUI 2", 145, 45)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    $g_idButton2a = GUICtrlCreateButton("Enable Button", 10, 10, 125, 25)
    GUISetState()
EndFunc   ;==>_Gui2
; -----------------------------------------------
Func _LaunchSAWWMM()
    Local $_sSrcPath = "C:\RML\SAW\SAWStudio64.exe"
    ; ------------------------------------------------
    Run($_sSrcPath)
    MouseMove(340, 195, 0)
    Sleep(2000)
EndFunc   ;==>_LaunchSAWWMM
; -----------------------------------------------
Func _ExitSAW()
    Local $_sSrcPath1a = "C:\RML\SAW\SAWStudio64.exe"
    Local $_sSrcPath1b = "SAWStudio64.exe"
    Local $PID = 0
    ; -----------------------------------------------
    ProcessClose($_sSrcPath1a)
    $PID = ProcessExists($_sSrcPath1b)
    If $PID Then ProcessClose($PID)
EndFunc   ;==>_ExitSAW
; -----------------------------------------------
Func _EnableHotKey()
    Local Static $hbHotKeyEnabled = True

    ConsoleWrite("$hbHotKeyEnabled=" & $hbHotKeyEnabled & @CRLF)

    If $hbHotKeyEnabled = True Then
        ; To enable hotkeys
        HotKeySet("{APPSKEY}", "_AccessMenuOption")
        GUICtrlSetData($g_idButton2a, "Disable HotKey")
        GUICtrlSetTip($g_idButton2a, "HotKey is now enabled!")
        $hbHotKeyEnabled = False
        ToolTip("Select [APPSKEY] to add SoundFile!", 84, 17, "HotKey Enabled", 1, $TIP_BALLOON)
    Else
        ; To disable hotkeys
        HotKeySet("{APPSKEY}")
        GUICtrlSetData($g_idButton2a, "Enable HotKey")
        GUICtrlSetTip($g_idButton2a, "HotKey is now disabled!")
        $hbHotKeyEnabled = True
        ToolTip("Select [Enable HotKey] to enable.", 84, 17, "HotKey Disabled", 1, $TIP_BALLOON)
    EndIf
    ; Provide time to dispay ToolTip
    Sleep(2000)
    ToolTip("")
EndFunc   ;==>_EnableHotKey
; -----------------------------------------------
Func _AccessMenuOption()
    ConsoleWrite("Add SoundFile - ok" & @CRLF)
    Return ; <- *** just for testing <-
    ; -----------------
    WinActivate("[CLASS:SAWSTUDIO_MAIN]", "")
    WinMenuSelectItem("[CLASS:SAWSTUDIO_MAIN]", "", "&File", "Add SoundFile To MT")
EndFunc   ;==>_AccessMenuOption
; -----------------------------------------------
Func _ExitMe()
    Exit
EndFunc   ;==>_ExitMe
; -----------------------------------------------

PS: Please do not take for granted - that is, "assume", that I fully-and-completely understand ALL that is transpiring in the above example! Thanks for your understanding!

Posted

Good day,

OK! Employing the "OnEventMode" example...appears to have resolved the present issue.

; -----------------------------------------------
; Adding Functions
; -----------------------------------------------
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("GUIOnEventMode", 1)
; -----------------------------------------------
Global $g_h_Gui2, $g_idButton1b, $g_idButton1c
; -----------------------------------------------
_Gui1()
; -----------------------------------------------
Func _Gui1()
    Local $h_Gui1 = GUICreate("GUI 1", 145, 105, 100, 100)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Main") ; Launch this function when the main GUI [X] is selected.
    ; -----------------------------------------------
    Local $idButton1a = GUICtrlCreateButton("Launch SAW", 10, 10, 125, 25)
    GUICtrlSetOnEvent($idButton1a, "On_Button1")
    ; -----------------
    $g_idButton1b = GUICtrlCreateButton("Add SoundFile", 10, 40, 125, 25)
    GUICtrlSetOnEvent(-1, "On_Button2")
    ; -----------------
    $g_idButton1c = GUICtrlCreateButton("Exit Saw", 10, 70, 125, 25)
    GUICtrlSetOnEvent(-1, "On_Button4")
    ; -----------------
    GUISetState(@SW_SHOW, $h_Gui1)
    ; -----------------
    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>_Gui1
; -----------------------------------------------
Func _Gui2()
    $g_h_Gui2 = GUICreate("GUI 2", 145, 45, 350, 350)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Secondary") ; Launch this function when the secondary GUI [X] is selected.
    ; -----------------------------------------------
    Local $g_idButton1b = GUICtrlCreateButton("Enable Button", 10, 10, 125, 25)
    ; -----------------------------------------------
    GUICtrlSetOnEvent($g_idButton1b, "On_Button3")
    ; -----------------
    GUISetState(@SW_SHOW, $g_h_Gui2)
EndFunc   ;==>_Gui2
; -----------------------------------------------
Func On_Close_Main()
    Exit
EndFunc   ;==>On_Close_Main
; -----------------------------------------------
Func On_Close_Secondary()
    GUIDelete($g_h_Gui2)
    GUICtrlSetState($g_idButton1b, $GUI_ENABLE)
EndFunc   ;==>On_Close_Secondary
; -----------------------------------------------
Func On_Button1()
    ;MsgBox($MB_OK, "MsgBox 1", "Launching SAW")
    Local $_sSrcPath = "C:\RML\SAW\SAWStudio64.exe"
    ; ------------------------------------------------
    Run($_sSrcPath)
    MouseMove(340, 195, 0)
    Sleep(2000)
EndFunc   ;==>On_Button1
; -----------------------------------------------
Func On_Button2()
    GUICtrlSetState($g_idButton1b, $GUI_DISABLE)
    _Gui2()
EndFunc   ;==>On_Button2
; -----------------------------------------------
Func On_Button3()
    Local Static $hbHotKeyEnabled = True

    ConsoleWrite("$hbHotKeyEnabled=" & $hbHotKeyEnabled & @CRLF)

    If $hbHotKeyEnabled = True Then
        ; To enable hotkeys
        HotKeySet("{APPSKEY}", "_AccessMenuOption")
        GUICtrlSetData($g_idButton1b, "Disable HotKey")
        GUICtrlSetTip($g_idButton1b, "HotKey is now enabled!")
        $hbHotKeyEnabled = False
        ToolTip("Select [APPSKEY] to add SoundFile!", 84, 17, "HotKey Enabled", 1, $TIP_BALLOON)
    Else
        ; To disable hotkeys
        HotKeySet("{APPSKEY}")
        GUICtrlSetData($g_idButton1b, "Enable HotKey")
        GUICtrlSetTip($g_idButton1b, "HotKey is now disabled!")
        $hbHotKeyEnabled = True
        ToolTip("Select [Enable HotKey] to enable.", 84, 17, "HotKey Disabled", 1, $TIP_BALLOON)
    EndIf
    ; Provide time to dispay ToolTip
    Sleep(2000)
    ToolTip("")
EndFunc   ;==>On_Button3
; -----------------------------------------------
Func On_Button4()
    Local $_sSrcPath1a = "C:\RML\SAW\SAWStudio64.exe"
    Local $_sSrcPath1b = "SAWStudio64.exe"
    Local $PID = 0
    ; -----------------------------------------------
    ProcessClose($_sSrcPath1a)
    $PID = ProcessExists($_sSrcPath1b)
    If $PID Then ProcessClose($PID)
EndFunc   ;==>On_Button4
; -----------------------------------------------
Func _AccessMenuOption()
    ;ConsoleWrite("Add SoundFile - ok" & @CRLF)
    ;Return ; <- *** just for testing <-
    ; -----------------
    WinActivate("[CLASS:SAWSTUDIO_MAIN]", "")
    WinMenuSelectItem("[CLASS:SAWSTUDIO_MAIN]", "", "&File", "Add SoundFile To MT")
EndFunc   ;==>_AccessMenuOption
; -----------------------------------------------

Now to deal with updating the  the correct button label....

Posted

Good day,

How is this solution...just update a global which was local, back to global [Line 42]...

; -----------------------------------------------
; Adding Functions
; -----------------------------------------------
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("GUIOnEventMode", 1)
; -----------------------------------------------
Global $g_h_Gui2, $g_idButton1b, $g_idButton1c, $g_idButton2
; -----------------------------------------------
_Gui1()
; -----------------------------------------------
Func _Gui1()
    Local $h_Gui1 = GUICreate("GUI 1", 145, 105, 100, 100)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Main") ; Launch this function when the main GUI [X] is selected.
    ; -----------------------------------------------
    Local $idButton1a = GUICtrlCreateButton("Launch SAW", 10, 10, 125, 25)
    GUICtrlSetOnEvent($idButton1a, "On_Button1")
    ; -----------------
    $g_idButton1b = GUICtrlCreateButton("Add SoundFile", 10, 40, 125, 25)
    GUICtrlSetOnEvent(-1, "On_Button2")
    ; -----------------
    $g_idButton1c = GUICtrlCreateButton("Exit Saw", 10, 70, 125, 25)
    GUICtrlSetOnEvent(-1, "On_Button4")
    ; -----------------
    GUISetState(@SW_SHOW, $h_Gui1)
    ; -----------------
    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>_Gui1
; -----------------------------------------------
Func _Gui2()
    $g_h_Gui2 = GUICreate("GUI 2", 145, 45, 350, 350)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Secondary") ; Launch this function when the secondary GUI [X] is selected.
    ; -----------------------------------------------
    $g_idButton2 = GUICtrlCreateButton("Enable HotKey", 10, 10, 125, 25)
    ; -----------------------------------------------
    GUICtrlSetOnEvent($g_idButton2, "On_Button3")
    ; -----------------
    GUISetState(@SW_SHOW, $g_h_Gui2)
EndFunc   ;==>_Gui2
; -----------------------------------------------
Func On_Close_Main()
    Exit
EndFunc   ;==>On_Close_Main
; -----------------------------------------------
Func On_Close_Secondary()
    GUIDelete($g_h_Gui2)
    GUICtrlSetState($g_idButton1b, $GUI_ENABLE)
EndFunc   ;==>On_Close_Secondary
; -----------------------------------------------
Func On_Button1()
    ;MsgBox($MB_OK, "MsgBox 1", "Launching SAW")
    Local $_sSrcPath = "C:\RML\SAW\SAWStudio64.exe"
    ; ------------------------------------------------
    Run($_sSrcPath)
    MouseMove(340, 195, 0)
    Sleep(2000)
EndFunc   ;==>On_Button1
; -----------------------------------------------
Func On_Button2()
    GUICtrlSetState($g_idButton1b, $GUI_DISABLE)
    _Gui2()
EndFunc   ;==>On_Button2
; -----------------------------------------------
Func On_Button3()
    Local Static $hbHotKeyEnabled = True

    ConsoleWrite("$hbHotKeyEnabled=" & $hbHotKeyEnabled & @CRLF)

    If $hbHotKeyEnabled = True Then
        ; To enable hotkeys
        HotKeySet("{APPSKEY}", "_AccessMenuOption")
        GUICtrlSetData($g_idButton2, "Disable HotKey")
        GUICtrlSetTip($g_idButton2, "HotKey is now enabled!")
        $hbHotKeyEnabled = False
        ToolTip("Select [APPSKEY] to add SoundFile!", 84, 17, "HotKey Enabled", 1, $TIP_BALLOON)
    Else
        ; To disable hotkeys
        HotKeySet("{APPSKEY}")
        GUICtrlSetData($g_idButton2, "Enable HotKey")
        GUICtrlSetTip($g_idButton2, "HotKey is now disabled!")
        $hbHotKeyEnabled = True
        ToolTip("Select [Enable HotKey] to enable.", 84, 17, "HotKey Disabled", 1, $TIP_BALLOON)
    EndIf
    ; Provide time to dispay ToolTip
    Sleep(2000)
    ToolTip("")
EndFunc   ;==>On_Button3
; -----------------------------------------------
Func On_Button4()
    Local $_sSrcPath1a = "C:\RML\SAW\SAWStudio64.exe"
    Local $_sSrcPath1b = "SAWStudio64.exe"
    Local $PID = 0
    ; -----------------------------------------------
    ProcessClose($_sSrcPath1a)
    $PID = ProcessExists($_sSrcPath1b)
    If $PID Then ProcessClose($PID)
EndFunc   ;==>On_Button4
; -----------------------------------------------
Func _AccessMenuOption()
    ;ConsoleWrite("Add SoundFile - ok" & @CRLF)
    ;Return ; <- *** just for testing <-
    ; -----------------
    WinActivate("[CLASS:SAWSTUDIO_MAIN]", "")
    WinMenuSelectItem("[CLASS:SAWSTUDIO_MAIN]", "", "&File", "Add SoundFile To MT")
EndFunc   ;==>_AccessMenuOption
; -----------------------------------------------

 

Posted

outline from "Managing Multiple GUIs".

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

gui1()

Func gui1()
    Local $hGUI1 = GUICreate("GUI 1", 200, 200, 100, 100)
    Local $idButton1 = GUICtrlCreateButton("Msgbox 1", 10, 10, 80, 30)
    Local $idButton2 = GUICtrlCreateButton("Show GUI 2", 10, 60, 80, 30)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ConsoleWrite("$GUI_EVENT_CLOSE=" & $GUI_EVENT_CLOSE & @CRLF)
                ExitLoop
            Case $idButton1
                MsgBox($MB_OK, "MsgBox 1", "Test from GUI 1")
            Case $idButton2
                ; Disable the first GUI
                GUISetState(@SW_DISABLE, $hGUI1)
                gui2()
                ; Re-enable the first GUI
                GUISetState(@SW_ENABLE, $hGUI1)
                Sleep(50)
                WinActivate($hGUI1)
        EndSwitch
    WEnd

    GUIDelete($hGUI1)

EndFunc   ;==>gui1

Func gui2()
    Local $hGUI2 = GUICreate("GUI 2", 200, 200, 350, 350)
    Local $idButton3 = GUICtrlCreateButton("MsgBox 2", 10, 10, 80, 30)
    GUISetState(@SW_SHOW)

    While 1
        ; We can only get messages from the second GUI
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idButton3
                MsgBox($MB_OK, "MsgBox 2", "Test from GUI 2")
        EndSwitch
    WEnd

    GUIDelete($hGUI2)

EndFunc   ;==>gui2

 

I know that I know nothing

Posted

this way (closing _Gui2 )
$g_idButton2a = GUICtrlCreateButton("Enable Button", 10, 10, 125, 25) in _Gui2
is not synchronized with the _EnableHotKey() function.
Because _Gui2 closes, while the function keeps $hbHotKeyEnabled static, and when _Gui2 reopens it does not know the state of $hbHotKeyEnabled, and it assumes that it is False and therefore starts with GUICtrlCreateButton("Enable Button", 10, 10, 125, 25)
In this case, you will either make $hbHotKeyEnabled Global, which will read _Gui2 when it starts and configure GUICtrlCreateButton("Enable Button", 10, 10, 125, 25) according to the state of $hbHotKeyEnabled.
or you will not close it but simply hide it (_Gui2) so that it remains updated

I know that I know nothing

Posted (edited)

Good day,

Following is my final offering...

; -----------------------------------------------
; v7c: Adding bordeless button to SAWStudio...
; -----------------------------------------------
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
; -----------------------------------------------
Opt("GUIOnEventMode", 1)
; -----------------------------------------------
Global $g_h_Gui2, $g_idButton1b, $g_idButton2a
; -----------------------------------------------
_Gui1()
; -----------------------------------------------
Func _Gui1()
    ;Local $h_Gui1 = GUICreate("GUI 1", 145, 105, 100, 100)
    Local $h_Gui1 = GUICreate("GUI 1", 145, 105)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Main") ; Launch this function when the main GUI [X] is selected.
    ; -----------------------------------------------
    Local $idButton1a = GUICtrlCreateButton("Launch SAW", 10, 10, 125, 25)
    GUICtrlSetOnEvent($idButton1a, "On_Button1a")
    ; -----------------
    $g_idButton1b = GUICtrlCreateButton("Add SoundFile", 10, 40, 125, 25)
    GUICtrlSetOnEvent(-1, "On_Button1b")
    ; -----------------
    Local $idButton1c = GUICtrlCreateButton("Exit Saw", 10, 70, 125, 25)
    GUICtrlSetOnEvent(-1, "On_Button1c")
    ; -----------------
    GUISetState(@SW_SHOW, $h_Gui1)
    ; -----------------
    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>_Gui1
; -----------------------------------------------
Func _Gui2()
    ;$g_h_Gui2 = GUICreate("GUI 2", 145, 45, 350, 350)
    $g_h_Gui2 = GUICreate("GUI 2", 130, 35, 90, 40, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    ; -----------------
    GUISetOnEvent($GUI_EVENT_CLOSE, "On_Close_Secondary") ; Launch this function when the secondary GUI [X] is selected.
    ; -----------------------------------------------
    $g_idButton2a = GUICtrlCreateButton("Enable HotKey", 10, 10, 125, 25)
    GUICtrlSetOnEvent($g_idButton2a, "On_Button2a")
    ; -----------------
    GUISetState(@SW_SHOW, $g_h_Gui2)
EndFunc   ;==>_Gui2
; -----------------------------------------------
Func On_Close_Main()
    Exit
EndFunc   ;==>On_Close_Main
; -----------------------------------------------
Func On_Close_Secondary()
    GUIDelete($g_h_Gui2)
    GUICtrlSetState($g_idButton1b, $GUI_ENABLE)
EndFunc   ;==>On_Close_Secondary
; -----------------------------------------------
Func On_Button1a()
    ;MsgBox($MB_OK, "MsgBox 1", "Launching SAW")
    Local $_sSrcPath = "C:\RML\SAW\SAWStudio64.exe"
    ; ------------------------------------------------
    Run($_sSrcPath)
    MouseMove(340, 195, 0)
    Sleep(2000)
EndFunc   ;==>On_Button1a
; -----------------------------------------------
Func On_Button1b()
    GUICtrlSetState($g_idButton1b, $GUI_DISABLE)
    _Gui2()
EndFunc   ;==>On_Button1b
; -----------------------------------------------
Func On_Button2a()
    Local Static $hbHotKeyEnabled = True
    ; -----------------------------------------------
    ;ConsoleWrite("$hbHotKeyEnabled=" & $hbHotKeyEnabled & @CRLF)
    ; -----------------------------------------------
    If $hbHotKeyEnabled = True Then
        ; To enable hotkeys
        HotKeySet("{APPSKEY}", "_AccessMenuOption")
        GUICtrlSetData($g_idButton2a, "Disable HotKey")
        GUICtrlSetTip($g_idButton2a, "HotKey is now enabled!")
        $hbHotKeyEnabled = False
        ToolTip("Select [APPSKEY] to add SoundFile!", 84, 17, "HotKey Enabled", 1, $TIP_BALLOON)
    Else
        ; To disable hotkeys
        HotKeySet("{APPSKEY}")
        GUICtrlSetData($g_idButton2a, "Enable HotKey")
        GUICtrlSetTip($g_idButton2a, "HotKey is now disabled!")
        $hbHotKeyEnabled = True
        ToolTip("Select [Enable HotKey] to enable.", 84, 17, "HotKey Disabled", 1, $TIP_BALLOON)
    EndIf
    ; -----------------------------------------------
    ; Provide time to dispay ToolTip
    Sleep(1500)
    ToolTip("")
EndFunc   ;==>On_Button2a
; -----------------------------------------------
Func On_Button1c()
    Local $_sSrcPath1a = "C:\RML\SAW\SAWStudio64.exe"
    Local $_sSrcPath1b = "SAWStudio64.exe"
    Local $PID = 0
    ; -----------------------------------------------
    ProcessClose($_sSrcPath1a)
    $PID = ProcessExists($_sSrcPath1b)
    If $PID Then ProcessClose($PID)
EndFunc   ;==>On_Button1c
; -----------------------------------------------
Func _AccessMenuOption()
    ;ConsoleWrite("Add SoundFile - ok" & @CRLF)
    ;Return ; <- *** just for testing <-
    ; -----------------
    WinActivate("[CLASS:SAWSTUDIO_MAIN]", "")
    WinMenuSelectItem("[CLASS:SAWSTUDIO_MAIN]", "", "&File", "Add SoundFile To MT")
EndFunc   ;==>_AccessMenuOption
; -----------------------------------------------

 

Lines 40 and 42 position and set the background colour fop the button.the button...see attached image...

All this is required to complete this offering is to be able to exit the border-less button - all without exiting the entire script! I simply cannot get my head around this one!!!

Sample.png

Edited by mr-es335
Posted (edited)

sorry but I'm confused with the logic flow.
Then why did you make it a popup? (and the window has no close button.)
How do you want to close GUI2 ? (with hotkey?)
What is the reason of GUI2 ? (enable/disable hotkey, Since it's closed.)

Isn't it better to move the enable/disable hotkey button to GUI1, and not need GUI2 at all?

Edited by ioa747

I know that I know nothing

Posted (edited)

Add (On_close_Secondary()) to the On_Button2a() function, something like this:

Func On_Button2a()
    ;at the end of the hotkey code add this:
    On_Close_Secondary()
EndFunc   ;==>On_Button2a

It will close the secondary gui after the hotkey is set.

Edited by Dan_555

Some of my script sourcecode

Posted

ioa747,

You stated:

Q1: Then why did you make it a popup? (and the window has no close button.)
R1: Entirely for "cosmetic purposes"...I simply liked the way the button "looked"!

Q2: How do you want to close GUI2 ? (with hotkey?)
R2: Yes! But each and every suggestion I tried, exited the entire script!

Q3: What is the reason of GUI2 ? (enable/disable hotkey, Since it's closed.)
R3: In my searching for a solution to R2, I was told that I required a 2nd GUI in order to accomplish this task.

Q4: Isn't it better to move the enable/disable hotkey button to GUI1, and not need GUI2 at all?
R4: Yes! That would indeed be preferable!

And Dan_555...your suggestion appears to do the job! Thanks for this! Appreciated!

  • Solution
Posted

recommend

; -----------------------------------------------
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
_Gui1()
; -----------------------------------------------
Func _Gui1()
    ;$h_Gui1 = GUICreate("GUI 1", 145, 135, 125, 100)
;~  Local $h_Gui1 = GUICreate("GUI 1", 145, 135, -1, -1, -1, $WS_EX_TOOLWINDOW)
    Local $h_Gui1 = GUICreate("GUI 1", 145, 135)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    Local $idButton1a = GUICtrlCreateButton("Launch SAW", 10, 10, 125, 25)
    ;Local $idButton1c = GUICtrlCreateButton("Add SoundFile", 10, 40, 125, 25)
    Local $idButton1c = GUICtrlCreateButton("Enable Button", 10, 40, 125, 25)
    Local $idButton1b = GUICtrlCreateButton("Exit SAW", 10, 70, 125, 25)
    Local $idButton1d = GUICtrlCreateButton("Exit", 10, 100, 125, 25)
    GUISetState(@SW_SHOW, $h_Gui1)

    GUICtrlSetTip($idButton1c, "add SoundFile HotKey is now disabled!")

    Local $idMsg
    ; -----------------------------------------------
    While 1
        $idMsg = GUIGetMsg()
        Switch $idMsg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idButton1a
                _LaunchSAWWMM()
            Case $idButton1b
                _ExitSAW()
            Case $idButton1d
                _ExitMe()
            Case $idButton1c
                _EnableHotKey($idButton1c)
        EndSwitch
    WEnd
    ; -----------------------------------------------
    GUIDelete($h_Gui1)
EndFunc   ;==>_Gui1
; -----------------------------------------------
Func _LaunchSAWWMM()
    Local $_sSrcPath = "C:\RML\SAW\SAWStudio64.exe"
    ; ------------------------------------------------
    Run($_sSrcPath)
    MouseMove(340, 195, 0)
    Sleep(2000)
EndFunc   ;==>_LaunchSAWWMM
; -----------------------------------------------
Func _ExitSAW()
    Local $_sSrcPath1a = "C:\RML\SAW\SAWStudio64.exe"
    Local $_sSrcPath1b = "SAWStudio64.exe"
    Local $PID = 0
    ; -----------------------------------------------
    ProcessClose($_sSrcPath1a)
    $PID = ProcessExists($_sSrcPath1b)
    If $PID Then ProcessClose($PID)
EndFunc   ;==>_ExitSAW
; -----------------------------------------------
Func _EnableHotKey($idButton)
    Local Static $hbHotKeyEnabled = True
    ;ConsoleWrite("$hbHotKeyEnabled=" & $hbHotKeyEnabled & @CRLF)
    If $hbHotKeyEnabled = True Then
        ; To enable hotkeys
        HotKeySet("{APPSKEY}", "_AccessMenuOption")
        GUICtrlSetData($idButton, "Disable HotKey")
        GUICtrlSetTip($idButton, "add SoundFile HotKey is now enabled!")
        $hbHotKeyEnabled = False
        ToolTip("Select [APPSKEY] to add SoundFile!", 84, 17, "HotKey Enabled", 1, $TIP_BALLOON)
    Else
        ; To disable hotkeys
        HotKeySet("{APPSKEY}")
        GUICtrlSetData($idButton, "Enable HotKey")
        GUICtrlSetTip($idButton, "add SoundFile HotKey is now disabled!")
        $hbHotKeyEnabled = True
        ToolTip("Select [Enable HotKey] to enable.", 84, 17, "HotKey Disabled", 1, $TIP_BALLOON)
    EndIf
    ; Provide time to dispay ToolTip
    Sleep(2000)
    ToolTip("")
EndFunc   ;==>_EnableHotKey
; -----------------------------------------------
Func _AccessMenuOption()
    ConsoleWrite("Add SoundFile - ok" & @CRLF)
    Return ; <- *** just for testing <-
    ; -----------------
    WinActivate("[CLASS:SAWSTUDIO_MAIN]", "")
    WinMenuSelectItem("[CLASS:SAWSTUDIO_MAIN]", "", "&File", "Add SoundFile To MT")
EndFunc   ;==>_AccessMenuOption
; -----------------------------------------------
Func _ExitMe()
    Exit
EndFunc   ;==>_ExitMe
; -----------------------------------------------

 

I know that I know nothing

Posted (edited)

ioa747,

Solved! This sampling has literally saved me a ton of work!!

Therefore...

"Muchas gracias! Merci mille fois! Grazie mille! Danke sehr! Dankjewel! Çok tesekkürler! Stokrotne dziek! Asante San! Dakujem! Tusen takk!" ...and finally, "Thanks a million!"

 

Edited by mr-es335

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...