Jump to content

Launch a "root" Menubar item


Go to solution Solved by Nine,

Recommended Posts

Posted

Good day,

Is the following..."possible"?

; -----------------------------------------------
#include <GUIConstantsEx.au3>
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Main()
; -----------------------------------------------
Func Main()
    Local $MainGuiTitle = " Session|Show Development"
    GUICreate($MainGuiTitle, 554, 20, 1260, 22)
    ;-----------------
    Local $mEnableDisableLIVE = GUICtrlCreateMenu("E&nable|Disable [LIVE]")
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Local $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
                ; -----------------
                ; Enable|Disable [LIVE] Options
            Case $mEnableDisableLIVE
                EnableDisableLIVE()
                ; -----------------
        EndSwitch
    WEnd
EndFunc   ;==>Main
; -----------------------------------------------
; -----------------------------------------------
; Enable|Disable [LIVE] Options
Func EnableDisableLIVE()
    ConsoleWrite("$EnableDisableLIVE=" & EnableDisableLIVE & @CRLF)
EndFunc   ;==>EnableDisableLIVE
; -----------------------------------------------

I need to be able to execute the script from the "root" Menubar item.

Posted

Good day

; https://www.autoitscript.com/forum/topic/212611-launch-a-root-menubar-item/#findComment-1540100

; -----------------------------------------------
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3> ; ***
; -----------------------------------------------
Opt("MustDeclareVars", 1)
; -----------------------------------------------
Main()
; -----------------------------------------------
Func Main()
    Local $MainGuiTitle = " Session|Show Development"
    GUICreate($MainGuiTitle, 554, 20, 1260, 22)
    ;-----------------
    Local $idFilemenu = GUICtrlCreateMenu("&Menu")
    Local $mEnableDisableLIVE = GUICtrlCreateMenuItem("E&nable|Disable [LIVE]", $idFilemenu)
;~  or
;~  Local $mEnableDisableLIVE = GUICtrlCreateLabel("E&nable|Disable [LIVE]", 3, 3, 150, 15, $SS_NOTIFY)
    ; -----------------------------------------------
    GUISetState(@SW_SHOW)
    ; -----------------------------------------------
    While 1
        Local $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                Exit
                ; -----------------
                ; Enable|Disable [LIVE] Options
            Case $mEnableDisableLIVE
                EnableDisableLIVE()
                ; -----------------
        EndSwitch
    WEnd
EndFunc   ;==>Main
; -----------------------------------------------
; -----------------------------------------------
; Enable|Disable [LIVE] Options
Func EnableDisableLIVE()
    ConsoleWrite("$EnableDisableLIVE" & @CRLF)
EndFunc   ;==>EnableDisableLIVE
; -----------------------------------------------

 

I know that I know nothing

  • Solution
Posted (edited)
#include <Constants.au3>
#include <GUIConstants.au3>

Opt("MustDeclareVars", True)

Example()

Func Example()
  Local $hGUI = GUICreate("Example", 300, 200)
  Local $idDummy = GUICtrlCreateMenu("dummy")
  Local $idMenu = GUICtrlCreateMenuItem("click me", -1)

  GUICtrlDelete($idDummy)
  GUISetState()

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $idMenu
        MsgBox($MB_OK, "Test", "Working")
    EndSwitch
  WEnd
EndFunc

 

Edited by Nine
  • Moderators
Posted

mr-es335,

A number of solutions in this thread:

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

 

Posted

interesting approach
however, it created a question for me

#include <Constants.au3>
#include <GUIConstants.au3>

Opt("MustDeclareVars", True)

Example()

Func Example()
    Local $hGUI = GUICreate("Example", 300, 200)
    Local $idDummy = GUICtrlCreateMenu("dummy")
    Local $idMenu = GUICtrlCreateMenuItem("click me", -1)        ; this  working but
;~  Local $idMenu = GUICtrlCreateMenuItem("click me", $idDummy)  ; this not working ?? 😕
    GUICtrlDelete($idDummy) ; ***
    GUISetState()

    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idMenu
                MsgBox($MB_OK, "Test", "Working")
        EndSwitch
    WEnd
EndFunc   ;==>Example

I know that I know nothing

Posted (edited)
#include <GuiMenu.au3>
#include <GUIConstants.au3>
Global Enum $e_idNew = 1000, $e_idOpen, $e_idSave
Example2()
Func Example2()
    Local $hGUI, $hFile, $hEdit, $hHelp, $hMain
    $hGUI = GUICreate("Menu", 400, 300)
    $hMain = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_AddMenuItem($hMain, "&New", $e_idNew)
    _GUICtrlMenu_AddMenuItem($hMain, "&Open", $e_idOpen)
    _GUICtrlMenu_AddMenuItem($hMain, "&Save", $e_idSave)
    _GUICtrlMenu_SetMenu($hGUI, $hMain)
    GUISetState(@SW_SHOW)
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIRegisterMsg($WM_COMMAND, "")
EndFunc   ;==>Example2

; Handle menu commands
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $lParam
    Switch _WinAPI_LoWord($wParam)
        Case $e_idNew
            MemoWrite("New")
        Case $e_idOpen
            MemoWrite("Open")
        Case $e_idSave
            MemoWrite("Save")
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

; Write message to memo
Func MemoWrite($sMessage)
    ConsoleWrite($sMessage & @CRLF)
EndFunc   ;==>MemoWrite

..this works too

Edit: in neither case ( this or prior examples ) the alt + letter works :(

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

@ioa747 The -1 do not refer to the last created control (like it means for all the other GUI functions) but it refers to the first level menu.

By putting $idDummy, you simply create an item menu under Dummy which you delete after...

Edited by Nine

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