XplatUIWin32.cs 39 KB

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