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.

827 lines
25 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // DirectUser COM+ API
  4. //
  5. // Copyright (C) 2000 by Microsoft Corporation
  6. //
  7. //-----------------------------------------------------------------------------
  8. namespace DUser
  9. {
  10. using System;
  11. using System.Runtime.InteropServices;
  12. public class Common
  13. {
  14. public enum StructFormat
  15. {
  16. Ansi = 1,
  17. Unicode = 2,
  18. Auto = 3,
  19. }
  20. [System.Runtime.InteropServices.ComVisible(false), sysstruct(format=StructFormat.Auto)]
  21. public class INITGADGET
  22. {
  23. public uint cbSize;
  24. public uint nThreadMode;
  25. public uint nMsgMode;
  26. public int hctxShare;
  27. }
  28. [dllimport("DUser.dll", EntryPoint="InitGadgets", SetLastError=true)]
  29. public static extern bool InitGadgets(INITGADGET ig);
  30. [dllimport("DUserCP.dll", EntryPoint="InitBridge", SetLastError=true)]
  31. public static extern bool InitBridge();
  32. [dllimport("kernel32.dll", EntryPoint="GetLastError")]
  33. public static extern uint GetLastError();
  34. public static void Init()
  35. {
  36. //
  37. // Initialize DUser
  38. //
  39. INITGADGET ig = new INITGADGET();
  40. ig.cbSize = 12;
  41. ig.nThreadMode = 1;
  42. ig.nMsgMode = 2;
  43. ig.hctxShare = 0;
  44. if (!InitGadgets(ig)) {
  45. throw new DUserException(GetLastError(), "Unable to initialized DUser");
  46. }
  47. if (!InitBridge()) {
  48. throw new DUserException(GetLastError(), "Unable to initialized DUser Bridge");
  49. }
  50. //
  51. // Initialize all of the DUser classes
  52. //
  53. BaseGadget.InitBaseGadget();
  54. MsgGadget.InitMsgGadget();
  55. Extension.InitExtension();
  56. DropTarget.InitDropTarget();
  57. Visual.InitVisual();
  58. Root.InitRoot();
  59. }
  60. public const int gmEvent = 32768;
  61. public const int gmDestroy = gmEvent + 1;
  62. public const int gmPaint = gmEvent + 2;
  63. public const int gmInput = gmEvent + 3;
  64. public const int gmChangeState = gmEvent + 4;
  65. public const int gmChangeRect = gmEvent + 5;
  66. public const int gmChangeStyle = gmEvent + 6;
  67. public const int gmQuery = gmEvent + 7;
  68. public const int gmSyncAdaptor = gmEvent + 8;
  69. [System.Runtime.InteropServices.ComVisible(false), sysstruct(format=StructFormat.Auto)]
  70. public class Msg
  71. {
  72. public uint cbSize;
  73. public int nMsg;
  74. public int hgadMsg;
  75. }
  76. [System.Runtime.InteropServices.ComVisible(false), sysstruct(format=StructFormat.Auto)]
  77. public class EventMsg : Msg
  78. {
  79. public uint nMsgFlags;
  80. }
  81. [System.Runtime.InteropServices.ComVisible(false), sysstruct(format=StructFormat.Auto)]
  82. public class MethodMsg : Msg
  83. {
  84. }
  85. [dllimport("DUser.dll", EntryPoint="FindGadgetClass", SetLastError=true)]
  86. public static extern int FindGadgetClass([marshal(UnmanagedType.LPWStr)] string sName, uint nVersion);
  87. [System.Runtime.InteropServices.ComVisible(false), sysstruct(format=StructFormat.Auto)]
  88. public class ContructInfo
  89. {
  90. }
  91. public const uint gprFailed = 0xFFFFFFFF;
  92. public const uint gprNotHandled = 0;
  93. public const uint gprComplete = 1;
  94. public const uint gprPartial = 2;
  95. public delegate uint GadgetEventProc(Common.EventMsg pmsg);
  96. public delegate void GadgetMethodProc(Common.MethodMsg pmsg);
  97. [dllimport("DUser.dll", EntryPoint="BuildGadget", SetLastError=true)]
  98. public static extern int BuildGadget(int hClass, ContructInfo ci);
  99. [dllimport("DUserCP.dll", EntryPoint="BuildBridgeGadget", SetLastError=true)]
  100. public static extern int BuildBridgeGadget(int hClass, ContructInfo ci,
  101. GadgetEventProc pfnEvent, GadgetMethodProc pfnMethod);
  102. [dllimport("DUser.dll", EntryPoint="CastGadgetDirect", SetLastError=true)]
  103. public static extern int CastGadgetDirect(int hgad);
  104. [System.Runtime.InteropServices.ComVisible(false), sysstruct(format=StructFormat.Auto)]
  105. public class POINT
  106. {
  107. public int x;
  108. public int y;
  109. }
  110. [System.Runtime.InteropServices.ComVisible(false), sysstruct(format=StructFormat.Auto)]
  111. public class SIZE
  112. {
  113. public int cx;
  114. public int cy;
  115. }
  116. [System.Runtime.InteropServices.ComVisible(false), sysstruct(format=StructFormat.Auto)]
  117. public class RECT
  118. {
  119. public int left;
  120. public int top;
  121. public int right;
  122. public int bottom;
  123. }
  124. [dllimport("DUser.dll", EntryPoint="GetStdColorBrushI")]
  125. public static extern int GetStdColorBrush(int idColor);
  126. };
  127. public class Gadget
  128. {
  129. public int pgad;
  130. protected int h(Gadget g)
  131. {
  132. return g != null ? g.pgad : 0;
  133. }
  134. protected bool s(uint hr)
  135. {
  136. return (hr & 0x80000000) == 0;
  137. }
  138. protected bool f(uint hr)
  139. {
  140. return (hr & 0x80000000) != 0;
  141. }
  142. public virtual uint OnEvent(Common.EventMsg pmsg)
  143. {
  144. return 0;
  145. }
  146. protected uint RawEventProc(Common.EventMsg pmsg)
  147. {
  148. return OnEvent(pmsg);
  149. }
  150. public virtual void OnMethod(Common.MethodMsg pmsg)
  151. {
  152. }
  153. protected void RawMethodProc(Common.MethodMsg pmsg)
  154. {
  155. OnMethod(pmsg);
  156. }
  157. };
  158. class DUserException : System.SystemException
  159. {
  160. public DUserException(uint error)
  161. {
  162. this.error = error;
  163. }
  164. public DUserException(uint error, string sReason) : base(sReason)
  165. {
  166. this.error = error;
  167. }
  168. public uint error;
  169. };
  170. //---------------------------------------------------------------------------
  171. //
  172. // Stub class BaseGadget
  173. //
  174. class BaseGadget : Gadget
  175. {
  176. private static int idBaseGadget;
  177. public static void InitBaseGadget()
  178. {
  179. idBaseGadget = Common.FindGadgetClass("BaseGadgetBridge", 1);
  180. if (idBaseGadget == 0) {
  181. throw new DUserException(Common.GetLastError(), "Unable to find registered BaseGadget");
  182. }
  183. }
  184. [dllimport("DUserCP.dll")]
  185. public static extern uint SBaseGadgetOnEvent(Common.EventMsg pmsg);
  186. public override uint OnEvent(Common.EventMsg pmsg)
  187. {
  188. return SBaseGadgetOnEvent(pmsg);
  189. }
  190. [dllimport("DUser.dll", EntryPoint="BaseGadgetOnEvent", SetLastError=true)]
  191. public static extern uint BaseGadgetOnEvent(Common.EventMsg pmsg);
  192. [dllimport("DUser.dll", EntryPoint="BaseGadgetGetFilter", SetLastError=true)]
  193. public static extern uint BaseGadgetGetFilter([@out] uint pnFilter);
  194. public const uint gmfiPaint = 0x00000001;
  195. public const uint gmfiInputKeyboard = 0x00000002;
  196. public const uint gmfiInputMouse = 0x00000004;
  197. public const uint gmfiInputMouseMove = 0x00000008;
  198. public const uint gmfiChangeState = 0x00000010;
  199. public const uint gmfiChangeRect = 0x00000020;
  200. public const uint gmfiChangeStyle = 0x00000040;
  201. public const uint gmfiAll = 0xFFFFFFFF;
  202. public void GetFilter(ref uint nFilter)
  203. {
  204. uint hr = BaseGadgetGetFilter(nFilter);
  205. if (f(hr)) {
  206. throw new DUserException(hr);
  207. }
  208. }
  209. [dllimport("DUser.dll", EntryPoint="BaseGadgetSetFilter", SetLastError=true)]
  210. public static extern uint BaseGadgetSetFilter(uint nNewFilter, uint nMask);
  211. public void SetFilter(uint nNewFilter, uint nMask)
  212. {
  213. uint hr = BaseGadgetSetFilter(nNewFilter, nMask);
  214. if (f(hr)) {
  215. throw new DUserException(hr);
  216. }
  217. }
  218. [dllimport("DUser.dll", EntryPoint="BaseGadgetAddHandler", SetLastError=true)]
  219. public static extern uint BaseGadgetAddHandler(int nMsg, int pgbHandler);
  220. public void AddHandler(int nMsg, BaseGadget vb)
  221. {
  222. uint hr = BaseGadgetAddHandler(nMsg, h(vb));
  223. if (f(hr)) {
  224. throw new DUserException(hr);
  225. }
  226. }
  227. [dllimport("DUser.dll", EntryPoint="BaseGadgetRemoveHandler", SetLastError=true)]
  228. public static extern uint BaseGadgetRemoveHandler(int nMsg, int pgbHandler);
  229. public void RemoveHandler(int nMsg, BaseGadget vb)
  230. {
  231. uint hr = BaseGadgetRemoveHandler(nMsg, h(vb));
  232. if (f(hr)) {
  233. throw new DUserException(hr);
  234. }
  235. }
  236. }
  237. //---------------------------------------------------------------------------
  238. //
  239. // Stub class MsgGadget
  240. //
  241. class MsgGadget : BaseGadget
  242. {
  243. private static int idMsgGadget;
  244. public static void InitMsgGadget()
  245. {
  246. idMsgGadget = Common.FindGadgetClass("MsgGadgetBridge", 1);
  247. if (idMsgGadget == 0) {
  248. throw new DUserException(Common.GetLastError(), "Unable to find registered MsgGadget");
  249. }
  250. }
  251. [dllimport("DUserCP.dll")]
  252. protected static extern uint SMsgGadgetOnEvent(Common.EventMsg pmsg);
  253. public override uint OnEvent(Common.EventMsg pmsg)
  254. {
  255. return SMsgGadgetOnEvent(pmsg);
  256. }
  257. }
  258. //---------------------------------------------------------------------------
  259. //
  260. // Stub class Extension
  261. //
  262. class Extension : MsgGadget
  263. {
  264. private static int idExtension;
  265. public static void InitExtension()
  266. {
  267. idExtension = Common.FindGadgetClass("ExtensionBridge", 1);
  268. if (idExtension == 0) {
  269. throw new System.SystemException("Unable to find registered Extension");
  270. }
  271. }
  272. [dllimport("DUser.dll", EntryPoint="ExtensionOnRemoveExisting", SetLastError=true)]
  273. public static extern int ExtensionOnRemoveExisting();
  274. [dllimport("DUser.dll", EntryPoint="ExtensionOnDestroySubject", SetLastError=true)]
  275. public static extern int ExtensionOnDestroySubject();
  276. [dllimport("DUser.dll", EntryPoint="ExtensionOnAsyncDestroy", SetLastError=true)]
  277. public static extern int ExtensionOnAsyncDestroy();
  278. }
  279. //---------------------------------------------------------------------------
  280. //
  281. // Stub class DropTarget
  282. //
  283. class DropTarget : Extension
  284. {
  285. private static int idDropTarget;
  286. public static void InitDropTarget()
  287. {
  288. idDropTarget = Common.FindGadgetClass("DropTargetBridge", 1);
  289. if (idDropTarget == 0) {
  290. throw new System.SystemException("Unable to find registered DropTarget");
  291. }
  292. }
  293. }
  294. //---------------------------------------------------------------------------
  295. //
  296. // Stub class Visual
  297. //
  298. class Visual : BaseGadget
  299. {
  300. private static int idVisual;
  301. public static void InitVisual()
  302. {
  303. idVisual = Common.FindGadgetClass("VisualBridge", 1);
  304. if (idVisual == 0) {
  305. throw new System.SystemException("Unable to find registered Visual");
  306. }
  307. }
  308. public class VisualCI : Common.ContructInfo
  309. {
  310. public int pgadParent;
  311. };
  312. public Visual(Visual vParent)
  313. {
  314. CommonBuild(vParent.pgad, idVisual);
  315. }
  316. public Visual(Visual vParent, int idClass)
  317. {
  318. CommonBuild(vParent.pgad, idClass);
  319. }
  320. public Visual(HGadget gadParent)
  321. {
  322. CommonBuild(Common.CastGadgetDirect(gadParent.hgad), idVisual);
  323. }
  324. public Visual(HGadget gadParent, int idClass)
  325. {
  326. CommonBuild(Common.CastGadgetDirect(gadParent.hgad), idClass);
  327. }
  328. protected Visual(int pgv)
  329. {
  330. this.pgad = pgv;
  331. }
  332. private void CommonBuild(int pgadParent, int idClass)
  333. {
  334. VisualCI ci = new VisualCI();
  335. ci.pgadParent = pgadParent;
  336. int pgvThis = Common.BuildBridgeGadget(idClass, ci,
  337. new Common.GadgetEventProc(this.RawEventProc), new Common.GadgetMethodProc(this.RawMethodProc));
  338. //int pgvThis = Common.BuildGadget(idClass, ci);
  339. if (pgvThis != 0) {
  340. this.pgad = pgvThis;
  341. } else {
  342. throw new DUserException(Common.GetLastError(), "Unable to create new Visual");
  343. }
  344. }
  345. [dllimport("DUserCP.dll")]
  346. public static extern uint SVisualOnEvent(Common.EventMsg pmsg);
  347. public override uint OnEvent(Common.EventMsg pmsg)
  348. {
  349. return SVisualOnEvent(pmsg);
  350. }
  351. public enum EOrder
  352. {
  353. voAny = 0,
  354. voBefore = 1,
  355. voBehind = 2,
  356. voTop = 3,
  357. voBottom = 4,
  358. };
  359. [dllimport("DUser.dll", EntryPoint="VisualSetOrder", SetLastError=true)]
  360. public static extern uint VisualSetOrder(int pgvThis, int pgvOther, uint nCmd);
  361. public void SetOrder(Visual vOther, EOrder o)
  362. {
  363. uint hr = VisualSetOrder(this.pgad, h(vOther), (uint) o);
  364. if (f(hr)) {
  365. throw new DUserException(hr);
  366. }
  367. }
  368. [dllimport("DUser.dll", EntryPoint="VisualSetParent", SetLastError=true)]
  369. public static extern uint VisualSetParent(int pgvThis, int pgvParent, int pgvOther, uint nCmd);
  370. public void SetParent(Visual vParent, Visual vOther, uint nCmd)
  371. {
  372. uint hr = VisualSetParent(this.pgad, h(vParent), h(vOther), nCmd);
  373. if (f(hr)) {
  374. throw new DUserException(hr);
  375. }
  376. }
  377. public enum EGadget
  378. {
  379. vgParent = 0,
  380. vgNext = 1,
  381. vgPrev = 2,
  382. vgTopChild = 3,
  383. vgBottomChild = 4,
  384. vgRoot = 5,
  385. };
  386. [dllimport("DUser.dll", EntryPoint="VisualGetGadget", SetLastError=true)]
  387. public static extern uint VisualGetGadget(int pgvThis, uint nCmd, [@out] int ppgv);
  388. public Visual GetGadget(EGadget nCmd)
  389. {
  390. int pgv = 0;
  391. uint hr = VisualGetGadget(this.pgad, (uint) nCmd, pgv);
  392. if (f(hr)) {
  393. throw new DUserException(hr);
  394. }
  395. return new Visual(pgv);
  396. }
  397. public const uint gsRelative = 0x00000001;
  398. public const uint gsVisible = 0x00000002;
  399. public const uint gsEnabled = 0x00000004;
  400. public const uint gsBuffered = 0x00000008;
  401. public const uint gsAllowSubClass = 0x00000010;
  402. public const uint gsKeyboardFocus = 0x00000020;
  403. public const uint gsMouseFocus = 0x00000040;
  404. public const uint gsClipInside = 0x00000080;
  405. public const uint gsClipSiblings = 0x00000100;
  406. public const uint gsHRedraw = 0x00000200;
  407. public const uint gsVRedraw = 0x00000400;
  408. public const uint gsOpaque = 0x00000800;
  409. public const uint gsZeroOrigin = 0x00001000;
  410. public const uint gsCustomHitTest = 0x00002000;
  411. public const uint gsAdaptor = 0x00004000;
  412. public const uint gsCached = 0x00008000;
  413. [dllimport("DUser.dll", EntryPoint="VisualGetStyle", SetLastError=true)]
  414. public static extern uint VisualGetStyle(int pgvThis, [@out] uint pnStyle);
  415. public uint GetStyle()
  416. {
  417. uint nStyle = 0;
  418. uint hr = VisualGetStyle(this.pgad, nStyle);
  419. if (f(hr)) {
  420. throw new DUserException(hr);
  421. }
  422. return nStyle;
  423. }
  424. [dllimport("DUser.dll", EntryPoint="VisualSetStyle", SetLastError=true)]
  425. public static extern uint VisualSetStyle(int pgvThis, uint nNewStyle, uint nMask);
  426. public void SetStyle(uint nNewStyle, uint nMask)
  427. {
  428. uint hr = VisualSetStyle(this.pgad, nNewStyle, nMask);
  429. if (f(hr)) {
  430. throw new DUserException(hr);
  431. }
  432. }
  433. [dllimport("DUser.dll", EntryPoint="VisualSetKeyboardFocus", SetLastError=true)]
  434. public static extern uint VisualSetKeyboardFocus(int pgvThis);
  435. public void SetKeyboardFocus()
  436. {
  437. uint hr = VisualSetKeyboardFocus(this.pgad);
  438. if (f(hr)) {
  439. throw new DUserException(hr);
  440. }
  441. }
  442. [dllimport("DUser.dll", EntryPoint="VisualIsParentChainStyle", SetLastError=true)]
  443. public static extern uint VisualIsParentChainStyle(int pgvThis, uint nStyle, [@out] int pfResult, uint nFlags);
  444. [dllimport("DUser.dll", EntryPoint="VisualGetProperty", SetLastError=true)]
  445. public static extern uint VisualGetProperty(int pgvThis, int id, [@out] int ppvValue);
  446. public int GetProperty(int id)
  447. {
  448. int pvValue = 0;
  449. uint hr = VisualGetProperty(this.pgad, id, pvValue);
  450. if (f(hr)) {
  451. throw new DUserException(hr);
  452. }
  453. return pvValue;
  454. }
  455. [dllimport("DUser.dll", EntryPoint="VisualSetProperty", SetLastError=true)]
  456. public static extern uint VisualSetProperty(int pgvThis, int id, int pvValue);
  457. public void SetProperty(int id, int pvValue)
  458. {
  459. uint hr = VisualSetProperty(this.pgad, id, pvValue);
  460. if (f(hr)) {
  461. throw new DUserException(hr);
  462. }
  463. }
  464. [dllimport("DUser.dll", EntryPoint="VisualRemoveProperty", SetLastError=true)]
  465. public static extern uint VisualRemoveProperty(int pgvThis, int id);
  466. public void RemoveProperty(int id)
  467. {
  468. uint hr = VisualRemoveProperty(this.pgad, id);
  469. if (f(hr)) {
  470. throw new DUserException(hr);
  471. }
  472. }
  473. [dllimport("DUser.dll", EntryPoint="VisualInvalidate", SetLastError=true)]
  474. public static extern uint VisualInvalidate(int pgvThis);
  475. public void Invalidate()
  476. {
  477. uint hr = VisualInvalidate(this.pgad);
  478. if (f(hr)) {
  479. throw new DUserException(hr);
  480. }
  481. }
  482. [dllimport("DUser.dll", EntryPoint="VisualSetFillI", SetLastError=true)]
  483. public static extern uint VisualSetFillI(int pgvThis, int hbrFill, byte bAlpha, int w, int h);
  484. public void SetFill(int hbrFill, byte bAlpha)
  485. {
  486. uint hr = VisualSetFillI(this.pgad, hbrFill, bAlpha, 0, 0);
  487. if (f(hr)) {
  488. throw new DUserException(hr);
  489. }
  490. }
  491. [dllimport("DUser.dll", EntryPoint="VisualGetScale", SetLastError=true)]
  492. public static extern uint VisualGetScale(int pgvThis, [@out] float pflX, [@out] float pflY);
  493. public void GetScale(ref float flX, ref float flY)
  494. {
  495. uint hr = VisualGetScale(this.pgad, flX, flY);
  496. if (f(hr)) {
  497. throw new DUserException(hr);
  498. }
  499. }
  500. [dllimport("DUser.dll", EntryPoint="VisualSetScale", SetLastError=true)]
  501. public static extern uint VisualSetScale(int pgvThis, float flX, float flY);
  502. public void VisualSetScale(float flX, float flY)
  503. {
  504. uint hr = VisualSetScale(this.pgad, flX, flY);
  505. if (f(hr)) {
  506. throw new DUserException(hr);
  507. }
  508. }
  509. [dllimport("DUser.dll", EntryPoint="VisualGetRotation", SetLastError=true)]
  510. public static extern uint VisualGetRotation(int pgvThis, [@out] float pflRotationRad);
  511. public void GetRotation(ref float flRotationRad)
  512. {
  513. uint hr = VisualGetRotation(this.pgad, flRotationRad);
  514. if (f(hr)) {
  515. throw new DUserException(hr);
  516. }
  517. }
  518. [dllimport("DUser.dll", EntryPoint="VisualSetRotation", SetLastError=true)]
  519. public static extern uint VisualSetRotation(int pgvThis, float flRotationRad);
  520. public void SetRotation(float flRotationRad)
  521. {
  522. uint hr = VisualSetRotation(this.pgad, flRotationRad);
  523. if (f(hr)) {
  524. throw new DUserException(hr);
  525. }
  526. }
  527. [dllimport("DUser.dll", EntryPoint="VisualGetCenterPoint", SetLastError=true)]
  528. public static extern uint VisualGetCenterPoint(int pgvThis, [@out] float pflX, [@out] float pflY);
  529. public void GetCenterPoint(ref float flX, ref float flY)
  530. {
  531. uint hr = VisualGetCenterPoint(this.pgad, flX, flY);
  532. if (f(hr)) {
  533. throw new DUserException(hr);
  534. }
  535. }
  536. [dllimport("DUser.dll", EntryPoint="VisualSetCenterPoint", SetLastError=true)]
  537. public static extern uint VisualSetCenterPoint(int pgvThis, float flX, float flY);
  538. public void SetCenterPoint(float flX, float flY)
  539. {
  540. uint hr = VisualSetCenterPoint(this.pgad, flX, flY);
  541. if (f(hr)) {
  542. throw new DUserException(hr);
  543. }
  544. }
  545. [System.Runtime.InteropServices.ComVisible(false), sysstruct(format=Common.StructFormat.Auto)]
  546. public class BUFFER_INFO
  547. {
  548. public uint cbSize;
  549. public uint nMask;
  550. public uint nStyle;
  551. public byte bAlpha;
  552. }
  553. [dllimport("DUser.dll", EntryPoint="VisualGetBufferInfo", SetLastError=true)]
  554. public static extern uint VisualGetBufferInfo(int pgvThis, [@out] BUFFER_INFO pbi);
  555. [dllimport("DUser.dll", EntryPoint="VisualSetBufferInfo", SetLastError=true)]
  556. public static extern uint VisualSetBufferInfo(int pgvThis, BUFFER_INFO pbi);
  557. [dllimport("DUser.dll", EntryPoint="VisualGetSize", SetLastError=true)]
  558. public static extern uint VisualGetSize(int pgvThis, [@out] Common.SIZE psizeLogicalPxl);
  559. public const uint sgrMove = 0x00000001;
  560. public const uint sgrSize = 0x00000002;
  561. public const uint sgrClient = 0x00000004;
  562. public const uint sgrParent = 0x00000008;
  563. [dllimport("DUser.dll", EntryPoint="VisualGetRect", SetLastError=true)]
  564. public static extern uint VisualGetRect(int pgvThis, uint nFlags, [@out] Common.RECT prcPxl);
  565. public void GetRect(uint nFlags, ref Common.RECT rcPxl)
  566. {
  567. uint hr = VisualGetRect(this.pgad, nFlags, rcPxl);
  568. if (f(hr)) {
  569. throw new DUserException(hr);
  570. }
  571. }
  572. [dllimport("DUser.dll", EntryPoint="VisualSetRect", SetLastError=true)]
  573. public static extern uint VisualSetRect(int pgvThis, uint nFlags, Common.RECT prcPxl);
  574. public void SetRect(uint nFlags, Common.RECT rc)
  575. {
  576. uint hr = VisualSetRect(this.pgad, nFlags, rc);
  577. if (f(hr)) {
  578. throw new DUserException(hr);
  579. }
  580. }
  581. public void SetRect(uint nFlags, int x, int y, int w, int h)
  582. {
  583. Common.RECT rc = new Common.RECT();
  584. rc.left = x;
  585. rc.top = y;
  586. rc.right = x + w;
  587. rc.bottom = y + h;
  588. uint hr = VisualSetRect(this.pgad, nFlags, rc);
  589. if (f(hr)) {
  590. throw new DUserException(hr);
  591. }
  592. }
  593. [dllimport("DUser.dll", EntryPoint="VisualMapPoints", SetLastError=true)]
  594. public static extern uint VisualMapPoints(int pgvThis, Visual pgvTo, [@out] Common.POINT rgptClientPxl, int cPts);
  595. }
  596. //---------------------------------------------------------------------------
  597. //
  598. // Stub class Root
  599. //
  600. class Root : Visual
  601. {
  602. private static int idRoot;
  603. public static void InitRoot()
  604. {
  605. idRoot = Common.FindGadgetClass("RootBridge", 1);
  606. if (idRoot == 0) {
  607. throw new DUserException(Common.GetLastError(), "Unable to find registered Root");
  608. }
  609. }
  610. public Root(Visual vParent) : base(vParent, idRoot)
  611. {
  612. }
  613. [dllimport("DUserCP.dll")]
  614. public static extern uint SRootOnEvent(Common.EventMsg pmsg);
  615. public override uint OnEvent(Common.EventMsg pmsg)
  616. {
  617. return SRootOnEvent(pmsg);
  618. }
  619. [dllimport("DUser.dll", EntryPoint="RootGetFocus", SetLastError=true)]
  620. public static extern uint RootGetFocus(int pgvThis, [@out] int ppgvFocus);
  621. public Visual GetFocus()
  622. {
  623. int pgvFocus = 0;
  624. uint hr = RootGetFocus(this.pgad, pgvFocus);
  625. if (f(hr)) {
  626. throw new DUserException(hr);
  627. }
  628. return new Visual(pgvFocus);
  629. }
  630. [dllimport("DUser.dll", EntryPoint="RootFindFromPoint", SetLastError=true)]
  631. public static extern uint RootFindFromPoint(int pgvThis, Common.POINT ptContainerPxl, uint nFlags, [@out] Common.POINT pptClientPxl, [@out] int ppgvFound);
  632. public void FindFromPoint(Common.POINT ptContainerPxl, uint nFlags, ref Common.POINT ptClientPxl, ref Visual vFound)
  633. {
  634. int pgvFound = 0;
  635. uint hr = RootFindFromPoint(this.pgad, ptContainerPxl, nFlags, ptClientPxl, pgvFound);
  636. if (f(hr)) {
  637. throw new DUserException(hr);
  638. }
  639. vFound = new Visual(pgvFound);
  640. }
  641. [System.Runtime.InteropServices.ComVisible(false), sysstruct(format=Common.StructFormat.Auto)]
  642. public class ROOT_INFO
  643. {
  644. public uint cbSize;
  645. public uint nMask;
  646. public uint nOptions;
  647. public uint nSurface;
  648. public uint nDropTarget;
  649. public int pal;
  650. }
  651. [dllimport("DUser.dll", EntryPoint="RootGetRootInfo", SetLastError=true)]
  652. public static extern uint RootGetRootInfo(int pgvThis, ROOT_INFO pri);
  653. public void GetRootInfo(ref ROOT_INFO ri)
  654. {
  655. uint hr = RootGetRootInfo(this.pgad, ri);
  656. if (f(hr)) {
  657. throw new DUserException(hr);
  658. }
  659. }
  660. [dllimport("DUser.dll", EntryPoint="RootSetRootInfo", SetLastError=true)]
  661. public static extern uint RootSetRootInfo(int pgvThis, ROOT_INFO pri);
  662. public void SetRootInfo(ROOT_INFO ri)
  663. {
  664. uint hr = RootSetRootInfo(this.pgad, ri);
  665. if (f(hr)) {
  666. throw new DUserException(hr);
  667. }
  668. }
  669. }
  670. }