Source code of Windows XP (NT5)
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.

272 lines
5.6 KiB

  1. #include "precomp.h"
  2. #pragma hdrstop
  3. #if 0
  4. if(lpMsg->message == WM_CLOSE) {
  5. DbgPrint("HOOK: got WM_CLOSE");
  6. if(GetWindowLong(lpMsg->hwnd,GWL_STYLE) & WS_SYSMENU) {
  7. UINT State = GetMenuState( GetSystemMenu(lpMsg->hwnd,FALSE),
  8. 1,
  9. MF_BYPOSITION
  10. );
  11. DbgPrint("; sysmenu state = %lx",State);
  12. }
  13. DbgPrint("\n");
  14. }
  15. #endif
  16. #ifdef SYMTAB_STATS
  17. extern void SymTabStatDump(void);
  18. #endif
  19. HHOOK MsgFilterHook,GetMsgHook;
  20. LRESULT
  21. GetMsgHookProc(
  22. int nCode,
  23. WPARAM wParam,
  24. LPARAM lParam
  25. )
  26. /*++
  27. Routine Description:
  28. Hook procedure to filter out alt+f4 when the close option in the
  29. system menu is disabled. Alt+f4 is handled in the default window
  30. procedure, and sends a WM_SYSCOMMAND message to the window even
  31. if the close option is disabled. The doc for EnableMenuItem says
  32. that an app that disables items in the system menu must process
  33. the WM_SYSCOMMAND message. This is arguably a bug in user but
  34. what the heck.
  35. Arguments:
  36. MainInfHandle - supplies handle open txtsetup.inf
  37. Return Value:
  38. None.
  39. --*/
  40. {
  41. if(nCode == HC_ACTION) {
  42. LPMSG lpMsg = (LPMSG)lParam;
  43. UINT State;
  44. if((lpMsg->message == WM_SYSCOMMAND)
  45. && ((lpMsg->wParam & 0xfff0) == SC_CLOSE)
  46. && (GetWindowLong(lpMsg->hwnd,GWL_STYLE) & WS_SYSMENU)) {
  47. State = GetMenuState(
  48. GetSystemMenu(lpMsg->hwnd,FALSE),
  49. SC_CLOSE,
  50. MF_BYCOMMAND
  51. );
  52. if((State != 0xffffffff) && (State & MF_DISABLED)) {
  53. lpMsg->message = WM_NULL;
  54. }
  55. }
  56. return(0L);
  57. } else {
  58. return(CallNextHookEx(GetMsgHook,nCode,wParam,lParam));
  59. }
  60. }
  61. LRESULT
  62. MsgFilterHookProc(
  63. int nCode,
  64. WPARAM wParam,
  65. LPARAM lParam
  66. )
  67. {
  68. LPMSG lpMsg = (LPMSG)lParam;
  69. HWND hWnd = NULL;
  70. CHAR szClassName[25];
  71. //
  72. // Examine type of action indicated. We need to process only positive
  73. // valued actions.
  74. //
  75. if ( nCode < 0 ) {
  76. return ( CallNextHookEx(MsgFilterHook,nCode,wParam,lParam) );
  77. }
  78. if((lpMsg->message == WM_KEYDOWN) && (lpMsg->wParam == VK_F6)) {
  79. if(GetKeyState(VK_LCONTROL) & GetKeyState(VK_RCONTROL) & (USHORT)0x8000) {
  80. SdBreakNow();
  81. } else if(GetKeyState(VK_LSHIFT) & GetKeyState(VK_RSHIFT) & (USHORT)0x8000) {
  82. SdTracingOn();
  83. }
  84. }
  85. //
  86. // First check that we received a keyboard message and whether the
  87. // message is for a dialog box
  88. //
  89. if ( lpMsg->message != WM_KEYDOWN || nCode != MSGF_DIALOGBOX) {
  90. return ( fFalse );
  91. }
  92. //
  93. // Now we have to detetrmine handle of current dialog window.
  94. // We know that class name of all our dialogs is MYDLG so
  95. // I am going through the chain of parent windows for current
  96. // focus windows until I will find parent dialog or NULL.
  97. //
  98. // hWnd = lpMsg->hwnd;
  99. // while ( hWnd ) {
  100. //
  101. // *szClassName = '\0';
  102. //
  103. // GetClassName(
  104. // hWnd,
  105. // (LPSTR)szClassName,
  106. // sizeof(szClassName)
  107. // );
  108. //
  109. // if ( lstrcmpi((LPSTR)szClassName,(LPSTR)CLS_MYDLGS ) == 0 ) {
  110. // break;
  111. // }
  112. //
  113. // hWnd = GetParent( hWnd );
  114. // }
  115. //
  116. // We only want to respond if we are in a child window of the dialog
  117. //
  118. hWnd = lpMsg->hwnd;
  119. if( hWnd && (hWnd = GetParent( hWnd))) {
  120. *szClassName = '\0';
  121. GetClassName(
  122. hWnd,
  123. (LPSTR)szClassName,
  124. sizeof(szClassName)
  125. );
  126. if ( lstrcmpi((LPSTR)szClassName,(LPSTR)CLS_MYDLGS ) != 0 ) {
  127. return ( fFalse );
  128. }
  129. }
  130. else {
  131. return ( fFalse );
  132. }
  133. // //
  134. // // Did we find anything ???
  135. // //
  136. //
  137. // if ( ! hWnd ) {
  138. // return ( fFalse );
  139. // }
  140. //
  141. // Convert keyboard messages came into WM_COMMANDs to
  142. // the found dialog. Return TRUE because we procecessed
  143. //
  144. switch (lpMsg->wParam) {
  145. case VK_F1:
  146. if ( GetDlgItem ( hWnd, IDC_H ) != (HWND)NULL ) {
  147. PostMessage(
  148. hWnd,
  149. WM_COMMAND,
  150. MAKELONG(IDC_H, BN_CLICKED),
  151. (LONG)lpMsg->lParam
  152. );
  153. }
  154. return ( fTrue );
  155. case VK_F3:
  156. if ( GetDlgItem ( hWnd, IDC_X ) != (HWND)NULL ) {
  157. PostMessage(
  158. hWnd,
  159. WM_COMMAND,
  160. MAKELONG(IDC_X, BN_CLICKED),
  161. (LONG)lpMsg->lParam
  162. );
  163. }
  164. return ( fTrue );
  165. #ifdef SYMTAB_STATS
  166. case VK_F2:
  167. SymTabStatDump();
  168. return ( fTrue );
  169. #endif
  170. #if DBG
  171. #ifdef MEMORY_CHECK
  172. case VK_F4:
  173. MemDump();
  174. return ( fTrue );
  175. #endif
  176. #endif
  177. default:
  178. break;
  179. }
  180. return ( fFalse );
  181. }
  182. BOOL
  183. FInitHook(
  184. VOID
  185. )
  186. {
  187. GetMsgHook = SetWindowsHookEx(
  188. WH_GETMESSAGE,
  189. GetMsgHookProc,
  190. NULL,
  191. GetCurrentThreadId()
  192. );
  193. MsgFilterHook = SetWindowsHookEx(
  194. WH_MSGFILTER,
  195. MsgFilterHookProc,
  196. NULL,
  197. GetCurrentThreadId()
  198. );
  199. return ( fTrue );
  200. }
  201. BOOL
  202. FTermHook(
  203. VOID
  204. )
  205. {
  206. UnhookWindowsHookEx(GetMsgHook);
  207. UnhookWindowsHookEx(MsgFilterHook);
  208. return ( fTrue );
  209. }