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