Option Explicit
Const ID_FILE_EXIT = 1051
Const ID_FILE_MRU_1 = 40001 Const ID_FILE_MRU_2 = 40002 Const ID_FILE_MRU_3 = 40003 Const ID_FILE_MRU_4 = 40004
Public m_cMRU As New cMRUFileList
Private Sub Form_Load() Dim Item As CommandBarAction CommandBars1.EnableActions With CommandBars1.Actions ' MRU Set Item = .Add(ID_FILE_MRU_1, "&1)", "1)", "", "File") Set Item = .Add(ID_FILE_MRU_2, "&2)", "2)", "", "File") Set Item = .Add(ID_FILE_MRU_3, "&3)", "3)", "", "File") Set Item = .Add(ID_FILE_MRU_4, "&4)", "4)", "", "File") ' EXIT .Add ID_FILE_EXIT, "Exit", "", "", "File" End With
Dim ControlFile As CommandBarPopup Set ControlFile = CommandBars1.ActiveMenuBar.Controls.Add(xtpControlPopup, 0, "&File", -1, False) With ControlFile.CommandBar ' MRU Group .Controls.Add xtpControlButton, ID_FILE_MRU_1, "" .Controls(.Controls.Count).BeginGroup = True .Controls.Add xtpControlButton, ID_FILE_MRU_2, "" .Controls.Add xtpControlButton, ID_FILE_MRU_3, "" .Controls.Add xtpControlButton, ID_FILE_MRU_4, "" ' .Controls.Add xtpControlButton, ID_FILE_EXIT, "" .Controls(.Controls.Count).BeginGroup = True End With
' Most Recently Used m_cMRU.MaxFileCount = 4 m_cMRU.Load "MyApp", "MySection" Call pDisplayMRU
End Sub
Private Sub CommandBars1_Execute(ByVal Control As XtremeCommandBars.ICommandBarControl) Dim i As Integer Dim strS As String Select Case Control.Id ' ... Case ID_FILE_MRU_1 To ID_FILE_MRU_4 Call LoadDocument(m_cMRU.file(CLng(Control.Id - ID_FILE_MRU_1 + 1))) Case ID_FILE_EXIT: Unload Me ' ... End Select
End Sub
Private Sub Command1_Click() LoadDocument ("File1") End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) m_cMRU.Save "MyApp", "MySection"
End Sub
Public Sub pDisplayMRU() Dim iFile As Integer Dim Item As CommandBarControl For iFile = 1 To m_cMRU.MaxFileCount Set Item = CommandBars1.FindControl(, ID_FILE_MRU_1 + (iFile - 1), , True) If Not (Item Is Nothing) Then If (iFile <= m_cMRU.FileCount) And (m_cMRU.FileExists(iFile)) Then Item.Visible = True Item.Caption = m_cMRU.MenuCaption(iFile) Item.DescriptionText = m_cMRU.file(iFile) If iFile = 1 Then Item.Checked = True End If Else Item.Visible = False End If End If Next iFile End Sub
Private Sub LoadDocument(fname As String)
m_cMRU.AddFile fname ' If FileExists Then ' m_cMRU.AddFile fname ' Else ' m_cMRU.RemoveFile fname ' End If pDisplayMRU End Sub
Private Sub SaveDocument(fname As String) m_cMRU.AddFile fname pDisplayMRU
End Sub
|