The GoldFinch command on the Viewer menu jumps to the Washington State Bird topic in the USA Tour sample title. (The Willow Goldfinch is the Washington state bird.) MENUDEMO uses this command to illustrate how to display a Viewer topic from an application.
Before displaying the topic, MENUDEMO checks to see whether or not the title is open. If it isn't, MENUDEMO opens it. This code, in the CheckLoadUsa function, appears as follows:
BOOL FAR PASCAL CheckLoadUsa (HWND hwnd)
{
static BOOL UsaLoaded = FALSE;
if (UsaLoaded)
return 0 ;
MVAPI(hwnd, BookPath, cmdContents, 0L);
UsaLoaded = TRUE;
return 0 ;
}
MENUDEMO uses the static constant UsaLoaded to indicate whether the USA Tour sample title has been opened or not. If this value is false, MENUDEMO loads the title by calling MVAPI and displaying the contents topic (cmdContents). MENUDEMO hard-codes the path for the BookPath parameter earlier in the program, as follows:
static BYTE BookPath[] = "c:/viewer/usa/usa.mvb";
Each command on the Viewer menu of MENUDEMO uses this function to make sure the USA Tour sample title is loaded before proceeding.
Now MENUDEMO is ready to display the topic. The IDM_TOPIC message controls topic display. To process IDM_TOPIC, MENUDEMO calls MVAPI as follows:
case IDM_TOPIC:
CheckLoadUsa(hwnd) ;
lstrcpy(Topic,"wa_statebird");
wsprintf(str, (LPSTR)JITemplate, (LPSTR)BookPath, (LPSTR)Topic);
MVAPI(hwnd, BookPath,cmdMacro,(DWORD)(LPSTR)str);
return 0 ;
The str variable holds the Viewer command JI, which jumps to the context string for the Washington State Bird topic. The lstrcpy and wsprintf calls construct the following command:
JI("c:/viewer/usa/usa.mvb", "wa_statebird")
The pieces of this command come from the variables JITemplate, BookPath, and Topic. The lstrcpy call copies the context string “wa_statebird” to Topic. The JITemplate template is assigned earlier in the program as follows:
static BYTE JITemplate[]= "JI(\"%s\",\"%s\")";
Thus, the MVAPI call includes a handle to the MENUDEMO application (hwnd), the path containing the title (BookPath), a constant telling Viewer to execute a command (cmdMacro), and the command to be executed (Str), as shown in the following code fragment:
MVAPI(hwnd, BookPath,cmdMacro,(DWORD)(LPSTR)str);