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.

151 lines
5.2 KiB

  1. namespace DUser
  2. {
  3. using System;
  4. using System.Runtime.InteropServices;
  5. public class HGadget
  6. {
  7. public int hgad;
  8. public HGadget(int hwnd)
  9. {
  10. int hgad = CreateGadget(hwnd, gcHwndHost, new GADGETPROC(this.RawGadgetProc), 0);
  11. if (hgad != 0)
  12. {
  13. this.hgad = hgad;
  14. }
  15. else
  16. {
  17. uint error = Common.GetLastError();
  18. throw new System.SystemException("Unable to create new HGadget");
  19. }
  20. }
  21. public HGadget(HGadget gadParent)
  22. {
  23. int hgad = CreateGadget(gadParent.hgad, gcSimple,
  24. new GADGETPROC(this.RawGadgetProc), 0);
  25. if (hgad != 0)
  26. {
  27. this.hgad = hgad;
  28. }
  29. else
  30. {
  31. uint error = Common.GetLastError();
  32. throw new System.SystemException("Unable to create new HGadget");
  33. }
  34. }
  35. public static uint gprFailed = 0xFFFFFFFF;
  36. public static uint gprNotHandled = 0;
  37. public static uint gprComplete = 1;
  38. public static uint gprPartial = 2;
  39. public delegate uint GADGETPROC(int hgadCur, int pvCur, Common.EventMsg pmsg);
  40. public static uint gcHwndHost = 0x00000001;
  41. public static uint gcSimple = 0x00000005;
  42. [dllimport("duser.dll", EntryPoint="CreateGadget", SetLastError=true)]
  43. public static extern int CreateGadget(int hParent, uint nFlags, GADGETPROC pfn, int pvData);
  44. [dllimport("user32.dll")]
  45. public static extern int MessageBox(int h, string m, string c, int type);
  46. public virtual uint GadgetProc(Common.EventMsg pmsg)
  47. {
  48. /*
  49. switch (pmsg.nMsg)
  50. {
  51. case Common.gmInput:
  52. MessageBox(0, "gmInput", "Gadget::GadgetProc()", 0);
  53. break;
  54. case Common.gmChangeState:
  55. MessageBox(0, "gmChangeState", "Gadget::GadgetProc()", 0);
  56. break;
  57. }
  58. */
  59. return gprNotHandled;
  60. }
  61. [dllimport("kernel32.dll", EntryPoint="OutputDebugString")]
  62. public static extern void OutputDebugString(string s);
  63. private uint RawGadgetProc(int hgadCur, int pvCur, Common.EventMsg pmsg)
  64. {
  65. System.Text.StringBuilder sb = new System.Text.StringBuilder();
  66. sb.Append("hgad: ");
  67. sb.Append(pmsg.hgadMsg);
  68. sb.Append(" MSG: ");
  69. sb.Append(pmsg.nMsg);
  70. sb.Append('\n');
  71. OutputDebugString(sb.ToString());
  72. return this.GadgetProc(pmsg);
  73. }
  74. public static uint gmfiPaint = 0x00000001;
  75. public static uint gmfiInputKeyboard = 0x00000002;
  76. public static uint gmfiInputMouse = 0x00000004;
  77. public static uint gmfiInputMouseMove = 0x00000008;
  78. public static uint gmfiChangeState = 0x00000010;
  79. public static uint gmfiChangeRect = 0x00000020;
  80. public static uint gmfiChangeStyle = 0x00000040;
  81. public static uint gmfiAll = 0xFFFFFFFF;
  82. [dllimport("duser.dll", EntryPoint="SetGadgetMessageFilter")]
  83. public static extern bool SetGadgetMessageFilter(int hgadChange, int pvCookie, uint nNewFilter, uint nMask);
  84. public void SetMessageFilter(uint nNewFilter, uint nMask)
  85. {
  86. SetGadgetMessageFilter(this.hgad, 0, nNewFilter, nMask);
  87. }
  88. public const uint gsRelative = 0x00000001;
  89. public const uint gsVisible = 0x00000002;
  90. public const uint gsEnabled = 0x00000004;
  91. public const uint gsBuffered = 0x00000008;
  92. public const uint gsAllowSubClass = 0x00000010;
  93. public const uint gsKeyboardFocus = 0x00000020;
  94. public const uint gsMouseFocus = 0x00000040;
  95. public const uint gsClipInside = 0x00000080;
  96. public const uint gsClipSiblings = 0x00000100;
  97. public const uint gsHRedraw = 0x00000200;
  98. public const uint gsVRedraw = 0x00000400;
  99. public const uint gsOpaque = 0x00000800;
  100. public const uint gsZeroOrigin = 0x00001000;
  101. public const uint gsCustomHitTest = 0x00002000;
  102. public const uint gsAdaptor = 0x00004000;
  103. public const uint gsCached = 0x00008000;
  104. [dllimport("duser.dll", EntryPoint="SetGadgetStyle")]
  105. public static extern bool SetGadgetStyle(int hgadChange, uint nNewStyle, uint nMask);
  106. public bool SetStyle(uint nNewStyle, uint nMask)
  107. {
  108. return SetGadgetStyle(this.hgad, nNewStyle, nMask);
  109. }
  110. [dllimport("duser.dll", EntryPoint="SetGadgetFillI")]
  111. public static extern bool SetGadgetFill(int hgadChange, int hbr, byte bAlpha, int w, int h);
  112. public bool SetFill(int hbr)
  113. {
  114. return SetGadgetFill(this.hgad, hbr, 255, 0, 0);
  115. }
  116. public const uint sgrMove = 0x00000001;
  117. public const uint sgrSize = 0x00000002;
  118. public const uint sgrClient = 0x00000004;
  119. public const uint sgrParent = 0x00000008;
  120. [dllimport("duser.dll", EntryPoint="SetGadgetRect", SetLastError=true)]
  121. public static extern bool SetGadgetRect(int hgadChange, int x, int y, int w, int h, uint nFlags);
  122. public bool SetRect(int x, int y, int w, int h, uint nFlags)
  123. {
  124. return SetGadgetRect(this.hgad, x, y, w, h, nFlags);
  125. }
  126. }
  127. }