XplatUIWin32.cs 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162
  1. // Permission is hereby granted, free of charge, to any person obtaining
  2. // a copy of this software and associated documentation files (the
  3. // "Software"), to deal in the Software without restriction, including
  4. // without limitation the rights to use, copy, modify, merge, publish,
  5. // distribute, sublicense, and/or sell copies of the Software, and to
  6. // permit persons to whom the Software is furnished to do so, subject to
  7. // the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be
  10. // included in all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. //
  20. // Copyright (c) 2004 Novell, Inc.
  21. //
  22. // Authors:
  23. // Peter Bartok [email protected]
  24. //
  25. //
  26. // $Revision: 1.28 $
  27. // $Modtime: $
  28. // $Log: XplatUIWin32.cs,v $
  29. // Revision 1.28 2004/08/23 19:39:30 pbartok
  30. // - Added method to move mouse cursor
  31. //
  32. // Revision 1.27 2004/08/21 20:51:27 pbartok
  33. // - Added method to get default display size
  34. //
  35. // Revision 1.26 2004/08/21 20:23:56 pbartok
  36. // - Added method to query current grab state
  37. // - Added argument to allow confining a grab to a window
  38. //
  39. // Revision 1.25 2004/08/21 18:35:38 pbartok
  40. // - Fixed bug with Async message handling
  41. // - Implemented getting the ModifierKeys
  42. //
  43. // Revision 1.24 2004/08/21 17:31:21 pbartok
  44. // - Drivers now return proper mouse state
  45. //
  46. // Revision 1.23 2004/08/20 20:39:07 pbartok
  47. // - Added jackson's Async code from X11 to Win32
  48. //
  49. // Revision 1.22 2004/08/20 20:02:45 pbartok
  50. // - Added method for setting the background color
  51. // - Added handling for erasing the window background
  52. //
  53. // Revision 1.21 2004/08/20 19:14:35 jackson
  54. // Expose functionality to send async messages through the driver
  55. //
  56. // Revision 1.20 2004/08/20 01:37:47 pbartok
  57. // - Added generation of MouseEnter, MouseLeave and MouseHover events
  58. // - Added cleanup on EndPaint
  59. //
  60. // Revision 1.19 2004/08/18 19:16:53 jordi
  61. // Move colors to a table
  62. //
  63. // Revision 1.18 2004/08/17 21:24:03 pbartok
  64. // - Finished IsVisible
  65. // - Added Win32GetWindowPlacement
  66. //
  67. // Revision 1.17 2004/08/13 21:42:15 pbartok
  68. // - Changed signature for GetCursorPos
  69. //
  70. // Revision 1.16 2004/08/13 19:00:15 jordi
  71. // implements PointToClient (ScreenToClient)
  72. //
  73. // Revision 1.15 2004/08/13 18:53:57 pbartok
  74. // - Changed GetWindowPos to also provide client area size
  75. // - Fixed broken prototypes for several win32 functions
  76. //
  77. // Revision 1.14 2004/08/12 22:59:03 pbartok
  78. // - Implemented method to get current mouse position
  79. //
  80. // Revision 1.13 2004/08/11 22:20:59 pbartok
  81. // - Signature fixes
  82. //
  83. // Revision 1.12 2004/08/11 19:41:38 jordi
  84. // Fixes ClientRect
  85. //
  86. // Revision 1.11 2004/08/11 19:19:44 pbartok
  87. // - We had SetWindowPos and MoveWindow to set window positions and size,
  88. // removed MoveWindow. We have GetWindowPos, so it made sense to keep
  89. // SetWindowPos as matching counterpart
  90. // - Added some X11 sanity checking
  91. //
  92. // Revision 1.10 2004/08/11 18:55:46 pbartok
  93. // - Added method to calculate difference between decorated window and raw
  94. // client area
  95. //
  96. // Revision 1.9 2004/08/10 18:47:16 jordi
  97. // Calls InvalidateRect before UpdateWindow
  98. //
  99. // Revision 1.8 2004/08/10 17:36:17 pbartok
  100. // - Implemented several methods
  101. //
  102. // Revision 1.7 2004/08/09 20:55:59 pbartok
  103. // - Removed Run method, was only required for initial development
  104. //
  105. // Revision 1.6 2004/08/09 20:51:25 pbartok
  106. // - Implemented GrabWindow/ReleaseWindow methods to allow pointer capture
  107. //
  108. // Revision 1.5 2004/08/09 16:05:16 jackson
  109. // These properties are handled by the theme now.
  110. //
  111. // Revision 1.4 2004/08/06 15:53:39 jordi
  112. // X11 keyboard navigation
  113. //
  114. // Revision 1.3 2004/08/04 20:11:24 pbartok
  115. // - Added Invalidate handling
  116. //
  117. // Revision 1.2 2004/07/21 16:19:17 jordi
  118. // LinkLabel control implementation
  119. //
  120. // Revision 1.1 2004/07/09 05:21:25 pbartok
  121. // - Initial check-in
  122. //
  123. //
  124. // NOT COMPLETE
  125. using System;
  126. using System.Drawing;
  127. using System.ComponentModel;
  128. using System.Collections;
  129. using System.Diagnostics;
  130. using System.Runtime.InteropServices;
  131. /// Win32 Version
  132. namespace System.Windows.Forms {
  133. internal class XplatUIWin32 : XplatUIDriver {
  134. #region Local Variables
  135. private static XplatUIWin32 instance;
  136. private static int ref_count;
  137. private static IntPtr FosterParent;
  138. internal static MouseButtons mouse_state;
  139. internal static Point mouse_position;
  140. internal static bool grab_confined;
  141. internal static IntPtr grab_hwnd;
  142. internal static Rectangle grab_area;
  143. internal static WndProc wnd_proc;
  144. internal static IntPtr prev_mouse_hwnd;
  145. internal static bool themes_enabled;
  146. private static Hashtable handle_data;
  147. #endregion // Local Variables
  148. #region Private Structs
  149. [StructLayout(LayoutKind.Sequential)]
  150. private struct WNDCLASS {
  151. internal int style;
  152. internal WndProc lpfnWndProc;
  153. internal int cbClsExtra;
  154. internal int cbWndExtra;
  155. internal IntPtr hInstance;
  156. internal IntPtr hIcon;
  157. internal IntPtr hCursor;
  158. internal IntPtr hbrBackground;
  159. internal string lpszMenuName;
  160. internal string lpszClassName;
  161. }
  162. [StructLayout(LayoutKind.Sequential)]
  163. private struct RECT {
  164. internal int left;
  165. internal int top;
  166. internal int right;
  167. internal int bottom;
  168. }
  169. [StructLayout(LayoutKind.Sequential)]
  170. private struct POINT {
  171. internal int x;
  172. internal int y;
  173. }
  174. internal enum WindowPlacementFlags {
  175. SW_HIDE = 0,
  176. SW_SHOWNORMAL = 1,
  177. SW_NORMAL = 1,
  178. SW_SHOWMINIMIZED = 2,
  179. SW_SHOWMAXIMIZED = 3,
  180. SW_MAXIMIZE = 3,
  181. SW_SHOWNOACTIVATE = 4,
  182. SW_SHOW = 5,
  183. SW_MINIMIZE = 6,
  184. SW_SHOWMINNOACTIVE = 7,
  185. SW_SHOWNA = 8,
  186. SW_RESTORE = 9,
  187. SW_SHOWDEFAULT = 10,
  188. SW_FORCEMINIMIZE = 11,
  189. SW_MAX = 11
  190. }
  191. [StructLayout(LayoutKind.Sequential)]
  192. private struct WINDOWPLACEMENT {
  193. internal uint length;
  194. internal uint flags;
  195. internal WindowPlacementFlags showCmd;
  196. internal POINT ptMinPosition;
  197. internal POINT ptMaxPosition;
  198. internal RECT rcNormalPosition;
  199. }
  200. [Flags]
  201. private enum TMEFlags {
  202. TME_HOVER = 0x00000001,
  203. TME_LEAVE = 0x00000002,
  204. TME_QUERY = unchecked((int)0x40000000),
  205. TME_CANCEL = unchecked((int)0x80000000)
  206. }
  207. [StructLayout(LayoutKind.Sequential)]
  208. private struct TRACKMOUSEEVENT {
  209. internal int size;
  210. internal TMEFlags dwFlags;
  211. internal IntPtr hWnd;
  212. internal int dwHoverTime;
  213. }
  214. [StructLayout(LayoutKind.Sequential)]
  215. private struct PAINTSTRUCT {
  216. internal IntPtr hdc;
  217. internal int fErase;
  218. internal RECT rcPaint;
  219. internal int fRestore;
  220. internal int fIncUpdate;
  221. internal int Reserved1;
  222. internal int Reserved2;
  223. internal int Reserved3;
  224. internal int Reserved4;
  225. internal int Reserved5;
  226. internal int Reserved6;
  227. internal int Reserved7;
  228. internal int Reserved8;
  229. }
  230. internal enum ClassStyle {
  231. CS_VREDRAW = 0x00000001,
  232. CS_HREDRAW = 0x00000002,
  233. CS_KEYCVTWINDOW = 0x00000004,
  234. CS_DBLCLKS = 0x00000008,
  235. CS_OWNDC = 0x00000020,
  236. CS_CLASSDC = 0x00000040,
  237. CS_PARENTDC = 0x00000080,
  238. CS_NOKEYCVT = 0x00000100,
  239. CS_NOCLOSE = 0x00000200,
  240. CS_SAVEBITS = 0x00000800,
  241. CS_BYTEALIGNCLIENT = 0x00001000,
  242. CS_BYTEALIGNWINDOW = 0x00002000,
  243. CS_GLOBALCLASS = 0x00004000,
  244. CS_IME = 0x00010000
  245. }
  246. internal enum PeekMessageFlags {
  247. PM_NOREMOVE = 0x00000000,
  248. PM_REMOVE = 0x00000001,
  249. PM_NOYIELD = 0x00000002
  250. }
  251. internal enum VirtualKeys {
  252. VK_LBUTTON = 0x01,
  253. VK_RBUTTON = 0x02,
  254. VK_CANCEL = 0x03,
  255. VK_MBUTTON = 0x04,
  256. VK_XBUTTON1 = 0x05,
  257. VK_XBUTTON2 = 0x06,
  258. VK_BACK = 0x08,
  259. VK_TAB = 0x09,
  260. VK_CLEAR = 0x0C,
  261. VK_RETURN = 0x0D,
  262. VK_SHIFT = 0x10,
  263. VK_CONTROL = 0x11,
  264. VK_MENU = 0x12,
  265. VK_CAPITAL = 0x14,
  266. VK_ESCAPE = 0x1B,
  267. VK_SPACE = 0x20,
  268. VK_PRIOR = 0x21,
  269. VK_NEXT = 0x22,
  270. VK_END = 0x23,
  271. VK_HOME = 0x24,
  272. VK_LEFT = 0x25,
  273. VK_UP = 0x26,
  274. VK_RIGHT = 0x27,
  275. VK_DOWN = 0x28,
  276. VK_SELECT = 0x29,
  277. VK_EXECUTE = 0x2B,
  278. VK_SNAPSHOT = 0x2C,
  279. VK_HELP = 0x2F,
  280. VK_0 = 0x30,
  281. VK_1 = 0x31,
  282. VK_2 = 0x32,
  283. VK_3 = 0x33,
  284. VK_4 = 0x34,
  285. VK_5 = 0x35,
  286. VK_6 = 0x36,
  287. VK_7 = 0x37,
  288. VK_8 = 0x38,
  289. VK_9 = 0x39,
  290. VK_A = 0x41,
  291. VK_B = 0x42,
  292. VK_C = 0x43,
  293. VK_D = 0x44,
  294. VK_E = 0x45,
  295. VK_F = 0x46,
  296. VK_G = 0x47,
  297. VK_H = 0x48,
  298. VK_I = 0x49,
  299. VK_J = 0x4A,
  300. VK_K = 0x4B,
  301. VK_L = 0x4C,
  302. VK_M = 0x4D,
  303. VK_N = 0x4E,
  304. VK_O = 0x4F,
  305. VK_P = 0x50,
  306. VK_Q = 0x51,
  307. VK_R = 0x52,
  308. VK_S = 0x53,
  309. VK_T = 0x54,
  310. VK_U = 0x55,
  311. VK_V = 0x56,
  312. VK_W = 0x57,
  313. VK_X = 0x58,
  314. VK_Y = 0x59,
  315. VK_Z = 0x5A,
  316. VK_NUMPAD0 = 0x60,
  317. VK_NUMPAD1 = 0x61,
  318. VK_NUMPAD2 = 0x62,
  319. VK_NUMPAD3 = 0x63,
  320. VK_NUMPAD4 = 0x64,
  321. VK_NUMPAD5 = 0x65,
  322. VK_NUMPAD6 = 0x66,
  323. VK_NUMPAD7 = 0x67,
  324. VK_NUMPAD8 = 0x68,
  325. VK_NUMPAD9 = 0x69,
  326. VK_MULTIPLY = 0x6A,
  327. VK_ADD = 0x6B,
  328. VK_SEPARATOR = 0x6C,
  329. VK_SUBTRACT = 0x6D,
  330. VK_DECIMAL = 0x6E,
  331. VK_DIVIDE = 0x6F,
  332. VK_ATTN = 0xF6,
  333. VK_CRSEL = 0xF7,
  334. VK_EXSEL = 0xF8,
  335. VK_EREOF = 0xF9,
  336. VK_PLAY = 0xFA,
  337. VK_ZOOM = 0xFB,
  338. VK_NONAME = 0xFC,
  339. VK_PA1 = 0xFD,
  340. VK_OEM_CLEAR = 0xFE,
  341. VK_LWIN = 0x5B,
  342. VK_RWIN = 0x5C,
  343. VK_APPS = 0x5D,
  344. VK_LSHIFT = 0xA0,
  345. VK_RSHIFT = 0xA1,
  346. VK_LCONTROL = 0xA2,
  347. VK_RCONTROL = 0xA3,
  348. VK_LMENU = 0xA4,
  349. VK_RMENU = 0xA5
  350. }
  351. internal enum GetSysColorIndex {
  352. COLOR_SCROLLBAR =0,
  353. COLOR_BACKGROUND =1,
  354. COLOR_ACTIVECAPTION =2,
  355. COLOR_INACTIVECAPTION =3,
  356. COLOR_MENU =4,
  357. COLOR_WINDOW =5,
  358. COLOR_WINDOWFRAME =6,
  359. COLOR_MENUTEXT =7,
  360. COLOR_WINDOWTEXT =8,
  361. COLOR_CAPTIONTEXT =9,
  362. COLOR_ACTIVEBORDER =10,
  363. COLOR_INACTIVEBORDER =11,
  364. COLOR_APPWORKSPACE =12,
  365. COLOR_HIGHLIGHT =13,
  366. COLOR_HIGHLIGHTTEXT =14,
  367. COLOR_BTNFACE =15,
  368. COLOR_BTNSHADOW =16,
  369. COLOR_GRAYTEXT =17,
  370. COLOR_BTNTEXT =18,
  371. COLOR_INACTIVECAPTIONTEXT =19,
  372. COLOR_BTNHIGHLIGHT =20,
  373. COLOR_3DDKSHADOW =21,
  374. COLOR_3DLIGHT =22,
  375. COLOR_INFOTEXT =23,
  376. COLOR_INFOBK =24,
  377. COLOR_DESKTOP =1,
  378. COLOR_3DFACE =16,
  379. COLOR_3DSHADOW =16,
  380. COLOR_3DHIGHLIGHT =20,
  381. COLOR_3DHILIGHT =20,
  382. COLOR_BTNHILIGHT =20,
  383. COLOR_MAXVALUE =24,/* Maximum value */
  384. }
  385. private enum LoadCursorType {
  386. IDC_ARROW =32512,
  387. IDC_IBEAM =32513,
  388. IDC_WAIT =32514,
  389. IDC_CROSS =32515,
  390. IDC_UPARROW =32516,
  391. IDC_SIZE =32640,
  392. IDC_ICON =32641,
  393. IDC_SIZENWSE =32642,
  394. IDC_SIZENESW =32643,
  395. IDC_SIZEWE =32644,
  396. IDC_SIZENS =32645,
  397. IDC_SIZEALL =32646,
  398. IDC_NO =32648,
  399. IDC_HAND =32649,
  400. IDC_APPSTARTING =32650,
  401. IDC_HELP =32651
  402. }
  403. [Flags]
  404. private enum WindowLong {
  405. GWL_WNDPROC = -4,
  406. GWL_HINSTANCE = -6,
  407. GWL_HWNDPARENT = -8,
  408. GWL_STYLE = -16,
  409. GWL_EXSTYLE = -20,
  410. GWL_USERDATA = -21,
  411. GWL_ID = -12
  412. }
  413. [Flags]
  414. private enum LogBrushStyle {
  415. BS_SOLID = 0,
  416. BS_NULL = 1,
  417. BS_HATCHED = 2,
  418. BS_PATTERN = 3,
  419. BS_INDEXED = 4,
  420. BS_DIBPATTERN = 5,
  421. BS_DIBPATTERNPT = 6,
  422. BS_PATTERN8X8 = 7,
  423. BS_DIBPATTERN8X8 = 8,
  424. BS_MONOPATTERN = 9
  425. }
  426. [Flags]
  427. private enum LogBrushHatch {
  428. HS_HORIZONTAL = 0, /* ----- */
  429. HS_VERTICAL = 1, /* ||||| */
  430. HS_FDIAGONAL = 2, /* \\\\\ */
  431. HS_BDIAGONAL = 3, /* ///// */
  432. HS_CROSS = 4, /* +++++ */
  433. HS_DIAGCROSS = 5, /* xxxxx */
  434. }
  435. private struct COLORREF {
  436. internal byte B;
  437. internal byte G;
  438. internal byte R;
  439. internal byte A;
  440. }
  441. [StructLayout(LayoutKind.Sequential)]
  442. private struct LOGBRUSH {
  443. internal LogBrushStyle lbStyle;
  444. internal COLORREF lbColor;
  445. internal LogBrushHatch lbHatch;
  446. }
  447. #endregion
  448. #region Constructor & Destructor
  449. private XplatUIWin32() {
  450. WNDCLASS wndClass;
  451. bool result;
  452. // Handle singleton stuff first
  453. ref_count=0;
  454. // Now regular initialization
  455. mouse_state = MouseButtons.None;
  456. mouse_position = Point.Empty;
  457. themes_enabled = false;
  458. // Prepare 'our' window class
  459. wnd_proc = new WndProc(NativeWindow.WndProc);
  460. wndClass.style = (int)ClassStyle.CS_OWNDC;
  461. wndClass.lpfnWndProc = wnd_proc;
  462. wndClass.cbClsExtra = 0;
  463. wndClass.cbWndExtra = 0;
  464. wndClass.hbrBackground = IntPtr.Zero;
  465. wndClass.hCursor = Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
  466. wndClass.hIcon = IntPtr.Zero;
  467. wndClass.hInstance = IntPtr.Zero;
  468. wndClass.lpszClassName = XplatUI.DefaultClassName;
  469. wndClass.lpszMenuName = "";
  470. result=Win32RegisterClass(ref wndClass);
  471. if (result==false) {
  472. Win32MessageBox(IntPtr.Zero, "Could not register the "+XplatUI.DefaultClassName+" window class, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
  473. }
  474. FosterParent=Win32CreateWindow(0, "Static", "Foster Parent Window", (int)WindowStyles.WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
  475. if (FosterParent==IntPtr.Zero) {
  476. Win32MessageBox(IntPtr.Zero, "Could not create foster window, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
  477. }
  478. handle_data = new Hashtable ();
  479. }
  480. ~XplatUIWin32() {
  481. Console.WriteLine("XplatUI Destructor called");
  482. }
  483. #endregion // Constructor & Destructor
  484. #region Private Support Methods
  485. private static IntPtr DefWndProc(IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) {
  486. return Win32DefWindowProc(hWnd, msg, wParam, lParam);
  487. }
  488. private void EraseWindowBackground(IntPtr hWnd, IntPtr hDc) {
  489. IntPtr hbr;
  490. LOGBRUSH lb;
  491. uint argb;
  492. RECT rect;
  493. //msg.wParam
  494. argb = (uint)Win32GetWindowLong(hWnd, WindowLong.GWL_USERDATA);
  495. lb = new LOGBRUSH();
  496. lb.lbColor.B = (byte)((argb & 0xff0000)>>16);
  497. lb.lbColor.G = (byte)((argb & 0xff00)>>8);
  498. lb.lbColor.R = (byte)(argb & 0xff);
  499. lb.lbStyle = LogBrushStyle.BS_SOLID;
  500. hbr = Win32CreateBrushIndirect(ref lb);
  501. Win32GetClientRect(hWnd, out rect);
  502. Win32FillRect(hDc, ref rect, hbr);
  503. Win32DeleteObject(hbr);
  504. }
  505. #endregion // Private Support Methods
  506. #region Static Properties
  507. internal override Keys ModifierKeys {
  508. get {
  509. short state;
  510. Keys key_state;
  511. key_state = Keys.None;
  512. state = Win32GetKeyState(VirtualKeys.VK_SHIFT);
  513. if ((state & 0x8000) != 0) {
  514. key_state |= Keys.Shift;
  515. }
  516. state = Win32GetKeyState(VirtualKeys.VK_CONTROL);
  517. if ((state & 0x8000) != 0) {
  518. key_state |= Keys.Control;
  519. }
  520. return key_state;
  521. }
  522. }
  523. internal override MouseButtons MouseButtons {
  524. get {
  525. return mouse_state;
  526. }
  527. }
  528. internal override Point MousePosition {
  529. get {
  530. return mouse_position;
  531. }
  532. }
  533. internal override bool DropTarget {
  534. get {
  535. return false;
  536. }
  537. set {
  538. if (value) {
  539. throw new NotImplementedException("Need to figure out D'n'D for Win32");
  540. }
  541. }
  542. }
  543. #endregion // Static Properties
  544. #region Singleton Specific Code
  545. public static XplatUIWin32 GetInstance() {
  546. if (instance==null) {
  547. instance=new XplatUIWin32();
  548. }
  549. ref_count++;
  550. return instance;
  551. }
  552. public int Reference {
  553. get {
  554. return ref_count;
  555. }
  556. }
  557. #endregion
  558. #region Public Static Methods
  559. internal override IntPtr InitializeDriver() {
  560. mouse_state=MouseButtons.None;
  561. mouse_position=Point.Empty;
  562. Console.WriteLine("#region #line XplatUI Win32 Constructor called");
  563. return IntPtr.Zero;
  564. }
  565. internal override void ShutdownDriver(IntPtr token) {
  566. Console.WriteLine("XplatUIWin32 ShutdownDriver called");
  567. }
  568. internal void Version() {
  569. Console.WriteLine("Xplat version $revision: $");
  570. }
  571. internal override void Exit() {
  572. Win32PostQuitMessage(0);
  573. }
  574. internal override void GetDisplaySize(out Size size) {
  575. RECT rect;
  576. Win32GetWindowRect(Win32GetDesktopWindow(), out rect);
  577. size = new Size(rect.right - rect.left, rect.bottom - rect.top);
  578. }
  579. internal override void EnableThemes() {
  580. themes_enabled=true;
  581. }
  582. internal override IntPtr CreateWindow(CreateParams cp) {
  583. IntPtr WindowHandle;
  584. IntPtr ParentHandle;
  585. ParentHandle=cp.Parent;
  586. if ((ParentHandle==IntPtr.Zero) && (cp.Style & (int)WindowStyles.WS_CHILD)!=0) {
  587. // We need to use our foster parent window until this poor child gets it's parent assigned
  588. ParentHandle=FosterParent;
  589. }
  590. WindowHandle = Win32CreateWindow((uint)cp.ExStyle, cp.ClassName, cp.Caption, (uint)cp.Style, cp.X, cp.Y, cp.Width, cp.Height, ParentHandle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
  591. if (WindowHandle==IntPtr.Zero) {
  592. uint error = Win32GetLastError();
  593. Win32MessageBox(IntPtr.Zero, "Error : " + error.ToString(), "Failed to create window", 0);
  594. }
  595. Win32SetWindowLong(WindowHandle, WindowLong.GWL_USERDATA, (IntPtr)ThemeEngine.Current.DefaultControlBackColor.ToArgb());
  596. return WindowHandle;
  597. }
  598. internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
  599. CreateParams create_params = new CreateParams();
  600. create_params.Caption = "";
  601. create_params.X = X;
  602. create_params.Y = Y;
  603. create_params.Width = Width;
  604. create_params.Height = Height;
  605. create_params.ClassName=XplatUI.DefaultClassName;
  606. create_params.ClassStyle = 0;
  607. create_params.ExStyle=0;
  608. create_params.Parent=IntPtr.Zero;
  609. create_params.Param=0;
  610. return CreateWindow(create_params);
  611. }
  612. internal override void DestroyWindow(IntPtr handle) {
  613. Console.WriteLine("#region #line");
  614. return;
  615. }
  616. internal override void RefreshWindow(IntPtr handle) {
  617. Win32InvalidateRect(handle, IntPtr.Zero, true);
  618. Win32UpdateWindow(handle);
  619. }
  620. internal override void SetWindowBackground(IntPtr handle, Color color) {
  621. Win32SetWindowLong(handle, WindowLong.GWL_USERDATA, (IntPtr)color.ToArgb());
  622. }
  623. [MonoTODO("Add support for internal table of windows/DCs for cleanup")]
  624. internal override PaintEventArgs PaintEventStart(IntPtr handle) {
  625. IntPtr hdc;
  626. PAINTSTRUCT ps;
  627. PaintEventArgs paint_event;
  628. RECT rect;
  629. Rectangle clip_rect;
  630. clip_rect = new Rectangle();
  631. rect = new RECT();
  632. ps = new PAINTSTRUCT();
  633. if (Win32GetUpdateRect(handle, ref rect, false)) {
  634. HandleData data;
  635. hdc = Win32BeginPaint(handle, ref ps);
  636. data = (HandleData) handle_data [0];
  637. if (data == null) {
  638. data = new HandleData();
  639. handle_data[0] = data;
  640. }
  641. data.DeviceContext=(Object)ps;
  642. // FIXME: Figure out why the rectangle is always 0 size
  643. clip_rect = new Rectangle(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right-ps.rcPaint.left, ps.rcPaint.bottom-ps.rcPaint.top);
  644. // clip_rect = new Rectangle(rect.top, rect.left, rect.right-rect.left, rect.bottom-rect.top);
  645. if (ps.fErase!=0) {
  646. EraseWindowBackground(handle, hdc);
  647. }
  648. } else {
  649. hdc = Win32GetDC(handle);
  650. // FIXME: Add the DC to internal list
  651. clip_rect = new Rectangle(rect.top, rect.left, rect.right-rect.left, rect.bottom-rect.top);
  652. }
  653. paint_event = new PaintEventArgs(Graphics.FromHdc(hdc), clip_rect);
  654. return paint_event;
  655. }
  656. internal override void PaintEventEnd(IntPtr handle) {
  657. HandleData data;
  658. PAINTSTRUCT ps;
  659. PaintEventArgs paint_event;
  660. data = (HandleData) handle_data [0];
  661. if (data == null) {
  662. data = new HandleData();
  663. handle_data[0] = data;
  664. }
  665. //paint_event.Graphics.Dispose();
  666. ps = (PAINTSTRUCT)data.DeviceContext;
  667. Win32EndPaint(handle, ref ps);
  668. }
  669. internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
  670. Win32MoveWindow(handle, x, y, width, height, true);
  671. return;
  672. }
  673. internal override void GetWindowPos(IntPtr handle, out int x, out int y, out int width, out int height, out int client_width, out int client_height) {
  674. RECT rect;
  675. POINT pt;
  676. Win32GetWindowRect(handle, out rect);
  677. width = rect.right - rect.left;
  678. height = rect.bottom - rect.top;
  679. pt.x=rect.left;
  680. pt.y=rect.top;
  681. Win32ScreenToClient(Win32GetParent(handle), ref pt);
  682. x = pt.x;
  683. y = pt.y;
  684. Win32GetClientRect(handle, out rect);
  685. client_width = rect.right - rect.left;
  686. client_height = rect.bottom - rect.top;
  687. return;
  688. }
  689. internal override void Activate(IntPtr handle) {
  690. Win32SetActiveWindow(handle);
  691. }
  692. internal override void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
  693. RECT rect;
  694. rect.left=rc.Left;
  695. rect.top=rc.Top;
  696. rect.right=rc.Right;
  697. rect.bottom=rc.Bottom;
  698. Win32InvalidateRect(handle, ref rect, clear);
  699. }
  700. internal override IntPtr DefWndProc(ref Message msg) {
  701. msg.Result=Win32DefWindowProc(msg.HWnd, (Msg)msg.Msg, msg.WParam, msg.LParam);
  702. return msg.Result;
  703. }
  704. internal override void HandleException(Exception e) {
  705. StackTrace st = new StackTrace(e);
  706. Win32MessageBox(IntPtr.Zero, e.Message+st.ToString(), "Exception", 0);
  707. Console.WriteLine("{0}{1}", e.Message, st.ToString());
  708. }
  709. internal override void DoEvents() {
  710. MSG msg = new MSG();
  711. while (Win32PeekMessage(ref msg, IntPtr.Zero, 0, 0, (uint)PeekMessageFlags.PM_REMOVE)!=true) {
  712. if (msg.message==Msg.WM_PAINT) {
  713. XplatUI.TranslateMessage(ref msg);
  714. XplatUI.DispatchMessage(ref msg);
  715. }
  716. }
  717. }
  718. internal override bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
  719. return Win32PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
  720. }
  721. internal override bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
  722. HandleData data;
  723. bool result;
  724. data = (HandleData) handle_data [0];
  725. if ((data!=null) && data.GetMessage(ref msg)) {
  726. return true;
  727. }
  728. result = Win32GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
  729. // We need to fake WM_MOUSE_ENTER/WM_MOUSE_LEAVE
  730. switch (msg.message) {
  731. case Msg.WM_LBUTTONDOWN: {
  732. mouse_state |= MouseButtons.Left;
  733. break;
  734. }
  735. case Msg.WM_MBUTTONDOWN: {
  736. mouse_state |= MouseButtons.Middle;
  737. break;
  738. }
  739. case Msg.WM_RBUTTONDOWN: {
  740. mouse_state |= MouseButtons.Right;
  741. break;
  742. }
  743. case Msg.WM_LBUTTONUP: {
  744. mouse_state &= ~MouseButtons.Left;
  745. break;
  746. }
  747. case Msg.WM_MBUTTONUP: {
  748. mouse_state &= ~MouseButtons.Middle;
  749. break;
  750. }
  751. case Msg.WM_RBUTTONUP: {
  752. mouse_state &= ~MouseButtons.Right;
  753. break;
  754. }
  755. case Msg.WM_ERASEBKGND: {
  756. EraseWindowBackground(msg.hwnd, msg.wParam);
  757. break;
  758. }
  759. case Msg.WM_ASYNC_MESSAGE: {
  760. GCHandle handle = (GCHandle)msg.lParam;
  761. AsyncMethodData asyncdata = (AsyncMethodData) handle.Target;
  762. AsyncMethodResult asyncresult = asyncdata.Result.Target as AsyncMethodResult;
  763. object ret = asyncdata.Method.DynamicInvoke (asyncdata.Args);
  764. if (asyncresult != null) {
  765. asyncresult.Complete (ret);
  766. }
  767. handle.Free ();
  768. break;
  769. }
  770. case Msg.WM_MOUSEMOVE: {
  771. if (msg.hwnd != prev_mouse_hwnd) {
  772. TRACKMOUSEEVENT tme;
  773. if (data == null) {
  774. data = new HandleData();
  775. handle_data[0] = data;
  776. }
  777. // The current message will be sent out next time around
  778. data.StoreMessage(ref msg);
  779. // This is the message we want to send at this point
  780. msg.message = Msg.WM_MOUSE_ENTER;
  781. prev_mouse_hwnd = msg.hwnd;
  782. tme = new TRACKMOUSEEVENT();
  783. tme.size = Marshal.SizeOf(tme);
  784. tme.hWnd = msg.hwnd;
  785. tme.dwFlags = TMEFlags.TME_LEAVE | TMEFlags.TME_HOVER;
  786. Win32TrackMouseEvent(ref tme);
  787. return result;
  788. }
  789. break;
  790. }
  791. case Msg.WM_MOUSELEAVE: {
  792. prev_mouse_hwnd = IntPtr.Zero;
  793. msg.message=Msg.WM_MOUSE_LEAVE;
  794. break;
  795. }
  796. }
  797. return result;
  798. }
  799. internal override bool TranslateMessage(ref MSG msg) {
  800. return Win32TranslateMessage(ref msg);
  801. }
  802. internal override bool DispatchMessage(ref MSG msg) {
  803. return Win32DispatchMessage(ref msg);
  804. }
  805. internal override bool Text(IntPtr handle, string text) {
  806. Win32SetWindowText(handle, text);
  807. return true;
  808. }
  809. internal override bool SetVisible(IntPtr handle, bool visible) {
  810. Console.WriteLine("Setting window visibility: {0}", visible);
  811. return true;
  812. }
  813. internal override bool IsVisible(IntPtr handle) {
  814. WINDOWPLACEMENT wndpl;
  815. wndpl = new WINDOWPLACEMENT();
  816. wndpl.length=(uint)Marshal.SizeOf(wndpl);
  817. Win32GetWindowPlacement(handle, ref wndpl);
  818. if ((wndpl.showCmd == WindowPlacementFlags.SW_SHOWMINIMIZED)) {
  819. return false;
  820. }
  821. return true;
  822. }
  823. internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
  824. return Win32SetParent(handle, parent);
  825. }
  826. internal override IntPtr GetParent(IntPtr handle) {
  827. return Win32GetParent(handle);
  828. }
  829. internal override void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
  830. grab_hwnd = hWnd;
  831. Win32SetCapture(hWnd);
  832. }
  833. internal override void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
  834. hWnd = grab_hwnd;
  835. GrabConfined = grab_confined;
  836. GrabArea = grab_area;
  837. }
  838. internal override void ReleaseWindow(IntPtr hWnd) {
  839. Win32ReleaseCapture();
  840. grab_hwnd = IntPtr.Zero;
  841. }
  842. internal override bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, bool HasMenu, out Rectangle WindowRect) {
  843. RECT rect;
  844. rect.left=ClientRect.Left;
  845. rect.top=ClientRect.Top;
  846. rect.right=ClientRect.Right;
  847. rect.bottom=ClientRect.Bottom;
  848. if (!Win32AdjustWindowRectEx(ref rect, Style, HasMenu, 0)) {
  849. WindowRect = new Rectangle(ClientRect.Left, ClientRect.Top, ClientRect.Width, ClientRect.Height);
  850. return false;
  851. }
  852. WindowRect = new Rectangle(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
  853. return true;
  854. }
  855. internal override void SetCursorPos(IntPtr handle, int x, int y) {
  856. Win32SetCursorPos(x, y);
  857. }
  858. internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
  859. POINT pt;
  860. Win32GetCursorPos(out pt);
  861. if (handle!=IntPtr.Zero) {
  862. Win32ScreenToClient(handle, ref pt);
  863. }
  864. x=pt.x;
  865. y=pt.y;
  866. }
  867. internal override void ScreenToClient(IntPtr handle, ref int x, ref int y)
  868. {
  869. POINT pnt;
  870. pnt.x = x;
  871. pnt.y = y;
  872. Win32ScreenToClient (handle, ref pnt);
  873. x = pnt.x;
  874. y = pnt.y;
  875. }
  876. internal override void SendAsyncMethod (AsyncMethodData method)
  877. {
  878. Win32PostMessage(FosterParent, Msg.WM_ASYNC_MESSAGE, IntPtr.Zero, (IntPtr)GCHandle.Alloc (method));
  879. }
  880. // Santa's little helper
  881. static void Where() {
  882. Console.WriteLine("Here: {0}", new StackTrace().ToString());
  883. }
  884. #endregion // Public Static Methods
  885. #region Win32 Imports
  886. [DllImport ("kernel32.dll", EntryPoint="GetLastError", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  887. private extern static uint Win32GetLastError();
  888. [DllImport ("user32.dll", EntryPoint="CreateWindowExA", CallingConvention=CallingConvention.StdCall)]
  889. internal extern static IntPtr Win32CreateWindow(uint dwExStyle, string lpClassName, string lpWindowName, uint dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lParam);
  890. [DllImport ("user32.dll", EntryPoint="PeekMessageA", CallingConvention=CallingConvention.StdCall)]
  891. internal extern static bool Win32PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags);
  892. [DllImport ("user32.dll", EntryPoint="GetMessageA", CallingConvention=CallingConvention.StdCall)]
  893. internal extern static bool Win32GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax);
  894. [DllImport ("user32.dll", EntryPoint="TranslateMessage", CallingConvention=CallingConvention.StdCall)]
  895. internal extern static bool Win32TranslateMessage(ref MSG msg);
  896. [DllImport ("user32.dll", EntryPoint="DispatchMessageA", CallingConvention=CallingConvention.StdCall)]
  897. internal extern static bool Win32DispatchMessage(ref MSG msg);
  898. [DllImport ("user32.dll", EntryPoint="MoveWindow", CallingConvention=CallingConvention.StdCall)]
  899. internal extern static bool Win32MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
  900. [DllImport ("user32.dll", EntryPoint="SetWindowTextA", CallingConvention=CallingConvention.StdCall)]
  901. internal extern static bool Win32SetWindowText(IntPtr hWnd, string lpString);
  902. [DllImport ("user32.dll", EntryPoint="SetParent", CallingConvention=CallingConvention.StdCall)]
  903. internal extern static IntPtr Win32SetParent(IntPtr hWnd, IntPtr hParent);
  904. [DllImport ("user32.dll", EntryPoint="RegisterClassA", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  905. private extern static bool Win32RegisterClass(ref WNDCLASS wndClass);
  906. [DllImport ("user32.dll", EntryPoint="LoadCursorA", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  907. private extern static IntPtr Win32LoadCursor(IntPtr hInstance, LoadCursorType type);
  908. [DllImport ("user32.dll", EntryPoint="DefWindowProcA", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  909. private extern static IntPtr Win32DefWindowProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
  910. [DllImport ("user32.dll", EntryPoint="PostQuitMessage", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  911. private extern static IntPtr Win32PostQuitMessage(int nExitCode);
  912. [DllImport ("user32.dll", EntryPoint="UpdateWindow", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  913. private extern static IntPtr Win32UpdateWindow(IntPtr hWnd);
  914. [DllImport ("user32.dll", EntryPoint="GetUpdateRect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  915. private extern static bool Win32GetUpdateRect(IntPtr hWnd, ref RECT rect, bool erase);
  916. [DllImport ("user32.dll", EntryPoint="BeginPaint", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  917. private extern static IntPtr Win32BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
  918. [DllImport ("user32.dll", EntryPoint="EndPaint", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  919. private extern static bool Win32EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
  920. [DllImport ("user32.dll", EntryPoint="GetDC", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  921. private extern static IntPtr Win32GetDC(IntPtr hWnd);
  922. [DllImport ("user32.dll", EntryPoint="ReleaseDC", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  923. private extern static IntPtr Win32ReleaseDC(IntPtr hWnd, IntPtr hDC);
  924. [DllImport ("user32.dll", EntryPoint="MessageBoxA", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  925. private extern static IntPtr Win32MessageBox(IntPtr hParent, string pText, string pCaption, uint uType);
  926. [DllImport ("user32.dll", EntryPoint="InvalidateRect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  927. private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, ref RECT lpRect, bool bErase);
  928. [DllImport ("user32.dll", EntryPoint="InvalidateRect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  929. private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
  930. [DllImport ("user32.dll", EntryPoint="SetCapture", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  931. private extern static IntPtr Win32SetCapture(IntPtr hWnd);
  932. [DllImport ("user32.dll", EntryPoint="ReleaseCapture", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  933. private extern static IntPtr Win32ReleaseCapture();
  934. [DllImport ("user32.dll", EntryPoint="GetWindowRect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  935. private extern static IntPtr Win32GetWindowRect(IntPtr hWnd, out RECT rect);
  936. [DllImport ("user32.dll", EntryPoint="GetClientRect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  937. private extern static IntPtr Win32GetClientRect(IntPtr hWnd, out RECT rect);
  938. [DllImport ("user32.dll", EntryPoint="ScreenToClient", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  939. private extern static bool Win32ScreenToClient(IntPtr hWnd, ref POINT pt);
  940. [DllImport ("user32.dll", EntryPoint="GetParent", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  941. private extern static IntPtr Win32GetParent(IntPtr hWnd);
  942. [DllImport ("user32.dll", EntryPoint="SetActiveWindow", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  943. private extern static IntPtr Win32SetActiveWindow(IntPtr hWnd);
  944. [DllImport ("user32.dll", EntryPoint="PostQuitMessage", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  945. private extern static IntPtr Win32PostQuitMessage(IntPtr hWnd);
  946. [DllImport ("user32.dll", EntryPoint="AdjustWindowRectEx", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  947. private extern static bool Win32AdjustWindowRectEx(ref RECT lpRect, int dwStyle, bool bMenu, int dwExStyle);
  948. [DllImport ("user32.dll", EntryPoint="GetCursorPos", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  949. private extern static bool Win32GetCursorPos(out POINT lpPoint);
  950. [DllImport ("user32.dll", EntryPoint="SetCursorPos", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  951. private extern static bool Win32SetCursorPos(int x, int y);
  952. [DllImport ("user32.dll", EntryPoint="GetWindowPlacement", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  953. private extern static bool Win32GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
  954. [DllImport ("user32.dll", EntryPoint="TrackMouseEvent", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  955. private extern static bool Win32TrackMouseEvent(ref TRACKMOUSEEVENT tme);
  956. [DllImport ("gdi32.dll", EntryPoint="CreateBrushIndirect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  957. private extern static IntPtr Win32CreateBrushIndirect(ref LOGBRUSH lb);
  958. [DllImport ("user32.dll", EntryPoint="FillRect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  959. private extern static int Win32FillRect(IntPtr hdc, ref RECT rect, IntPtr hbr);
  960. [DllImport ("user32.dll", EntryPoint="SetWindowLong", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  961. private extern static IntPtr Win32SetWindowLong(IntPtr hwnd, WindowLong index, IntPtr value);
  962. [DllImport ("user32.dll", EntryPoint="GetWindowLong", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  963. private extern static IntPtr Win32GetWindowLong(IntPtr hwnd, WindowLong index);
  964. [DllImport ("gdi32.dll", EntryPoint="DeleteObject", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  965. private extern static bool Win32DeleteObject(IntPtr o);
  966. [DllImport ("user32.dll", EntryPoint="PostMessage", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  967. private extern static bool Win32PostMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
  968. [DllImport ("user32.dll", EntryPoint="GetKeyState", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  969. private extern static short Win32GetKeyState(VirtualKeys nVirtKey);
  970. [DllImport ("user32.dll", EntryPoint="GetDesktopWindow", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
  971. private extern static IntPtr Win32GetDesktopWindow();
  972. #endregion
  973. }
  974. }