Jump to content

Recent Files Menu


BPBNA
 Share

Recommended Posts

Just like:

#include <GUIConstants.au3>

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

Global $defaultstatus = "Ready"
Global $status
Dim $count          = 0
Dim $lastindex      = 0
Dim $maxrecentfiles = 5 ; max 5 recent files
Dim $recentfiles[$maxrecentfiles][2]

$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()
    
    Switch $msg
        Case $fileitem
            $file = FileOpenDialog("Choose file...", @TempDir, "All (*.*)")
            If @error = 0 Then
                $found = 0
                For $i = 0 To $maxrecentfiles - 1
                    If $file = $recentfiles[$i][1] Then
                        $found = 1
                        ExitLoop
                    EndIf
                Next
                
                If Not $found Then
                    $item = GUICtrlCreateMenuitem ($file, $recentfilesmenu, 0)
                    
                    If $count > $maxrecentfiles - 1 Then
                        GUICtrlDelete($recentfiles[$lastindex][0])
                    EndIf
                    
                    $recentfiles[$lastindex][0] = $item
                    $recentfiles[$lastindex][1] = $file
                    
                    $lastindex = $lastindex + 1
                    If $lastindex = $maxrecentfiles Then $lastindex = 0
                    
                    $count = $count + 1
                EndIf
            EndIf

        Case $viewstatusitem
            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
    
        Case $GUI_EVENT_CLOSE, $cancelbutton, $exititem
            ExitLoop
            
        Case $infoitem
            Msgbox(0, "Info", "Only a test...")
            
        Case Else
            For $i = 0 To $maxrecentfiles - 1
                If $msg > 0 And $msg = $recentfiles[$i][0] Then
                    $file = $recentfiles[$i][1] ; now you have the file that was clicked
                    Msgbox(0, "Open File", $file)
                    ExitLoop
                EndIf                   
            Next
    EndSwitch
WEnd

GUIDelete()

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