vbAccelerator - Contents of code file: frmTestCDlg.frm

VERSION 5.00
Begin VB.Form frmTestCDLg 
   Caption         =   "vbAccelerator CommonDialog in EXE"
   ClientHeight    =   4320
   ClientLeft      =   4275
   ClientTop       =   2640
   ClientWidth     =   5430
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   Icon            =   "frmTestCDlg.frx":0000
   LinkTopic       =   "Form1"
   ScaleHeight     =   4320
   ScaleWidth      =   5430
   Begin VB.CommandButton cmdOpen 
      Caption         =   "&Open..."
      Default         =   -1  'True
      Height          =   375
      Left            =   960
      TabIndex        =   3
      Top             =   3360
      Width           =   1095
   End
   Begin VB.TextBox txtContents 
      BeginProperty Font 
         Name            =   "Lucida Console"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   2475
      Left            =   960
      MultiLine       =   -1  'True
      ScrollBars      =   3  'Both
      TabIndex        =   2
      Top             =   840
      Width           =   4335
   End
   Begin VB.TextBox txtFilter 
      BackColor       =   &H8000000F&
      Height          =   315
      Left            =   960
      Locked          =   -1  'True
      TabIndex        =   1
      Top             =   420
      Width           =   4335
   End
   Begin VB.TextBox txtFileName 
      BackColor       =   &H8000000F&
      Height          =   285
      Left            =   960
      Locked          =   -1  'True
      TabIndex        =   0
      Top             =   60
      Width           =   4335
   End
   Begin VB.Label lblContents 
      Caption         =   "&Contents:"
      Height          =   255
      Left            =   60
      TabIndex        =   6
      Top             =   900
      Width           =   915
   End
   Begin VB.Label lblFilter 
      Caption         =   "Fil&ter:"
      Height          =   255
      Left            =   60
      TabIndex        =   5
      Top             =   480
      Width           =   915
   End
   Begin VB.Label lblFileName 
      Caption         =   "&File name:"
      Height          =   255
      Left            =   60
      TabIndex        =   4
      Top             =   60
      Width           =   915
   End
End
Attribute VB_Name = "frmTestCDLg"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private WithEvents m_cHookDlg As cCommonDialog
Attribute m_cHookDlg.VB_VarHelpID = -1

Private Function GetFileText(ByVal sFIle As String) As String
Dim nFile As Integer
Dim sText As String
Dim bFileOpen As Boolean

On Error GoTo GetFileTextError
    
    nFile = FreeFile
    Open sFIle For Binary Access Read Lock Write As #nFile
    bFileOpen = True
    sText = String$(LOF(nFile), 0)
    Get #nFile, 1, sText
    Close #nFile
    bFileOpen = False
    GetFileText = sText
    Exit Function
    
GetFileTextError:
    GetFileText = Err.Number
    If (bFileOpen) Then
        Close #nFile
    End If
    Exit Function

End Function

Private Sub cmdOpen_Click()
On Error GoTo cmdHookError

   With m_cHookDlg
      .DialogTitle = "Choose Text FIle"
      .CancelError = True
      .flags = OFN_FILEMUSTEXIST Or OFN_PATHMUSTEXIST Or OFN_HIDEREADONLY
      .InitDir = "C:\STEVEMAC"
      .Filter = "Internet documents (*.HTM)|*.HTM|Text files (*.TXT)|*.TXT|All
       Files (*.*)|*.*"
      .FilterIndex = 1
      .HookDialog = True
      .ShowOpen

      txtFileName = .Filename
      txtFilter = .Filter
      txtContents = GetFileText(.Filename)
        
   End With
   
   Exit Sub

cmdHookError:
   If (Err.Number <> 20001) Then
      MsgBox "Error: " & Err.Description
   End If
   
End Sub

Private Sub Form_Load()
   Set m_cHookDlg = New cCommonDialog
End Sub

Private Sub m_cHookDlg_InitDialog(ByVal hDlg As Long)
   m_cHookDlg.CentreDialog hDlg, Me
End Sub