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.

512 lines
17 KiB

  1. // --------------------------------------------------------------------------
  2. //
  3. // WINABLE.H
  4. //
  5. // Hooking mechanism to receive system events.
  6. //
  7. // --------------------------------------------------------------------------
  8. #ifndef _WINABLE_
  9. #define _WINABLE_
  10. #if !defined(_WINABLE_)
  11. #define WINABLEAPI DECLSPEC_IMPORT
  12. #else
  13. #define WINABLEAPI
  14. #endif
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif // __cplusplus
  18. #include <stdarg.h>
  19. #if (WINVER < 0x0500) // these structures and functions
  20. // are in NT 5.00 and above winuser.h
  21. //
  22. // In USER32
  23. //
  24. //
  25. // This gets GUI information out of context. If you pass in a NULL thread ID,
  26. // we will get the 'global' information, using the foreground thread. This
  27. // is guaranteed to be the real active window, focus window, etc. Yes, you
  28. // could do it yourself by calling GetForegorundWindow, getting the thread ID
  29. // of that window via GetWindowThreadProcessId, then passing the ID into
  30. // GetGUIThreadInfo(). However, that takes three calls and aside from being
  31. // a pain, anything could happen in the middle. So passing in NULL gets
  32. // you stuff in one call and hence also works right.
  33. //
  34. typedef struct tagGUITHREADINFO
  35. {
  36. DWORD cbSize;
  37. DWORD flags;
  38. HWND hwndActive;
  39. HWND hwndFocus;
  40. HWND hwndCapture;
  41. HWND hwndMenuOwner;
  42. HWND hwndMoveSize;
  43. HWND hwndCaret;
  44. RECT rcCaret;
  45. } GUITHREADINFO, FAR * LPGUITHREADINFO;
  46. #define GUI_CARETBLINKING 0x00000001
  47. #define GUI_INMOVESIZE 0x00000002
  48. #define GUI_INMENUMODE 0x00000004
  49. #define GUI_SYSTEMMENUMODE 0x00000008
  50. #define GUI_POPUPMENUMODE 0x00000010
  51. BOOL
  52. WINAPI
  53. GetGUIThreadInfo(
  54. DWORD idThread,
  55. LPGUITHREADINFO lpgui
  56. );
  57. UINT
  58. WINAPI
  59. GetWindowModuleFileNameW(
  60. HWND hwnd,
  61. LPWSTR lpFileName,
  62. UINT cchFileName
  63. );
  64. UINT
  65. WINAPI
  66. GetWindowModuleFileNameA(
  67. HWND hwnd,
  68. LPSTR lpFileName,
  69. UINT cchFileName
  70. );
  71. #ifdef UNICODE
  72. #define GetWindowModuleFileName GetWindowModuleFileNameW
  73. #else
  74. #define GetWindowModuleFileName GetWindowModuleFileNameA
  75. #endif
  76. #endif // WINVER < 0x0500
  77. //
  78. // This returns FALSE if the caller doesn't have permissions to do this
  79. // esp. if someone else is dorking with input. I.E., if some other thread
  80. // disabled input, and thread 2 tries to diable/enable it, the call will
  81. // fail since thread 1 has the cookie.
  82. //
  83. BOOL
  84. WINAPI
  85. BlockInput(
  86. BOOL fBlockIt
  87. );
  88. #if (_WIN32_WINNT < 0x0403) // these structures and this function prototype
  89. // are in NT 4.03 and above winuser.h
  90. //
  91. // Note that the dwFlags field uses the same flags as keybd_event and
  92. // mouse_event, depending on what type of input this is.
  93. //
  94. typedef struct tagMOUSEINPUT {
  95. LONG dx;
  96. LONG dy;
  97. DWORD mouseData;
  98. DWORD dwFlags;
  99. DWORD time;
  100. DWORD dwExtraInfo;
  101. } MOUSEINPUT, *PMOUSEINPUT, FAR* LPMOUSEINPUT;
  102. typedef struct tagKEYBDINPUT {
  103. WORD wVk;
  104. WORD wScan;
  105. DWORD dwFlags;
  106. DWORD time;
  107. DWORD dwExtraInfo;
  108. } KEYBDINPUT, *PKEYBDINPUT, FAR* LPKEYBDINPUT;
  109. typedef struct tagHARDWAREINPUT {
  110. DWORD uMsg;
  111. WORD wParamL;
  112. WORD wParamH;
  113. DWORD dwExtraInfo;
  114. } HARDWAREINPUT, *PHARDWAREINPUT, FAR* LPHARDWAREINPUT;
  115. #define INPUT_MOUSE 0
  116. #define INPUT_KEYBOARD 1
  117. #define INPUT_HARDWARE 2
  118. typedef struct tagINPUT {
  119. DWORD type;
  120. union
  121. {
  122. MOUSEINPUT mi;
  123. KEYBDINPUT ki;
  124. HARDWAREINPUT hi;
  125. };
  126. } INPUT, *PINPUT, FAR* LPINPUT;
  127. //
  128. // This returns the number of inputs played back. It will disable input
  129. // first, play back as many as possible, then reenable input. In the middle
  130. // it will pulse the RIT to make sure that the fixed input queue doesn't
  131. // fill up.
  132. //
  133. UINT
  134. WINAPI
  135. SendInput(
  136. UINT cInputs, // number of input in the array
  137. LPINPUT pInputs, // array of inputs
  138. int cbSize); // sizeof(INPUT)
  139. #endif // (_WIN32_WINNT < 0x0403)
  140. #define CCHILDREN_FRAME 7
  141. #if WINVER < 0x0500 // these structures and functions
  142. // are in NT 5.00 and above winuser.h
  143. //
  144. // This generates a notification that anyone watching for it will get.
  145. // This call is superfast if nobody is hooking anything.
  146. //
  147. WINABLEAPI
  148. void
  149. WINAPI
  150. NotifyWinEvent(
  151. DWORD event,
  152. HWND hwnd,
  153. LONG idObject,
  154. LONG idChild
  155. );
  156. //
  157. // hwnd + idObject can be used with OLEACC.DLL's OleGetObjectFromWindow()
  158. // to get an interface pointer to the container. indexChild is the item
  159. // within the container in question. Setup a VARIANT with vt VT_I4 and
  160. // lVal the indexChild and pass that in to all methods. Then you
  161. // are raring to go.
  162. //
  163. //
  164. // Common object IDs (cookies, only for sending WM_GETOBJECT to get at the
  165. // thing in question). Positive IDs are reserved for apps (app specific),
  166. // negative IDs are system things and are global, 0 means "just little old
  167. // me".
  168. //
  169. #define CHILDID_SELF 0
  170. // Reserved IDs for system objects
  171. #define OBJID_WINDOW ((LONG)0x00000000)
  172. #define OBJID_SYSMENU ((LONG)0xFFFFFFFF)
  173. #define OBJID_TITLEBAR ((LONG)0xFFFFFFFE)
  174. #define OBJID_MENU ((LONG)0xFFFFFFFD)
  175. #define OBJID_CLIENT ((LONG)0xFFFFFFFC)
  176. #define OBJID_VSCROLL ((LONG)0xFFFFFFFB)
  177. #define OBJID_HSCROLL ((LONG)0xFFFFFFFA)
  178. #define OBJID_SIZEGRIP ((LONG)0xFFFFFFF9)
  179. #define OBJID_CARET ((LONG)0xFFFFFFF8)
  180. #define OBJID_CURSOR ((LONG)0xFFFFFFF7)
  181. #define OBJID_ALERT ((LONG)0xFFFFFFF6)
  182. #define OBJID_SOUND ((LONG)0xFFFFFFF5)
  183. #define CCHILDREN_FRAME 7
  184. //
  185. // System Alerts (indexChild of system ALERT notification)
  186. //
  187. #define ALERT_SYSTEM_INFORMATIONAL 1 // MB_INFORMATION
  188. #define ALERT_SYSTEM_WARNING 2 // MB_WARNING
  189. #define ALERT_SYSTEM_ERROR 3 // MB_ERROR
  190. #define ALERT_SYSTEM_QUERY 4 // MB_QUESTION
  191. #define ALERT_SYSTEM_CRITICAL 5 // HardSysErrBox
  192. #define CALERT_SYSTEM 6
  193. typedef DWORD HWINEVENTHOOK;
  194. typedef VOID (CALLBACK* WINEVENTPROC)(
  195. HWINEVENTHOOK hEvent,
  196. DWORD event,
  197. HWND hwnd,
  198. LONG idObject,
  199. LONG idChild,
  200. DWORD idEventThread,
  201. DWORD dwmsEventTime);
  202. #define WINEVENT_OUTOFCONTEXT 0x0000 // Events are ASYNC
  203. #define WINEVENT_SKIPOWNTHREAD 0x0001 // Don't call back for events on installer's thread
  204. #define WINEVENT_SKIPOWNPROCESS 0x0002 // Don't call back for events on installer's process
  205. #define WINEVENT_INCONTEXT 0x0004 // Events are SYNC, this causes your dll to be injected into every process
  206. #define WINEVENT_32BITCALLER 0x8000 // ;Internal
  207. #define WINEVENT_VALID 0x8007 // ;Internal
  208. WINABLEAPI
  209. HWINEVENTHOOK
  210. WINAPI
  211. SetWinEventHook(
  212. DWORD eventMin,
  213. DWORD eventMax,
  214. HMODULE hmodWinEventProc, // Must pass this if global!
  215. WINEVENTPROC lpfnWinEventProc,
  216. DWORD idProcess, // Can be zero; all processes
  217. DWORD idThread, // Can be zero; all threads
  218. DWORD dwFlags
  219. );
  220. //
  221. // Returns zero on failure, or a DWORD ID if success. We will clean up any
  222. // event hooks installed by the current process when it goes away, if it
  223. // hasn't cleaned the hooks up itself. But to dynamically unhook, call
  224. // UnhookWinEvents().
  225. //
  226. WINABLEAPI
  227. BOOL
  228. WINAPI
  229. UnhookWinEvent(
  230. HWINEVENTHOOK hEvent);
  231. //
  232. // If idProcess isn't zero but idThread is, will hook all threads in that
  233. // process.
  234. // If idThread isn't zero but idProcess is, will hook idThread only.
  235. // If both are zero, will hook everything
  236. //
  237. //
  238. // EVENT DEFINITION
  239. //
  240. #define EVENT_MIN 0x00000001
  241. #define EVENT_MAX 0x7FFFFFFF
  242. //
  243. // EVENT_SYSTEM_SOUND
  244. // Sent when a sound is played. Currently nothing is generating this, we
  245. // are going to be cleaning up the SOUNDSENTRY feature in the control panel
  246. // and will use this at that time. Applications implementing WinEvents
  247. // are perfectly welcome to use it. Clients of IAccessible* will simply
  248. // turn around and get back a non-visual object that describes the sound.
  249. //
  250. #define EVENT_SYSTEM_SOUND 0x0001
  251. //
  252. // EVENT_SYSTEM_ALERT
  253. // Sent when an alert needs to be given to the user. MessageBoxes generate
  254. // alerts for example.
  255. //
  256. #define EVENT_SYSTEM_ALERT 0x0002
  257. //
  258. // EVENT_SYSTEM_FOREGROUND
  259. // Sent when the foreground (active) window changes, even if it is changing
  260. // to another window in the same thread as the previous one.
  261. //
  262. #define EVENT_SYSTEM_FOREGROUND 0x0003
  263. //
  264. // EVENT_SYSTEM_MENUSTART
  265. // EVENT_SYSTEM_MENUEND
  266. // Sent when entering into and leaving from menu mode (system, app bar, and
  267. // track popups).
  268. //
  269. #define EVENT_SYSTEM_MENUSTART 0x0004
  270. #define EVENT_SYSTEM_MENUEND 0x0005
  271. //
  272. // EVENT_SYSTEM_MENUPOPUPSTART
  273. // EVENT_SYSTEM_MENUPOPUPEND
  274. // Sent when a menu popup comes up and just before it is taken down. Note
  275. // that for a call to TrackPopupMenu(), a client will see EVENT_SYSTEM_MENUSTART
  276. // followed almost immediately by EVENT_SYSTEM_MENUPOPUPSTART for the popup
  277. // being shown.
  278. //
  279. #define EVENT_SYSTEM_MENUPOPUPSTART 0x0006
  280. #define EVENT_SYSTEM_MENUPOPUPEND 0x0007
  281. //
  282. // EVENT_SYSTEM_CAPTURESTART
  283. // EVENT_SYSTEM_CAPTUREEND
  284. // Sent when a window takes the capture and releases the capture.
  285. //
  286. #define EVENT_SYSTEM_CAPTURESTART 0x0008
  287. #define EVENT_SYSTEM_CAPTUREEND 0x0009
  288. //
  289. // EVENT_SYSTEM_MOVESIZESTART
  290. // EVENT_SYSTEM_MOVESIZEEND
  291. // Sent when a window enters and leaves move-size dragging mode.
  292. //
  293. #define EVENT_SYSTEM_MOVESIZESTART 0x000A
  294. #define EVENT_SYSTEM_MOVESIZEEND 0x000B
  295. //
  296. // EVENT_SYSTEM_CONTEXTHELPSTART
  297. // EVENT_SYSTEM_CONTEXTHELPEND
  298. // Sent when a window enters and leaves context sensitive help mode.
  299. //
  300. #define EVENT_SYSTEM_CONTEXTHELPSTART 0x000C
  301. #define EVENT_SYSTEM_CONTEXTHELPEND 0x000D
  302. //
  303. // EVENT_SYSTEM_DRAGDROPSTART
  304. // EVENT_SYSTEM_DRAGDROPEND
  305. // Sent when a window enters and leaves drag drop mode. Note that it is up
  306. // to apps and OLE to generate this, since the system doesn't know. Like
  307. // EVENT_SYSTEM_SOUND, it will be a while before this is prevalent.
  308. //
  309. #define EVENT_SYSTEM_DRAGDROPSTART 0x000E
  310. #define EVENT_SYSTEM_DRAGDROPEND 0x000F
  311. //
  312. // EVENT_SYSTEM_DIALOGSTART
  313. // EVENT_SYSTEM_DIALOGEND
  314. // Sent when a dialog comes up and just before it goes away.
  315. //
  316. #define EVENT_SYSTEM_DIALOGSTART 0x0010
  317. #define EVENT_SYSTEM_DIALOGEND 0x0011
  318. //
  319. // EVENT_SYSTEM_SCROLLINGSTART
  320. // EVENT_SYSTEM_SCROLLINGEND
  321. // Sent when beginning and ending the tracking of a scrollbar in a window,
  322. // and also for scrollbar controls.
  323. //
  324. #define EVENT_SYSTEM_SCROLLINGSTART 0x0012
  325. #define EVENT_SYSTEM_SCROLLINGEND 0x0013
  326. //
  327. // EVENT_SYSTEM_SWITCHSTART
  328. // EVENT_SYSTEM_SWITCHEND
  329. // Sent when beginning and ending alt-tab mode with the switch window.
  330. //
  331. #define EVENT_SYSTEM_SWITCHSTART 0x0014
  332. #define EVENT_SYSTEM_SWITCHEND 0x0015
  333. //
  334. // EVENT_SYSTEM_MINIMIZESTART
  335. // EVENT_SYSTEM_MINIMIZEEND
  336. // Sent when a window minimizes and just before it restores.
  337. //
  338. #define EVENT_SYSTEM_MINIMIZESTART 0x0016
  339. #define EVENT_SYSTEM_MINIMIZEEND 0x0017
  340. //
  341. // Object events
  342. //
  343. // The system AND apps generate these. The system generates these for
  344. // real windows. Apps generate these for objects within their window which
  345. // act like a separate control, e.g. an item in a list view.
  346. //
  347. // For all events, if you want detailed accessibility information, callers
  348. // should
  349. // * Call AccessibleObjectFromWindow() with the hwnd, idObject parameters
  350. // of the event, and IID_IAccessible as the REFIID, to get back an
  351. // IAccessible* to talk to
  352. // * Initialize and fill in a VARIANT as VT_I4 with lVal the idChild
  353. // parameter of the event.
  354. // * If idChild isn't zero, call get_accChild() in the container to see
  355. // if the child is an object in its own right. If so, you will get
  356. // back an IDispatch* object for the child. You should release the
  357. // parent, and call QueryInterface() on the child object to get its
  358. // IAccessible*. Then you talk directly to the child. Otherwise,
  359. // if get_accChild() returns you nothing, you should continue to
  360. // use the child VARIANT. You will ask the container for the properties
  361. // of the child identified by the VARIANT. In other words, the
  362. // child in this case is accessible but not a full-blown object.
  363. // Like a button on a titlebar which is 'small' and has no children.
  364. //
  365. //
  366. #define EVENT_OBJECT_CREATE 0x8000 // hwnd + ID + idChild is created item
  367. #define EVENT_OBJECT_DESTROY 0x8001 // hwnd + ID + idChild is destroyed item
  368. #define EVENT_OBJECT_SHOW 0x8002 // hwnd + ID + idChild is shown item
  369. #define EVENT_OBJECT_HIDE 0x8003 // hwnd + ID + idChild is hidden item
  370. #define EVENT_OBJECT_REORDER 0x8004 // hwnd + ID + idChild is parent of zordering children
  371. //
  372. // NOTE:
  373. // Minimize the number of notifications!
  374. //
  375. // When you are hiding a parent object, obviously all child objects are no
  376. // longer visible on screen. They still have the same "visible" status,
  377. // but are not truly visible. Hence do not send HIDE notifications for the
  378. // children also. One implies all. The same goes for SHOW.
  379. //
  380. #define EVENT_OBJECT_FOCUS 0x8005 // hwnd + ID + idChild is focused item
  381. #define EVENT_OBJECT_SELECTION 0x8006 // hwnd + ID + idChild is selected item (if only one), or idChild is OBJID_WINDOW if complex
  382. #define EVENT_OBJECT_SELECTIONADD 0x8007 // hwnd + ID + idChild is item added
  383. #define EVENT_OBJECT_SELECTIONREMOVE 0x8008 // hwnd + ID + idChild is item removed
  384. #define EVENT_OBJECT_SELECTIONWITHIN 0x8009 // hwnd + ID + idChild is parent of changed selected items
  385. //
  386. // NOTES:
  387. // There is only one "focused" child item in a parent. This is the place
  388. // keystrokes are going at a given moment. Hence only send a notification
  389. // about where the NEW focus is going. A NEW item getting the focus already
  390. // implies that the OLD item is losing it.
  391. //
  392. // SELECTION however can be multiple. Hence the different SELECTION
  393. // notifications. Here's when to use each:
  394. //
  395. // (1) Send a SELECTION notification in the simple single selection
  396. // case (like the focus) when the item with the selection is
  397. // merely moving to a different item within a container. hwnd + ID
  398. // is the container control, idChildItem is the new child with the
  399. // selection.
  400. //
  401. // (2) Send a SELECTIONADD notification when a new item has simply been added
  402. // to the selection within a container. This is appropriate when the
  403. // number of newly selected items is very small. hwnd + ID is the
  404. // container control, idChildItem is the new child added to the selection.
  405. //
  406. // (3) Send a SELECTIONREMOVE notification when a new item has simply been
  407. // removed from the selection within a container. This is appropriate
  408. // when the number of newly selected items is very small, just like
  409. // SELECTIONADD. hwnd + ID is the container control, idChildItem is the
  410. // new child removed from the selection.
  411. //
  412. // (4) Send a SELECTIONWITHIN notification when the selected items within a
  413. // control have changed substantially. Rather than propagate a large
  414. // number of changes to reflect removal for some items, addition of
  415. // others, just tell somebody who cares that a lot happened. It will
  416. // be faster an easier for somebody watching to just turn around and
  417. // query the container control what the new bunch of selected items
  418. // are.
  419. //
  420. #define EVENT_OBJECT_STATECHANGE 0x800A // hwnd + ID + idChild is item w/ state change
  421. #define EVENT_OBJECT_LOCATIONCHANGE 0x800B // hwnd + ID + idChild is moved/sized item
  422. #define EVENT_OBJECT_NAMECHANGE 0x800C // hwnd + ID + idChild is item w/ name change
  423. #define EVENT_OBJECT_DESCRIPTIONCHANGE 0x800D // hwnd + ID + idChild is item w/ desc change
  424. #define EVENT_OBJECT_VALUECHANGE 0x800E // hwnd + ID + idChild is item w/ value change
  425. #define EVENT_OBJECT_PARENTCHANGE 0x800F // hwnd + ID + idChild is item w/ new parent
  426. #define EVENT_OBJECT_HELPCHANGE 0x8010 // hwnd + ID + idChild is item w/ help change
  427. #define EVENT_OBJECT_DEFACTIONCHANGE 0x8011 // hwnd + ID + idChild is item w/ def action change
  428. #define EVENT_OBJECT_ACCELERATORCHANGE 0x8012 // hwnd + ID + idChild is item w/ keybd accel change
  429. #endif // WINVER < 0x0500
  430. #ifdef __cplusplus
  431. }
  432. #endif // __cplusplus
  433. #endif // !_WINABLE_