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.

247 lines
6.4 KiB

  1. /*++
  2. *
  3. * WOW v3.5
  4. *
  5. * Copyright (c) 1980-1994, Microsoft Corporation
  6. *
  7. * DEBUG.C
  8. * USER16 debug support
  9. *
  10. * History:
  11. *
  12. * Created 18-Aug-94 by Dave Hart (davehart)
  13. * Copied from WIN31 and edited (as little as possible) for WOW16.
  14. * At this time, all we want is GetSystemDebugState.
  15. --*/
  16. /* Debug api support */
  17. #include "user.h"
  18. #ifndef WOW
  19. #include "menu.h"
  20. typedef struct tagMSGR
  21. {
  22. LPARAM lParam;
  23. WPARAM wParam;
  24. WORD message;
  25. HWND hwnd;
  26. } MSGR;
  27. typedef MSGR FAR *LPMSGR;
  28. /* A debug hook gets called by Windows just before calling any other type of
  29. * hook. Let us call the hook which is about to be called as "App hook"; Debug
  30. * hook is provided with all the details of the App hook so that it can decide
  31. * whether to prevent Windows from calling the App hook or not; If the debug
  32. * hook wants Windows to skip the call to the App hook, it must return TRUE;
  33. * Otherwise, it must call the DefHookProc.
  34. */
  35. /* Debug Hooks recieve three params just like anyother type of hook:
  36. iCode = Hook Code (must be HC_ACTION in the current implementaion).
  37. wParam = hook type of the App hook, which is about to be called by
  38. Windows.
  39. lParam = a FAR pointer to DEBUGHOOKSTRUCT structure which contains all
  40. the details about the App hook;
  41. */
  42. /* Our helper call which returns a pointer to the senders message queue.
  43. */
  44. LPMSGR FAR PASCAL QuerySendMessageReversed(void);
  45. BOOL API QuerySendMessage(HANDLE h1, HANDLE h2, HANDLE h3, LPMSG lpmsg)
  46. {
  47. LPMSGR lpmsgr;
  48. if (h1 || h2 || h3)
  49. return(FALSE);
  50. if (!InSendMessage())
  51. return(FALSE);
  52. /* Get the inter task sendmessage we are servicing out of the apps queue.
  53. */
  54. lpmsgr = QuerySendMessageReversed();
  55. lpmsg->hwnd = lpmsgr->hwnd;
  56. lpmsg->message = lpmsgr->message;
  57. lpmsg->wParam = lpmsgr->wParam;
  58. lpmsg->lParam = lpmsgr->lParam;
  59. return(TRUE);
  60. }
  61. typedef struct
  62. {
  63. BOOL fOldHardwareInputState;
  64. BOOL fMessageBox;
  65. BOOL fDialog;
  66. BOOL fMenu;
  67. BOOL fInsideMenuLoop;
  68. PPOPUPMENU pGlobalPopupMenu;
  69. RECT rcClipCursor;
  70. HWND hwndFocus;
  71. HWND hwndActive;
  72. HWND hwndSysModal;
  73. HWND hwndCapture;
  74. } SAVESTATESTRUCT;
  75. typedef SAVESTATESTRUCT NEAR *PSAVESTATESTRUCT;
  76. typedef SAVESTATESTRUCT FAR *LPSAVESTATESTRUCT;
  77. static PSAVESTATESTRUCT pLockInputSaveState=NULL;
  78. BOOL API LockInput(HANDLE h1, HWND hwndInput, BOOL fLock)
  79. {
  80. if (h1)
  81. return(FALSE);
  82. if (fLock)
  83. {
  84. if (pLockInputSaveState)
  85. {
  86. /* Save state struct currently in use.
  87. */
  88. DebugErr(DBF_ERROR, "LockInput() called when already locked");
  89. return(NULL);
  90. }
  91. if (!hwndInput || hwndInput != GetTopLevelWindow(hwndInput))
  92. return(FALSE);
  93. pLockInputSaveState=(PSAVESTATESTRUCT)UserLocalAlloc(ST_LOCKINPUTSTATE,
  94. LPTR,
  95. sizeof(SAVESTATESTRUCT));
  96. if (!pLockInputSaveState)
  97. /* No memory, can't lock.
  98. */
  99. return(FALSE);
  100. if (hwndInput)
  101. ChangeToCurrentTask(hwndInput, hwndDesktop);
  102. LockMyTask(TRUE);
  103. /* Set global which tells us a task is locked. Needs to be set after
  104. * calling LockMyTask...
  105. */
  106. hTaskLockInput = GetCurrentTask();
  107. /* For DBCS, save are we in a dlg box global. */
  108. pLockInputSaveState->fDialog = fDialog;
  109. /* Save menu state and clear it so that the debugger can bring up menus
  110. * if needed.
  111. */
  112. pLockInputSaveState->fMenu = fMenu;
  113. pLockInputSaveState->fInsideMenuLoop = fInsideMenuLoop;
  114. fMenu = FALSE;
  115. fInsideMenuLoop = FALSE;
  116. pLockInputSaveState->pGlobalPopupMenu = pGlobalPopupMenu;
  117. pGlobalPopupMenu = NULL;
  118. /* Change focus etc without sending messages...
  119. */
  120. pLockInputSaveState->hwndFocus = hwndFocus;
  121. pLockInputSaveState->hwndActive = hwndActive;
  122. hwndFocus = hwndInput;
  123. hwndActive = hwndInput;
  124. /* Save capture and set it to null */
  125. pLockInputSaveState->hwndCapture = hwndCapture;
  126. SetCapture(NULL);
  127. /* Save sysmodal window */
  128. pLockInputSaveState->hwndSysModal= hwndSysModal;
  129. pLockInputSaveState->fMessageBox = fMessageBox;
  130. SetSysModalWindow(hwndInput);
  131. /* Save clipcursor rect */
  132. CopyRect(&pLockInputSaveState->rcClipCursor, &rcCursorClip);
  133. ClipCursor(NULL);
  134. /* Enable hardware input so that we can get mouse/keyboard messages.
  135. */
  136. pLockInputSaveState->fOldHardwareInputState=EnableHardwareInput(TRUE);
  137. }
  138. else
  139. {
  140. if (!pLockInputSaveState)
  141. {
  142. /* Save state struct not in use, nothing to restore.
  143. */
  144. DebugErr(DBF_ERROR, "LockInput called with input already unlocked");
  145. return(NULL);
  146. }
  147. /* For DBCS, save are we in a dlg box global. */
  148. fDialog = pLockInputSaveState->fDialog;
  149. /* Restore clipcursor rect */
  150. ClipCursor(&pLockInputSaveState->rcClipCursor);
  151. /* Set active and focus windows manually so we avoid sending messages to
  152. * the applications.
  153. */
  154. hwndFocus = pLockInputSaveState->hwndFocus;
  155. hwndActive= pLockInputSaveState->hwndActive;
  156. SetSysModalWindow(pLockInputSaveState->hwndSysModal);
  157. fMessageBox = pLockInputSaveState->fMessageBox;
  158. pGlobalPopupMenu = pLockInputSaveState->pGlobalPopupMenu;
  159. fMenu = pLockInputSaveState->fMenu;
  160. fInsideMenuLoop = pLockInputSaveState->fInsideMenuLoop;
  161. SetCapture(pLockInputSaveState->hwndCapture);
  162. EnableHardwareInput(pLockInputSaveState->fOldHardwareInputState);
  163. /* Unset global which tells us a task is locked. Has to be unset before
  164. * we call LockMyTask...
  165. */
  166. hTaskLockInput = NULL;
  167. LockMyTask(FALSE);
  168. LocalFree((HANDLE)pLockInputSaveState);
  169. pLockInputSaveState = NULL;
  170. }
  171. return(TRUE);
  172. }
  173. #endif // !WOW
  174. LONG API GetSystemDebugState(void)
  175. {
  176. LONG returnval = 0;
  177. HANDLE hTask;
  178. hTask = GetCurrentTask();
  179. if (!GetTaskQueue(hTask))
  180. returnval = returnval | SDS_NOTASKQUEUE;
  181. #ifndef WOW
  182. if (fMenu)
  183. returnval = returnval | SDS_MENU;
  184. if (fDialog)
  185. returnval = returnval | SDS_DIALOG;
  186. if (fTaskIsLocked)
  187. returnval = returnval | SDS_TASKLOCKED;
  188. if (hwndSysModal)
  189. returnval = returnval | SDS_SYSMODAL;
  190. #endif // !WOW
  191. return(returnval);
  192. }