FILEVIEW is a sample program that demonstrates how to insert the Viewing ActiveX control into a Visual Basic application and use it to display documents.

Create a New Visual Basic Project 6.0

  1. Start a new project by choosing New Project from the File menu.

  2. Add the Viewing Control to the project. From the Project menu, select Components.

  3. In the Components dialog box, select HPE KeyView OLE Control module from the Controls list box. Click OK.

    If the HPE KeyView OLE Control module is not listed in the Controls list box, click Browse to locate and register the control.

    The Viewing icon appears in the Toolbox.

Draw the Controls

Draw the controls on the form according to the diagram above. Use the following controls:




Command button


Drive list box

Directory list box

File list box

Viewing control

Set Objects and Properties

After you design the form, you need to set the following properties:






File Viewer




1-Fixed Single


Command button



NOTE: Note: Use the default settings for all other properties and objects.

Create Event Procedures

In the File Viewer application, create the following event procedures for five different controls. After you have completed these event procedures, you can compile and run the application.

Form Load event: The Form_Load event sets the drive and path to the drive and directory where the sample application is loaded, and specifies whether initialization information is stored in the registry or the kvsdk.ini file. Add the following code to the Form_Load event procedure:

Private Sub Form_Load()
    Drive1.Drive = App.Path
    Dir1.Path = App.Path
    KEYview1.RegIniMode = 1
    KEYview1.RegIniName = "kvsdk.ini"
End Sub

Command button Click event: The command button’s Click event ends the application. Add the following code to the Command1_Click event procedure:

Private Sub Command1_Click ()
    Unload Me
    End                ' Ends the application.
End Sub

Drive list and directory list boxes Change events: To make the drive, directory, and file list boxes work together, add the following code to the Drive1_Change and Dir1_Change event procedures:

Private Sub Drive1_Change ()
    Dir1.Path = Drive1.Drive        ' Update directory path.
End Sub
Private Sub Dir1_Change ()
    File1.Path = Dir1.Path        ' Update files.
End Sub

File list box Double-click event: The File1_DblClick event procedure for the file list box displays the full path name of the selected file in the label control, and displays the picture itself in the image control. You need the following code:

Private Sub File1_DblClick ()
    If Right(File1.Path, 1) <> "\" Then
        Label1.Caption = File1.Path & "\" & File1.FileName
    Else            ' If root directory
        Label1.Caption = File1.Path & File1.FileName
    End If
    nRet = KEYview1.Open(Label1.Caption)
End Sub

Notice how the full path name is constructed: