Jump to content

Recommended Posts

Posted (edited)

Good day,
I hope that the day finds you well!

What I require is to have 3 GUI's present, all in differing locations. Or 1 GUI with three different positions? Are either of these two scenarios possible?

GUI #1: GUICtrlCreateMenu("Test Menu")
• GUICreate("!", 100, 23, 1200, 23)
GUI #2: DisplayHotKeyOption()
• $sDisplayHotKeyOption = GUICreate("", 117, 18, 210, 86, $WS_POPUP, $WS_EX_TOPMOST)
GUI #3: LiveGuiLabelA()
• $sLabelA = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST)

Here is the simplified script:

; -----------------------------------------------
#RequireAdmin
; -----------------------------------------------
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $sLabelA, $sLabelB, $sDisplayHotKeyOption, $iMenuPosition
; -----------------------------------------------
Main()
; -----------------------------------------------
Func Main()
    GUICreate("!", 100, 23, 1200, 23)
    WinSetOnTop("!", "", $WINDOWS_ONTOP)
    ; -----------------------------------------------
    Local $mMenu = GUICtrlCreateMenu("Test Menu")
    Local $mEnableDisableName1 = GUICtrlCreateMenuItem("Display HotKey Option", $mMenu)
    Local $mEnableDisableName2 = GUICtrlCreateMenuItem("Launch LiveGuiLabelA", $mMenu)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Local $idMsg = GUIGetMsg()
        Switch $idMsg
            Case $GUI_EVENT_CLOSE
                Exit
                ; -----------------
            Case $mEnableDisableName1
                DisplayHotKeyLabel()
                DisplayHotKeyOption()
            Case $mEnableDisableName2
                AddF10Label()
                LiveGuiLabelA()
;~              AddF12Label()   ; ⚠ Called by LiveGuiLabelA() ⚠
;~              LiveGuiLabelB() ; ⚠ Called by LiveGuiLabelA() ⚠
;~              ⚠ Need to Return to the Main() Function here!! ⚠
        EndSwitch
    WEnd
EndFunc   ;==>Main
; -----------------------------------------------
Func DisplayHotKeyLabel()
    Local $sMessage = "Displaying HotKey Label..." & @CRLF & @CRLF, $iWidth = 350, $iHeight = 45
    Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>AddF10Label
