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.

169 lines
3.8 KiB

  1. // fixhelp.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12. #include "stdafx.h"
  13. #include "fixhelp.h"
  14. BOOL g_fDisableStandardHelp = FALSE ;
  15. HHOOK g_HelpFixHook = (HHOOK) 0 ;
  16. LRESULT CALLBACK HelpFixControlProc(
  17. HWND hwnd,
  18. UINT uMsg,
  19. WPARAM wParam,
  20. LPARAM lParam);
  21. LRESULT CALLBACK HelpFixDialogProc(
  22. HWND hwnd,
  23. UINT uMsg,
  24. WPARAM wParam,
  25. LPARAM lParam);
  26. LRESULT CALLBACK HelpFixHook(
  27. int code,
  28. WPARAM wParam,
  29. LPARAM lParam) ;
  30. class CWordPadCWnd : public CWnd
  31. {
  32. public:
  33. LRESULT CallDWP(UINT nMsg, WPARAM wParam, LPARAM lParam)
  34. {
  35. return DefWindowProc(nMsg, wParam, lParam) ;
  36. }
  37. } ;
  38. void FixHelp(CWnd* pWnd, BOOL fFixWndProc)
  39. {
  40. //
  41. // Subclass the main window proc if we are supposed to
  42. // and if MFC has alread subclassed it
  43. //
  44. if (fFixWndProc)
  45. {
  46. if (GetWindowLongPtr(pWnd->m_hWnd, GWLP_WNDPROC) == (LONG_PTR)AfxWndProc)
  47. {
  48. SetWindowLongPtr(pWnd->m_hWnd, GWLP_WNDPROC,
  49. (LONG_PTR)HelpFixDialogProc);
  50. }
  51. }
  52. //
  53. // Search all child windows. If their window proc
  54. // is AfxWndProc, then subclass with our window proc
  55. //
  56. CWnd* pWndChild = pWnd->GetWindow(GW_CHILD);
  57. while(pWndChild != NULL)
  58. {
  59. if (GetWindowLongPtr(pWndChild->GetSafeHwnd(), GWLP_WNDPROC) == (LONG_PTR)AfxWndProc)
  60. {
  61. SetWindowLongPtr(pWndChild->GetSafeHwnd(), GWLP_WNDPROC,
  62. (LONG_PTR)HelpFixControlProc);
  63. }
  64. pWndChild = pWndChild->GetWindow(GW_HWNDNEXT);
  65. }
  66. }
  67. LRESULT CALLBACK HelpFixControlProc(
  68. HWND hwnd,
  69. UINT uMsg,
  70. WPARAM wParam,
  71. LPARAM lParam)
  72. {
  73. if (uMsg == WM_HELP)
  74. {
  75. //
  76. // bypass MFC's handler, message will be sent to
  77. // parent of the control
  78. //
  79. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  80. }
  81. return AfxWndProc(hwnd,uMsg,wParam,lParam);
  82. }
  83. LRESULT CALLBACK HelpFixDialogProc(
  84. HWND hwnd,
  85. UINT uMsg,
  86. WPARAM wParam,
  87. LPARAM lParam)
  88. {
  89. if (uMsg == WM_HELP)
  90. {
  91. CWordPadCWnd* pWnd = (CWordPadCWnd *) CWnd::FromHandlePermanent(hwnd) ;
  92. //
  93. // bypass MFC's handler, message will be sent to window proc for
  94. // the dialog box
  95. //
  96. if (NULL != pWnd)
  97. {
  98. return pWnd->CallDWP(uMsg, wParam, lParam) ;
  99. }
  100. }
  101. return AfxWndProc(hwnd,uMsg,wParam,lParam);
  102. }
  103. void SetHelpFixHook(void)
  104. {
  105. g_HelpFixHook = ::SetWindowsHookEx(
  106. WH_CALLWNDPROC,
  107. (HOOKPROC) HelpFixHook,
  108. NULL,
  109. ::GetCurrentThreadId());
  110. }
  111. void RemoveHelpFixHook(void)
  112. {
  113. ::UnhookWindowsHookEx(g_HelpFixHook) ;
  114. g_HelpFixHook = (HHOOK) 0 ;
  115. }
  116. LRESULT CALLBACK HelpFixHook(
  117. int code,
  118. WPARAM wParam,
  119. LPARAM lParam)
  120. {
  121. if (code < 0)
  122. {
  123. return ::CallNextHookEx(
  124. g_HelpFixHook,
  125. code,
  126. wParam,
  127. lParam) ;
  128. }
  129. CWPSTRUCT *pcwps = (CWPSTRUCT *) lParam ;
  130. if (pcwps->message == WM_INITDIALOG)
  131. {
  132. CWnd *pWnd = CWnd::FromHandlePermanent(pcwps->hwnd) ;
  133. if (pWnd != NULL)
  134. {
  135. FixHelp(pWnd, TRUE) ;
  136. }
  137. }
  138. return ::CallNextHookEx(
  139. g_HelpFixHook,
  140. code,
  141. wParam,
  142. lParam) ;
  143. }