vbAccelerator - Contents of code file: frmRecentDocuments.frm

VERSION 5.00
Begin VB.Form frmRecentDocuments 
   Caption         =   "Recent Documents Sample"
   ClientHeight    =   6045
   ClientLeft      =   3150
   ClientTop       =   2565
   ClientWidth     =   6390
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmRecentDocuments.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   6045
   ScaleWidth      =   6390
   Begin VB.TextBox txtRecentDocsPath 
      Height          =   375
      Left            =   1200
      Locked          =   -1  'True
      TabIndex        =   8
      Top             =   1740
      Width           =   4995
   End
   Begin VB.ListBox lstRecent 
      Height          =   2985
      Left            =   1200
      TabIndex        =   6
      Top             =   2160
      Width           =   4995
   End
   Begin VB.CommandButton cmdClear 
      Caption         =   "&Clear Recent Documents"
      Height          =   555
      Left            =   2880
      TabIndex        =   5
      Top             =   5220
      Width           =   1575
   End
   Begin VB.CommandButton cmdList 
      Caption         =   "&List Recent Documents"
      Height          =   555
      Left            =   1200
      TabIndex        =   4
      Top             =   5220
      Width           =   1575
   End
   Begin VB.CommandButton cmdAdd 
      Caption         =   "A&dd to Recent Documents"
      Height          =   555
      Left            =   1200
      TabIndex        =   3
      Top             =   540
      Width           =   1575
   End
   Begin VB.CommandButton cmdPick 
      Caption         =   "..."
      Height          =   375
      Left            =   5700
      TabIndex        =   2
      Top             =   120
      Width           =   435
   End
   Begin VB.TextBox txtFile 
      Height          =   375
      Left            =   1200
      TabIndex        =   1
      Top             =   120
      Width           =   4395
   End
   Begin VB.Label lblRecent 
      Caption         =   "&Recent Documents Path:"
      Height          =   735
      Left            =   120
      TabIndex        =   7
      Top             =   1800
      Width           =   1035
   End
   Begin VB.Label lblFile 
      Caption         =   "&File:"
      Height          =   255
      Left            =   180
      TabIndex        =   0
      Top             =   180
      Width           =   1035
   End
End
Attribute VB_Name = "frmRecentDocuments"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

' SHAutoComplete:
Private Enum SHAutoCompleteFlags
   SHACF_DEFAULT = &H0                           ' // Currently
    (SHACF_FILESYSTEM | SHACF_URLALL)
   SHACF_FILESYSTEM = &H1                        ' // This includes the File
    System as well as the rest of the shell (Desktop\My Computer\Control Panel\)
   SHACF_URLHISTORY = &H2                        ' // URLs in the User's History
   SHACF_URLMRU = &H4                            ' // URLs in the User's
    Recently Used list.
   SHACF_USETAB = &H8                            ' // Use the tab to move thru
    the autocomplete possibilities instead of to the next dialog/window control.
   SHACF_URLALL = (SHACF_URLHISTORY Or SHACF_URLMRU)
   SHACF_FILESYS_ONLY = &H10                     ' // This includes the File
    System
   SHACF_FILESYS_DIRS = &H20                     ' // Same as
    SHACF_FILESYS_ONLY except it only includes directories, UNC servers, and
    UNC server shares.
   SHACF_AUTOSUGGEST_FORCE_ON = &H10000000       ' // Ignore the registry
    default and force the feature on.
   SHACF_AUTOSUGGEST_FORCE_OFF = &H20000000      ' // Ignore the registry
    default and force the feature off.
   SHACF_AUTOAPPEND_FORCE_ON = &H40000000        ' // Ignore the registry
    default and force the feature on. (Also know as AutoComplete)
   SHACF_AUTOAPPEND_FORCE_OFF = &H80000000       ' // Ignore the registry
    default and force the feature off. (Also know as AutoComplete)
End Enum
Private Declare Function SHAutoComplete Lib "shlwapi.dll" ( _
   ByVal hwndEdit As Long, ByVal dwFlags As Long) As Long


Private m_cRecentDocuments As New cRecentDocuments


Private Sub cmdAdd_Click()
   On Error Resume Next
   m_cRecentDocuments.AddToRecentDocs txtFile.Text
   If Not (Err.Number = 0) Then
      MsgBox "Failed to add " & txtFile.Text & ":" & vbCrLf & Err.Description,
       vbExclamation
   End If
End Sub


Private Sub cmdClear_Click()
   If (vbYes = MsgBox("Are you sure you want to clear your recent documents?",
    vbYesNo Or vbQuestion)) Then
      m_cRecentDocuments.Clear
   End If
End Sub

Private Sub cmdList_Click()
   '
   lstRecent.Clear
   
   ' Get the recent documents path:
   txtRecentDocsPath.Text = m_cRecentDocuments.Path
   
   ' List the items:
   Dim i As Long
   For i = 1 To m_cRecentDocuments.Count
      lstRecent.AddItem m_cRecentDocuments.Item(i).Path
   Next i
      
   '
End Sub

Private Sub cmdPick_Click()
   '
   Dim c As New cCommonDialog
   Dim sFile As String
   If (c.VBGetOpenFileName(sFile, , , , , , "All Files (*.*)|*.*", , , , ,
    Me.hwnd)) Then
      txtFile.Text = sFile
   End If
   '
End Sub

Private Sub Form_Load()
   ' Initialise:
   txtFile.Text = App.Path & "\RecentDocuments.exe"
   ' Autocomplete text box:
   SHAutoComplete txtFile.hwnd, SHACF_FILESYS_ONLY
End Sub