; -----------------------------------------------
Func DisplayHotKeyOption()
    $sDisplayHotKeyOption = GUICreate("", 117, 18, 210, 86, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(10, 600, 0, "Seqoe UI")
    GUISetBkColor(0x3D3D3D)
    ; -----------------------------------------------
    $iMenuPosition = GUICtrlCreateLabel(" Enable HotKey", 0, 0, 117, 18, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Switch GUIGetMsg()
            Case $iMenuPosition
                Local $bHotKeyEnabled = EnableDisableHotKey()
                If $bHotKeyEnabled = True Then ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>DisplayHotKeyOption
; -----------------------------------------------
Func EnableDisableHotKey()
    Local Static $bHotKeyEnabled = True
    ; -----------------------------------------------
    If $bHotKeyEnabled = True Then
        HotKeySet("{APPSKEY}", "UpdateScenes") ; The script that is to be executed!
        GUICtrlSetData($iMenuPosition, "Disable HotKey")
        $bHotKeyEnabled = False
    Else
        HotKeySet("{APPSKEY}")
        GUICtrlSetData($iMenuPosition, "Enable HotKey")
        GUIDelete($sDisplayHotKeyOption)
        $bHotKeyEnabled = True
    EndIf
    Return $bHotKeyEnabled
EndFunc   ;==>EnableDisableHotKey
; -----------------------------------------------
Func UpdateScenes()
    Local $sMessage = "Updating Scenes..." & @CRLF & @CRLF, $iWidth = 350, $iHeight = 45
    Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>UpdateScenes
; -----------------------------------------------
; -----------------------------------------------
Func LiveGuiLabelA()
    $sLabelA = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    ; -----------------------------------------------
    Local $sColRow = GUICtrlCreateLabel(" For F10", 0, 0, 75, 23, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Switch GUIGetMsg()
            Case $sColRow
                GUIDelete($sLabelA)
                AddF12Label()
                LiveGuiLabelB()
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>LiveGuiLabelA
; -----------------------------------------------
Func AddF10Label()
    Local $sMessage = "Add F10 Label..." & @CRLF & @CRLF, $iWidth = 350, $iHeight = 45
    Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>AddF10Label
; -----------------------------------------------
Func LiveGuiLabelB()
    $sLabelB = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    ; -----------------------------------------------
    Local $sColRow = GUICtrlCreateLabel(" For F12", 0, 0, 75, 23, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Switch GUIGetMsg()
            Case $sColRow
                GUIDelete($sLabelB)
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>LiveGuiLabelB
; -----------------------------------------------
Func AddF12Label()
    Local $sMessage = "Add F12 Label..." & @CRLF & @CRLF, $iWidth = 350, $iHeight = 45
    Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>AddF12Label
; -----------------------------------------------

As always...any assistance in this matter would be greatly appreciated!

Edited by mr-es335
  • mr-es335 changed the title to Launch 3 Gui's at the same time?!?
Posted (edited)

Jos,

Here is what I have thus far - but not working as expected or as should:

; -----------------------------------------------
#RequireAdmin
; -----------------------------------------------
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; -----------------------------------------------
Opt("GUIOnEventMode", 1)
; -----------------------------------------------
Global $sDisplayHotKeyOption, $iMenuPosition, $sLabelA, $sLabelB
; -----------------------------------------------
Form1()
; -----------------------------------------------
Func Form1()
    Local $Form1 = GUICreate("", 235, 75)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    GUISetOnEvent($GUI_EVENT_CLOSE, "CloseForm1")
    ; -----------------------------------------------
    Local $sCol1Row1 = GUICtrlCreateButton("Display HotKey Label", 10, 10, 215, 25)
    GUICtrlSetOnEvent($sCol1Row1, "DisplayHotKeyOption")
    Local $sCol1Row2 = GUICtrlCreateButton("For F10", 10, 40, 215, 25)
    GUICtrlSetOnEvent($sCol1Row2, "LiveGuiLabelA")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW, $Form1)
    ; -----------------------------------------------
    While 1
        Sleep(10)
    WEnd
EndFunc   ;==>Form1
; -----------------------------------------------
Func CloseForm1()
    Exit
EndFunc   ;==>CloseForm1
; -----------------------------------------------
Func LiveGuiLabelA()
    $sLabelA = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    ; -----------------------------------------------
    Local $sColRow = GUICtrlCreateLabel(" For F10", 0, 0, 75, 23, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Switch GUIGetMsg()
            Case $sColRow
                GUIDelete($sLabelA)
                AddF12Label()
                LiveGuiLabelB()
;~              Exit
        EndSwitch
    WEnd
EndFunc   ;==>LiveGuiLabelA
; -----------------------------------------------
Func LiveGuiLabelB()
    $sLabelB = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    ; -----------------------------------------------
    Local $sColRow = GUICtrlCreateLabel(" For F12", 0, 0, 75, 23, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Switch GUIGetMsg()
            Case $sColRow
                GUIDelete($sLabelB)
;~              Exit
        EndSwitch
    WEnd
EndFunc   ;==>LiveGuiLabelB
; -----------------------------------------------
Func AddF12Label()
    Local $sMessage = "Add F12 Label..." & @CRLF & @CRLF, $iWidth = 350, $iHeight = 45
    Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>AddF12Label
; -----------------------------------------------
Func DisplayHotKeyOption()
    $sDisplayHotKeyOption = GUICreate("", 117, 18, 210, 86, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(10, 600, 0, "Seqoe UI")
    GUISetBkColor(0x3D3D3D)
    ; -----------------------------------------------
    $iMenuPosition = GUICtrlCreateLabel(" Enable HotKey", 0, 0, 117, 18, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Switch GUIGetMsg()
            Case $iMenuPosition
                Local $bHotKeyEnabled = EnableDisableHotKey()
                If $bHotKeyEnabled = True Then ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>DisplayHotKeyOption
; -----------------------------------------------
Func EnableDisableHotKey()
    Local Static $bHotKeyEnabled = True
    ; -----------------------------------------------
    If $bHotKeyEnabled = True Then
        HotKeySet("{APPSKEY}", "UpdateScenes") ; The script that is to be executed!
        GUICtrlSetData($iMenuPosition, "Disable HotKey")
        $bHotKeyEnabled = False
    Else
        HotKeySet("{APPSKEY}")
        GUICtrlSetData($iMenuPosition, "Enable HotKey")
        GUIDelete($sDisplayHotKeyOption)
        $bHotKeyEnabled = True
    EndIf
    Return $bHotKeyEnabled
EndFunc   ;==>EnableDisableHotKey
; -----------------------------------------------
Func UpdateScenes()
    Local $sMessage = "Updating Scenes..." & @CRLF & @CRLF, $iWidth = 350, $iHeight = 45
    Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>UpdateScenes
; -----------------------------------------------

PS: For your interest, I also complied the 3 scripts and called them as usual...works fine.

Edited by mr-es335
Posted

Here is a beginning.

; -----------------------------------------------
;~ #RequireAdmin
; -----------------------------------------------
#include <AutoItConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("GUIOnEventMode", 1)
; -----------------------------------------------
Global $Form1, $sCol1Row1, $sCol1Row2
Global $sDisplayHotKeyOption, $iMenuPosition
Global $sLabelA, $sColRowA
Global $sLabelB, $sColRowB
; -----------------------------------------------
Form1()
; -----------------------------------------------
Func Form1()
    $Form1 = GUICreate("", 235, 75)
    GUISetFont(14, 800, 0, "Calibri")
    ; -----------------------------------------------
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm")
    ; -----------------------------------------------
    $sCol1Row1 = GUICtrlCreateButton("Display HotKey Label", 10, 10, 215, 25)
    GUICtrlSetOnEvent($sCol1Row1, "DisplayHotKeyOption")
    $sCol1Row2 = GUICtrlCreateButton("For F10", 10, 40, 215, 25)
    GUICtrlSetOnEvent($sCol1Row2, "LiveGuiLabelA")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW, $Form1)
    ; -----------------------------------------------
    While 1
        Sleep(40)
    WEnd
EndFunc   ;==>Form1
; -----------------------------------------------
Func DisplayHotKeyOption()
    $sDisplayHotKeyOption = GUICreate("", 117, 18, 210, 86, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(10, 600, 0, "Seqoe UI")
    GUISetBkColor(0x3D3D3D)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm")
    ; -----------------------------------------------
    $iMenuPosition = GUICtrlCreateLabel(" Enable HotKey", 0, 0, 117, 18, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetOnEvent($iMenuPosition, "EnableDisableHotKey")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    GUICtrlSetState($sCol1Row1, $GUI_DISABLE)
EndFunc   ;==>DisplayHotKeyOption
; -----------------------------------------------
Func LiveGuiLabelA()
    $sLabelA = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm")
    ; -----------------------------------------------
    $sColRowA = GUICtrlCreateLabel(" For F10", 0, 0, 75, 23, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetOnEvent($sColRowA, "_ColRow")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    GUICtrlSetState($sCol1Row2, $GUI_DISABLE)
EndFunc   ;==>LiveGuiLabelA
; -----------------------------------------------
Func _ColRow()
    ConsoleWrite("@GUI_CtrlId=" & @GUI_CtrlId & @CRLF)
    Switch @GUI_CtrlId
        Case $sColRowA
            WinClose($sLabelA)
            AddF12Label()
            LiveGuiLabelB()
        Case $sColRowB
            WinClose($sLabelB)
    EndSwitch
EndFunc   ;==>_ColRow
; -----------------------------------------------
Func LiveGuiLabelB()
    $sLabelB = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm")
    ; -----------------------------------------------
    $sColRowB = GUICtrlCreateLabel(" For F12", 0, 0, 75, 23, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetOnEvent($sColRowB, "_ColRow")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)

EndFunc   ;==>LiveGuiLabelB
; -----------------------------------------------
Func AddF12Label()
    Local $sMessage = "Add F12 Label..." & @CRLF & @CRLF, $iWidth = 350, $iHeight = 45
    Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>AddF12Label
; -----------------------------------------------
Func EnableDisableHotKey()
    Local Static $bHotKeyEnabled = True
    ; -----------------------------------------------
    If $bHotKeyEnabled = True Then
        HotKeySet("{APPSKEY}", "UpdateScenes") ; The script that is to be executed!
        GUICtrlSetData($iMenuPosition, "Disable HotKey")
        $bHotKeyEnabled = False
    Else
        WinClose($sDisplayHotKeyOption)
        HotKeySet("{APPSKEY}")
        GUICtrlSetData($iMenuPosition, "Enable HotKey")
        $bHotKeyEnabled = True
    EndIf
    Return $bHotKeyEnabled
EndFunc   ;==>EnableDisableHotKey
; -----------------------------------------------
Func UpdateScenes()
    Local $sMessage = "Updating Scenes..." & @CRLF & @CRLF, $iWidth = 350, $iHeight = 45
    Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>UpdateScenes
; -----------------------------------------------
Func _CloseForm()
    Switch @GUI_WinHandle
        Case $Form1
            MsgBox($MB_OK, "GUI Event", "You selected CLOSE in the main window! Exiting...")
            Exit
        Case $sDisplayHotKeyOption
            GUIDelete($sDisplayHotKeyOption)
            GUICtrlSetState($sCol1Row1, $GUI_ENABLE)
        Case $sLabelA, $sLabelB
            GUIDelete(@GUI_WinHandle)
            GUICtrlSetState($sCol1Row2, $GUI_ENABLE)
    EndSwitch
EndFunc   ;==>SpecialEvents
; -----------------------------------------------

 

I know that I know nothing

Posted

ioa747,

To the rescue...as always...thanks!

However, though I have converted the button script to a menu script, when F10 is display, upon selecting F10, the F10 Function Key should then be triggered.

And when F12 is display, upon selecting F12, the F12 Function Key should then be triggered.

Any ideas?

Posted

as I said it is a beginning, it is more for you to see the way.
I do not have a complete picture of your script,
but only fragments of what I understood from reading the above.
From what I understood, F10 works like this. You display the label and do not activateF10,  but wait for you to press it first.
For F12 I did not understand the function you are calling, I only saw SplashTextOn in AddF12Label

I know that I know nothing

Posted

ioa747,

The AddF12Label was just a [placeholder] for the actual pressing of F12.

When F10 is displayed, when selecting F10, the F10 view will be invoked [via Send("{F10}")]

Then the F10 label switches to F12.

When F12 is displayed, when selecting F12, the F12 view will be invoked [via Send("{F12}")]

Posted (edited)

Here is the more specific script:

; -----------------------------------------------
#RequireAdmin
; -----------------------------------------------
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Global $sLabelA, $sLabelB, $sDisplayHotKeyOption, $iMenuPosition
; -----------------------------------------------
Main()
; -----------------------------------------------
Func Main()
    GUICreate("!", 100, 23, 1200, 23)
    WinSetOnTop("!", "", $WINDOWS_ONTOP)
    ; -----------------------------------------------
    Local $mMenu = GUICtrlCreateMenu("Test Menu")
    Local $mEnableDisableName2 = GUICtrlCreateMenuItem("Launch LiveGuiLabelA", $mMenu)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Local $idMsg = GUIGetMsg()
        Switch $idMsg
            Case $GUI_EVENT_CLOSE
                Exit
                ; -----------------
            Case $mEnableDisableName2
                LiveGuiLabelA()
        EndSwitch
    WEnd
EndFunc   ;==>Main
; -----------------------------------------------
Func LiveGuiLabelA()
    $sLabelA = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    ; -----------------------------------------------
    Local $sColRow = GUICtrlCreateLabel(" For F10", 0, 0, 75, 23, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Switch GUIGetMsg()
            Case $sColRow
                GUIDelete($sLabelA)
                SendF10()
                LiveGuiLabelB()
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>LiveGuiLabelA
; -----------------------------------------------
Func SendF10()
    WinActivate("[CLASS:SAC_MAIN]", "")
    Sleep(100)
    Send("{F10}") ; Select: F10
EndFunc   ;==>SendF10
; -----------------------------------------------
Func LiveGuiLabelB()
    $sLabelB = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    ; -----------------------------------------------
    Local $sColRow = GUICtrlCreateLabel(" For F12", 0, 0, 75, 23, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Switch GUIGetMsg()
            Case $sColRow
                GUIDelete($sLabelB)
                ReturnMe()
                Exit
        EndSwitch
    WEnd
EndFunc   ;==>LiveGuiLabelB
; -----------------------------------------------
Func ReturnMe()
    MouseClick($MOUSE_CLICK_LEFT, 1413, 98, 1, 0) ;Exit Ampsim
    Sleep(100)
    ; -----------------------------------------------
    WinClose("[CLASS:metapad]", "")
    ; -----------------------------------------------
    Send("{F12}") ; Select: F12
    ; -----------------------------------------------
    MouseMove(658, 58, 0)
EndFunc   ;==>ReturnMe
; -----------------------------------------------

 

Edited by mr-es335
  • Solution
Posted

will be transformed into GUIOnEventMode , like this.
(I didn't delete the extras for comparison)

; -----------------------------------------------
;~ #RequireAdmin
; -----------------------------------------------
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
; -----------------------------------------------
;~ Global $sLabelA, $sLabelB, $sDisplayHotKeyOption, $iMenuPosition
Global $hMainGUI, $mEnableDisableName2
Global $sLabelA, $sColRowA
Global $sLabelB, $sColRowB
; -----------------------------------------------
Main()
; -----------------------------------------------
Func Main()
    $hMainGUI = GUICreate("!", 100, 23, 1200, 23)
    WinSetOnTop("!", "", $WINDOWS_ONTOP)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm")
    ; -----------------------------------------------
    Local $mMenu = GUICtrlCreateMenu("Test Menu")
    $mEnableDisableName2 = GUICtrlCreateMenuItem("Launch LiveGuiLabelA", $mMenu)
    GUICtrlSetOnEvent($mEnableDisableName2, "LiveGuiLabelA")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Sleep(100)
    WEnd
;~  While 1
;~      Local $idMsg = GUIGetMsg()
;~      Switch $idMsg
;~          Case $GUI_EVENT_CLOSE
;~              Exit
;~              ; -----------------
;~          Case $mEnableDisableName2
;~              LiveGuiLabelA()
;~      EndSwitch
;~  WEnd
EndFunc   ;==>Main
; -----------------------------------------------
Func LiveGuiLabelA()
    $sLabelA = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm")
    ; -----------------------------------------------
    $sColRowA = GUICtrlCreateLabel(" For F10", 0, 0, 75, 23, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetOnEvent($sColRowA, "_ColRow")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
;~  While 1
;~      Switch GUIGetMsg()
;~          Case $sColRowA
;~              GUIDelete($sLabelA)
;~              SendF10()
;~              LiveGuiLabelB()
;~              Exit
;~      EndSwitch
;~  WEnd
EndFunc   ;==>LiveGuiLabelA
; -----------------------------------------------
Func _ColRow()
    Switch @GUI_CtrlId
        Case $sColRowA
            WinClose($sLabelA)
            SendF10()
            LiveGuiLabelB()
            ;Exit ; excessive ⚠
        Case $sColRowB
            WinClose($sLabelB)
            ReturnMe()
            Exit ; <-- The last one is enough.⚠
    EndSwitch
EndFunc   ;==>_ColRow
; -----------------------------------------------
Func SendF10()
    WinActivate("[CLASS:SAC_MAIN]", "")
    Sleep(100)
    Send("{F10}") ; Select: F10

    ToolTip('Send("{F10}")') ; Debuging only ⚠
    Sleep(1000)              ; Debuging only ⚠
    ToolTip('')              ; Debuging only ⚠
EndFunc   ;==>SendF10
; -----------------------------------------------
Func LiveGuiLabelB()
    $sLabelB = GUICreate("", 75, 23, 620, 48, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm")
    ; -----------------------------------------------
    $sColRowB = GUICtrlCreateLabel(" For F12", 0, 0, 75, 23, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetOnEvent($sColRowB, "_ColRow")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
;~  While 1
;~      Switch GUIGetMsg()
;~          Case $sColRowB
;~              GUIDelete($sLabelB)
;~              ReturnMe()
;~              Exit
;~      EndSwitch
;~  WEnd
EndFunc   ;==>LiveGuiLabelB
; -----------------------------------------------
Func ReturnMe()
    MouseClick($MOUSE_CLICK_LEFT, 1413, 98, 1, 0) ;Exit Ampsim
    Sleep(100)
    ; -----------------------------------------------
    WinClose("[CLASS:metapad]", "")
    ; -----------------------------------------------
    Send("{F12}") ; Select: F12
    ToolTip('Send("{F12}")') ; Debuging only ⚠
    Sleep(1000)              ; Debuging only ⚠
    ToolTip('')              ; Debuging only ⚠
    ; -----------------------------------------------
    MouseMove(658, 58, 0)
EndFunc   ;==>ReturnMe
; ; -----------------------------------------------
Func _CloseForm()
    Switch @GUI_WinHandle
        Case $hMainGUI
            If MsgBox($MB_YESNO + $MB_ICONWARNING, "GUI Event", "You selected CLOSE in the main window! Exiting?") = $IDYES Then
                Exit
            EndIf
        Case $sLabelA, $sLabelB
            GUIDelete(@GUI_WinHandle)
    EndSwitch
EndFunc   ;==>_CloseForm
; -----------------------------------------------

 

I know that I know nothing

Posted

Here is the completed "sample" script...

; -----------------------------------------------
;~ #RequireAdmin
; -----------------------------------------------
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1)
; -----------------------------------------------
Global $hMainGUI, $mEnableF10
Global $mLaunchSAC, $mExitSAC, $sDisplayLabel
Global $sLabelA, $sColRowA
Global $sLabelB, $sColRowB
Global $sDisplayHotKeyOption, $iMenuPosition
; -----------------------------------------------
Main()
; -----------------------------------------------
Func Main()
    $hMainGUI = GUICreate("Me", 100, 23, 1200, 23)
    WinSetOnTop("Me", "", $WINDOWS_ONTOP)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm")
    ; -----------------------------------------------
    Local $mMenu = GUICtrlCreateMenu("Test Menu")
    $mLaunchSAC = GUICtrlCreateMenuItem("Launch SAC", $mMenu)
    GUICtrlSetOnEvent($mLaunchSAC, "LaunchSAC")
    ; -----------------
    $sDisplayLabel = GUICtrlCreateMenuItem("Display HotKey Label", $mMenu)
    GUICtrlSetOnEvent($sDisplayLabel, "DisplayLabel")
    ; -----------------
    $mEnableF10 = GUICtrlCreateMenuItem("Enable F10", $mMenu)
    GUICtrlSetOnEvent($mEnableF10, "EnableF10")
    ; -----------------
    $mExitSAC = GUICtrlCreateMenuItem("Exit SAC", $mMenu)
    GUICtrlSetOnEvent($mExitSAC, "ExitSAC")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Sleep(100)
    WEnd
EndFunc   ;==>Main
; -----------------------------------------------
Func LaunchSAC()
    Local $sSrcPath = "C:\RML\SAC\SAC64.exe G:\Session_Master\Session_Master.mxs"
    ; -----------------------------------------------
    Run($sSrcPath)
    WinWait("[CLASS:SAC_MAIN]", "")
    Send("{F12}") ; Select: F12
    MouseClick($MOUSE_CLICK_LEFT, 24, 52, 1, 0)
    MouseMove(959, 576, 0)
    Sleep(2000)
EndFunc   ;==>LaunchSAC
; -----------------------------------------------
Func ExitSAC()
    Local $sSrcPath1a = "C:\RML\SAC\SAC64.exe"
    Local $sSrcPath1b = "SAC64.exe"
    Local $PID = 0
    ; -----------------------------------------------
    ProcessClose($sSrcPath1a)
    $PID = ProcessExists($sSrcPath1b)
    If $PID Then ProcessClose($PID)
EndFunc   ;==>ExitSAC
; -----------------------------------------------
Func EnableF10()
    $sLabelA = GUICreate("", 75, 23, 620, 52, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm")
    ; -----------------------------------------------
    $sColRowA = GUICtrlCreateLabel(" For F10", 0, 0, 75, 23, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetOnEvent($sColRowA, "_ColRow")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
EndFunc   ;==>EnableF10
; -----------------------------------------------
Func DisplayLabel()
    $sDisplayHotKeyOption = GUICreate("", 117, 18, 210, 91, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(10, 600, 0, "Seqoe UI")
    GUISetBkColor(0x3D3D3D)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm")
    ; -----------------------------------------------
    $iMenuPosition = GUICtrlCreateLabel(" Enable HotKey", 0, 0, 117, 18, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetOnEvent($iMenuPosition, "EnableDisableHotKey")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    GUICtrlSetState($sDisplayLabel, $GUI_DISABLE)
EndFunc   ;==>DisplayLabel
; -----------------------------------------------
Func _ColRow()
    Switch @GUI_CtrlId
        Case $sColRowA
            WinClose($sLabelA)
            SendF10()
            EnableF12()
        Case $sColRowB
            WinClose($sLabelB)
            ReturnMe()
;~          Exit    ; Keep the GUI alive!⚠
    EndSwitch
EndFunc   ;==>_ColRow
; -----------------------------------------------
Func SendF10()
    WinActivate("[CLASS:SAC_MAIN]", "")
    Sleep(100)
    Send("{F10}") ; Select: F10
EndFunc   ;==>SendF10
; -----------------------------------------------
Func EnableF12()
    $sLabelB = GUICreate("", 75, 23, 620, 52, $WS_POPUP, $WS_EX_TOPMOST)
    GUISetFont(14, 800, 0, "Calibri")
    GUISetBkColor(0x3D3D3D)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm")
    ; -----------------------------------------------
    $sColRowB = GUICtrlCreateLabel(" For F12", 0, 0, 75, 23, $SS_CENTER)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUICtrlSetOnEvent($sColRowB, "_ColRow")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
EndFunc   ;==>EnableF12
; -----------------------------------------------
Func ReturnMe()
    WinActivate("[CLASS:SAC_MAIN]", "")
    Sleep(100)
    Send("{F12}") ; Select: F12
EndFunc   ;==>ReturnMe
; -----------------------------------------------
Func EnableDisableHotKey()
    Local Static $bHotKeyEnabled = True
    ; -----------------------------------------------
    If $bHotKeyEnabled = True Then
        HotKeySet("{APPSKEY}", "UpdateScenes") ; The script that is to be executed!
        GUICtrlSetData($iMenuPosition, "Disable HotKey")
        $bHotKeyEnabled = False
    Else
        WinClose($sDisplayHotKeyOption)
        HotKeySet("{APPSKEY}")
        GUICtrlSetData($iMenuPosition, "Enable HotKey")
        $bHotKeyEnabled = True
    EndIf
    Return $bHotKeyEnabled
EndFunc   ;==>EnableDisableHotKey
; -----------------------------------------------
Func UpdateScenes()
    Local $sMessage = "Updating Scenes..." & @CRLF & @CRLF, $iWidth = 350, $iHeight = 45
    Local $iOpt = 1, $sFontName = "FuturaBQ-DemiBold", $iFontSize = 14
    ; -----------------------------------------------
    SplashTextOn("", $sMessage, $iWidth, $iHeight, -1, -1, $iOpt, $sFontName, $iFontSize)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>UpdateScenes
; -----------------------------------------------
Func _CloseForm()
    Switch @GUI_WinHandle
        Case $hMainGUI
            Exit
        Case $sLabelA, $sLabelB
            GUIDelete(@GUI_WinHandle)
    EndSwitch
EndFunc   ;==>_CloseForm
; -----------------------------------------------

I removed Line 104 to keep the menu alive.

Posted (edited)

ioa747,

One little thing that I have noticed, in each of the other examples when EnableDisableHotKey() is sued, when selecting the Disable HotKey label, the function is exited. In this present example, the label "toggles" back-and-forth - with the function never exiting?!?

Func EnableDisableHotKey()
    Local Static $bHotKeyEnabled = True
    ; -----------------------------------------------
    If $bHotKeyEnabled = True Then
        HotKeySet("{APPSKEY}", "UpdateScenes") ; The script that is to be executed!
        GUICtrlSetData($iMenuPosition, "Disable HotKey")
        $bHotKeyEnabled = False
    Else
        ; WinClose($sDisplayHotKeyOption)
        ; GUIDelete($sDisplayHotKeyOption)
        HotKeySet("{APPSKEY}")
        GUICtrlSetData($iMenuPosition, "Enable HotKey")
        $bHotKeyEnabled = True
    EndIf
    Return $bHotKeyEnabled
EndFunc   ;==>EnableDisableHotKey
; -----------------------------------------------

I did notice the following:

1) The previous script implemented: GUIDelete($sDisplayHotKeyOption)
2) This current script implements: WinClose($sDisplayHotKeyOption)

May I ask "Why?" WinClose was chosen over GUIDelete?

PS: I just noticed that if implementing GUIDelete($sDisplayHotKeyOption), the Menu option is not re-enabled?!?

 

Edited by mr-es335
Posted


This happens because, while you declared
GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseForm")
in the DisplayLabel for the $sDisplayHotKeyOption GUI,
you did not put the Event handler in _CloseForm
add it, as below, and then it will Close too

Func _CloseForm()
    Switch @GUI_WinHandle
        Case $hMainGUI
            Exit
        Case $sLabelA, $sLabelB, $sDisplayHotKeyOption
            GUIDelete(@GUI_WinHandle)
    EndSwitch
EndFunc   ;==>_CloseForm

 

4 hours ago, mr-es335 said:

May I ask "Why?" WinClose was chosen over GUIDelete?

it's more of a matter of order, and normal flow.
When you call WinClose what does it do? it sends a message to the window to close, and the GUI calls $GUI_EVENT_CLOSE, and calls the function you declared in GUISetOnEvent.
In our case _CloseForm()

In case you had a flow that after calling the GUI, activated another GUI, or a button,
you would put them in the _CloseForm() function e.g.
Case $sDisplayHotKeyOption
    GUIDelete($sDisplayHotKeyOption)
    GUICtrlSetState($sCol1Row1, $GUI_ENABLE)

and it would follow the flow

With GUIDelete, the flow will change,
and you should put them there when you call GUIDelete

I hope I enlightened you :)

I know that I know nothing

Posted

ioa747,

"I hope I enlightened you..." Yes, yo did! Thank yo very much!

Thus far, the updated button-to-menu script appears to be working as it should. I have a few more tests to run and will keep you updated.

However, as always, ioa747, your assistance has been -  and indeed, is, an invaluable source of to me. Thank you so very much.

PS: I will mark your solution(s) as "solved"...again!

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