Copyright (c) 1991, 1992 Borland International, Inc.
PURPOSE: Illustrates calls to WinHelp and context-sensitive help.
HelpEx loads library MenuHook, which detects F1 keystrokes in
the HelpEx application menus.
FUNCTIONS:
WinMain() - Calls initialization function, processes message loop.
InitApplication() - Initializes window data and registers window class.
InitInstance() - Saves instance handle and creates main window.
MainWndProc() - Processes window messages.
About() - Processes messages for "About" dialog box.
MakeHelpPathName() - Derives path name of help file.
case WM_COMMAND:
/* Was F1 just pressed in a menu, or are we in help mode */
/* (Shift-F1)? */
if (bHelp) {
UINT id = GET_WM_COMMAND_ID(wParam, lParam);
dwHelpContextId =
(id == IDM_NEW) ? (DWORD) HELPID_FILE_NEW :
(id == IDM_OPEN) ? (DWORD) HELPID_FILE_OPEN :
(id == IDM_SAVE) ? (DWORD) HELPID_FILE_SAVE :
(id == IDM_SAVEAS) ? (DWORD) HELPID_FILE_SAVE_AS :
(id == IDM_PRINT) ? (DWORD) HELPID_FILE_PRINT :
(id == IDM_EXIT) ? (DWORD) HELPID_FILE_EXIT :
(id == IDM_UNDO) ? (DWORD) HELPID_EDIT_UNDO :
(id == IDM_CUT) ? (DWORD) HELPID_EDIT_CUT :
(id == IDM_CLEAR) ? (DWORD) HELPID_EDIT_CLEAR :
(id == IDM_COPY) ? (DWORD) HELPID_EDIT_COPY :
(id == IDM_PASTE) ? (DWORD) HELPID_EDIT_PASTE :
(DWORD) 0L;
if (!dwHelpContextId)
{
MessageBox( hWnd, "Help not available for Help Menu item",
"Help Example", MB_OK );
return (DefWindowProc(hWnd, message, wParam, lParam));
}
switch (GET_WM_COMMAND_ID(wParam, lParam)) {
case IDM_NEW:
case IDM_OPEN:
case IDM_SAVE:
case IDM_SAVEAS:
case IDM_PRINT:
case IDM_UNDO:
case IDM_CUT:
case IDM_CLEAR:
case IDM_COPY:
case IDM_PASTE:
MessageBox(hWnd,
"Command not implemented",
"Help Example",
MB_OK);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
case IDM_HELP_INDEX:
WinHelp(hWnd,szHelpFileName,HELP_INDEX,0L);
break;
case IDM_HELP_KEYBOARD:
WinHelp(hWnd,szHelpFileName,HELP_KEY,(DWORD)(LPSTR)"keys");
break;
case IDM_HELP_HELP:
WinHelp(hWnd,"WINHELP.HLP",HELP_INDEX,0L);
break;
case IDM_ABOUT:
lpProcAbout = (DLGPROC)MakeProcInstance((FARPROC)About, hInst);
DialogBox(hInst,
"AboutBox",
hWnd,
lpProcAbout);
#ifndef __FLAT__
FreeProcInstance((FARPROC)lpProcAbout);
// required for 16-bit applications only
#endif
/* If F1 without shift, then call up help main index topic */
else {
WinHelp(hWnd,szHelpFileName,HELP_INDEX,0L);
}
}
else if (wParam == VK_ESCAPE && bHelp) {
/* Escape during help mode: turn help mode off */
bHelp = FALSE;
#if defined(__WIN32__)
SetCursor((HCURSOR)GetClassLong(hWnd,GCL_HCURSOR));
#else
SetCursor((HCURSOR)GetClassWord(hWnd,GCW_HCURSOR));
#endif
}
break;
case WM_SETCURSOR:
/* In help mode it is necessary to reset the cursor in response */
/* to every WM_SETCURSOR message.Otherwise, by default, Windows */
/* will reset the cursor to that of the window class. */
PURPOSE: HelpEx assumes that the .HLP help file is in the same
directory as the HelpEx executable.This function derives
the full path name of the help file from the path of the
executable.