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:
-
InitializeVAPIcalls either theGetPrivateProfileStringWindows function orRegQueryValueExto get the value ofHOMEin theGeneralsection of thekvsdk.inifile or Windows registry.GetPrivateProfileStringgets the value fromkvsdk.ini, andRegQueryValueExgets the value from the registry. TheHOMEsetting specifies the location of the Viewing SDKbindirectory.InitializeVAPIdemonstrates how to get this setting from both the registry andkvsdk.inifile. By default,InitializeVAPIgets the value fromkvsdk.ini. -
InitializeVAPIthen 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
uProfileTypetoPROFILEDF_USE_REG. -
Set
lpszRegistryNameto 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
uProfileTypetoPROFILEDF_USE_INI. -
Set
lpszIniFileNameto 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
TPVAPIOpenDocInfoExstructure. -
Send VAPI a
VAPIM_INITmessage with thewParamset toVAPIMWP_INIT_OPENDOCEX, and thelParamset to the address of theTPVAPIOpenDocInfoExstructure.
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);