jwawinable.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. {******************************************************************************}
  2. { }
  3. { Hooking mechanism to receive system events interface Unit for Object Pascal }
  4. { }
  5. { Portions created by Microsoft are Copyright (C) 1995-2001 Microsoft }
  6. { Corporation. All Rights Reserved. }
  7. { }
  8. { The original file is: winable.h, released June 2000. The original Pascal }
  9. { code is: WinAble.pas, released December 2000. The initial developer of the }
  10. { Pascal code is Marcel van Brakel (brakelm att chello dott nl). }
  11. { }
  12. { Portions created by Marcel van Brakel are Copyright (C) 1999-2001 }
  13. { Marcel van Brakel. All Rights Reserved. }
  14. { }
  15. { Obtained through: Joint Endeavour of Delphi Innovators (Project JEDI) }
  16. { }
  17. { You may retrieve the latest version of this file at the Project JEDI }
  18. { APILIB home page, located at http://jedi-apilib.sourceforge.net }
  19. { }
  20. { The contents of this file are used with permission, subject to the Mozilla }
  21. { Public License Version 1.1 (the "License"); you may not use this file except }
  22. { in compliance with the License. You may obtain a copy of the License at }
  23. { http://www.mozilla.org/MPL/MPL-1.1.html }
  24. { }
  25. { Software distributed under the License is distributed on an "AS IS" basis, }
  26. { WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for }
  27. { the specific language governing rights and limitations under the License. }
  28. { }
  29. { Alternatively, the contents of this file may be used under the terms of the }
  30. { GNU Lesser General Public License (the "LGPL License"), in which case the }
  31. { provisions of the LGPL License are applicable instead of those above. }
  32. { If you wish to allow use of your version of this file only under the terms }
  33. { of the LGPL License and not to allow others to use your version of this file }
  34. { under the MPL, indicate your decision by deleting the provisions above and }
  35. { replace them with the notice and other provisions required by the LGPL }
  36. { License. If you do not delete the provisions above, a recipient may use }
  37. { your version of this file under either the MPL or the LGPL License. }
  38. { }
  39. { For more information about the LGPL: http://www.gnu.org/copyleft/lesser.html }
  40. { }
  41. {******************************************************************************}
  42. unit JwaWinAble;
  43. {$WEAKPACKAGEUNIT}
  44. {$HPPEMIT ''}
  45. {$HPPEMIT '#include "WinAble.h"'}
  46. {$HPPEMIT ''}
  47. {$I jediapilib.inc}
  48. interface
  49. uses
  50. JwaWinType;
  51. //
  52. // This gets GUI information out of context. If you pass in a NULL thread ID,
  53. // we will get the 'global' information, using the foreground thread. This
  54. // is guaranteed to be the real active window, focus window, etc. Yes, you
  55. // could do it yourself by calling GetForegorundWindow, getting the thread ID
  56. // of that window via GetWindowThreadProcessId, then passing the ID into
  57. // GetGUIThreadInfo(). However, that takes three calls and aside from being
  58. // a pain, anything could happen in the middle. So passing in NULL gets
  59. // you stuff in one call and hence also works right.
  60. //
  61. type
  62. LPGUITHREADINFO = ^GUITHREADINFO;
  63. {$EXTERNALSYM LPGUITHREADINFO}
  64. tagGUITHREADINFO = record
  65. cbSize: DWORD;
  66. flags: DWORD;
  67. hwndActive: HWND;
  68. hwndFocus: HWND;
  69. hwndCapture: HWND;
  70. hwndMenuOwner: HWND;
  71. hwndMoveSize: HWND;
  72. hwndCaret: HWND;
  73. rcCaret: RECT;
  74. end;
  75. {$EXTERNALSYM tagGUITHREADINFO}
  76. GUITHREADINFO = tagGUITHREADINFO;
  77. {$EXTERNALSYM GUITHREADINFO}
  78. TGuiThreadInfo = GUITHREADINFO;
  79. PGuiThreadInfo = LPGUITHREADINFO;
  80. const
  81. GUI_CARETBLINKING = $00000001;
  82. {$EXTERNALSYM GUI_CARETBLINKING}
  83. GUI_INMOVESIZE = $00000002;
  84. {$EXTERNALSYM GUI_INMOVESIZE}
  85. GUI_INMENUMODE = $00000004;
  86. {$EXTERNALSYM GUI_INMENUMODE}
  87. GUI_SYSTEMMENUMODE = $00000008;
  88. {$EXTERNALSYM GUI_SYSTEMMENUMODE}
  89. GUI_POPUPMENUMODE = $00000010;
  90. {$EXTERNALSYM GUI_POPUPMENUMODE}
  91. function GetGUIThreadInfo(idThread: DWORD; var lpgui: GUITHREADINFO): BOOL; stdcall;
  92. {$EXTERNALSYM GetGUIThreadInfo}
  93. function GetWindowModuleFileNameW(hwnd: HWND; lpFileName: LPWSTR; cchFileName: UINT): UINT; stdcall;
  94. {$EXTERNALSYM GetWindowModuleFileNameW}
  95. function GetWindowModuleFileNameA(hwnd: HWND; lpFileName: LPSTR; cchFileName: UINT): UINT; stdcall;
  96. {$EXTERNALSYM GetWindowModuleFileNameA}
  97. function GetWindowModuleFileName(hwnd: HWND; lpFileName: LPTSTR; cchFileName: UINT): UINT; stdcall;
  98. {$EXTERNALSYM GetWindowModuleFileName}
  99. //
  100. // This returns FALSE if the caller doesn't have permissions to do this
  101. // esp. if someone else is dorking with input. I.E., if some other thread
  102. // disabled input, and thread 2 tries to diable/enable it, the call will
  103. // fail since thread 1 has the cookie.
  104. //
  105. function BlockInput(fBlockIt: BOOL): BOOL; stdcall;
  106. {$EXTERNALSYM BlockInput}
  107. //
  108. // Note that the dwFlags field uses the same flags as keybd_event and
  109. // mouse_event, depending on what type of input this is.
  110. //
  111. type
  112. LPMOUSEINPUT = ^MOUSEINPUT;
  113. {$EXTERNALSYM LPMOUSEINPUT}
  114. PMOUSEINPUT = ^MOUSEINPUT;
  115. {$EXTERNALSYM PMOUSEINPUT}
  116. tagMOUSEINPUT = record
  117. dx: LONG;
  118. dy: LONG;
  119. mouseData: DWORD;
  120. dwFlags: DWORD;
  121. time: DWORD;
  122. dwExtraInfo: DWORD;
  123. end;
  124. {$EXTERNALSYM tagMOUSEINPUT}
  125. MOUSEINPUT = tagMOUSEINPUT;
  126. {$EXTERNALSYM MOUSEINPUT}
  127. TMouseInput = MOUSEINPUT;
  128. LPKEYBDINPUT = ^KEYBDINPUT;
  129. {$EXTERNALSYM LPKEYBDINPUT}
  130. PKEYBDINPUT = ^KEYBDINPUT;
  131. {$EXTERNALSYM PKEYBDINPUT}
  132. tagKEYBDINPUT = record
  133. wVk: WORD;
  134. wScan: WORD;
  135. dwFlags: DWORD;
  136. time: DWORD;
  137. dwExtraInfo: DWORD;
  138. end;
  139. {$EXTERNALSYM tagKEYBDINPUT}
  140. KEYBDINPUT = tagKEYBDINPUT;
  141. {$EXTERNALSYM KEYBDINPUT}
  142. TKeybdInput = KEYBDINPUT;
  143. LPHARDWAREINPUT = ^HARDWAREINPUT;
  144. {$EXTERNALSYM LPHARDWAREINPUT}
  145. PHARDWAREINPUT = ^HARDWAREINPUT;
  146. {$EXTERNALSYM PHARDWAREINPUT}
  147. tagHARDWAREINPUT = record
  148. uMsg: DWORD;
  149. wParamL: WORD;
  150. wParamH: WORD;
  151. dwExtraInfo: DWORD;
  152. end;
  153. {$EXTERNALSYM tagHARDWAREINPUT}
  154. HARDWAREINPUT = tagHARDWAREINPUT;
  155. {$EXTERNALSYM HARDWAREINPUT}
  156. THardwareInput = HARDWAREINPUT;
  157. const
  158. INPUT_MOUSE = 0;
  159. {$EXTERNALSYM INPUT_MOUSE}
  160. INPUT_KEYBOARD = 1;
  161. {$EXTERNALSYM INPUT_KEYBOARD}
  162. INPUT_HARDWARE = 2;
  163. {$EXTERNALSYM INPUT_HARDWARE}
  164. type
  165. LPINPUT = ^INPUT;
  166. {$EXTERNALSYM LPINPUT}
  167. PINPUT = ^INPUT;
  168. {$EXTERNALSYM PINPUT}
  169. tagINPUT = record
  170. type_: DWORD;
  171. case Integer of
  172. 0: (mi: MOUSEINPUT);
  173. 1: (ki: KEYBDINPUT);
  174. 2: (hi: HARDWAREINPUT);
  175. end;
  176. {$EXTERNALSYM tagINPUT}
  177. INPUT = tagINPUT;
  178. {$EXTERNALSYM INPUT}
  179. TInput = INPUT;
  180. //
  181. // This returns the number of inputs played back. It will disable input
  182. // first, play back as many as possible, then reenable input. In the middle
  183. // it will pulse the RIT to make sure that the fixed input queue doesn't
  184. // fill up.
  185. //
  186. function SendInput(cInputs: UINT; pInputs: LPINPUT; cbSize: Integer): UINT; stdcall;
  187. {$EXTERNALSYM SendInput}
  188. const
  189. CCHILDREN_FRAME = 7;
  190. {$EXTERNALSYM CCHILDREN_FRAME}
  191. //
  192. // This generates a notification that anyone watching for it will get.
  193. // This call is superfast if nobody is hooking anything.
  194. //
  195. procedure NotifyWinEvent(event: DWORD; hwnd: HWND; idObject, idChild: LONG); stdcall;
  196. {$EXTERNALSYM NotifyWinEvent}
  197. //
  198. // hwnd + idObject can be used with OLEACC.DLL's OleGetObjectFromWindow()
  199. // to get an interface pointer to the container. indexChild is the item
  200. // within the container in question. Setup a VARIANT with vt VT_I4 and
  201. // lVal the indexChild and pass that in to all methods. Then you
  202. // are raring to go.
  203. //
  204. //
  205. // Common object IDs (cookies, only for sending WM_GETOBJECT to get at the
  206. // thing in question). Positive IDs are reserved for apps (app specific),
  207. // negative IDs are system things and are global, 0 means "just little old
  208. // me".
  209. //
  210. const
  211. CHILDID_SELF = 0;
  212. {$EXTERNALSYM CHILDID_SELF}
  213. // Reserved IDs for system objects
  214. OBJID_WINDOW = DWORD($00000000);
  215. {$EXTERNALSYM OBJID_WINDOW}
  216. OBJID_SYSMENU = DWORD($FFFFFFFF);
  217. {$EXTERNALSYM OBJID_SYSMENU}
  218. OBJID_TITLEBAR = DWORD($FFFFFFFE);
  219. {$EXTERNALSYM OBJID_TITLEBAR}
  220. OBJID_MENU = DWORD($FFFFFFFD);
  221. {$EXTERNALSYM OBJID_MENU}
  222. OBJID_CLIENT = DWORD($FFFFFFFC);
  223. {$EXTERNALSYM OBJID_CLIENT}
  224. OBJID_VSCROLL = DWORD($FFFFFFFB);
  225. {$EXTERNALSYM OBJID_VSCROLL}
  226. OBJID_HSCROLL = DWORD($FFFFFFFA);
  227. {$EXTERNALSYM OBJID_HSCROLL}
  228. OBJID_SIZEGRIP = DWORD($FFFFFFF9);
  229. {$EXTERNALSYM OBJID_SIZEGRIP}
  230. OBJID_CARET = DWORD($FFFFFFF8);
  231. {$EXTERNALSYM OBJID_CARET}
  232. OBJID_CURSOR = DWORD($FFFFFFF7);
  233. {$EXTERNALSYM OBJID_CURSOR}
  234. OBJID_ALERT = DWORD($FFFFFFF6);
  235. {$EXTERNALSYM OBJID_ALERT}
  236. OBJID_SOUND = DWORD($FFFFFFF5);
  237. {$EXTERNALSYM OBJID_SOUND}
  238. //
  239. // System Alerts (indexChild of system ALERT notification)
  240. //
  241. ALERT_SYSTEM_INFORMATIONAL = 1; // MB_INFORMATION
  242. {$EXTERNALSYM ALERT_SYSTEM_INFORMATIONAL}
  243. ALERT_SYSTEM_WARNING = 2; // MB_WARNING
  244. {$EXTERNALSYM ALERT_SYSTEM_WARNING}
  245. ALERT_SYSTEM_ERROR = 3; // MB_ERROR
  246. {$EXTERNALSYM ALERT_SYSTEM_ERROR}
  247. ALERT_SYSTEM_QUERY = 4; // MB_QUESTION
  248. {$EXTERNALSYM ALERT_SYSTEM_QUERY}
  249. ALERT_SYSTEM_CRITICAL = 5; // HardSysErrBox
  250. {$EXTERNALSYM ALERT_SYSTEM_CRITICAL}
  251. CALERT_SYSTEM = 6;
  252. {$EXTERNALSYM CALERT_SYSTEM}
  253. type
  254. HWINEVENTHOOK = DWORD;
  255. {$EXTERNALSYM HWINEVENTHOOK}
  256. WINEVENTPROC = procedure(
  257. hEvent: HWINEVENTHOOK;
  258. event: DWORD;
  259. hwnd: HWND;
  260. idObject: LONG;
  261. idChild: LONG;
  262. idEventThread: DWORD;
  263. dwmsEventTime: DWORD); stdcall;
  264. {$EXTERNALSYM WINEVENTPROC}
  265. TWinEventProc = WINEVENTPROC;
  266. const
  267. WINEVENT_OUTOFCONTEXT = $0000; // Events are ASYNC
  268. {$EXTERNALSYM WINEVENT_OUTOFCONTEXT}
  269. WINEVENT_SKIPOWNTHREAD = $0001; // Don't call back for events on installer's thread
  270. {$EXTERNALSYM WINEVENT_SKIPOWNTHREAD}
  271. WINEVENT_SKIPOWNPROCESS = $0002; // Don't call back for events on installer's process
  272. {$EXTERNALSYM WINEVENT_SKIPOWNPROCESS}
  273. WINEVENT_INCONTEXT = $0004; // Events are SYNC, this causes your dll to be injected into every process
  274. {$EXTERNALSYM WINEVENT_INCONTEXT}
  275. WINEVENT_32BITCALLER = $8000; // ;Internal
  276. {$EXTERNALSYM WINEVENT_32BITCALLER}
  277. WINEVENT_VALID = $8007; // ;Internal
  278. {$EXTERNALSYM WINEVENT_VALID}
  279. function SetWinEventHook(eventMin, eventMax: DWORD; hmodWinEventProc: HMODULE;
  280. lpfnWinEventProc: WINEVENTPROC; idProcess, idThread, dwFlags: DWORD): HWINEVENTHOOK; stdcall;
  281. {$EXTERNALSYM SetWinEventHook}
  282. //
  283. // Returns zero on failure, or a DWORD ID if success. We will clean up any
  284. // event hooks installed by the current process when it goes away, if it
  285. // hasn't cleaned the hooks up itself. But to dynamically unhook, call
  286. // UnhookWinEvents().
  287. //
  288. function UnhookWinEvent(hEvent: HWINEVENTHOOK): BOOL; stdcall;
  289. {$EXTERNALSYM UnhookWinEvent}
  290. //
  291. // If idProcess isn't zero but idThread is, will hook all threads in that
  292. // process.
  293. // If idThread isn't zero but idProcess is, will hook idThread only.
  294. // If both are zero, will hook everything
  295. //
  296. //
  297. // EVENT DEFINITION
  298. //
  299. const
  300. EVENT_MIN = $00000001;
  301. {$EXTERNALSYM EVENT_MIN}
  302. EVENT_MAX = $7FFFFFFF;
  303. {$EXTERNALSYM EVENT_MAX}
  304. //
  305. // EVENT_SYSTEM_SOUND
  306. // Sent when a sound is played. Currently nothing is generating this, we
  307. // are going to be cleaning up the SOUNDSENTRY feature in the control panel
  308. // and will use this at that time. Applications implementing WinEvents
  309. // are perfectly welcome to use it. Clients of IAccessible* will simply
  310. // turn around and get back a non-visual object that describes the sound.
  311. //
  312. EVENT_SYSTEM_SOUND = $0001;
  313. {$EXTERNALSYM EVENT_SYSTEM_SOUND}
  314. //
  315. // EVENT_SYSTEM_ALERT
  316. // Sent when an alert needs to be given to the user. MessageBoxes generate
  317. // alerts for example.
  318. //
  319. EVENT_SYSTEM_ALERT = $0002;
  320. {$EXTERNALSYM EVENT_SYSTEM_ALERT}
  321. //
  322. // EVENT_SYSTEM_FOREGROUND
  323. // Sent when the foreground (active) window changes, even if it is changing
  324. // to another window in the same thread as the previous one.
  325. //
  326. EVENT_SYSTEM_FOREGROUND = $0003;
  327. {$EXTERNALSYM EVENT_SYSTEM_FOREGROUND}
  328. //
  329. // EVENT_SYSTEM_MENUSTART
  330. // EVENT_SYSTEM_MENUEND
  331. // Sent when entering into and leaving from menu mode (system, app bar, and
  332. // track popups).
  333. //
  334. EVENT_SYSTEM_MENUSTART = $0004;
  335. {$EXTERNALSYM EVENT_SYSTEM_MENUSTART}
  336. EVENT_SYSTEM_MENUEND = $0005;
  337. {$EXTERNALSYM EVENT_SYSTEM_MENUEND}
  338. //
  339. // EVENT_SYSTEM_MENUPOPUPSTART
  340. // EVENT_SYSTEM_MENUPOPUPEND
  341. // Sent when a menu popup comes up and just before it is taken down. Note
  342. // that for a call to TrackPopupMenu(), a client will see EVENT_SYSTEM_MENUSTART
  343. // followed almost immediately by EVENT_SYSTEM_MENUPOPUPSTART for the popup
  344. // being shown.
  345. //
  346. EVENT_SYSTEM_MENUPOPUPSTART = $0006;
  347. {$EXTERNALSYM EVENT_SYSTEM_MENUPOPUPSTART}
  348. EVENT_SYSTEM_MENUPOPUPEND = $0007;
  349. {$EXTERNALSYM EVENT_SYSTEM_MENUPOPUPEND}
  350. //
  351. // EVENT_SYSTEM_CAPTURESTART
  352. // EVENT_SYSTEM_CAPTUREEND
  353. // Sent when a window takes the capture and releases the capture.
  354. //
  355. EVENT_SYSTEM_CAPTURESTART = $0008;
  356. {$EXTERNALSYM EVENT_SYSTEM_CAPTURESTART}
  357. EVENT_SYSTEM_CAPTUREEND = $0009;
  358. {$EXTERNALSYM EVENT_SYSTEM_CAPTUREEND}
  359. //
  360. // EVENT_SYSTEM_MOVESIZESTART
  361. // EVENT_SYSTEM_MOVESIZEEND
  362. // Sent when a window enters and leaves move-size dragging mode.
  363. //
  364. EVENT_SYSTEM_MOVESIZESTART = $000A;
  365. {$EXTERNALSYM EVENT_SYSTEM_MOVESIZESTART}
  366. EVENT_SYSTEM_MOVESIZEEND = $000B;
  367. {$EXTERNALSYM EVENT_SYSTEM_MOVESIZEEND}
  368. //
  369. // EVENT_SYSTEM_CONTEXTHELPSTART
  370. // EVENT_SYSTEM_CONTEXTHELPEND
  371. // Sent when a window enters and leaves context sensitive help mode.
  372. //
  373. EVENT_SYSTEM_CONTEXTHELPSTART = $000C;
  374. {$EXTERNALSYM EVENT_SYSTEM_CONTEXTHELPSTART}
  375. EVENT_SYSTEM_CONTEXTHELPEND = $000D;
  376. {$EXTERNALSYM EVENT_SYSTEM_CONTEXTHELPEND}
  377. //
  378. // EVENT_SYSTEM_DRAGDROPSTART
  379. // EVENT_SYSTEM_DRAGDROPEND
  380. // Sent when a window enters and leaves drag drop mode. Note that it is up
  381. // to apps and OLE to generate this, since the system doesn't know. Like
  382. // EVENT_SYSTEM_SOUND, it will be a while before this is prevalent.
  383. //
  384. EVENT_SYSTEM_DRAGDROPSTART = $000E;
  385. {$EXTERNALSYM EVENT_SYSTEM_DRAGDROPSTART}
  386. EVENT_SYSTEM_DRAGDROPEND = $000F;
  387. {$EXTERNALSYM EVENT_SYSTEM_DRAGDROPEND}
  388. //
  389. // EVENT_SYSTEM_DIALOGSTART
  390. // EVENT_SYSTEM_DIALOGEND
  391. // Sent when a dialog comes up and just before it goes away.
  392. //
  393. EVENT_SYSTEM_DIALOGSTART = $0010;
  394. {$EXTERNALSYM EVENT_SYSTEM_DIALOGSTART}
  395. EVENT_SYSTEM_DIALOGEND = $0011;
  396. {$EXTERNALSYM EVENT_SYSTEM_DIALOGEND}
  397. //
  398. // EVENT_SYSTEM_SCROLLINGSTART
  399. // EVENT_SYSTEM_SCROLLINGEND
  400. // Sent when beginning and ending the tracking of a scrollbar in a window,
  401. // and also for scrollbar controls.
  402. //
  403. EVENT_SYSTEM_SCROLLINGSTART = $0012;
  404. {$EXTERNALSYM EVENT_SYSTEM_SCROLLINGSTART}
  405. EVENT_SYSTEM_SCROLLINGEND = $0013;
  406. {$EXTERNALSYM EVENT_SYSTEM_SCROLLINGEND}
  407. //
  408. // EVENT_SYSTEM_SWITCHSTART
  409. // EVENT_SYSTEM_SWITCHEND
  410. // Sent when beginning and ending alt-tab mode with the switch window.
  411. //
  412. EVENT_SYSTEM_SWITCHSTART = $0014;
  413. {$EXTERNALSYM EVENT_SYSTEM_SWITCHSTART}
  414. EVENT_SYSTEM_SWITCHEND = $0015;
  415. {$EXTERNALSYM EVENT_SYSTEM_SWITCHEND}
  416. //
  417. // EVENT_SYSTEM_MINIMIZESTART
  418. // EVENT_SYSTEM_MINIMIZEEND
  419. // Sent when a window minimizes and just before it restores.
  420. //
  421. EVENT_SYSTEM_MINIMIZESTART = $0016;
  422. {$EXTERNALSYM EVENT_SYSTEM_MINIMIZESTART}
  423. EVENT_SYSTEM_MINIMIZEEND = $0017;
  424. {$EXTERNALSYM EVENT_SYSTEM_MINIMIZEEND}
  425. //
  426. // Object events
  427. //
  428. // The system AND apps generate these. The system generates these for
  429. // real windows. Apps generate these for objects within their window which
  430. // act like a separate control, e.g. an item in a list view.
  431. //
  432. // For all events, if you want detailed accessibility information, callers
  433. // should
  434. // * Call AccessibleObjectFromWindow() with the hwnd, idObject parameters
  435. // of the event, and IID_IAccessible as the REFIID, to get back an
  436. // IAccessible* to talk to
  437. // * Initialize and fill in a VARIANT as VT_I4 with lVal the idChild
  438. // parameter of the event.
  439. // * If idChild isn't zero, call get_accChild() in the container to see
  440. // if the child is an object in its own right. If so, you will get
  441. // back an IDispatch* object for the child. You should release the
  442. // parent, and call QueryInterface() on the child object to get its
  443. // IAccessible*. Then you talk directly to the child. Otherwise,
  444. // if get_accChild() returns you nothing, you should continue to
  445. // use the child VARIANT. You will ask the container for the properties
  446. // of the child identified by the VARIANT. In other words, the
  447. // child in this case is accessible but not a full-blown object.
  448. // Like a button on a titlebar which is 'small' and has no children.
  449. //
  450. //
  451. EVENT_OBJECT_CREATE = $8000; // hwnd + ID + idChild is created item
  452. {$EXTERNALSYM EVENT_OBJECT_CREATE}
  453. EVENT_OBJECT_DESTROY = $8001; // hwnd + ID + idChild is destroyed item
  454. {$EXTERNALSYM EVENT_OBJECT_DESTROY}
  455. EVENT_OBJECT_SHOW = $8002; // hwnd + ID + idChild is shown item
  456. {$EXTERNALSYM EVENT_OBJECT_SHOW}
  457. EVENT_OBJECT_HIDE = $8003; // hwnd + ID + idChild is hidden item
  458. {$EXTERNALSYM EVENT_OBJECT_HIDE}
  459. EVENT_OBJECT_REORDER = $8004; // hwnd + ID + idChild is parent of zordering children
  460. {$EXTERNALSYM EVENT_OBJECT_REORDER}
  461. //
  462. // NOTE:
  463. // Minimize the number of notifications!
  464. //
  465. // When you are hiding a parent object, obviously all child objects are no
  466. // longer visible on screen. They still have the same "visible" status,
  467. // but are not truly visible. Hence do not send HIDE notifications for the
  468. // children also. One implies all. The same goes for SHOW.
  469. //
  470. EVENT_OBJECT_FOCUS = $8005; // hwnd + ID + idChild is focused item
  471. {$EXTERNALSYM EVENT_OBJECT_FOCUS}
  472. EVENT_OBJECT_SELECTION = $8006; // hwnd + ID + idChild is selected item (if only one), or idChild is OBJID_WINDOW if complex
  473. {$EXTERNALSYM EVENT_OBJECT_SELECTION}
  474. EVENT_OBJECT_SELECTIONADD = $8007; // hwnd + ID + idChild is item added
  475. {$EXTERNALSYM EVENT_OBJECT_SELECTIONADD}
  476. EVENT_OBJECT_SELECTIONREMOVE = $8008; // hwnd + ID + idChild is item removed
  477. {$EXTERNALSYM EVENT_OBJECT_SELECTIONREMOVE}
  478. EVENT_OBJECT_SELECTIONWITHIN = $8009; // hwnd + ID + idChild is parent of changed selected items
  479. {$EXTERNALSYM EVENT_OBJECT_SELECTIONWITHIN}
  480. //
  481. // NOTES:
  482. // There is only one "focused" child item in a parent. This is the place
  483. // keystrokes are going at a given moment. Hence only send a notification
  484. // about where the NEW focus is going. A NEW item getting the focus already
  485. // implies that the OLD item is losing it.
  486. //
  487. // SELECTION however can be multiple. Hence the different SELECTION
  488. // notifications. Here's when to use each:
  489. //
  490. // (1) Send a SELECTION notification in the simple single selection
  491. // case (like the focus) when the item with the selection is
  492. // merely moving to a different item within a container. hwnd + ID
  493. // is the container control, idChildItem is the new child with the
  494. // selection.
  495. //
  496. // (2) Send a SELECTIONADD notification when a new item has simply been added
  497. // to the selection within a container. This is appropriate when the
  498. // number of newly selected items is very small. hwnd + ID is the
  499. // container control, idChildItem is the new child added to the selection.
  500. //
  501. // (3) Send a SELECTIONREMOVE notification when a new item has simply been
  502. // removed from the selection within a container. This is appropriate
  503. // when the number of newly selected items is very small, just like
  504. // SELECTIONADD. hwnd + ID is the container control, idChildItem is the
  505. // new child removed from the selection.
  506. //
  507. // (4) Send a SELECTIONWITHIN notification when the selected items within a
  508. // control have changed substantially. Rather than propagate a large
  509. // number of changes to reflect removal for some items, addition of
  510. // others, just tell somebody who cares that a lot happened. It will
  511. // be faster an easier for somebody watching to just turn around and
  512. // query the container control what the new bunch of selected items
  513. // are.
  514. //
  515. EVENT_OBJECT_STATECHANGE = $800A; // hwnd + ID + idChild is item w/ state change
  516. {$EXTERNALSYM EVENT_OBJECT_STATECHANGE}
  517. EVENT_OBJECT_LOCATIONCHANGE = $800B; // hwnd + ID + idChild is moved/sized item
  518. {$EXTERNALSYM EVENT_OBJECT_LOCATIONCHANGE}
  519. EVENT_OBJECT_NAMECHANGE = $800C; // hwnd + ID + idChild is item w/ name change
  520. {$EXTERNALSYM EVENT_OBJECT_NAMECHANGE}
  521. EVENT_OBJECT_DESCRIPTIONCHANGE = $800D; // hwnd + ID + idChild is item w/ desc change
  522. {$EXTERNALSYM EVENT_OBJECT_DESCRIPTIONCHANGE}
  523. EVENT_OBJECT_VALUECHANGE = $800E; // hwnd + ID + idChild is item w/ value change
  524. {$EXTERNALSYM EVENT_OBJECT_VALUECHANGE}
  525. EVENT_OBJECT_PARENTCHANGE = $800F; // hwnd + ID + idChild is item w/ new parent
  526. {$EXTERNALSYM EVENT_OBJECT_PARENTCHANGE}
  527. EVENT_OBJECT_HELPCHANGE = $8010; // hwnd + ID + idChild is item w/ help change
  528. {$EXTERNALSYM EVENT_OBJECT_HELPCHANGE}
  529. EVENT_OBJECT_DEFACTIONCHANGE = $8011; // hwnd + ID + idChild is item w/ def action change
  530. {$EXTERNALSYM EVENT_OBJECT_DEFACTIONCHANGE}
  531. EVENT_OBJECT_ACCELERATORCHANGE = $8012; // hwnd + ID + idChild is item w/ keybd accel change
  532. {$EXTERNALSYM EVENT_OBJECT_ACCELERATORCHANGE}
  533. implementation
  534. const
  535. user32 = 'user32.dll';
  536. {$IFDEF UNICODE}
  537. AWSuffix = 'W';
  538. {$ELSE}
  539. AWSuffix = 'A';
  540. {$ENDIF UNICODE}
  541. {$IFDEF DYNAMIC_LINK}
  542. var
  543. _GetGUIThreadInfo: Pointer;
  544. function GetGUIThreadInfo;
  545. begin
  546. GetProcedureAddress(_GetGUIThreadInfo, user32, 'GetGUIThreadInfo');
  547. asm
  548. MOV ESP, EBP
  549. POP EBP
  550. JMP [_GetGUIThreadInfo]
  551. end;
  552. end;
  553. var
  554. _GetWindowModuleFileNameW: Pointer;
  555. function GetWindowModuleFileNameW;
  556. begin
  557. GetProcedureAddress(_GetWindowModuleFileNameW, user32, 'GetWindowModuleFileNameW');
  558. asm
  559. MOV ESP, EBP
  560. POP EBP
  561. JMP [_GetWindowModuleFileNameW]
  562. end;
  563. end;
  564. var
  565. _GetWindowModuleFileNameA: Pointer;
  566. function GetWindowModuleFileNameA;
  567. begin
  568. GetProcedureAddress(_GetWindowModuleFileNameA, user32, 'GetWindowModuleFileNameA');
  569. asm
  570. MOV ESP, EBP
  571. POP EBP
  572. JMP [_GetWindowModuleFileNameA]
  573. end;
  574. end;
  575. var
  576. _GetWindowModuleFileName: Pointer;
  577. function GetWindowModuleFileName;
  578. begin
  579. GetProcedureAddress(_GetWindowModuleFileName, user32, 'GetWindowModuleFileName' + AWSuffix);
  580. asm
  581. MOV ESP, EBP
  582. POP EBP
  583. JMP [_GetWindowModuleFileName]
  584. end;
  585. end;
  586. var
  587. _BlockInput: Pointer;
  588. function BlockInput;
  589. begin
  590. GetProcedureAddress(_BlockInput, user32, 'BlockInput');
  591. asm
  592. MOV ESP, EBP
  593. POP EBP
  594. JMP [_BlockInput]
  595. end;
  596. end;
  597. var
  598. _SendInput: Pointer;
  599. function SendInput;
  600. begin
  601. GetProcedureAddress(_SendInput, user32, 'SendInput');
  602. asm
  603. MOV ESP, EBP
  604. POP EBP
  605. JMP [_SendInput]
  606. end;
  607. end;
  608. var
  609. _NotifyWinEvent: Pointer;
  610. procedure NotifyWinEvent;
  611. begin
  612. GetProcedureAddress(_NotifyWinEvent, user32, 'NotifyWinEvent');
  613. asm
  614. MOV ESP, EBP
  615. POP EBP
  616. JMP [_NotifyWinEvent]
  617. end;
  618. end;
  619. var
  620. _SetWinEventHook: Pointer;
  621. function SetWinEventHook;
  622. begin
  623. GetProcedureAddress(_SetWinEventHook, user32, 'SetWinEventHook');
  624. asm
  625. MOV ESP, EBP
  626. POP EBP
  627. JMP [_SetWinEventHook]
  628. end;
  629. end;
  630. var
  631. _UnhookWinEvent: Pointer;
  632. function UnhookWinEvent;
  633. begin
  634. GetProcedureAddress(_UnhookWinEvent, user32, 'UnhookWinEvent');
  635. asm
  636. MOV ESP, EBP
  637. POP EBP
  638. JMP [_UnhookWinEvent]
  639. end;
  640. end;
  641. {$ELSE}
  642. function GetGUIThreadInfo; external user32 name 'GetGUIThreadInfo';
  643. function GetWindowModuleFileNameW; external user32 name 'GetWindowModuleFileNameW';
  644. function GetWindowModuleFileNameA; external user32 name 'GetWindowModuleFileNameA';
  645. function GetWindowModuleFileName; external user32 name 'GetWindowModuleFileName' + AWSuffix;
  646. function BlockInput; external user32 name 'BlockInput';
  647. function SendInput; external user32 name 'SendInput';
  648. procedure NotifyWinEvent; external user32 name 'NotifyWinEvent';
  649. function SetWinEventHook; external user32 name 'SetWinEventHook';
  650. function UnhookWinEvent; external user32 name 'UnhookWinEvent';
  651. {$ENDIF DYNAMIC_LINK}
  652. end.