hellovapi
hellovapi
is a simple program that demonstrates how to use Viewing SDK to display documents in your application. The program creates a Windows application window, and then creates a child window that the Viewing SDK uses to display documents. The Viewing SDK is controlled by sending Windows-style messages to the child window. The set of messages that you send to the child window form the Viewing API (VAPI). The child window is known as a VAPI window. The VAPI messages are described in Message Parameters.
Load kvvapi.dll
Before you can create a VAPI window, you must load the VAPI library (kvvapi.dll
) by using the LoadLibrary
function. In hellovapi
, the library is loaded in the InitializeVAPI
function which is called during the processing of the WM_CREATE
message.
The library is loaded in the following way:
-
InitializeVAPI
calls either theGetPrivateProfileString
Windows function orRegQueryValueEx
to get the value ofHOME
in theGeneral
section of thekvsdk.ini
file or Windows registry.GetPrivateProfileString
gets the value fromkvsdk.ini
, andRegQueryValueEx
gets the value from the registry. TheHOME
setting specifies the location of the Viewing SDKbin
directory.InitializeVAPI
demonstrates how to get this setting from both the registry andkvsdk.ini
file. By default,InitializeVAPI
gets the value fromkvsdk.ini
. -
InitializeVAPI
then creates the path to the VAPI library and loads it:wsprintf (szDLLPath, TEXT("%s\\%s"), szHome, VAPIDF_VAPI_DLL_NAME); hLibVAPI = LoadLibrary (szDLLPath);
Create the VAPI Window
After the VAPI library is loaded, the program creates the VAPI window by calling CreateWindow
with a class name of VAPIDF_VAPI_WINDOW_CLASS_NAME
:
hWndVAPI = CreateWindow (VAPIDF_VAPI_WINDOW_CLASS_NAME, NULL, WS_CHILD | WS_DISABLED, rc.left, rc.top, rc.right, rc.bottom, hWnd, NULL, hLibVAPI, &CreateParams);
The last parameter passes in a pointer to VAPI creation information. This creation information is in the structure of type TPVAPICreateParams
, and tells VAPI where to locate the initialization settings, and whether they are in the registry or in kvsdk.ini
. The hellovapi
program uses the bUseRegistry
global variable to specify whether to get the settings from the registry or kvsdk.ini
.
By default, hellovapi
tells VAPI to use the kvsdk.ini
file that was located with the call to InitializeVAPI
. The path to the kvsdk.ini
file is stored in the szIniFileName
global variable.
To specify the registry
-
Set
uProfileType
toPROFILEDF_USE_REG
. -
Set
lpszRegistryName
to the registry name of the Viewing SDK key under the main branchHKEY_LOCAL_MACHINE\SOFTWARE
. The default isVerity\Viewing SDK
.
To specify an initialization file
-
Set
uProfileType
toPROFILEDF_USE_INI
. -
Set
lpszIniFileName
to the location of the initialization file.NOTE: The strings that you pass in for initialization information must be ASCII strings. If your application is in Unicode, you must convert the strings to ASCII before you pass them in.
// Initialize the parameters for the creation of the VAPIwindow.// memset (&CreateParams, 0, sizeof(TPVAPICreateParams)); if (bUseRegistry) { CreateParams.uProfileType = PROFILEDF_USE_REG; CreateParams.lpszRegistryName = REGISTRY_NAME_ASCII; } else { CreateParams.uProfileType = PROFILEDF_USE_INI; CreateParams.lpszIniFileName = szIniFileName; }
Open a Document
To tell VAPI to open a document
-
Create a
TPVAPIOpenDocInfoEx
structure. -
Send VAPI a
VAPIM_INIT
message with thewParam
set toVAPIMWP_INIT_OPENDOCEX
, and thelParam
set to the address of theTPVAPIOpenDocInfoEx
structure.
This is demonstrated in the OpenDoc
function. It uses a Windows Open dialog box to get the name of a file, and sets the lpszFilePath
parameter of the TPVAPIOpenDocInfoEx
structure to this file name. If it is successful, the VAPIM_INIT
message returns VAPI_RETURN_SUCCESS
.
NOTE: The file name must be an ASCII string. If your application is in Unicode, you must convert the string to ASCII before passing it in.
// Open the document.//
memset (&OpenDocInfo, 0, sizeof(TPVAPIOpenDocInfoEx));
OpenDocInfo.lpszFilePath = szFileName;
lResult = SendMessage (hWndVAPI, VAPIM_INIT, VAPIMWP_INIT_OPENDOCEX,
(LPARAM)&OpenDocInfo);