Web
Viewer ActiveX Control
Copyright 1997 by Distinct Corporation.
All rights reserved.
Usage | Properties | Events | Methods | Header
The Distinct WebViewer ActiveX control allows developers to integrate viewing of web documents into their applications. This custom control supports many document types such as HTML, JPEG, GIF, XBM, AIFF, AU, TXT, and more.
Though the Distinct WebViewer control displays the contents of local files, this control becomes powerful when used in conjunction with the Distinct Http ActiveX control. Remote documents can be downloaded to the local machine via the Http ActiveX control and then viewed using the WebViewer control.
See the section entitled "Using Distinct ActiveX controls in various environments" on how to add the control to your project.
Unlike other ActiveX controls from Distinct, the WebViewer control is visible at runtime and has its own viewing area. The contents of the document are displayed within this area. The FileName property must contain the complete path of the document to be viewed, and the BaseDir property must specify the directory containing the document to be viewed. The Display method can be used to display the contents of the document.
Before calling any other method, the Start method must be called once (generally when the application loads) to initialize various components of the control. Similarly, before quitting the application, the Stop method must be called to cleanup the components initialized by the control. To ensure proper behavior of the control, it is important to call these methods correctly.
By handling the OnReportStatus and OnReportProgress events, the application can track the status of a file being displayed and the progress of the display.
BaseDir
Base directory of file to be viewed
FileName
File to be viewed
OnError
Local error has occurred
OnLink
Url link information
OnReportProgress
Report progress during display
OnReportStatus
Report status during display
Display
Display document
Start
Initialize various components
Stop
Cleanup initialized components
The following provides a complete listing of the D_VIEW.TXT definition file. If your application uses more than one Distinct custom control in the same form, then some definitions will conflict. For example, the FTP Client custom control includes the definition
Global Const ACTION_DISCONNECT = 3
in the D_FTP.TXT file and the Telnet custom control includes the definition
Global Const ACTION_DISCONNECT = 2
in the D_TNET.TXT file. To avoid this conflict, you must rename at least one of the constants (eg. FTP_ACTION_DISCONNECT or TNET_ACTION_DISCONNECT).
' WebViewer ActiveX Control
' (C) Copyright 1996, 1997 by Distinct Corporation
' All rights reserved
' error codes
Global Const ERR_IN_ACTION = 1
Global Const ERR_CANNOT_PERFORM_ACTION = 2
Global Const ERR_FILE_NOT_DEFINED = 3
Global Const ERR_UNABLE_TO_DISPLAY = 4
Summary
Base directory of file to be viewed
Description
The BaseDir property must be set to the directory of the document to be viewed. The document may contain multiple images that are stored in subdirectories. In order for the control to load these images, the BaseDir property must specify the base directory containing the document. If the BaseDir property is not set then these images will not appear in the document.
The BaseDir property must be specified before invoking the Display method.
This property can be changed at design time, or at run time. There is no default value for this property.
Example
WebViewer.FileName = "c:\temp\index.htm"
WebViewer.BaseDir = "c:\temp"
Summary
File to be viewed.
Description
The FileName property must be specified before invoking the Display method. This property must be set to the path and name of the document to viewed.
The WebViewer ActiveX control supports the following file formats:
File Extensions | Meaning |
.WAV, .AU, .AIFF | Audio files |
.HTM, .HTML | HTML files |
.JPG, .JPEG, .GIF, .XBM | Image files |
.MOV | Video files (QuickTime movie) |
.TXT, .H, .C | Plain text files |
This property can be changed at design time, or at run time. There is no default value for this property.
Example
WebViewer.FileName = "c:\temp\index.htm"
Summary
Local error has occurred.
Description
The OnError event occurs when a property is accessed in an illegal way or when a connection with the remote server cannot be established. The table below lists all possible error codes delivered by this event.
Value | Meaning |
ERR_IN_ACTION | Another action is in progress. |
ERR_CANNOT_PERFORM_ACTION | Unable to initialize. |
ERR_FILE_NOT_DEFINED | File not specified. |
ERR_UNABLE_TO_DISPLAY | Unable to display file. |
The following describes each error in more detail.
ERR_IN_ACTION
Another action is already in progress.
ERR_CANNOT_PERFORM_ACTION
Unable to initialize the underlying Distinct support files. There may
be a license violation.
ERR_FILE_NOT_DEFINED
File not specified. The FileName property must be set before the Display
method is invoked.
ERR_UNABLE_TO_DISPLAY
Unable to display file. The control was unable to display the file.
The document type may not be supported by the control.
Example
Sub WebViewer_OnError (ErrorCode
As Integer)
If ErrorCode = ERR_UNABLE_TO_DISPLAY Then
MsgBox "Unable to display file", 64, "Sample Program"
End If
End Sub
Summary
Url link information.
Description
This event occurs whenever a link is clicked within an HTML document.
The URL for the link is passed as the argument. This information can be used to obtain the link documents.
The application can use this Url information, in conjunction with the HTTP ActiveX control, to download the document for the link, and then view it using the WebViewer ActiveX control.
Example
Sub WebViewer_OnLink (Url
As String)
' display url
Message = "You have clicked on " + Url
MsgBox Message, 64, "Sample Program"
End Sub
Summary
Report progress during display.
Description
The OnReportProgress event occurs several times during the Display method to inform the application of the progress. It delivers the number of bytes of the file currently displayed.
The parameters Number and Total represent the number of bytes currently displayed and the total length of the file.
As the display proceeds, one or more OnReportProgress events will occur to deliver the number of bytes displayed so far. The application can process this data and display the progress (eg. update a progress bar or status bar).
Example
Sub WebViewer_OnReportProgress (Bytes
As Long, Total As Long)
' display number of bytes displayed
NumBytes = NumBytes + Bytes
StatusBar.Panels(2).Text = "Bytes: " & NumBytes &
" / " & Total
End Sub
Summary
Report status during display.
Description
The OnReportStatus event occurs several times during the Display method to inform the application of the status of the request.
The Status parameter gives a textual information about the status of the display. For example, the Status parameter may be "Reading File" or "Finished".
As the display proceeds, one or more OnReportStatus events will occur to keep the application informed. The application can process this data and display the status (eg. update a status bar).
Example
Sub WebViewer_OnReportStatus
(Status As String)
' display transaction status
StatusBar.Panels(1).Text = "Status: " + Status
End Sub
Summary
Display document.
Syntax
Boolean Display () |
Description
To display the contents of a file, invoke the Display method. The FileName property must be set before calling this method. The OnReportProgress and OnReportStatus events will occur during this method.
If an error occurs, then the OnError event will be fired. The application should set a flag in the OnError event, so that it can determine if the function was successful. In addition, the application may want to display an error message in the OnError event to inform the user of the error. Please check the reference page of the OnError event for a complete listing of error codes.
The Display method returns True if successful; otherwise, it returns False.
Example
Result = WebViewer.Display ()
Summary
Initialize various components.
Syntax
Boolean Start () |
Description
The Start method initializes various components of the WebViewer control. This method must be called before calling the Display method. The Display method will fail if the control is not initialized.
Usually the Start method is called when the application is loaded. The Stop method must be called before the application quits to cleanup any initialized components.
The Start method returns True if successful, otherwise, it returns False.
Example
Result = WebViewer.Start ()
Summary
Cleanup initialized components.
Syntax
Boolean Stop () |
Description
The Stop method cleans up the various components initialized at the Start method. This method must be called before quitting the application. Usually the Start method is called when the application is loaded and the Stop method is called just before the application quits.
To ensure proper behavior of the WebViewer control, the application must initialize and cleanup in the manner described.
The Stop method returns True if successful, otherwise, it returns False.
Example
Result = WebViewer.Stop ()