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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2004 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
31 using System.Drawing.Imaging;
32 using System.ComponentModel;
33 using System.Collections;
34 using System.Diagnostics;
36 using System.Runtime.InteropServices;
41 namespace System.Windows.Forms {
42 internal class XplatUIWin32 : XplatUIDriver {
43 #region Local Variables
44 private static XplatUIWin32 instance;
45 private static int ref_count;
46 private static IntPtr FosterParent;
48 internal static MouseButtons mouse_state;
49 internal static Point mouse_position;
50 internal static bool grab_confined;
51 internal static IntPtr grab_hwnd;
52 internal static Rectangle grab_area;
53 internal static WndProc wnd_proc;
54 internal static IntPtr prev_mouse_hwnd;
55 internal static IntPtr override_cursor;
57 internal static bool themes_enabled;
58 private Hashtable timer_list;
59 private static Queue message_queue;
60 private static IntPtr clip_magic = new IntPtr(27051977);
62 private static Win32DnD DnD;
63 #endregion // Local Variables
65 #region Private Structs
66 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
67 private struct WNDCLASS {
69 internal WndProc lpfnWndProc;
70 internal int cbClsExtra;
71 internal int cbWndExtra;
72 internal IntPtr hInstance;
73 internal IntPtr hIcon;
74 internal IntPtr hCursor;
75 internal IntPtr hbrBackground;
76 [MarshalAs(UnmanagedType.LPWStr)]
77 internal string lpszMenuName;
78 [MarshalAs(UnmanagedType.LPWStr)]
79 internal string lpszClassName;
82 [StructLayout(LayoutKind.Sequential)]
83 internal struct RECT {
90 [StructLayout(LayoutKind.Sequential)]
91 internal struct POINT {
96 internal enum SPIAction {
97 SPI_GETWORKAREA = 0x0030
100 internal enum WindowPlacementFlags {
104 SW_SHOWMINIMIZED = 2,
105 SW_SHOWMAXIMIZED = 3,
107 SW_SHOWNOACTIVATE = 4,
110 SW_SHOWMINNOACTIVE = 7,
114 SW_FORCEMINIMIZE = 11,
118 [StructLayout(LayoutKind.Sequential)]
119 private struct WINDOWPLACEMENT {
120 internal uint length;
122 internal WindowPlacementFlags showCmd;
123 internal POINT ptMinPosition;
124 internal POINT ptMaxPosition;
125 internal RECT rcNormalPosition;
128 [StructLayout(LayoutKind.Sequential)]
129 internal struct NCCALCSIZE_PARAMS {
133 internal IntPtr lppos;
137 private enum TMEFlags {
138 TME_HOVER = 0x00000001,
139 TME_LEAVE = 0x00000002,
140 TME_QUERY = unchecked((int)0x40000000),
141 TME_CANCEL = unchecked((int)0x80000000)
144 [StructLayout(LayoutKind.Sequential)]
145 private struct TRACKMOUSEEVENT {
147 internal TMEFlags dwFlags;
148 internal IntPtr hWnd;
149 internal int dwHoverTime;
152 [StructLayout(LayoutKind.Sequential)]
153 private struct PAINTSTRUCT {
156 internal RECT rcPaint;
157 internal int fRestore;
158 internal int fIncUpdate;
159 internal int Reserved1;
160 internal int Reserved2;
161 internal int Reserved3;
162 internal int Reserved4;
163 internal int Reserved5;
164 internal int Reserved6;
165 internal int Reserved7;
166 internal int Reserved8;
169 internal enum ClassStyle {
170 CS_VREDRAW = 0x00000001,
171 CS_HREDRAW = 0x00000002,
172 CS_KEYCVTWINDOW = 0x00000004,
173 CS_DBLCLKS = 0x00000008,
174 CS_OWNDC = 0x00000020,
175 CS_CLASSDC = 0x00000040,
176 CS_PARENTDC = 0x00000080,
177 CS_NOKEYCVT = 0x00000100,
178 CS_NOCLOSE = 0x00000200,
179 CS_SAVEBITS = 0x00000800,
180 CS_BYTEALIGNCLIENT = 0x00001000,
181 CS_BYTEALIGNWINDOW = 0x00002000,
182 CS_GLOBALCLASS = 0x00004000,
186 internal enum SetWindowPosZOrder {
194 internal enum SetWindowPosFlags {
195 SWP_ASYNCWINDOWPOS = 0x4000,
196 SWP_DEFERERASE = 0x2000,
197 SWP_DRAWFRAME = 0x0020,
198 SWP_FRAMECHANGED = 0x0020,
199 SWP_HIDEWINDOW = 0x0080,
200 SWP_NOACTIVATE = 0x0010,
201 SWP_NOCOPYBITS = 0x0100,
203 SWP_NOOWNERZORDER = 0x0200,
204 SWP_NOREDRAW = 0x0008,
205 SWP_NOREPOSITION = 0x0200,
206 SWP_NOENDSCHANGING = 0x0400,
208 SWP_NOZORDER = 0x0004,
209 SWP_SHOWWINDOW = 0x0040
212 internal enum GetSysColorIndex {
214 COLOR_BACKGROUND = 1,
215 COLOR_ACTIVECAPTION = 2,
216 COLOR_INACTIVECAPTION = 3,
219 COLOR_WINDOWFRAME = 6,
221 COLOR_WINDOWTEXT = 8,
222 COLOR_CAPTIONTEXT = 9,
223 COLOR_ACTIVEBORDER = 10,
224 COLOR_INACTIVEBORDER = 11,
225 COLOR_APPWORKSPACE = 12,
226 COLOR_HIGHLIGHT = 13,
227 COLOR_HIGHLIGHTTEXT = 14,
229 COLOR_BTNSHADOW = 16,
232 COLOR_INACTIVECAPTIONTEXT = 19,
233 COLOR_BTNHIGHLIGHT = 20,
234 COLOR_3DDKSHADOW = 21,
240 COLOR_GRADIENTACTIVECAPTION = 27,
241 COLOR_GRADIENTINACTIVECAPTION = 28,
242 COLOR_MENUHIGHLIGHT = 29,
248 COLOR_3DHIGHLIGHT = 20,
249 COLOR_3DHILIGHT = 20,
250 COLOR_BTNHILIGHT = 20,
251 COLOR_MAXVALUE = 24,/* Maximum value */
254 private enum LoadCursorType {
263 IDC_SIZENWSE = 32642,
264 IDC_SIZENESW = 32643,
270 IDC_APPSTARTING = 32650,
276 private enum WindowLong {
287 private enum LogBrushStyle {
296 BS_DIBPATTERN8X8 = 8,
301 private enum LogBrushHatch {
302 HS_HORIZONTAL = 0, /* ----- */
303 HS_VERTICAL = 1, /* ||||| */
304 HS_FDIAGONAL = 2, /* \\\\\ */
305 HS_BDIAGONAL = 3, /* ///// */
306 HS_CROSS = 4, /* +++++ */
307 HS_DIAGCROSS = 5, /* xxxxx */
310 internal struct COLORREF {
317 [StructLayout(LayoutKind.Sequential)]
318 private struct LOGBRUSH {
319 internal LogBrushStyle lbStyle;
320 internal COLORREF lbColor;
321 internal LogBrushHatch lbHatch;
324 [StructLayout(LayoutKind.Sequential)]
325 internal struct TEXTMETRIC {
326 internal int tmHeight;
327 internal int tmAscent;
328 internal int tmDescent;
329 internal int tmInternalLeading;
330 internal int tmExternalLeading;
331 internal int tmAveCharWidth;
332 internal int tmMaxCharWidth;
333 internal int tmWeight;
334 internal int tmOverhang;
335 internal int tmDigitizedAspectX;
336 internal int tmDigitizedAspectY;
337 internal byte tmFirstChar;
338 internal byte tmLastChar;
339 internal byte tmDefaultChar;
340 internal byte tmBreakChar;
341 internal byte tmItalic;
342 internal byte tmUnderlined;
343 internal byte tmStruckOut;
344 internal byte tmPitchAndFamily;
345 internal byte tmCharSet;
349 private enum ScrollWindowExFlags {
351 SW_SCROLLCHILDREN = 0x0001,
352 SW_INVALIDATE = 0x0002,
354 SW_SMOOTHSCROLL = 0x0010
357 internal enum SystemMetrics {
374 SM_CXFULLSCREEN = 16,
375 SM_CYFULLSCREEN = 17,
376 SM_CYKANJIWINDOW = 18,
377 SM_MOUSEPRESENT = 19,
396 SM_CXICONSPACING = 38,
397 SM_CYICONSPACING = 39,
398 SM_MENUDROPALIGNMENT = 40,
401 SM_CMOUSEBUTTONS = 43,
402 SM_CXFIXEDFRAME = SM_CXDLGFRAME,
403 SM_CYFIXEDFRAME = SM_CYDLGFRAME,
404 SM_CXSIZEFRAME = SM_CXFRAME,
405 SM_CYSIZEFRAME = SM_CYFRAME,
409 SM_CXMINSPACING = 47,
410 SM_CYMINSPACING = 48,
433 SM_MIDEASTENABLED = 74,
434 SM_MOUSEWHEELPRESENT = 75,
435 SM_XVIRTUALSCREEN = 76,
436 SM_YVIRTUALSCREEN = 77,
437 SM_CXVIRTUALSCREEN = 78,
438 SM_CYVIRTUALSCREEN = 79,
440 SM_SAMEDISPLAYFORMAT = 81,
442 SM_CXFOCUSBORDER = 83,
443 SM_CYFOCUSBORDER = 84,
449 // We'll only support _WIN32_IE < 0x0500 for now
450 internal enum NotifyIconMessage {
451 NIM_ADD = 0x00000000,
452 NIM_MODIFY = 0x00000001,
453 NIM_DELETE = 0x00000002,
457 internal enum NotifyIconFlags {
458 NIF_MESSAGE = 0x00000001,
459 NIF_ICON = 0x00000002,
460 NIF_TIP = 0x00000004,
463 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
464 internal struct NOTIFYICONDATA {
465 internal uint cbSize;
466 internal IntPtr hWnd;
468 internal NotifyIconFlags uFlags;
469 internal uint uCallbackMessage;
470 internal IntPtr hIcon;
471 [MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)]
472 internal string szTip;
476 internal enum DCExFlags {
477 DCX_WINDOW = 0x00000001,
478 DCX_CACHE = 0x00000002,
479 DCX_NORESETATTRS = 0x00000004,
480 DCX_CLIPCHILDREN = 0x00000008,
481 DCX_CLIPSIBLINGS = 0x00000010,
482 DCX_PARENTCLIP = 0x00000020,
483 DCX_EXCLUDERGN = 0x00000040,
484 DCX_INTERSECTRGN = 0x00000080,
485 DCX_EXCLUDEUPDATE = 0x00000100,
486 DCX_INTERSECTUPDATE = 0x00000200,
487 DCX_LOCKWINDOWUPDATE = 0x00000400,
488 DCX_USESTYLE = 0x00010000,
489 DCX_VALIDATE = 0x00200000
492 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
493 internal struct CLIENTCREATESTRUCT {
494 internal IntPtr hWindowMenu;
495 internal uint idFirstChild;
498 private enum ClassLong : int {
500 GCL_HBRBACKGROUND = -10,
504 GCL_CBWNDEXTRA = -18,
505 GCL_CBCLSEXTRA = -20,
512 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
513 internal struct MINMAXINFO {
514 internal POINT ptReserved;
515 internal POINT ptMaxSize;
516 internal POINT ptMaxPosition;
517 internal POINT ptMinTrackSize;
518 internal POINT ptMaxTrackSize;
522 internal enum GAllocFlags : uint {
524 GMEM_MOVEABLE = 0x0002,
525 GMEM_NOCOMPACT = 0x0010,
526 GMEM_NODISCARD = 0x0020,
527 GMEM_ZEROINIT = 0x0040,
528 GMEM_MODIFY = 0x0080,
529 GMEM_DISCARDABLE = 0x0100,
530 GMEM_NOT_BANKED = 0x1000,
532 GMEM_DDESHARE = 0x2000,
533 GMEM_NOTIFY = 0x4000,
534 GMEM_LOWER = GMEM_NOT_BANKED,
535 GMEM_VALID_FLAGS = 0x7F72,
536 GMEM_INVALID_HANDLE = 0x8000,
537 GHND = (GMEM_MOVEABLE | GMEM_ZEROINIT),
538 GPTR = (GMEM_FIXED | GMEM_ZEROINIT)
541 internal enum ROP2DrawMode : int {
561 internal enum PenStyle : int {
573 internal enum StockObject : int {
580 HOLLOW_BRUSH = NULL_BRUSH,
585 ANSI_FIXED_FONT = 11,
588 DEVICE_DEFAULT_FONT = 14,
589 DEFAULT_PALETTE = 15,
590 SYSTEM_FIXED_FONT = 16
593 internal enum HatchStyle : int {
603 #region Constructor & Destructor
604 private XplatUIWin32() {
608 // Handle singleton stuff first
611 DnD = new Win32DnD();
613 mouse_state = MouseButtons.None;
614 mouse_position = Point.Empty;
616 message_queue = new Queue();
618 themes_enabled = false;
620 // Prepare 'our' window class
621 wnd_proc = new WndProc(NativeWindow.WndProc);
622 wndClass.style = (int)(ClassStyle.CS_OWNDC | ClassStyle.CS_DBLCLKS);
623 wndClass.lpfnWndProc = wnd_proc;
624 wndClass.cbClsExtra = 0;
625 wndClass.cbWndExtra = 0;
626 wndClass.hbrBackground = IntPtr.Zero;
627 wndClass.hCursor = Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
628 wndClass.hIcon = IntPtr.Zero;
629 wndClass.hInstance = IntPtr.Zero;
630 wndClass.lpszClassName = XplatUI.DefaultClassName;
631 wndClass.lpszMenuName = "";
633 result=Win32RegisterClass(ref wndClass);
635 Win32MessageBox(IntPtr.Zero, "Could not register the "+XplatUI.DefaultClassName+" window class, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
638 FosterParent=Win32CreateWindow(0, "static", "Foster Parent Window", (int)WindowStyles.WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
640 if (FosterParent==IntPtr.Zero) {
641 Win32MessageBox(IntPtr.Zero, "Could not create foster window, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
644 timer_list = new Hashtable ();
646 #endregion // Constructor & Destructor
648 #region Private Support Methods
649 private static IntPtr DefWndProc(IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) {
650 return Win32DefWindowProc(hWnd, msg, wParam, lParam);
653 private static bool MessageWaiting {
655 if (message_queue.Count == 0) {
662 private static bool RetrieveMessage(ref MSG msg) {
665 if (message_queue.Count == 0) {
669 message = (MSG)message_queue.Dequeue();
675 private static bool StoreMessage(ref MSG msg) {
676 MSG message = new MSG();
679 message_queue.Enqueue(message);
684 internal static String AnsiToString(IntPtr ansi_data) {
685 return (string)Marshal.PtrToStringAnsi(ansi_data);
688 internal static String UnicodeToString(IntPtr unicode_data) {
689 return (string)Marshal.PtrToStringUni(unicode_data);
692 internal static Image DIBtoImage(IntPtr dib_data) {
697 BITMAPINFOHEADER bmi;
704 header = new byte[54]; // Size of a BMP file header, without palette
706 header[0] = (byte)'B';
707 header[1] = (byte)'M';
708 // 2, 3, 4 and 5 = unsigned int size
709 // 6, 7, 8 and 9 = reserved
710 // 10, 11, 12 and 13 = offset to image data
712 // Create a fake BMP header
713 bmi = (BITMAPINFOHEADER)Marshal.PtrToStructure(dib_data, typeof(BITMAPINFOHEADER));
715 ncolors = (int)bmi.biClrUsed;
717 if (bmi.biBitCount != 24) {
718 ncolors = (int)(1 << bmi.biBitCount);
721 palettesize = ncolors * 4;
723 imagesize = (int)bmi.biSizeImage;
724 if (imagesize == 0) {
725 imagesize = (int)(((((bmi.biWidth * bmi.biBitCount) + 31) & ~31) >> 3) * bmi.biHeight);
728 size = 54 + palettesize + imagesize;
729 offset = 54 + palettesize;
730 buffer = new byte[size];
732 // Copy the fake BMP file header
733 header[2] = (byte)size;
734 header[3] = (byte)(size >> 8);
735 header[4] = (byte)(size >> 16);
736 header[5] = (byte)(size >> 24);
738 header[10] = (byte)offset;
739 header[11] = (byte)(offset >> 8);
740 header[12] = (byte)(offset >> 16);
741 header[13] = (byte)(offset >> 24);
743 Array.Copy(header, 0, buffer, 0, 14);
745 for (int i = 14; i < size; i++) {
746 buffer[i] = Marshal.ReadByte(dib_data, i - 14);
749 ms = new MemoryStream(buffer, 0, size, false);
750 bmp = new Bitmap(ms);
755 internal static byte[] ImageToDIB(Image image) {
760 ms = new MemoryStream();
761 image.Save(ms, ImageFormat.Bmp);
762 buffer = ms.GetBuffer();
764 // Filter out the file header
765 retbuf = new byte[buffer.Length];
766 Array.Copy(buffer, 14, retbuf, 0, buffer.Length - 14);
770 internal static IntPtr DupGlobalMem(IntPtr mem) {
776 len = Win32GlobalSize(mem);
777 mem_ptr = Win32GlobalLock(mem);
779 dup = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE, (int)len);
780 dup_ptr = Win32GlobalLock(dup);
782 Win32CopyMemory(dup_ptr, mem_ptr, (int)len);
784 Win32GlobalUnlock(mem);
785 Win32GlobalUnlock(dup);
789 #endregion // Private Support Methods
791 #region Static Properties
792 internal override Keys ModifierKeys {
797 key_state = Keys.None;
799 state = Win32GetKeyState(VirtualKeys.VK_SHIFT);
800 if ((state & 0x8000) != 0) {
801 key_state |= Keys.Shift;
803 state = Win32GetKeyState(VirtualKeys.VK_CONTROL);
804 if ((state & 0x8000) != 0) {
805 key_state |= Keys.Control;
808 state = Win32GetKeyState(VirtualKeys.VK_MENU);
809 if ((state & 0x8000) != 0) {
810 key_state |= Keys.Alt;
817 internal override MouseButtons MouseButtons {
823 internal override Point MousePosition {
825 return mouse_position;
829 internal override bool DropTarget {
836 //throw new NotImplementedException("Need to figure out D'n'D for Win32");
841 internal override int Caption {
843 return Win32GetSystemMetrics(SystemMetrics.SM_CYCAPTION);
847 internal override Size CursorSize {
849 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CYCURSOR));
853 internal override bool DragFullWindows {
859 internal override Size DragSize {
861 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXDRAG), Win32GetSystemMetrics(SystemMetrics.SM_CYDRAG));
865 internal override Size FrameBorderSize {
867 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXFRAME), Win32GetSystemMetrics(SystemMetrics.SM_CYFRAME));
871 internal override Size IconSize {
873 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXICON), Win32GetSystemMetrics(SystemMetrics.SM_CYICON));
877 internal override Size MaxWindowTrackSize {
879 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMAXTRACK), Win32GetSystemMetrics(SystemMetrics.SM_CYMAXTRACK));
883 internal override Size MinimizedWindowSize {
885 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINIMIZED), Win32GetSystemMetrics(SystemMetrics.SM_CYMINIMIZED));
889 internal override Size MinimizedWindowSpacingSize {
891 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINSPACING), Win32GetSystemMetrics(SystemMetrics.SM_CYMINSPACING));
895 internal override Size MinimumWindowSize {
897 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMIN), Win32GetSystemMetrics(SystemMetrics.SM_CYMIN));
901 internal override Size MinWindowTrackSize {
903 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINTRACK), Win32GetSystemMetrics(SystemMetrics.SM_CYMINTRACK));
907 internal override Size SmallIconSize {
909 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXSMICON), Win32GetSystemMetrics(SystemMetrics.SM_CYSMICON));
913 internal override int MouseButtonCount {
915 return Win32GetSystemMetrics(SystemMetrics.SM_CMOUSEBUTTONS);
919 internal override bool MouseButtonsSwapped {
921 return Win32GetSystemMetrics(SystemMetrics.SM_SWAPBUTTON) != 0;
925 internal override bool MouseWheelPresent {
927 return Win32GetSystemMetrics(SystemMetrics.SM_MOUSEWHEELPRESENT) != 0;
931 internal override Rectangle VirtualScreen {
933 return new Rectangle( Win32GetSystemMetrics(SystemMetrics.SM_XVIRTUALSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_YVIRTUALSCREEN),
934 Win32GetSystemMetrics(SystemMetrics.SM_CXVIRTUALSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_CYVIRTUALSCREEN));
938 internal override Rectangle WorkingArea {
943 Win32SystemParametersInfo(SPIAction.SPI_GETWORKAREA, 0, ref rect, 0);
944 return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
945 //return new Rectangle(0, 0, Win32GetSystemMetrics(SystemMetrics.SM.SM_CXSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_CYSCREEN));
948 #endregion // Static Properties
950 #region Singleton Specific Code
951 public static XplatUIWin32 GetInstance() {
952 if (instance==null) {
953 instance=new XplatUIWin32();
959 public int Reference {
966 #region Public Static Methods
967 internal override IntPtr InitializeDriver() {
971 internal override void ShutdownDriver(IntPtr token) {
972 Console.WriteLine("XplatUIWin32 ShutdownDriver called");
976 internal void Version() {
977 Console.WriteLine("Xplat version $revision: $");
980 internal override void Exit() {
981 Win32PostQuitMessage(0);
984 internal override void GetDisplaySize(out Size size) {
987 Win32GetWindowRect(Win32GetDesktopWindow(), out rect);
989 size = new Size(rect.right - rect.left, rect.bottom - rect.top);
992 internal override void EnableThemes() {
996 internal override IntPtr CreateWindow(CreateParams cp) {
1004 ParentHandle=cp.Parent;
1006 if ((ParentHandle==IntPtr.Zero) && (cp.Style & (int)(WindowStyles.WS_CHILD))!=0) {
1007 // We need to use our foster parent window until this poor child gets it's parent assigned
1008 ParentHandle=FosterParent;
1011 lParam = IntPtr.Zero;
1012 if (cp.Param != null && cp.Param is CLIENTCREATESTRUCT) {
1013 lParam = Marshal.AllocHGlobal(Marshal.SizeOf(cp.Param));
1014 Marshal.StructureToPtr(cp.Param, lParam, false);
1017 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, lParam);
1019 if (lParam != IntPtr.Zero) {
1020 Marshal.FreeHGlobal(lParam);
1023 if (WindowHandle==IntPtr.Zero) {
1024 uint error = Win32GetLastError();
1026 Win32MessageBox(IntPtr.Zero, "Error : " + error.ToString(), "Failed to create window, class '"+cp.ClassName+"'", 0);
1029 hwnd.ClientWindow = WindowHandle;
1031 Win32SetWindowLong(WindowHandle, WindowLong.GWL_USERDATA, (uint)ThemeEngine.Current.DefaultControlBackColor.ToArgb());
1033 return WindowHandle;
1036 internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
1037 CreateParams create_params = new CreateParams();
1039 create_params.Caption = "";
1040 create_params.X = X;
1041 create_params.Y = Y;
1042 create_params.Width = Width;
1043 create_params.Height = Height;
1045 create_params.ClassName=XplatUI.DefaultClassName;
1046 create_params.ClassStyle = 0;
1047 create_params.ExStyle=0;
1048 create_params.Parent=IntPtr.Zero;
1049 create_params.Param=0;
1051 return CreateWindow(create_params);
1054 internal override void DestroyWindow(IntPtr handle) {
1057 hwnd = Hwnd.ObjectFromHandle(handle);
1058 Win32DestroyWindow(handle);
1063 internal override FormWindowState GetWindowState(IntPtr handle) {
1066 style = Win32GetWindowLong(handle, WindowLong.GWL_STYLE);
1067 if ((style & (uint)WindowStyles.WS_MAXIMIZE) != 0) {
1068 return FormWindowState.Maximized;
1069 } else if ((style & (uint)WindowStyles.WS_MINIMIZE) != 0) {
1070 return FormWindowState.Minimized;
1072 return FormWindowState.Normal;
1075 internal override void SetWindowState(IntPtr hwnd, FormWindowState state) {
1077 case FormWindowState.Normal: {
1078 Win32ShowWindow(hwnd, WindowPlacementFlags.SW_SHOWNORMAL);
1082 case FormWindowState.Minimized: {
1083 Win32ShowWindow(hwnd, WindowPlacementFlags.SW_SHOWMINIMIZED);
1087 case FormWindowState.Maximized: {
1088 Win32ShowWindow(hwnd, WindowPlacementFlags.SW_SHOWMAXIMIZED);
1094 internal override void SetWindowStyle(IntPtr handle, CreateParams cp) {
1095 Win32SetWindowLong(handle, WindowLong.GWL_STYLE, (uint)cp.Style);
1096 Win32SetWindowLong(handle, WindowLong.GWL_EXSTYLE, (uint)cp.ExStyle);
1099 internal override void UpdateWindow(IntPtr handle) {
1100 Win32UpdateWindow(handle);
1103 [MonoTODO("FIXME - Add support for internal table of windows/DCs for cleanup; handle client=false to draw in NC area")]
1104 internal override PaintEventArgs PaintEventStart(IntPtr handle, bool client) {
1107 PaintEventArgs paint_event;
1109 Rectangle clip_rect;
1112 clip_rect = new Rectangle();
1114 ps = new PAINTSTRUCT();
1116 hwnd = Hwnd.ObjectFromHandle(handle);
1118 if (Win32GetUpdateRect(handle, ref rect, false)) {
1119 hdc = Win32BeginPaint(handle, ref ps);
1121 hwnd.user_data = (object)ps;
1123 clip_rect = new Rectangle(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right-ps.rcPaint.left, ps.rcPaint.bottom-ps.rcPaint.top);
1125 hdc = Win32GetDC(handle);
1126 // FIXME: Add the DC to internal list
1127 clip_rect = new Rectangle(rect.top, rect.left, rect.right-rect.left, rect.bottom-rect.top);
1130 hwnd.client_dc = Graphics.FromHdc(hdc);
1131 paint_event = new PaintEventArgs(hwnd.client_dc, clip_rect);
1136 internal override void PaintEventEnd(IntPtr handle, bool client) {
1140 hwnd = Hwnd.ObjectFromHandle(handle);
1141 hwnd.client_dc.Dispose();
1143 if (hwnd.user_data != null) {
1144 ps = (PAINTSTRUCT)hwnd.user_data;
1145 Win32EndPaint(handle, ref ps);
1150 internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
1151 Win32MoveWindow(handle, x, y, width, height, true);
1155 internal override void GetWindowPos(IntPtr handle, bool is_toplevel, out int x, out int y, out int width, out int height, out int client_width, out int client_height) {
1159 Win32GetWindowRect(handle, out rect);
1160 width = rect.right - rect.left;
1161 height = rect.bottom - rect.top;
1165 Win32ScreenToClient(Win32GetParent(handle), ref pt);
1169 Win32GetClientRect(handle, out rect);
1170 client_width = rect.right - rect.left;
1171 client_height = rect.bottom - rect.top;
1175 internal override void Activate(IntPtr handle) {
1176 Win32SetActiveWindow(handle);
1179 internal override void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
1184 rect.right=rc.Right;
1185 rect.bottom=rc.Bottom;
1186 Win32InvalidateRect(handle, ref rect, clear);
1189 internal override IntPtr DefWndProc(ref Message msg) {
1190 msg.Result=Win32DefWindowProc(msg.HWnd, (Msg)msg.Msg, msg.WParam, msg.LParam);
1194 internal override void HandleException(Exception e) {
1195 StackTrace st = new StackTrace(e);
1196 Win32MessageBox(IntPtr.Zero, e.Message+st.ToString(), "Exception", 0);
1197 Console.WriteLine("{0}{1}", e.Message, st.ToString());
1200 internal override void DoEvents() {
1201 MSG msg = new MSG();
1203 if (override_cursor != IntPtr.Zero) {
1204 Cursor.Current = null;
1207 while (Win32PeekMessage(ref msg, IntPtr.Zero, 0, 0, (uint)PeekMessageFlags.PM_REMOVE)!=true) {
1208 if (msg.message==Msg.WM_PAINT) {
1209 XplatUI.TranslateMessage(ref msg);
1210 XplatUI.DispatchMessage(ref msg);
1215 internal override bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
1216 return Win32PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
1219 internal override bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
1222 if (RetrieveMessage(ref msg)) {
1226 result = Win32GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
1228 // We need to fake WM_MOUSE_ENTER/WM_MOUSE_LEAVE
1229 switch (msg.message) {
1230 case Msg.WM_LBUTTONDOWN: {
1231 mouse_state |= MouseButtons.Left;
1235 case Msg.WM_MBUTTONDOWN: {
1236 mouse_state |= MouseButtons.Middle;
1240 case Msg.WM_RBUTTONDOWN: {
1241 mouse_state |= MouseButtons.Right;
1245 case Msg.WM_LBUTTONUP: {
1246 mouse_state &= ~MouseButtons.Left;
1250 case Msg.WM_MBUTTONUP: {
1251 mouse_state &= ~MouseButtons.Middle;
1255 case Msg.WM_RBUTTONUP: {
1256 mouse_state &= ~MouseButtons.Right;
1260 case Msg.WM_ASYNC_MESSAGE: {
1261 XplatUIDriverSupport.ExecuteClientMessage((GCHandle)msg.lParam);
1265 case Msg.WM_MOUSEMOVE: {
1266 if (msg.hwnd != prev_mouse_hwnd) {
1267 TRACKMOUSEEVENT tme;
1269 // The current message will be sent out next time around
1270 StoreMessage(ref msg);
1272 // This is the message we want to send at this point
1273 msg.message = Msg.WM_MOUSE_ENTER;
1275 prev_mouse_hwnd = msg.hwnd;
1277 tme = new TRACKMOUSEEVENT();
1278 tme.size = Marshal.SizeOf(tme);
1279 tme.hWnd = msg.hwnd;
1280 tme.dwFlags = TMEFlags.TME_LEAVE | TMEFlags.TME_HOVER;
1281 Win32TrackMouseEvent(ref tme);
1287 case Msg.WM_DROPFILES: {
1288 return Win32DnD.HandleWMDropFiles(ref msg);
1291 case Msg.WM_MOUSELEAVE: {
1292 prev_mouse_hwnd = IntPtr.Zero;
1293 msg.message=Msg.WM_MOUSE_LEAVE;
1297 case Msg.WM_TIMER: {
1298 Timer timer=(Timer)timer_list[(int)msg.wParam];
1300 if (timer != null) {
1310 internal override bool TranslateMessage(ref MSG msg) {
1311 return Win32TranslateMessage(ref msg);
1314 internal override IntPtr DispatchMessage(ref MSG msg) {
1315 return Win32DispatchMessage(ref msg);
1318 internal override bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
1320 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOP, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1322 } else if (!Bottom) {
1323 Win32SetWindowPos(hWnd, AfterhWnd, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1325 Win32SetWindowPos(hWnd, (IntPtr)SetWindowPosZOrder.HWND_BOTTOM, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1331 internal override bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
1333 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1336 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_NOTOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1341 internal override bool Text(IntPtr handle, string text) {
1342 Win32SetWindowText(handle, text);
1346 internal override bool GetText(IntPtr handle, out string text) {
1349 sb = new StringBuilder(256);
1350 Win32GetWindowText(handle, sb, sb.Capacity);
1351 text = sb.ToString();
1355 internal override bool SetVisible(IntPtr handle, bool visible) {
1357 Win32ShowWindow(handle, WindowPlacementFlags.SW_SHOWNORMAL);
1359 Win32ShowWindow(handle, WindowPlacementFlags.SW_HIDE);
1364 internal override bool IsVisible(IntPtr handle) {
1365 return IsWindowVisible (handle);
1368 internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
1369 return Win32SetParent(handle, parent);
1372 internal override IntPtr GetParent(IntPtr handle) {
1373 return Win32GetParent(handle);
1376 internal override void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
1378 Win32SetCapture(hWnd);
1381 internal override void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
1383 GrabConfined = grab_confined;
1384 GrabArea = grab_area;
1387 internal override void UngrabWindow(IntPtr hWnd) {
1388 Win32ReleaseCapture();
1389 grab_hwnd = IntPtr.Zero;
1392 internal override bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, int ExStyle, IntPtr MenuHandle, out Rectangle WindowRect) {
1395 rect.left=ClientRect.Left;
1396 rect.top=ClientRect.Top;
1397 rect.right=ClientRect.Right;
1398 rect.bottom=ClientRect.Bottom;
1400 if (!Win32AdjustWindowRectEx(ref rect, Style, MenuHandle != IntPtr.Zero, ExStyle)) {
1401 WindowRect = new Rectangle(ClientRect.Left, ClientRect.Top, ClientRect.Width, ClientRect.Height);
1405 WindowRect = new Rectangle(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
1409 internal override void SetCursor(IntPtr window, IntPtr cursor) {
1410 Win32SetCursor(cursor);
1414 internal override void ShowCursor(bool show) {
1415 Win32ShowCursor(show);
1418 internal override void OverrideCursor(IntPtr cursor) {
1419 Win32SetCursor(cursor);
1422 internal override IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
1424 Bitmap cursor_bitmap;
1432 // Win32 only allows creation cursors of a certain size
1433 if ((bitmap.Width != Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)) || (bitmap.Width != Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR))) {
1434 cursor_bitmap = new Bitmap(bitmap, new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)));
1435 cursor_mask = new Bitmap(mask, new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)));
1437 cursor_bitmap = bitmap;
1441 width = cursor_bitmap.Width;
1442 height = cursor_bitmap.Height;
1444 cursor_bits = new Byte[(width / 8) * height];
1445 mask_bits = new Byte[(width / 8) * height];
1447 for (int y = 0; y < height; y++) {
1448 for (int x = 0; x < width; x++) {
1449 pixel = cursor_bitmap.GetPixel(x, y);
1451 if (pixel == cursor_pixel) {
1452 cursor_bits[y * width / 8 + x / 8] |= (byte)(0x80 >> (x % 8));
1455 pixel = cursor_mask.GetPixel(x, y);
1457 if (pixel == mask_pixel) {
1458 mask_bits[y * width / 8 + x / 8] |= (byte)(0x80 >> (x % 8));
1463 cursor = Win32CreateCursor(IntPtr.Zero, xHotSpot, yHotSpot, width, height, mask_bits, cursor_bits);
1468 [MonoTODO("Define the missing cursors")]
1469 internal override IntPtr DefineStdCursor(StdCursor id) {
1471 case StdCursor.AppStarting: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_APPSTARTING);
1472 case StdCursor.Arrow: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
1473 case StdCursor.Cross: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_CROSS);
1474 case StdCursor.Default: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
1475 case StdCursor.Hand: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_HAND);
1476 case StdCursor.Help: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_HELP);
1477 case StdCursor.HSplit: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1478 case StdCursor.IBeam: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_IBEAM);
1479 case StdCursor.No: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_NO);
1480 case StdCursor.NoMove2D: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1481 case StdCursor.NoMoveHoriz: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1482 case StdCursor.NoMoveVert: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1483 case StdCursor.PanEast: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1484 case StdCursor.PanNE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1485 case StdCursor.PanNorth: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1486 case StdCursor.PanNW: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1487 case StdCursor.PanSE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1488 case StdCursor.PanSouth: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1489 case StdCursor.PanSW: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1490 case StdCursor.PanWest: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1491 case StdCursor.SizeAll: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZEALL);
1492 case StdCursor.SizeNESW: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENESW);
1493 case StdCursor.SizeNS: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENS);
1494 case StdCursor.SizeNWSE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENWSE);
1495 case StdCursor.SizeWE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZEWE);
1496 case StdCursor.UpArrow: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_UPARROW);
1497 case StdCursor.VSplit: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1498 case StdCursor.WaitCursor: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_WAIT);
1500 throw new NotImplementedException ();
1503 internal override void DestroyCursor(IntPtr cursor) {
1504 if ((cursor.ToInt32() < (int)LoadCursorType.First) || (cursor.ToInt32() > (int)LoadCursorType.Last)) {
1505 Win32DestroyCursor(cursor);
1510 internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
1511 throw new NotImplementedException ();
1514 internal override void SetCursorPos(IntPtr handle, int x, int y) {
1515 Win32SetCursorPos(x, y);
1518 internal override void EnableWindow(IntPtr handle, bool Enable) {
1519 Win32EnableWindow(handle, Enable);
1522 internal override void SetModal(IntPtr handle, bool Modal) {
1523 // we do nothing on Win32; Application.cs simulates modal dialogs by disabling all toplevel windows
1526 internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
1529 Win32GetCursorPos(out pt);
1531 if (handle!=IntPtr.Zero) {
1532 Win32ScreenToClient(handle, ref pt);
1539 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y)
1541 POINT pnt = new POINT();
1545 Win32ScreenToClient (handle, ref pnt);
1551 internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) {
1552 POINT pnt = new POINT();
1557 Win32ClientToScreen(handle, ref pnt);
1563 internal override void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
1564 ScreenToClient(handle, ref x, ref y);
1567 internal override void MenuToScreen(IntPtr handle, ref int x, ref int y) {
1568 ClientToScreen(handle, ref x, ref y);
1571 internal override void SendAsyncMethod (AsyncMethodData method)
1573 Win32PostMessage(FosterParent, Msg.WM_ASYNC_MESSAGE, IntPtr.Zero, (IntPtr)GCHandle.Alloc (method));
1576 internal override void SetTimer (Timer timer)
1580 index = timer.GetHashCode();
1583 timer_list[index]=timer;
1586 Win32SetTimer(FosterParent, index, (uint)timer.Interval, IntPtr.Zero);
1589 internal override void KillTimer (Timer timer)
1593 index = timer.GetHashCode();
1595 Win32KillTimer(FosterParent, index);
1598 timer_list.Remove(index);
1603 private void CaretCallback(object sender, EventArgs e) {
1604 Console.WriteLine("CaretCallback hit");
1607 internal override void CreateCaret(IntPtr hwnd, int width, int height) {
1608 Win32CreateCaret(hwnd, IntPtr.Zero, width, height);
1611 internal override void DestroyCaret(IntPtr hwnd) {
1612 Win32DestroyCaret();
1615 internal override void SetCaretPos(IntPtr hwnd, int x, int y) {
1616 Win32SetCaretPos(x, y);
1619 internal override void CaretVisible(IntPtr hwnd, bool visible) {
1621 Win32ShowCaret(hwnd);
1623 Win32HideCaret(hwnd);
1627 internal override void SetFocus(IntPtr hwnd) {
1628 Win32SetFocus(hwnd);
1631 internal override IntPtr GetActive() {
1632 return Win32GetActiveWindow();
1635 internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
1639 tm = new TEXTMETRIC();
1641 dc = Win32GetDC(IntPtr.Zero);
1642 Win32SelectObject(dc, font.ToHfont());
1643 if (Win32GetTextMetrics(dc, ref tm) == false) {
1644 Win32ReleaseDC(IntPtr.Zero, dc);
1649 Win32ReleaseDC(IntPtr.Zero, dc);
1651 ascent = tm.tmAscent;
1652 descent = tm.tmDescent;
1657 internal override void ScrollWindow(IntPtr hwnd, Rectangle rectangle, int XAmount, int YAmount, bool with_children) {
1661 rect.left = rectangle.X;
1662 rect.top = rectangle.Y;
1663 rect.right = rectangle.Right;
1664 rect.bottom = rectangle.Bottom;
1666 Win32ScrollWindowEx(hwnd, XAmount, YAmount, ref rect, ref rect, IntPtr.Zero, IntPtr.Zero, ScrollWindowExFlags.SW_INVALIDATE | ScrollWindowExFlags.SW_ERASE | (with_children ? ScrollWindowExFlags.SW_SCROLLCHILDREN : ScrollWindowExFlags.SW_NONE));
1667 Win32UpdateWindow(hwnd);
1670 internal override void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount, bool with_children) {
1671 Win32ScrollWindowEx(hwnd, XAmount, YAmount, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, ScrollWindowExFlags.SW_INVALIDATE | ScrollWindowExFlags.SW_ERASE | (with_children ? ScrollWindowExFlags.SW_SCROLLCHILDREN : ScrollWindowExFlags.SW_NONE));
1674 internal override bool SystrayAdd(IntPtr hwnd, string tip, Icon icon, out ToolTip tt) {
1677 nid = new NOTIFYICONDATA();
1679 nid.cbSize = (uint)Marshal.SizeOf(nid);
1682 nid.uCallbackMessage = (uint)Msg.WM_USER;
1683 nid.uFlags = NotifyIconFlags.NIF_MESSAGE;
1687 nid.uFlags |= NotifyIconFlags.NIF_TIP;
1691 nid.hIcon = icon.Handle;
1692 nid.uFlags |= NotifyIconFlags.NIF_ICON;
1697 return Win32Shell_NotifyIcon(NotifyIconMessage.NIM_ADD, ref nid);
1700 internal override bool SystrayChange(IntPtr hwnd, string tip, Icon icon, ref ToolTip tt) {
1703 nid = new NOTIFYICONDATA();
1705 nid.cbSize = (uint)Marshal.SizeOf(nid);
1706 nid.hIcon = icon.Handle;
1709 nid.uCallbackMessage = (uint)Msg.WM_USER;
1710 nid.uFlags = NotifyIconFlags.NIF_MESSAGE;
1714 nid.uFlags |= NotifyIconFlags.NIF_TIP;
1718 nid.hIcon = icon.Handle;
1719 nid.uFlags |= NotifyIconFlags.NIF_ICON;
1722 return Win32Shell_NotifyIcon(NotifyIconMessage.NIM_MODIFY, ref nid);
1725 internal override void SystrayRemove(IntPtr hwnd, ref ToolTip tt) {
1728 nid = new NOTIFYICONDATA();
1730 nid.cbSize = (uint)Marshal.SizeOf(nid);
1735 Win32Shell_NotifyIcon(NotifyIconMessage.NIM_DELETE, ref nid);
1739 internal override void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
1743 style = Win32GetWindowLong(handle, WindowLong.GWL_STYLE);
1744 exstyle = Win32GetWindowLong(handle, WindowLong.GWL_EXSTYLE);
1746 switch (border_style) {
1747 case FormBorderStyle.None: {
1748 style &= ~(uint)WindowStyles.WS_BORDER;
1749 exstyle &= ~(uint)WindowStyles.WS_EX_CLIENTEDGE;
1753 case FormBorderStyle.FixedSingle: {
1754 style |= (uint)WindowStyles.WS_BORDER;
1755 exstyle &= ~(uint)WindowStyles.WS_EX_CLIENTEDGE;
1759 case FormBorderStyle.Fixed3D: {
1760 style &= ~(uint)WindowStyles.WS_BORDER;
1761 exstyle |= (uint)WindowStyles.WS_EX_CLIENTEDGE;
1766 Win32SetWindowLong(handle, WindowLong.GWL_STYLE, style);
1767 Win32SetWindowLong(handle, WindowLong.GWL_EXSTYLE, exstyle);
1769 Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0,
1770 SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE);
1773 internal override void SetMenu(IntPtr handle, IntPtr menu_handle) {
1774 // Trigger WM_NCCALC
1775 Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1779 internal override Graphics GetMenuDC(IntPtr hwnd, IntPtr ncpaint_region) {
1784 // hdc = Win32GetDCEx(hwnd, ncpaint_region, DCExFlags.DCX_WINDOW | DCExFlags.DCX_INTERSECTRGN | DCExFlags.DCX_USESTYLE);
1785 hdc = Win32GetDCEx(hwnd, ncpaint_region, DCExFlags.DCX_WINDOW);
1787 g = Graphics.FromHdc(hdc);
1789 Win32ReleaseDC(hwnd, hdc);
1794 internal override Point GetMenuOrigin(IntPtr handle) {
1795 return new Point(SystemInformation.FrameBorderSize.Width, SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight);
1799 internal override void ReleaseMenuDC(IntPtr hwnd, Graphics dc) {
1803 internal override void SetIcon(IntPtr hwnd, Icon icon) {
1804 Win32SendMessage(hwnd, Msg.WM_SETICON, (IntPtr)1, icon.Handle); // 1 = large icon (0 would be small)
1807 internal override void ClipboardClose(IntPtr handle) {
1808 if (handle != clip_magic) {
1809 throw new ArgumentException("handle is not a valid clipboard handle");
1811 Win32CloseClipboard();
1814 internal override int ClipboardGetID(IntPtr handle, string format) {
1815 if (handle != clip_magic) {
1816 throw new ArgumentException("handle is not a valid clipboard handle");
1818 if (format == "Text" ) return 1;
1819 else if (format == "Bitmap" ) return 2;
1820 else if (format == "MetaFilePict" ) return 3;
1821 else if (format == "SymbolicLink" ) return 4;
1822 else if (format == "DataInterchangeFormat" ) return 5;
1823 else if (format == "Tiff" ) return 6;
1824 else if (format == "OEMText" ) return 7;
1825 else if (format == "DeviceIndependentBitmap" ) return 8;
1826 else if (format == "Palette" ) return 9;
1827 else if (format == "PenData" ) return 10;
1828 else if (format == "RiffAudio" ) return 11;
1829 else if (format == "WaveAudio" ) return 12;
1830 else if (format == "UnicodeText" ) return 13;
1831 else if (format == "EnhancedMetafile" ) return 14;
1832 else if (format == "FileDrop" ) return 15;
1833 else if (format == "Locale" ) return 16;
1835 return (int)Win32RegisterClipboardFormat(format);
1838 internal override IntPtr ClipboardOpen() {
1839 Win32OpenClipboard(FosterParent);
1843 internal override int[] ClipboardAvailableFormats(IntPtr handle) {
1848 if (handle != clip_magic) {
1856 format = Win32EnumClipboardFormats(format);
1860 } while (format != 0);
1863 result = new int[count];
1867 format = Win32EnumClipboardFormats(format);
1869 result[count++] = (int)format;
1871 } while (format != 0);
1877 internal override object ClipboardRetrieve(IntPtr handle, int type, XplatUI.ClipboardToObject converter) {
1882 if (handle != clip_magic) {
1883 throw new ArgumentException("handle is not a valid clipboard handle");
1886 hmem = Win32GetClipboardData((uint)type);
1887 if (hmem == IntPtr.Zero) {
1891 data = Win32GlobalLock(hmem);
1892 if (data == IntPtr.Zero) {
1893 uint error = Win32GetLastError();
1894 Console.WriteLine("Error: {0}", error);
1900 switch ((ClipboardFormats)type) {
1901 case ClipboardFormats.CF_TEXT: {
1902 obj = AnsiToString(data);
1906 case ClipboardFormats.CF_DIB: {
1907 obj = DIBtoImage(data);
1911 case ClipboardFormats.CF_UNICODETEXT: {
1912 obj = UnicodeToString(data);
1917 if (converter != null && !converter(type, data, out obj)) {
1923 Win32GlobalUnlock(hmem);
1929 internal override void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
1934 if (handle != clip_magic) {
1935 throw new ArgumentException("handle is not a valid clipboard handle");
1940 Win32EmptyClipboard();
1945 if (obj is string) {
1946 type = (int)ClipboardFormats.CF_UNICODETEXT;
1947 } else if (obj is Image) {
1948 type = (int)ClipboardFormats.CF_DIB;
1952 switch((ClipboardFormats)type) {
1953 case ClipboardFormats.CF_UNICODETEXT: {
1954 hmem = Marshal.StringToHGlobalUni((string)obj);
1955 Win32EmptyClipboard();
1956 Win32SetClipboardData((uint)type, hmem);
1960 case ClipboardFormats.CF_DIB: {
1961 data = ImageToDIB((Image)obj);
1963 hmem = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
1964 hmem_ptr = Win32GlobalLock(hmem);
1965 Marshal.Copy(data, 0, hmem_ptr, data.Length);
1966 Win32GlobalUnlock(hmem);
1967 Win32EmptyClipboard();
1968 Win32SetClipboardData((uint)type, hmem);
1973 if (converter != null && converter(ref type, obj, out data)) {
1974 hmem = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
1975 hmem_ptr = Win32GlobalLock(hmem);
1976 Marshal.Copy(data, 0, hmem_ptr, data.Length);
1977 Win32GlobalUnlock(hmem);
1978 Win32EmptyClipboard();
1979 Win32SetClipboardData((uint)type, hmem);
1986 internal override void SetAllowDrop(IntPtr hwnd, bool allowed) {
1988 Win32DnD.RegisterDropTarget(hwnd);
1990 Win32DnD.UnregisterDropTarget(hwnd);
1994 internal override DragDropEffects StartDrag(IntPtr hwnd, object data, DragDropEffects allowedEffects) {
1995 return Win32DnD.StartDrag(hwnd, data, allowedEffects);
1998 internal override void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
2007 Win32ClientToScreen(handle, ref pt);
2009 // If we want the standard hatch pattern we would
2010 // need to create a brush
2013 pen = Win32CreatePen(PenStyle.PS_SOLID, line_width, IntPtr.Zero);
2015 hdc = Win32GetDC(IntPtr.Zero);
2016 Win32SetROP2(hdc, ROP2DrawMode.R2_NOT);
2017 oldpen = Win32SelectObject(hdc, pen);
2019 // We might need to add clipping to the WindowRect of 'handle' - right now we're drawing on the desktop
2021 Win32MoveToEx(hdc, pt.x + rect.Left, pt.y + rect.Top, IntPtr.Zero);
2022 if ((rect.Width > 0) && (rect.Height > 0)) {
2023 Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Top);
2024 Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Bottom);
2025 Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Bottom);
2026 Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Top);
2028 if (rect.Width > 0) {
2029 Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Top);
2031 Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Bottom);
2035 Win32SelectObject(hdc, oldpen);
2036 Win32DeleteObject(pen);
2037 Win32ReleaseDC(IntPtr.Zero, hdc);
2040 internal override SizeF GetAutoScaleSize(Font font) {
2043 string magic_string = "The quick brown fox jumped over the lazy dog.";
2044 double magic_number = 44.549996948242189;
2046 g = Graphics.FromHwnd(FosterParent);
2048 width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
2049 return new SizeF(width, font.Height);
2052 internal override int KeyboardSpeed {
2054 Console.WriteLine ("KeyboardSpeed: need to query Windows");
2057 // Return values range from 0 to 31 which map to 2.5 to 30 repetitions per second.
2063 internal override int KeyboardDelay {
2065 Console.WriteLine ("KeyboardDelay: need to query Windows");
2068 // Return values must range from 0 to 4, 0 meaning 250ms,
2069 // and 4 meaning 1000 ms.
2075 internal override event EventHandler Idle;
2077 // Santa's little helper
2078 static void Where() {
2079 Console.WriteLine("Here: {0}", new StackTrace().ToString());
2081 #endregion // Public Static Methods
2083 #region Win32 Imports
2084 [DllImport ("kernel32.dll", EntryPoint="GetLastError", CallingConvention=CallingConvention.StdCall)]
2085 private extern static uint Win32GetLastError();
2087 [DllImport ("user32.dll", EntryPoint="CreateWindowExW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2088 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);
2090 [DllImport ("user32.dll", EntryPoint="DestroyWindow", CallingConvention=CallingConvention.StdCall)]
2091 internal extern static bool Win32DestroyWindow(IntPtr hWnd);
2093 [DllImport ("user32.dll", EntryPoint="PeekMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2094 internal extern static bool Win32PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags);
2096 [DllImport ("user32.dll", EntryPoint="GetMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2097 internal extern static bool Win32GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax);
2099 [DllImport ("user32.dll", EntryPoint="TranslateMessage", CallingConvention=CallingConvention.StdCall)]
2100 internal extern static bool Win32TranslateMessage(ref MSG msg);
2102 [DllImport ("user32.dll", EntryPoint="DispatchMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2103 internal extern static IntPtr Win32DispatchMessage(ref MSG msg);
2105 [DllImport ("user32.dll", EntryPoint="MoveWindow", CallingConvention=CallingConvention.StdCall)]
2106 internal extern static bool Win32MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
2108 [DllImport ("user32.dll", EntryPoint="SetWindowPos", CallingConvention=CallingConvention.StdCall)]
2109 internal extern static bool Win32SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SetWindowPosFlags Flags);
2111 [DllImport ("user32.dll", EntryPoint="SetWindowPos", CallingConvention=CallingConvention.StdCall)]
2112 internal extern static bool Win32SetWindowPos(IntPtr hWnd, SetWindowPosZOrder pos, int x, int y, int cx, int cy, SetWindowPosFlags Flags);
2114 [DllImport ("user32.dll", EntryPoint="SetWindowTextW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2115 internal extern static bool Win32SetWindowText(IntPtr hWnd, string lpString);
2117 [DllImport ("user32.dll", EntryPoint="GetWindowTextW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2118 internal extern static bool Win32GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
2120 [DllImport ("user32.dll", EntryPoint="SetParent", CallingConvention=CallingConvention.StdCall)]
2121 internal extern static IntPtr Win32SetParent(IntPtr hWnd, IntPtr hParent);
2123 [DllImport ("user32.dll", EntryPoint="RegisterClassW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2124 private extern static bool Win32RegisterClass(ref WNDCLASS wndClass);
2126 [DllImport ("user32.dll", EntryPoint="LoadCursorW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2127 private extern static IntPtr Win32LoadCursor(IntPtr hInstance, LoadCursorType type);
2129 [DllImport ("user32.dll", EntryPoint="ShowCursor", CallingConvention=CallingConvention.StdCall)]
2130 private extern static IntPtr Win32ShowCursor(bool bShow);
2132 [DllImport ("user32.dll", EntryPoint="SetCursor", CallingConvention=CallingConvention.StdCall)]
2133 private extern static IntPtr Win32SetCursor(IntPtr hCursor);
2135 [DllImport ("user32.dll", EntryPoint="CreateCursor", CallingConvention=CallingConvention.StdCall)]
2136 private extern static IntPtr Win32CreateCursor(IntPtr hInstance, int xHotSpot, int yHotSpot, int nWidth, int nHeight, Byte[] pvANDPlane, Byte[] pvORPlane);
2138 [DllImport ("user32.dll", EntryPoint="DestroyCursor", CallingConvention=CallingConvention.StdCall)]
2139 private extern static bool Win32DestroyCursor(IntPtr hCursor);
2141 [DllImport ("user32.dll", EntryPoint="DefWindowProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2142 private extern static IntPtr Win32DefWindowProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
2144 [DllImport ("user32.dll", EntryPoint="DefDlgProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2145 private extern static IntPtr Win32DefDlgProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
2147 [DllImport ("user32.dll", EntryPoint="PostQuitMessage", CallingConvention=CallingConvention.StdCall)]
2148 private extern static IntPtr Win32PostQuitMessage(int nExitCode);
2150 [DllImport ("user32.dll", EntryPoint="UpdateWindow", CallingConvention=CallingConvention.StdCall)]
2151 private extern static IntPtr Win32UpdateWindow(IntPtr hWnd);
2153 [DllImport ("user32.dll", EntryPoint="GetUpdateRect", CallingConvention=CallingConvention.StdCall)]
2154 private extern static bool Win32GetUpdateRect(IntPtr hWnd, ref RECT rect, bool erase);
2156 [DllImport ("user32.dll", EntryPoint="BeginPaint", CallingConvention=CallingConvention.StdCall)]
2157 private extern static IntPtr Win32BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
2159 [DllImport ("user32.dll", EntryPoint="EndPaint", CallingConvention=CallingConvention.StdCall)]
2160 private extern static bool Win32EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
2162 [DllImport ("user32.dll", EntryPoint="GetDC", CallingConvention=CallingConvention.StdCall)]
2163 private extern static IntPtr Win32GetDC(IntPtr hWnd);
2165 [DllImport ("user32.dll", EntryPoint="GetDCEx", CallingConvention=CallingConvention.StdCall)]
2166 private extern static IntPtr Win32GetDCEx(IntPtr hWnd, IntPtr hRgn, DCExFlags flags);
2168 [DllImport ("user32.dll", EntryPoint="ReleaseDC", CallingConvention=CallingConvention.StdCall)]
2169 private extern static IntPtr Win32ReleaseDC(IntPtr hWnd, IntPtr hDC);
2171 [DllImport ("user32.dll", EntryPoint="MessageBoxW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2172 private extern static IntPtr Win32MessageBox(IntPtr hParent, string pText, string pCaption, uint uType);
2174 [DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
2175 private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, ref RECT lpRect, bool bErase);
2177 [DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
2178 private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
2180 [DllImport ("user32.dll", EntryPoint="SetCapture", CallingConvention=CallingConvention.StdCall)]
2181 private extern static IntPtr Win32SetCapture(IntPtr hWnd);
2183 [DllImport ("user32.dll", EntryPoint="ReleaseCapture", CallingConvention=CallingConvention.StdCall)]
2184 private extern static IntPtr Win32ReleaseCapture();
2186 [DllImport ("user32.dll", EntryPoint="GetWindowRect", CallingConvention=CallingConvention.StdCall)]
2187 private extern static IntPtr Win32GetWindowRect(IntPtr hWnd, out RECT rect);
2189 [DllImport ("user32.dll", EntryPoint="GetClientRect", CallingConvention=CallingConvention.StdCall)]
2190 private extern static IntPtr Win32GetClientRect(IntPtr hWnd, out RECT rect);
2192 [DllImport ("user32.dll", EntryPoint="ScreenToClient", CallingConvention=CallingConvention.StdCall)]
2193 private extern static bool Win32ScreenToClient(IntPtr hWnd, ref POINT pt);
2195 [DllImport ("user32.dll", EntryPoint="ClientToScreen", CallingConvention=CallingConvention.StdCall)]
2196 private extern static bool Win32ClientToScreen(IntPtr hWnd, ref POINT pt);
2198 [DllImport ("user32.dll", EntryPoint="GetParent", CallingConvention=CallingConvention.StdCall)]
2199 private extern static IntPtr Win32GetParent(IntPtr hWnd);
2201 [DllImport ("user32.dll", EntryPoint="SetActiveWindow", CallingConvention=CallingConvention.StdCall)]
2202 private extern static IntPtr Win32SetActiveWindow(IntPtr hWnd);
2204 [DllImport ("user32.dll", EntryPoint="AdjustWindowRectEx", CallingConvention=CallingConvention.StdCall)]
2205 private extern static bool Win32AdjustWindowRectEx(ref RECT lpRect, int dwStyle, bool bMenu, int dwExStyle);
2207 [DllImport ("user32.dll", EntryPoint="GetCursorPos", CallingConvention=CallingConvention.StdCall)]
2208 private extern static bool Win32GetCursorPos(out POINT lpPoint);
2210 [DllImport ("user32.dll", EntryPoint="SetCursorPos", CallingConvention=CallingConvention.StdCall)]
2211 private extern static bool Win32SetCursorPos(int x, int y);
2213 [DllImport ("user32.dll", EntryPoint="GetWindowPlacement", CallingConvention=CallingConvention.StdCall)]
2214 private extern static bool Win32GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
2216 [DllImport ("user32.dll", EntryPoint="TrackMouseEvent", CallingConvention=CallingConvention.StdCall)]
2217 private extern static bool Win32TrackMouseEvent(ref TRACKMOUSEEVENT tme);
2219 [DllImport ("gdi32.dll", EntryPoint="CreateBrushIndirect", CallingConvention=CallingConvention.StdCall)]
2220 private extern static IntPtr Win32CreateBrushIndirect(ref LOGBRUSH lb);
2222 [DllImport ("user32.dll", EntryPoint="FillRect", CallingConvention=CallingConvention.StdCall)]
2223 private extern static int Win32FillRect(IntPtr hdc, ref RECT rect, IntPtr hbr);
2225 [DllImport ("user32.dll", EntryPoint="SetWindowLong", CallingConvention=CallingConvention.StdCall)]
2226 private extern static uint Win32SetWindowLong(IntPtr hwnd, WindowLong index, uint value);
2228 [DllImport ("user32.dll", EntryPoint="GetWindowLong", CallingConvention=CallingConvention.StdCall)]
2229 private extern static uint Win32GetWindowLong(IntPtr hwnd, WindowLong index);
2231 [DllImport ("gdi32.dll", EntryPoint="DeleteObject", CallingConvention=CallingConvention.StdCall)]
2232 private extern static bool Win32DeleteObject(IntPtr o);
2234 [DllImport ("user32.dll", EntryPoint="PostMessage", CallingConvention=CallingConvention.StdCall)]
2235 private extern static bool Win32PostMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
2237 [DllImport ("user32.dll", EntryPoint="GetKeyState", CallingConvention=CallingConvention.StdCall)]
2238 private extern static short Win32GetKeyState(VirtualKeys nVirtKey);
2240 [DllImport ("user32.dll", EntryPoint="GetDesktopWindow", CallingConvention=CallingConvention.StdCall)]
2241 private extern static IntPtr Win32GetDesktopWindow();
2243 [DllImport ("user32.dll", EntryPoint="SetTimer", CallingConvention=CallingConvention.StdCall)]
2244 private extern static IntPtr Win32SetTimer(IntPtr hwnd, int nIDEvent, uint uElapse, IntPtr timerProc);
2246 [DllImport ("user32.dll", EntryPoint="KillTimer", CallingConvention=CallingConvention.StdCall)]
2247 private extern static IntPtr Win32KillTimer(IntPtr hwnd, int nIDEvent);
2249 [DllImport ("user32.dll", EntryPoint="ShowWindow", CallingConvention=CallingConvention.StdCall)]
2250 private extern static IntPtr Win32ShowWindow(IntPtr hwnd, WindowPlacementFlags nCmdShow);
2252 [DllImport ("user32.dll", EntryPoint="EnableWindow", CallingConvention=CallingConvention.StdCall)]
2253 private extern static IntPtr Win32EnableWindow(IntPtr hwnd, bool Enabled);
2255 [DllImport ("user32.dll", EntryPoint="SetFocus", CallingConvention=CallingConvention.StdCall)]
2256 internal extern static IntPtr Win32SetFocus(IntPtr hwnd);
2258 [DllImport ("user32.dll", EntryPoint="CreateCaret", CallingConvention=CallingConvention.StdCall)]
2259 internal extern static bool Win32CreateCaret(IntPtr hwnd, IntPtr hBitmap, int nWidth, int nHeight);
2261 [DllImport ("user32.dll", EntryPoint="DestroyCaret", CallingConvention=CallingConvention.StdCall)]
2262 private extern static bool Win32DestroyCaret();
2264 [DllImport ("user32.dll", EntryPoint="ShowCaret", CallingConvention=CallingConvention.StdCall)]
2265 private extern static bool Win32ShowCaret(IntPtr hwnd);
2267 [DllImport ("user32.dll", EntryPoint="HideCaret", CallingConvention=CallingConvention.StdCall)]
2268 private extern static bool Win32HideCaret(IntPtr hwnd);
2270 [DllImport ("user32.dll", EntryPoint="SetCaretPos", CallingConvention=CallingConvention.StdCall)]
2271 private extern static bool Win32SetCaretPos(int X, int Y);
2273 [DllImport ("user32.dll", EntryPoint="GetCaretBlinkTime", CallingConvention=CallingConvention.StdCall)]
2274 private extern static uint Win32GetCaretBlinkTime();
2276 [DllImport ("gdi32.dll", EntryPoint="GetTextMetricsW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2277 internal extern static bool Win32GetTextMetrics(IntPtr hdc, ref TEXTMETRIC tm);
2279 [DllImport ("gdi32.dll", EntryPoint="SelectObject", CallingConvention=CallingConvention.StdCall)]
2280 internal extern static IntPtr Win32SelectObject(IntPtr hdc, IntPtr hgdiobject);
2282 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2283 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
2285 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2286 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2288 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2289 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2291 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2292 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2294 [DllImport ("user32.dll", EntryPoint="GetActiveWindow", CallingConvention=CallingConvention.StdCall)]
2295 private extern static IntPtr Win32GetActiveWindow();
2297 [DllImport ("user32.dll", EntryPoint="GetSystemMetrics", CallingConvention=CallingConvention.StdCall)]
2298 private extern static int Win32GetSystemMetrics(SystemMetrics nIndex);
2300 [DllImport ("shell32.dll", EntryPoint="Shell_NotifyIconW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2301 private extern static bool Win32Shell_NotifyIcon(NotifyIconMessage dwMessage, ref NOTIFYICONDATA lpData);
2303 [DllImport ("gdi32.dll", EntryPoint="CreateRectRgn", CallingConvention=CallingConvention.StdCall)]
2304 internal extern static IntPtr Win32CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
2306 [DllImport ("user32.dll", EntryPoint="IsWindowVisible", CallingConvention=CallingConvention.StdCall)]
2307 private extern static bool IsWindowVisible(IntPtr hwnd);
2309 [DllImport ("user32.dll", EntryPoint="SetClassLong", CallingConvention=CallingConvention.StdCall)]
2310 private extern static bool Win32SetClassLong(IntPtr hwnd, ClassLong nIndex, IntPtr dwNewLong);
2312 [DllImport ("user32.dll", EntryPoint="SendMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2313 private extern static bool Win32SendMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
2315 [DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2316 private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref RECT rect, uint fWinIni);
2318 [DllImport ("user32.dll", EntryPoint="OpenClipboard", CallingConvention=CallingConvention.StdCall)]
2319 private extern static bool Win32OpenClipboard(IntPtr hwnd);
2321 [DllImport ("user32.dll", EntryPoint="EmptyClipboard", CallingConvention=CallingConvention.StdCall)]
2322 private extern static bool Win32EmptyClipboard();
2324 [DllImport ("user32.dll", EntryPoint="RegisterClipboardFormatW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2325 private extern static uint Win32RegisterClipboardFormat(string format);
2327 [DllImport ("user32.dll", EntryPoint="CloseClipboard", CallingConvention=CallingConvention.StdCall)]
2328 private extern static bool Win32CloseClipboard();
2330 [DllImport ("user32.dll", EntryPoint="EnumClipboardFormats", CallingConvention=CallingConvention.StdCall)]
2331 private extern static uint Win32EnumClipboardFormats(uint format);
2333 [DllImport ("user32.dll", EntryPoint="GetClipboardData", CallingConvention=CallingConvention.StdCall)]
2334 private extern static IntPtr Win32GetClipboardData(uint format);
2336 [DllImport ("user32.dll", EntryPoint="SetClipboardData", CallingConvention=CallingConvention.StdCall)]
2337 private extern static IntPtr Win32SetClipboardData(uint format, IntPtr handle);
2339 [DllImport ("kernel32.dll", EntryPoint="GlobalAlloc", CallingConvention=CallingConvention.StdCall)]
2340 internal extern static IntPtr Win32GlobalAlloc(GAllocFlags Flags, int dwBytes);
2342 [DllImport ("kernel32.dll", EntryPoint="CopyMemory", CallingConvention=CallingConvention.StdCall)]
2343 internal extern static void Win32CopyMemory(IntPtr Destination, IntPtr Source, int length);
2345 [DllImport ("kernel32.dll", EntryPoint="GlobalFree", CallingConvention=CallingConvention.StdCall)]
2346 internal extern static IntPtr Win32GlobalFree(IntPtr hMem);
2348 [DllImport ("kernel32.dll", EntryPoint="GlobalSize", CallingConvention=CallingConvention.StdCall)]
2349 internal extern static uint Win32GlobalSize(IntPtr hMem);
2351 [DllImport ("kernel32.dll", EntryPoint="GlobalLock", CallingConvention=CallingConvention.StdCall)]
2352 internal extern static IntPtr Win32GlobalLock(IntPtr hMem);
2354 [DllImport ("kernel32.dll", EntryPoint="GlobalUnlock", CallingConvention=CallingConvention.StdCall)]
2355 internal extern static IntPtr Win32GlobalUnlock(IntPtr hMem);
2357 [DllImport ("gdi32.dll", EntryPoint="SetROP2", CallingConvention=CallingConvention.StdCall)]
2358 internal extern static int Win32SetROP2(IntPtr hdc, ROP2DrawMode fnDrawMode);
2360 [DllImport ("gdi32.dll", EntryPoint="MoveToEx", CallingConvention=CallingConvention.StdCall)]
2361 internal extern static bool Win32MoveToEx(IntPtr hdc, int x, int y, ref POINT lpPoint);
2363 [DllImport ("gdi32.dll", EntryPoint="MoveToEx", CallingConvention=CallingConvention.StdCall)]
2364 internal extern static bool Win32MoveToEx(IntPtr hdc, int x, int y, IntPtr lpPoint);
2366 [DllImport ("gdi32.dll", EntryPoint="LineTo", CallingConvention=CallingConvention.StdCall)]
2367 internal extern static bool Win32LineTo(IntPtr hdc, int x, int y);
2369 [DllImport ("gdi32.dll", EntryPoint="CreatePen", CallingConvention=CallingConvention.StdCall)]
2370 internal extern static IntPtr Win32CreatePen(PenStyle fnPenStyle, int nWidth, ref COLORREF color);
2372 [DllImport ("gdi32.dll", EntryPoint="CreatePen", CallingConvention=CallingConvention.StdCall)]
2373 internal extern static IntPtr Win32CreatePen(PenStyle fnPenStyle, int nWidth, IntPtr color);
2375 [DllImport ("gdi32.dll", EntryPoint="GetStockObject", CallingConvention=CallingConvention.StdCall)]
2376 internal extern static IntPtr Win32GetStockObject(StockObject fnObject);
2378 [DllImport ("gdi32.dll", EntryPoint="CreateHatchBrush", CallingConvention=CallingConvention.StdCall)]
2379 internal extern static IntPtr Win32CreateHatchBrush(HatchStyle fnStyle, IntPtr color);
2381 [DllImport ("gdi32.dll", EntryPoint="CreateHatchBrush", CallingConvention=CallingConvention.StdCall)]
2382 internal extern static IntPtr Win32CreateHatchBrush(HatchStyle fnStyle, ref COLORREF color);