home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / C++ / FreeCommandLineTools.exe / Include / winable.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-01-31  |  16.9 KB  |  516 lines

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