home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / include / winable.h < prev    next >
C/C++ Source or Header  |  1998-04-25  |  17KB  |  508 lines

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