Jump to content

How do I check the state of auto-generated menu buttons?


Recommended Posts

If you use the code from GUICtrlCreateMenu and you look at the part that dynamically adds a file path to the $recentfilemenu menu:

If $msg = $fileitem Then
        $file = FileOpenDialog("Choose file...",@TempDir,"All (*.*)")
        If @error <> 1 Then GUICtrlCreateMenuitem ($file,$recentfilesmenu)
    EndIf

This works great but the problem is, since the new recently opened files are now buttons, how do I check the state of them in the while loop in the example below so I can either run the path if it's clicked off of the Recent File menu or have that path write to some dialog box somewhere? Can anyone help me out pls??? I'm new to Autoit so I apologize if this is a simple question. I've also searched the online documentation and the forum and can't find anything referencing this.

#include <GUIConstants.au3>

GUICreate("My GUI menu",300,200)

Global $defaultstatus = "Ready"
Global $status

$filemenu = GUICtrlCreateMenu ("&File")
$fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)
GUICtrlSetState(-1,$GUI_DEFBUTTON)
$helpmenu = GUICtrlCreateMenu ("?")
$saveitem = GUICtrlCreateMenuitem ("Save",$filemenu)
GUICtrlSetState(-1,$GUI_DISABLE)
$infoitem = GUICtrlCreateMenuitem ("Info",$helpmenu)
$exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)
$recentfilesmenu = GUICtrlCreateMenu ("Recent Files",$filemenu,1)

$separator1 = GUICtrlCreateMenuitem ("",$filemenu,2)   ; create a separator line

$viewmenu = GUICtrlCreateMenu("View",-1,1) ; is created before "?" menu
$viewstatusitem = GUICtrlCreateMenuitem ("Statusbar",$viewmenu)
GUICtrlSetState(-1,$GUI_CHECKED)
$okbutton = GUICtrlCreateButton ("OK",50,130,70,20)
GUICtrlSetState(-1,$GUI_FOCUS)
$cancelbutton = GUICtrlCreateButton ("Cancel",180,130,70,20)

$statuslabel = GUICtrlCreateLabel ($defaultstatus,0,165,300,16,BitOr($SS_SIMPLE,$SS_SUNKEN))

GUISetState ()
While 1
    $msg = GUIGetMsg()
    
    If $msg = $fileitem Then
        $file = FileOpenDialog("Choose file...",@TempDir,"All (*.*)")
        If @error <> 1 Then GUICtrlCreateMenuitem ($file,$recentfilesmenu)
    EndIf 
    If $msg = $viewstatusitem Then
        If BitAnd(GUICtrlRead($viewstatusitem),$GUI_CHECKED) = $GUI_CHECKED Then
            GUICtrlSetState($viewstatusitem,$GUI_UNCHECKED)
            GUICtrlSetState($statuslabel,$GUI_HIDE)
        Else
            GUICtrlSetState($viewstatusitem,$GUI_CHECKED)
            GUICtrlSetState($statuslabel,$GUI_SHOW)
        EndIf
    EndIf
    If $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton Or $msg = $exititem Then ExitLoop
    If $msg = $infoitem Then Msgbox(0,"Info","Only a test...")
WEnd
GUIDelete()

Exit

My Additions:- RunAs AdminDeviant Fun:- Variable Sound Volume

Link to comment
Share on other sites

Hello!

Sorry i don`t full understand you, since i know english is bad.

run the path if it's clicked off of the Recent File menu

This?:

#include <GUIConstants.au3>

Opt("GuiOnEventMode", 1)

Global $defaultstatus = "Ready"
Global $status

GUICreate("My GUI menu",300,200)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")

$filemenu = GUICtrlCreateMenu ("&File")
$fileitem = GUICtrlCreateMenuitem ("Open",$filemenu)
GUICtrlSetState(-1,$GUI_DEFBUTTON)
GUICtrlSetOnEvent(-1, "Open")
$saveitem = GUICtrlCreateMenuitem ("Save",$filemenu)


$helpmenu = GUICtrlCreateMenu ("?")
GUICtrlSetState(-1,$GUI_DISABLE)
$infoitem = GUICtrlCreateMenuitem ("Info",$helpmenu)
$exititem = GUICtrlCreateMenuitem ("Exit",$filemenu)
GUICtrlSetOnEvent(-1, "Quit")

$recentfilesmenu = GUICtrlCreateMenu ("Recent Files",$filemenu,1)

$separator1 = GUICtrlCreateMenuitem ("",$filemenu,2)   ; create a separator line

$viewmenu = GUICtrlCreateMenu("View", -1, 1) ; is created before "?" menu
$viewstatusitem = GUICtrlCreateMenuitem ("Statusbar",$viewmenu)
GUICtrlSetState(-1,$GUI_CHECKED)
GUICtrlSetOnEvent(-1, "SetStatus")

$okbutton = GUICtrlCreateButton ("OK",50,130,70,20)
GUICtrlSetState(-1,$GUI_FOCUS)

$cancelbutton = GUICtrlCreateButton ("Cancel",180,130,70,20)
GUICtrlSetOnEvent(-1, "Quit")

$statuslabel = GUICtrlCreateLabel ($defaultstatus,0,165,300,16,BitOr($SS_SIMPLE,$SS_SUNKEN))

GUISetState ()

While 1
    Sleep(100)
WEnd

Func Quit()
    Exit
EndFunc

Func Open()
    Local $sMenuItem
    Local $file = FileOpenDialog("Choose file...",@TempDir,"All (*.*)")
    If Not @error Then $sMenuItem = GUICtrlCreateMenuitem ($file,$recentfilesmenu)
    GUICtrlSetOnEvent(-1, "GetPath")
EndFunc

Func SetStatus()
    If BitAnd(GUICtrlRead($viewstatusitem),$GUI_CHECKED) = $GUI_CHECKED Then
        GUICtrlSetState($viewstatusitem,$GUI_UNCHECKED)
        GUICtrlSetState($statuslabel,$GUI_HIDE)
    Else
        GUICtrlSetState($viewstatusitem,$GUI_CHECKED)
        GUICtrlSetState($statuslabel,$GUI_SHOW)
    EndIf
EndFunc

Func GetPath()
    ShellExecute(GUICtrlRead(@GUI_CtrlId, 1))
EndFunc

:)

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