Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
4.9 KiB

  1. /**************************************************************************
  2. *
  3. * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. * PURPOSE.
  7. *
  8. * Copyright (c) 1992 - 1995 Microsoft Corporation. All Rights Reserved.
  9. *
  10. **************************************************************************/
  11. /****************************************************************************
  12. *
  13. * help.c: Help system interface
  14. *
  15. * Vidcap32 Source code
  16. *
  17. ***************************************************************************/
  18. /*
  19. * supports F1 key help in app and in dialog by installing a hook,
  20. *
  21. * Keep track of which dialog is currently displayed in a global:
  22. * dialog ids are also topic ids in the help file.
  23. */
  24. #include <windows.h>
  25. #include <windowsx.h>
  26. #include <string.h>
  27. #include "help.h"
  28. int CurrentDialogID = 0;
  29. // app info passed to helpinit
  30. HINSTANCE hInstance;
  31. TCHAR HelpFile[MAX_PATH];
  32. HWND hwndApp;
  33. //hook proc and old msg filter
  34. #ifdef _WIN32
  35. HHOOK hOurHook;
  36. #else
  37. FARPROC fnOldMsgFilter = NULL;
  38. FARPROC fnMsgHook = NULL;
  39. #endif
  40. // call DialogBoxParam, but ensuring correct help processing:
  41. // assumes that each Dialog Box ID is a context number in the help file.
  42. // calls MakeProcInstance as necessary. Uses instance data passed to
  43. // HelpInit().
  44. INT_PTR
  45. DoDialog(
  46. HWND hwndParent, // parent window
  47. int DialogID, // dialog resource id
  48. DLGPROC fnDialog, // dialog proc
  49. LPARAM lParam // passed as lparam in WM_INITDIALOG
  50. )
  51. {
  52. int olddialog;
  53. //DLGPROC fn;
  54. INT_PTR result;
  55. // remember current id (for nested dialogs)
  56. olddialog = CurrentDialogID;
  57. // save the current id so the hook proc knows what help to display
  58. CurrentDialogID = DialogID;
  59. //fn = (DLGPROC) MakeProcInstance(fnDialog, hInstance);
  60. result = DialogBoxParam(
  61. hInstance,
  62. MAKEINTRESOURCE(CurrentDialogID),
  63. hwndParent,
  64. fnDialog,
  65. lParam);
  66. //FreeProcInstance(fn);
  67. CurrentDialogID = olddialog;
  68. return result;
  69. }
  70. // set the help context id for a dialog displayed other than by DoDialog
  71. // (eg by GetOpenFileName). Returns the old help context that you must
  72. // restore by a further call to this function
  73. int
  74. SetCurrentHelpContext(int DialogID)
  75. {
  76. int oldid = CurrentDialogID;
  77. CurrentDialogID = DialogID;
  78. return(oldid);
  79. }
  80. // return TRUE if lpMsg is a non-repeat F1 key message
  81. BOOL
  82. IsHelpKey(LPMSG lpMsg)
  83. {
  84. return lpMsg->message == WM_KEYDOWN &&
  85. lpMsg->wParam == VK_F1 &&
  86. !(HIWORD(lpMsg->lParam) & KF_REPEAT) &&
  87. GetKeyState(VK_SHIFT) >= 0 &&
  88. GetKeyState(VK_CONTROL) >= 0 &&
  89. GetKeyState(VK_MENU) >= 0;
  90. }
  91. LRESULT CALLBACK
  92. HelpMsgHook(int nCode, WPARAM wParam, LPARAM lParam)
  93. {
  94. if (nCode >= 0) {
  95. if (IsHelpKey((LPMSG)lParam)) {
  96. if (CurrentDialogID != 0) {
  97. WinHelp(hwndApp, HelpFile, HELP_CONTEXT, CurrentDialogID);
  98. } else {
  99. WinHelp(hwndApp, HelpFile, HELP_CONTENTS, 0);
  100. }
  101. }
  102. }
  103. #ifdef _WIN32
  104. return CallNextHookEx(hOurHook, nCode, wParam, lParam);
  105. #else
  106. return DefHookProc(nCode, wParam, lParam, fnOldMsgFilter);
  107. #endif
  108. }
  109. // help init - initialise the support for the F1 key help
  110. BOOL
  111. HelpInit(HINSTANCE hinstance, LPSTR helpfilepath, HWND hwnd)
  112. {
  113. LPSTR pch;
  114. // save app details
  115. hwndApp = hwnd;
  116. hInstance = hinstance;
  117. // assume that the help file is in the same directory as the executable-
  118. // get the executable path, and replace the filename with the help
  119. // file name.
  120. GetModuleFileName(hinstance, HelpFile, sizeof(HelpFile));
  121. // find the final backslash, and append the help file name there
  122. pch = _fstrrchr(HelpFile, '\\');
  123. pch++;
  124. lstrcpy(pch, helpfilepath);
  125. // install a hook for msgs and save old one
  126. #ifdef _WIN32
  127. hOurHook = SetWindowsHookEx(
  128. WH_MSGFILTER,
  129. (HOOKPROC) HelpMsgHook,
  130. NULL, GetCurrentThreadId());
  131. #else
  132. fnMsgHook = (FARPROC) MakeProcInstance(HelpMsgHook, hInstance);
  133. fnOldMsgFilter = SetWindowsHook(WH_MSGFILTER, (HOOKPROC) fnMsgHook);
  134. #endif
  135. return(TRUE);
  136. }
  137. // shutdown the help system
  138. void
  139. HelpShutdown(void)
  140. {
  141. #ifdef _WIN32
  142. UnhookWindowsHookEx(hOurHook);
  143. #else
  144. if (fnOldMsgFilter) {
  145. UnhookWindowsHook(WH_MSGFILTER, fnMsgHook);
  146. FreeProcInstance(fnMsgHook);
  147. }
  148. #endif
  149. WinHelp(hwndApp, HelpFile, HELP_QUIT, 0);
  150. }
  151. // start help at the contents page
  152. void
  153. HelpContents(void)
  154. {
  155. WinHelp(hwndApp, HelpFile, HELP_CONTENTS, 0);
  156. }
  157.