Create a Viewing API Window

You must create a new VAPI window for each document that you open; each VAPI window manages only one document at a time.

You can create multiple VAPI windows to handle multiple documents simultaneously. After you create a VAPI window, you can use the Viewing API to manage the document by sending messages to the window and receiving notification messages from the window. When you are finished with the document, you destroy its VAPI window.

To create the VAPI window, use the standard Windows API functions CreateWindow() or CreateWindowEx(), with the following parameter values:



LPCTSTR lpClassName

VAPIDF_VAPI_WINDOW_CLASS_NAME (defined in kvvapi.h).

LPCTSTR lpWindowName


DWORD dwStyle


int x, y

0, 0

int nWidth

The width of the application (parent) window.

int nHeight

The height of the application (parent) window.

HWND hWndParent

The handle of the application window. (See note below.)




The handle of the VAPI library.

LPVOID lpParam

A pointer to a TPVAPICreateParams structure that specifies optional parameters. Through this structure, you specify whether you are using an initialization file or registry settings.

For example:

                    WS_CHILD | WS_DISABLED,
                    rc.left,, rc.right, rc.bottom,

Get the Viewer Window of the Document

The Viewer window is a document-specific window that the VAPI window creates when you open a document. Because the Viewer window is controlled by the VAPI window, normally you should not need the handle of the Viewer window.

The Viewer window is subclassed by the VAPI window. That is, when the VAPI window creates the Viewer window, it subclasses the Viewer window so that the VAPI window intercepts all messages sent to the Viewer window. This allows the VAPI window to control the Viewer window and to handle the right-mouse context menu and common operations such as SaveAs.

Depending on the document type, the Viewer window might also create several child windows in order to handle the document. For example, when you open a spreadsheet document, the VAPI window creates a [WorkBook] Viewer window, which in turn creates a [SpreadSheet] Viewer window for each spreadsheet page when it is accessed. All VAPI child windows are destroyed when the VAPI window is destroyed.