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-2006 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;
56 internal static bool caret_visible;
58 internal static bool themes_enabled;
59 private Hashtable timer_list;
60 private static Queue message_queue;
61 private static IntPtr clip_magic = new IntPtr(27051977);
62 private static int scroll_width;
63 private static int scroll_height;
64 private static Hashtable wm_nc_registered;
65 private static RECT clipped_cursor_rect;
66 private Hashtable registered_classes;
67 private Hwnd HwndCreating; // the Hwnd we are currently creating (see CreateWindow)
69 #endregion // Local Variables
71 #region Private Structs
72 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
73 private struct WNDCLASS {
75 internal WndProc lpfnWndProc;
76 internal int cbClsExtra;
77 internal int cbWndExtra;
78 internal IntPtr hInstance;
79 internal IntPtr hIcon;
80 internal IntPtr hCursor;
81 internal IntPtr hbrBackground;
82 [MarshalAs(UnmanagedType.LPWStr)]
83 internal string lpszMenuName;
84 [MarshalAs(UnmanagedType.LPWStr)]
85 internal string lpszClassName;
88 [StructLayout(LayoutKind.Sequential)]
89 internal struct RECT {
95 public RECT (int left, int top, int right, int bottom)
100 this.bottom = bottom;
103 #region Instance Properties
104 public int Height { get { return bottom - top; } }
105 public int Width { get { return right - left; } }
106 public Size Size { get { return new Size (Width, Height); } }
107 public Point Location { get { return new Point (left, top); } }
110 #region Instance Methods
111 public Rectangle ToRectangle ()
113 return Rectangle.FromLTRB (left, top, right, bottom);
116 public static RECT FromRectangle (Rectangle rectangle)
118 return new RECT (rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom);
121 public override int GetHashCode ()
123 return left ^ ((top << 13) | (top >> 0x13))
124 ^ ((Width << 0x1a) | (Width >> 6))
125 ^ ((Height << 7) | (Height >> 0x19));
128 public override string ToString ()
130 return String.Format("RECT left={0}, top={1}, right={2}, bottom={3}, width={4}, height={5}", left, top, right, bottom, right-left, bottom-top);
134 #region Operator overloads
135 public static implicit operator Rectangle (RECT rect)
137 return Rectangle.FromLTRB (rect.left, rect.top, rect.right, rect.bottom);
140 public static implicit operator RECT (Rectangle rect)
142 return new RECT (rect.Left, rect.Top, rect.Right, rect.Bottom);
147 internal enum SPIAction {
148 SPI_GETACTIVEWINDOWTRACKING = 0x1000,
149 SPI_GETACTIVEWNDTRKTIMEOUT = 0x2002,
150 SPI_GETANIMATION = 0x0048,
151 SPI_GETCARETWIDTH = 0x2006,
152 SPI_GETCOMBOBOXANIMATION = 0x1004,
153 SPI_GETDRAGFULLWINDOWS = 0x0026,
154 SPI_GETDROPSHADOW = 0x1024,
155 SPI_GETFONTSMOOTHING = 0x004A,
156 SPI_GETFONTSMOOTHINGCONTRAST = 0x200C,
157 SPI_GETFONTSMOOTHINGTYPE = 0x200A,
158 SPI_GETGRADIENTCAPTIONS = 0x1008,
159 SPI_GETHOTTRACKING = 0x100E,
160 SPI_GETICONTITLEWRAP = 0x0019,
161 SPI_GETKEYBOARDSPEED = 0x000A,
162 SPI_GETKEYBOARDDELAY = 0x0016,
163 SPI_GETKEYBOARDCUES = 0x100A,
164 SPI_GETKEYBOARDPREF = 0x0044,
165 SPI_GETLISTBOXSMOOTHSCROLLING = 0x1006,
166 SPI_GETMENUANIMATION = 0x1002,
167 SPI_GETMENUDROPALIGNMENT = 0x001B,
168 SPI_GETMENUFADE = 0x1012,
169 SPI_GETMENUSHOWDELAY = 0x006A,
170 SPI_GETMOUSESPEED = 0x0070,
171 SPI_GETSELECTIONFADE = 0x1014,
172 SPI_GETSNAPTODEFBUTTON = 0x005F,
173 SPI_GETTOOLTIPANIMATION = 0x1016,
174 SPI_GETWORKAREA = 0x0030,
175 SPI_GETMOUSEHOVERWIDTH = 0x0062,
176 SPI_GETMOUSEHOVERHEIGHT = 0x0064,
177 SPI_GETMOUSEHOVERTIME = 0x0066,
178 SPI_GETUIEFFECTS = 0x103E,
179 SPI_GETWHEELSCROLLLINES = 0x0068
182 internal enum WindowPlacementFlags {
186 SW_SHOWMINIMIZED = 2,
187 SW_SHOWMAXIMIZED = 3,
189 SW_SHOWNOACTIVATE = 4,
192 SW_SHOWMINNOACTIVE = 7,
196 SW_FORCEMINIMIZE = 11,
200 [StructLayout(LayoutKind.Sequential)]
201 private struct WINDOWPLACEMENT {
202 internal uint length;
204 internal WindowPlacementFlags showCmd;
205 internal POINT ptMinPosition;
206 internal POINT ptMaxPosition;
207 internal RECT rcNormalPosition;
210 [StructLayout(LayoutKind.Sequential)]
211 internal struct NCCALCSIZE_PARAMS {
215 internal IntPtr lppos;
219 private enum TMEFlags {
220 TME_HOVER = 0x00000001,
221 TME_LEAVE = 0x00000002,
222 TME_NONCLIENT = 0x00000010,
223 TME_QUERY = unchecked((int)0x40000000),
224 TME_CANCEL = unchecked((int)0x80000000)
227 [StructLayout(LayoutKind.Sequential)]
228 private struct TRACKMOUSEEVENT {
230 internal TMEFlags dwFlags;
231 internal IntPtr hWnd;
232 internal int dwHoverTime;
235 [StructLayout(LayoutKind.Sequential)]
236 private struct PAINTSTRUCT {
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;
252 [StructLayout(LayoutKind.Sequential)]
253 internal struct KEYBDINPUT {
255 internal short wScan;
256 internal Int32 dwFlags;
258 internal UIntPtr dwExtraInfo;
261 [StructLayout(LayoutKind.Sequential)]
262 internal struct MOUSEINPUT {
265 internal Int32 mouseData;
266 internal Int32 dwFlags;
268 internal UIntPtr dwExtraInfo;
271 [StructLayout(LayoutKind.Sequential)]
272 internal struct HARDWAREINPUT {
274 internal short wParamL;
275 internal short wParamH;
278 [StructLayout(LayoutKind.Explicit)]
279 internal struct INPUT {
284 internal MOUSEINPUT mi;
287 internal KEYBDINPUT ki;
290 internal HARDWAREINPUT hi;
293 [StructLayout (LayoutKind.Sequential)]
294 public struct ANIMATIONINFO {
295 internal uint cbSize;
296 internal int iMinAnimate;
299 internal enum InputFlags {
300 KEYEVENTF_EXTENDEDKEY = 0x0001,
301 KEYEVENTF_KEYUP = 0x0002,
302 KEYEVENTF_SCANCODE = 0x0003,
303 KEYEVENTF_UNICODE = 0x0004,
306 internal enum ClassStyle {
307 CS_VREDRAW = 0x00000001,
308 CS_HREDRAW = 0x00000002,
309 CS_KEYCVTWINDOW = 0x00000004,
310 CS_DBLCLKS = 0x00000008,
311 CS_OWNDC = 0x00000020,
312 CS_CLASSDC = 0x00000040,
313 CS_PARENTDC = 0x00000080,
314 CS_NOKEYCVT = 0x00000100,
315 CS_NOCLOSE = 0x00000200,
316 CS_SAVEBITS = 0x00000800,
317 CS_BYTEALIGNCLIENT = 0x00001000,
318 CS_BYTEALIGNWINDOW = 0x00002000,
319 CS_GLOBALCLASS = 0x00004000,
322 CS_DROPSHADOW = 0x00020000
325 internal enum SetWindowPosZOrder {
333 internal enum SetWindowPosFlags {
334 SWP_ASYNCWINDOWPOS = 0x4000,
335 SWP_DEFERERASE = 0x2000,
336 SWP_DRAWFRAME = 0x0020,
337 SWP_FRAMECHANGED = 0x0020,
338 SWP_HIDEWINDOW = 0x0080,
339 SWP_NOACTIVATE = 0x0010,
340 SWP_NOCOPYBITS = 0x0100,
342 SWP_NOOWNERZORDER = 0x0200,
343 SWP_NOREDRAW = 0x0008,
344 SWP_NOREPOSITION = 0x0200,
345 SWP_NOENDSCHANGING = 0x0400,
347 SWP_NOZORDER = 0x0004,
348 SWP_SHOWWINDOW = 0x0040
351 internal enum GetSysColorIndex {
353 COLOR_BACKGROUND = 1,
354 COLOR_ACTIVECAPTION = 2,
355 COLOR_INACTIVECAPTION = 3,
358 COLOR_WINDOWFRAME = 6,
360 COLOR_WINDOWTEXT = 8,
361 COLOR_CAPTIONTEXT = 9,
362 COLOR_ACTIVEBORDER = 10,
363 COLOR_INACTIVEBORDER = 11,
364 COLOR_APPWORKSPACE = 12,
365 COLOR_HIGHLIGHT = 13,
366 COLOR_HIGHLIGHTTEXT = 14,
368 COLOR_BTNSHADOW = 16,
371 COLOR_INACTIVECAPTIONTEXT = 19,
372 COLOR_BTNHIGHLIGHT = 20,
373 COLOR_3DDKSHADOW = 21,
379 COLOR_GRADIENTACTIVECAPTION = 27,
380 COLOR_GRADIENTINACTIVECAPTION = 28,
381 COLOR_MENUHIGHLIGHT = 29,
387 COLOR_3DHIGHLIGHT = 20,
388 COLOR_3DHILIGHT = 20,
389 COLOR_BTNHILIGHT = 20,
390 COLOR_MAXVALUE = 24,/* Maximum value */
393 private enum LoadCursorType {
402 IDC_SIZENWSE = 32642,
403 IDC_SIZENESW = 32643,
409 IDC_APPSTARTING = 32650,
414 private enum AncestorType {
421 private enum WindowLong {
432 private enum LogBrushStyle {
441 BS_DIBPATTERN8X8 = 8,
446 private enum LogBrushHatch {
447 HS_HORIZONTAL = 0, /* ----- */
448 HS_VERTICAL = 1, /* ||||| */
449 HS_FDIAGONAL = 2, /* \\\\\ */
450 HS_BDIAGONAL = 3, /* ///// */
451 HS_CROSS = 4, /* +++++ */
452 HS_DIAGCROSS = 5, /* xxxxx */
455 internal struct COLORREF {
462 [StructLayout(LayoutKind.Sequential)]
463 private struct LOGBRUSH {
464 internal LogBrushStyle lbStyle;
465 internal COLORREF lbColor;
466 internal LogBrushHatch lbHatch;
469 [StructLayout(LayoutKind.Sequential)]
470 internal struct TEXTMETRIC {
471 internal int tmHeight;
472 internal int tmAscent;
473 internal int tmDescent;
474 internal int tmInternalLeading;
475 internal int tmExternalLeading;
476 internal int tmAveCharWidth;
477 internal int tmMaxCharWidth;
478 internal int tmWeight;
479 internal int tmOverhang;
480 internal int tmDigitizedAspectX;
481 internal int tmDigitizedAspectY;
482 internal short tmFirstChar;
483 internal short tmLastChar;
484 internal short tmDefaultChar;
485 internal short tmBreakChar;
486 internal byte tmItalic;
487 internal byte tmUnderlined;
488 internal byte tmStruckOut;
489 internal byte tmPitchAndFamily;
490 internal byte tmCharSet;
493 public enum TernaryRasterOperations : uint
495 SRCCOPY = 0x00CC0020,
496 SRCPAINT = 0x00EE0086,
498 SRCINVERT = 0x00660046,
499 SRCERASE = 0x00440328,
500 NOTSRCCOPY = 0x00330008,
501 NOTSRCERASE = 0x001100A6,
502 MERGECOPY = 0x00C000CA,
503 MERGEPAINT = 0x00BB0226,
504 PATCOPY = 0x00F00021,
505 PATPAINT = 0x00FB0A09,
506 PATINVERT = 0x005A0049,
507 DSTINVERT = 0x00550009,
508 BLACKNESS = 0x00000042,
509 WHITENESS = 0x00FF0062
513 private enum ScrollWindowExFlags {
515 SW_SCROLLCHILDREN = 0x0001,
516 SW_INVALIDATE = 0x0002,
518 SW_SMOOTHSCROLL = 0x0010
521 internal enum SystemMetrics {
538 SM_CXFULLSCREEN = 16,
539 SM_CYFULLSCREEN = 17,
540 SM_CYKANJIWINDOW = 18,
541 SM_MOUSEPRESENT = 19,
560 SM_CXICONSPACING = 38,
561 SM_CYICONSPACING = 39,
562 SM_MENUDROPALIGNMENT = 40,
565 SM_CMOUSEBUTTONS = 43,
566 SM_CXFIXEDFRAME = SM_CXDLGFRAME,
567 SM_CYFIXEDFRAME = SM_CYDLGFRAME,
568 SM_CXSIZEFRAME = SM_CXFRAME,
569 SM_CYSIZEFRAME = SM_CYFRAME,
573 SM_CXMINSPACING = 47,
574 SM_CYMINSPACING = 48,
597 SM_MIDEASTENABLED = 74,
598 SM_MOUSEWHEELPRESENT = 75,
599 SM_XVIRTUALSCREEN = 76,
600 SM_YVIRTUALSCREEN = 77,
601 SM_CXVIRTUALSCREEN = 78,
602 SM_CYVIRTUALSCREEN = 79,
604 SM_SAMEDISPLAYFORMAT = 81,
606 SM_CXFOCUSBORDER = 83,
607 SM_CYFOCUSBORDER = 84,
613 // We'll only support _WIN32_IE < 0x0500 for now
614 internal enum NotifyIconMessage {
615 NIM_ADD = 0x00000000,
616 NIM_MODIFY = 0x00000001,
617 NIM_DELETE = 0x00000002,
621 internal enum NotifyIconFlags {
622 NIF_MESSAGE = 0x00000001,
623 NIF_ICON = 0x00000002,
624 NIF_TIP = 0x00000004,
625 NIF_STATE = 0x00000008,
626 NIF_INFO = 0x00000010
629 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
630 internal struct NOTIFYICONDATA {
631 internal uint cbSize;
632 internal IntPtr hWnd;
634 internal NotifyIconFlags uFlags;
635 internal uint uCallbackMessage;
636 internal IntPtr hIcon;
637 [MarshalAs(UnmanagedType.ByValTStr, SizeConst=128)]
638 internal string szTip;
639 internal int dwState;
640 internal int dwStateMask;
641 [MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]
642 internal string szInfo;
643 internal int uTimeoutOrVersion;
644 [MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)]
645 internal string szInfoTitle;
647 internal ToolTipIcon dwInfoFlags;
649 internal int dwInfoFlags;
654 internal enum DCExFlags {
655 DCX_WINDOW = 0x00000001,
656 DCX_CACHE = 0x00000002,
657 DCX_NORESETATTRS = 0x00000004,
658 DCX_CLIPCHILDREN = 0x00000008,
659 DCX_CLIPSIBLINGS = 0x00000010,
660 DCX_PARENTCLIP = 0x00000020,
661 DCX_EXCLUDERGN = 0x00000040,
662 DCX_INTERSECTRGN = 0x00000080,
663 DCX_EXCLUDEUPDATE = 0x00000100,
664 DCX_INTERSECTUPDATE = 0x00000200,
665 DCX_LOCKWINDOWUPDATE = 0x00000400,
666 DCX_USESTYLE = 0x00010000,
667 DCX_VALIDATE = 0x00200000
670 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
671 internal struct CLIENTCREATESTRUCT {
672 internal IntPtr hWindowMenu;
673 internal uint idFirstChild;
676 private enum ClassLong : int {
678 GCL_HBRBACKGROUND = -10,
682 GCL_CBWNDEXTRA = -18,
683 GCL_CBCLSEXTRA = -20,
691 internal enum GAllocFlags : uint {
693 GMEM_MOVEABLE = 0x0002,
694 GMEM_NOCOMPACT = 0x0010,
695 GMEM_NODISCARD = 0x0020,
696 GMEM_ZEROINIT = 0x0040,
697 GMEM_MODIFY = 0x0080,
698 GMEM_DISCARDABLE = 0x0100,
699 GMEM_NOT_BANKED = 0x1000,
701 GMEM_DDESHARE = 0x2000,
702 GMEM_NOTIFY = 0x4000,
703 GMEM_LOWER = GMEM_NOT_BANKED,
704 GMEM_VALID_FLAGS = 0x7F72,
705 GMEM_INVALID_HANDLE = 0x8000,
706 GHND = (GMEM_MOVEABLE | GMEM_ZEROINIT),
707 GPTR = (GMEM_FIXED | GMEM_ZEROINIT)
710 internal enum ROP2DrawMode : int {
730 internal enum PenStyle : int {
742 internal enum PatBltRop : int {
744 PATINVERT = 0x5a0049,
745 DSTINVERT = 0x550009,
746 BLACKNESS = 0x000042,
747 WHITENESS = 0xff0062,
750 internal enum StockObject : int {
757 HOLLOW_BRUSH = NULL_BRUSH,
762 ANSI_FIXED_FONT = 11,
765 DEVICE_DEFAULT_FONT = 14,
766 DEFAULT_PALETTE = 15,
767 SYSTEM_FIXED_FONT = 16
770 internal enum HatchStyle : int {
780 internal enum SndFlags : int {
783 SND_NODEFAULT = 0x0002,
787 SND_NOWAIT = 0x00002000,
788 SND_ALIAS = 0x00010000,
789 SND_ALIAS_ID = 0x00110000,
790 SND_FILENAME = 0x00020000,
791 SND_RESOURCE = 0x00040004,
793 SND_APPLICATION = 0x0080,
797 internal enum LayeredWindowAttributes : int {
802 public enum ACLineStatus : byte {
808 public enum BatteryFlag : byte {
813 NoSystemBattery = 128,
817 [StructLayout (LayoutKind.Sequential)]
818 public class SYSTEMPOWERSTATUS {
819 public ACLineStatus _ACLineStatus;
820 public BatteryFlag _BatteryFlag;
821 public Byte _BatteryLifePercent;
822 public Byte _Reserved1;
823 public Int32 _BatteryLifeTime;
824 public Int32 _BatteryFullLifeTime;
828 #region Constructor & Destructor
829 private XplatUIWin32() {
830 // Handle singleton stuff first
833 mouse_state = MouseButtons.None;
834 mouse_position = Point.Empty;
836 message_queue = new Queue();
838 themes_enabled = false;
840 wnd_proc = new WndProc(InternalWndProc);
842 FosterParent=Win32CreateWindow(WindowExStyles.WS_EX_TOOLWINDOW, "static", "Foster Parent Window", WindowStyles.WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
844 if (FosterParent==IntPtr.Zero) {
845 Win32MessageBox(IntPtr.Zero, "Could not create foster window, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
848 scroll_height = Win32GetSystemMetrics(SystemMetrics.SM_CYHSCROLL);
849 scroll_width = Win32GetSystemMetrics(SystemMetrics.SM_CXVSCROLL);
851 timer_list = new Hashtable ();
852 registered_classes = new Hashtable ();
854 #endregion // Constructor & Destructor
856 #region Private Support Methods
858 private string RegisterWindowClass (int classStyle)
862 lock (registered_classes) {
863 class_name = (string)registered_classes[classStyle];
865 if (class_name != null)
868 class_name = string.Format ("Mono.WinForms.{0}.{1}", System.Threading.Thread.GetDomainID ().ToString (), classStyle);
872 wndClass.style = classStyle;
873 wndClass.lpfnWndProc = wnd_proc;
874 wndClass.cbClsExtra = 0;
875 wndClass.cbWndExtra = 0;
876 wndClass.hbrBackground = (IntPtr)(GetSysColorIndex.COLOR_WINDOW + 1);
877 wndClass.hCursor = Win32LoadCursor (IntPtr.Zero, LoadCursorType.IDC_ARROW);
878 wndClass.hIcon = IntPtr.Zero;
879 wndClass.hInstance = IntPtr.Zero;
880 wndClass.lpszClassName = class_name;
881 wndClass.lpszMenuName = "";
883 bool result = Win32RegisterClass (ref wndClass);
886 Win32MessageBox (IntPtr.Zero, "Could not register the window class, win32 error " + Win32GetLastError ().ToString (), "Oops", 0);
888 registered_classes[classStyle] = class_name;
894 private static bool RetrieveMessage(ref MSG msg) {
897 if (message_queue.Count == 0) {
901 message = (MSG)message_queue.Dequeue();
907 private static bool StoreMessage(ref MSG msg) {
908 MSG message = new MSG();
911 message_queue.Enqueue(message);
916 internal static String AnsiToString(IntPtr ansi_data) {
917 return (string)Marshal.PtrToStringAnsi(ansi_data);
920 internal static String UnicodeToString(IntPtr unicode_data) {
921 return (string)Marshal.PtrToStringUni(unicode_data);
924 internal static Image DIBtoImage(IntPtr dib_data) {
925 BITMAPINFOHEADER bmi;
936 bmi = (BITMAPINFOHEADER)Marshal.PtrToStructure(dib_data, typeof(BITMAPINFOHEADER));
938 ncolors = (int)bmi.biClrUsed;
940 if (bmi.biBitCount < 24) {
941 ncolors = (int)(1 << bmi.biBitCount);
944 //palettesize = ncolors * 4;
946 imagesize = (int)bmi.biSizeImage;
947 if (imagesize == 0) {
948 imagesize = (int)(((((bmi.biWidth * bmi.biBitCount) + 31) & ~31) >> 3) * bmi.biHeight);
951 switch(bmi.biBitCount) {
952 case 1: { // Monochrome
953 bmp = new Bitmap(bmi.biWidth, bmi.biHeight, PixelFormat.Format1bppIndexed);
954 palette = new int[2];
959 bmp = new Bitmap(bmi.biWidth, bmi.biHeight, PixelFormat.Format4bppIndexed);
960 palette = new int[16];
965 bmp = new Bitmap(bmi.biWidth, bmi.biHeight, PixelFormat.Format8bppIndexed);
966 palette = new int[256];
972 bmp = new Bitmap(bmi.biWidth, bmi.biHeight, PixelFormat.Format32bppArgb);
973 palette = new int[0];
978 throw new Exception("Unexpected number of bits:" + bmi.biBitCount.ToString());
982 if (bmi.biBitCount < 24) {
983 pal = bmp.Palette; // Managed palette
984 Marshal.Copy((IntPtr)((int)dib_data + Marshal.SizeOf(typeof(BITMAPINFOHEADER))), palette, 0, palette.Length);
986 for (int i = 0; i < ncolors; i++) {
987 pal.Entries[i] = Color.FromArgb(palette[i] | unchecked((int)0xff000000));
992 bytesPerLine = (int)((((bmi.biWidth * bmi.biBitCount) + 31) & ~31) >> 3);
993 bits = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
995 imagebits = new byte[bytesPerLine];
997 for (int y = 0; y < bmi.biHeight; y++) {
998 // Copy from source to managed
999 Marshal.Copy((IntPtr)((int)dib_data + Marshal.SizeOf(typeof(BITMAPINFOHEADER)) + palette.Length * 4 + bytesPerLine * y), imagebits, 0, bytesPerLine);
1001 // Copy from managed to dest
1002 Marshal.Copy(imagebits, 0, (IntPtr)((int)bits.Scan0 + bits.Stride * (bmi.biHeight - 1 - y)), imagebits.Length);
1005 bmp.UnlockBits(bits);
1010 internal static byte[] ImageToDIB(Image image) {
1015 ms = new MemoryStream();
1016 image.Save(ms, ImageFormat.Bmp);
1017 buffer = ms.GetBuffer();
1019 // Filter out the file header
1020 retbuf = new byte[buffer.Length];
1021 Array.Copy(buffer, 14, retbuf, 0, buffer.Length - 14);
1025 internal static IntPtr DupGlobalMem(IntPtr mem) {
1031 len = Win32GlobalSize(mem);
1032 mem_ptr = Win32GlobalLock(mem);
1034 dup = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE, (int)len);
1035 dup_ptr = Win32GlobalLock(dup);
1037 Win32CopyMemory(dup_ptr, mem_ptr, (int)len);
1039 Win32GlobalUnlock(mem);
1040 Win32GlobalUnlock(dup);
1045 private int GetSystemParametersInfoInt (SPIAction spi)
1049 Win32SystemParametersInfo (spi, 0, ref value, 0);
1054 private bool GetSystemParametersInfoBool (SPIAction spi)
1058 Win32SystemParametersInfo (spi, 0, ref value, 0);
1062 #endregion // Private Support Methods
1064 #region Static Properties
1065 internal override int ActiveWindowTrackingDelay {
1066 get { return GetSystemParametersInfoInt (SPIAction.SPI_GETACTIVEWNDTRKTIMEOUT); }
1069 internal override int CaretWidth {
1071 // Supported on 2k, XP, 2k3 +
1072 if (Environment.OSVersion.Version.Major < 5)
1073 throw new NotSupportedException ();
1075 return GetSystemParametersInfoInt (SPIAction.SPI_GETCARETWIDTH);
1079 internal override int FontSmoothingContrast {
1081 // Supported on XP, 2k3 +
1082 if (Environment.OSVersion.Version.Major < 5 || (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0))
1083 throw new NotSupportedException ();
1085 return GetSystemParametersInfoInt (SPIAction.SPI_GETFONTSMOOTHINGCONTRAST);
1089 internal override int FontSmoothingType {
1091 // Supported on XP, 2k3 +
1092 if (Environment.OSVersion.Version.Major < 5 || (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0))
1093 throw new NotSupportedException ();
1095 return GetSystemParametersInfoInt (SPIAction.SPI_GETFONTSMOOTHINGTYPE);
1099 internal override int HorizontalResizeBorderThickness {
1100 get { return Win32GetSystemMetrics (SystemMetrics.SM_CXSIZEFRAME); }
1103 internal override bool IsActiveWindowTrackingEnabled {
1104 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETACTIVEWINDOWTRACKING); }
1107 internal override bool IsComboBoxAnimationEnabled {
1108 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETCOMBOBOXANIMATION); }
1111 internal override bool IsDropShadowEnabled {
1113 // Supported on XP, 2k3 +
1114 if (Environment.OSVersion.Version.Major < 5 || (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0))
1115 throw new NotSupportedException ();
1117 return GetSystemParametersInfoBool (SPIAction.SPI_GETDROPSHADOW);
1121 internal override bool IsFontSmoothingEnabled {
1122 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETFONTSMOOTHING); }
1125 internal override bool IsHotTrackingEnabled {
1126 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETHOTTRACKING); }
1129 internal override bool IsIconTitleWrappingEnabled {
1130 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETICONTITLEWRAP); }
1133 internal override bool IsKeyboardPreferred {
1134 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETKEYBOARDPREF); }
1137 internal override bool IsListBoxSmoothScrollingEnabled {
1138 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETLISTBOXSMOOTHSCROLLING); }
1141 internal override bool IsMenuAnimationEnabled {
1142 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETMENUANIMATION); }
1145 internal override bool IsMenuFadeEnabled {
1146 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETMENUFADE); }
1149 internal override bool IsMinimizeRestoreAnimationEnabled {
1151 ANIMATIONINFO ai = new ANIMATIONINFO ();
1152 ai.cbSize = (uint)Marshal.SizeOf (ai);
1154 Win32SystemParametersInfo (SPIAction.SPI_GETANIMATION, 0, ref ai, 0);
1155 return ai.iMinAnimate == 0 ? false : true;
1159 internal override bool IsSelectionFadeEnabled {
1160 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETSELECTIONFADE); }
1163 internal override bool IsSnapToDefaultEnabled {
1164 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETSNAPTODEFBUTTON); }
1167 internal override bool IsTitleBarGradientEnabled {
1168 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETGRADIENTCAPTIONS); }
1171 internal override bool IsToolTipAnimationEnabled {
1172 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETTOOLTIPANIMATION); }
1175 internal override Size MenuBarButtonSize {
1177 return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXMENUSIZE),
1178 Win32GetSystemMetrics (SystemMetrics.SM_CYMENUSIZE));
1182 internal override int MenuShowDelay {
1183 get { return GetSystemParametersInfoInt (SPIAction.SPI_GETMENUSHOWDELAY); }
1186 internal override int MouseSpeed {
1187 get { return GetSystemParametersInfoInt (SPIAction.SPI_GETMOUSESPEED); }
1190 internal override LeftRightAlignment PopupMenuAlignment {
1191 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETMENUDROPALIGNMENT) == true ? LeftRightAlignment.Left : LeftRightAlignment.Right; }
1195 internal override PowerStatus PowerStatus {
1197 SYSTEMPOWERSTATUS p = new SYSTEMPOWERSTATUS ();
1199 Win32GetSystemPowerStatus (p);
1201 PowerStatus ps = new PowerStatus ((BatteryChargeStatus)p._BatteryFlag, p._BatteryFullLifeTime, (float)p._BatteryLifePercent / 255f, p._BatteryLifeTime, (PowerLineStatus)p._ACLineStatus);
1208 internal override int SizingBorderWidth {
1209 get { return Win32GetSystemMetrics (SystemMetrics.SM_CXSIZEFRAME); }
1212 internal override Size SmallCaptionButtonSize {
1214 return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXSMSIZE),
1215 Win32GetSystemMetrics (SystemMetrics.SM_CYSMSIZE));
1219 internal override bool UIEffectsEnabled {
1220 get { return GetSystemParametersInfoBool (SPIAction.SPI_GETUIEFFECTS); }
1223 internal override int VerticalResizeBorderThickness {
1224 get { return Win32GetSystemMetrics (SystemMetrics.SM_CYSIZEFRAME); }
1227 internal override void RaiseIdle (EventArgs e)
1233 internal override Keys ModifierKeys {
1238 key_state = Keys.None;
1240 state = Win32GetKeyState(VirtualKeys.VK_SHIFT);
1241 if ((state & 0x8000) != 0) {
1242 key_state |= Keys.Shift;
1244 state = Win32GetKeyState(VirtualKeys.VK_CONTROL);
1245 if ((state & 0x8000) != 0) {
1246 key_state |= Keys.Control;
1249 state = Win32GetKeyState(VirtualKeys.VK_MENU);
1250 if ((state & 0x8000) != 0) {
1251 key_state |= Keys.Alt;
1258 internal override MouseButtons MouseButtons {
1264 internal override Point MousePosition {
1266 return mouse_position;
1270 internal override Size MouseHoverSize {
1275 Win32SystemParametersInfo(SPIAction.SPI_GETMOUSEHOVERWIDTH, 0, ref width, 0);
1276 Win32SystemParametersInfo(SPIAction.SPI_GETMOUSEHOVERWIDTH, 0, ref height, 0);
1277 return new Size(width, height);
1281 internal override int MouseHoverTime {
1285 Win32SystemParametersInfo(SPIAction.SPI_GETMOUSEHOVERTIME, 0, ref time, 0);
1290 internal override int MouseWheelScrollDelta {
1293 Win32SystemParametersInfo(SPIAction.SPI_GETWHEELSCROLLLINES, 0, ref delta, 0);
1298 internal override int HorizontalScrollBarHeight {
1300 return scroll_height;
1304 internal override bool UserClipWontExposeParent {
1311 internal override int VerticalScrollBarWidth {
1313 return scroll_width;
1317 internal override int MenuHeight {
1319 return Win32GetSystemMetrics(SystemMetrics.SM_CYMENU);
1323 internal override Size Border3DSize {
1325 return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXEDGE),
1326 Win32GetSystemMetrics (SystemMetrics.SM_CYEDGE));
1330 internal override Size BorderSize {
1332 return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXBORDER),
1333 Win32GetSystemMetrics (SystemMetrics.SM_CYBORDER));
1337 internal override bool DropTarget {
1344 //throw new NotImplementedException("Need to figure out D'n'D for Win32");
1349 internal override Size CaptionButtonSize {
1351 return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXSIZE),
1352 Win32GetSystemMetrics (SystemMetrics.SM_CYSIZE));
1356 internal override int CaptionHeight {
1358 return Win32GetSystemMetrics(SystemMetrics.SM_CYCAPTION);
1362 internal override Size CursorSize {
1364 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CYCURSOR));
1368 internal override bool DragFullWindows {
1371 Win32SystemParametersInfo (SPIAction.SPI_GETDRAGFULLWINDOWS, 0, ref full, 0);
1376 internal override Size DragSize {
1378 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXDRAG), Win32GetSystemMetrics(SystemMetrics.SM_CYDRAG));
1382 internal override Size DoubleClickSize {
1384 return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXDOUBLECLK),
1385 Win32GetSystemMetrics (SystemMetrics.SM_CYDOUBLECLK));
1389 internal override int DoubleClickTime {
1391 return Win32GetDoubleClickTime ();
1395 internal override Size FixedFrameBorderSize {
1397 return new Size (Win32GetSystemMetrics (SystemMetrics.SM_CXFIXEDFRAME),
1398 Win32GetSystemMetrics (SystemMetrics.SM_CYFIXEDFRAME));
1402 internal override Size FrameBorderSize {
1404 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXFRAME), Win32GetSystemMetrics(SystemMetrics.SM_CYFRAME));
1408 internal override Size IconSize {
1410 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXICON), Win32GetSystemMetrics(SystemMetrics.SM_CYICON));
1414 internal override Size MaxWindowTrackSize {
1416 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMAXTRACK), Win32GetSystemMetrics(SystemMetrics.SM_CYMAXTRACK));
1420 internal override bool MenuAccessKeysUnderlined {
1423 Win32SystemParametersInfo (SPIAction.SPI_GETKEYBOARDCUES, 0, ref underlined, 0);
1424 return (underlined != 0);
1428 internal override Size MinimizedWindowSize {
1430 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINIMIZED), Win32GetSystemMetrics(SystemMetrics.SM_CYMINIMIZED));
1434 internal override Size MinimizedWindowSpacingSize {
1436 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINSPACING), Win32GetSystemMetrics(SystemMetrics.SM_CYMINSPACING));
1440 internal override Size MinimumWindowSize {
1442 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMIN), Win32GetSystemMetrics(SystemMetrics.SM_CYMIN));
1446 internal override Size MinWindowTrackSize {
1448 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINTRACK), Win32GetSystemMetrics(SystemMetrics.SM_CYMINTRACK));
1452 internal override Size SmallIconSize {
1454 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXSMICON), Win32GetSystemMetrics(SystemMetrics.SM_CYSMICON));
1458 internal override int MouseButtonCount {
1460 return Win32GetSystemMetrics(SystemMetrics.SM_CMOUSEBUTTONS);
1464 internal override bool MouseButtonsSwapped {
1466 return Win32GetSystemMetrics(SystemMetrics.SM_SWAPBUTTON) != 0;
1470 internal override bool MouseWheelPresent {
1472 return Win32GetSystemMetrics(SystemMetrics.SM_MOUSEWHEELPRESENT) != 0;
1476 internal override Rectangle VirtualScreen {
1478 return new Rectangle( Win32GetSystemMetrics(SystemMetrics.SM_XVIRTUALSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_YVIRTUALSCREEN),
1479 Win32GetSystemMetrics(SystemMetrics.SM_CXVIRTUALSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_CYVIRTUALSCREEN));
1483 internal override Rectangle WorkingArea {
1488 Win32SystemParametersInfo(SPIAction.SPI_GETWORKAREA, 0, ref rect, 0);
1489 return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
1490 //return new Rectangle(0, 0, Win32GetSystemMetrics(SystemMetrics.SM.SM_CXSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_CYSCREEN));
1494 internal override bool ThemesEnabled {
1496 return XplatUIWin32.themes_enabled;
1501 #endregion // Static Properties
1503 #region Singleton Specific Code
1504 public static XplatUIWin32 GetInstance() {
1505 if (instance==null) {
1506 instance=new XplatUIWin32();
1512 public int Reference {
1519 #region Public Static Methods
1520 internal override IntPtr InitializeDriver() {
1524 internal override void ShutdownDriver(IntPtr token) {
1525 Console.WriteLine("XplatUIWin32 ShutdownDriver called");
1529 internal void Version() {
1530 Console.WriteLine("Xplat version $revision: $");
1533 internal override void AudibleAlert() {
1534 Win32PlaySound("Default", IntPtr.Zero, SndFlags.SND_ALIAS | SndFlags.SND_ASYNC | SndFlags.SND_NOSTOP | SndFlags.SND_NOWAIT);
1537 internal override void GetDisplaySize(out Size size) {
1540 Win32GetWindowRect(Win32GetDesktopWindow(), out rect);
1542 size = new Size(rect.right - rect.left, rect.bottom - rect.top);
1545 internal override void EnableThemes() {
1546 themes_enabled=true;
1549 internal override IntPtr CreateWindow(CreateParams cp) {
1550 IntPtr WindowHandle;
1551 IntPtr ParentHandle;
1556 ParentHandle=cp.Parent;
1558 if ((ParentHandle==IntPtr.Zero) && (cp.Style & (int)(WindowStyles.WS_CHILD))!=0) {
1559 // We need to use our foster parent window until this poor child gets it's parent assigned
1560 ParentHandle = FosterParent;
1563 if ( ((cp.Style & (int)(WindowStyles.WS_CHILD | WindowStyles.WS_POPUP))==0) && ((cp.ExStyle & (int)WindowExStyles.WS_EX_APPWINDOW) == 0)) {
1564 // If we want to be hidden from the taskbar we need to be 'owned' by
1565 // something not on the taskbar. FosterParent is just that
1566 ParentHandle = FosterParent;
1570 if (cp.HasWindowManager) {
1571 location = Hwnd.GetNextStackedFormLocation (cp, Hwnd.ObjectFromHandle (cp.Parent));
1573 location = new Point (cp.X, cp.Y);
1576 string class_name = RegisterWindowClass (cp.ClassStyle);
1577 HwndCreating = hwnd;
1579 WindowHandle = Win32CreateWindow (cp.WindowExStyle, class_name, cp.Caption, cp.WindowStyle, location.X, location.Y, cp.Width, cp.Height, ParentHandle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
1581 HwndCreating = null;
1583 if (WindowHandle==IntPtr.Zero) {
1584 uint error = Win32GetLastError();
1586 Win32MessageBox(IntPtr.Zero, "Error : " + error.ToString(), "Failed to create window, class '"+cp.ClassName+"'", 0);
1589 hwnd.ClientWindow = WindowHandle;
1591 Win32SetWindowLong(WindowHandle, WindowLong.GWL_USERDATA, (uint)ThemeEngine.Current.DefaultControlBackColor.ToArgb());
1593 return WindowHandle;
1596 internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
1597 CreateParams create_params = new CreateParams();
1599 create_params.Caption = "";
1600 create_params.X = X;
1601 create_params.Y = Y;
1602 create_params.Width = Width;
1603 create_params.Height = Height;
1605 create_params.ClassName=XplatUI.DefaultClassName;
1606 create_params.ClassStyle = 0;
1607 create_params.ExStyle=0;
1608 create_params.Parent=IntPtr.Zero;
1609 create_params.Param=0;
1611 return CreateWindow(create_params);
1614 internal override void DestroyWindow(IntPtr handle) {
1617 hwnd = Hwnd.ObjectFromHandle(handle);
1618 Win32DestroyWindow(handle);
1623 internal override void SetWindowMinMax(IntPtr handle, Rectangle maximized, Size min, Size max) {
1624 // We do nothing, Form has to handle WM_GETMINMAXINFO
1628 internal override FormWindowState GetWindowState(IntPtr handle) {
1631 style = Win32GetWindowLong(handle, WindowLong.GWL_STYLE);
1632 if ((style & (uint)WindowStyles.WS_MAXIMIZE) != 0) {
1633 return FormWindowState.Maximized;
1634 } else if ((style & (uint)WindowStyles.WS_MINIMIZE) != 0) {
1635 return FormWindowState.Minimized;
1637 return FormWindowState.Normal;
1640 internal override void SetWindowState(IntPtr hwnd, FormWindowState state) {
1642 case FormWindowState.Normal: {
1643 Win32ShowWindow(hwnd, WindowPlacementFlags.SW_RESTORE);
1647 case FormWindowState.Minimized: {
1648 Win32ShowWindow(hwnd, WindowPlacementFlags.SW_MINIMIZE);
1652 case FormWindowState.Maximized: {
1653 Win32ShowWindow(hwnd, WindowPlacementFlags.SW_MAXIMIZE);
1659 internal override void SetWindowStyle(IntPtr handle, CreateParams cp) {
1661 Win32SetWindowLong(handle, WindowLong.GWL_STYLE, (uint)cp.Style);
1662 Win32SetWindowLong(handle, WindowLong.GWL_EXSTYLE, (uint)cp.ExStyle);
1664 if ((cp.ExStyle & (int) WindowExStyles.WS_EX_TOOLWINDOW) > 0 ||
1665 ((cp.WindowStyle & (WindowStyles.WS_CAPTION)) != WindowStyles.WS_CAPTION && cp.control is Form))
1666 XplatUI.RequestNCRecalc (handle);
1669 internal override double GetWindowTransparency(IntPtr handle)
1671 LayeredWindowAttributes lwa;
1675 if (0 == Win32GetLayeredWindowAttributes (handle, out clrRef, out alpha, out lwa))
1678 return ((double)alpha) / 255.0;
1681 internal override void SetWindowTransparency(IntPtr handle, double transparency, Color key) {
1682 LayeredWindowAttributes lwa = LayeredWindowAttributes.LWA_ALPHA;
1683 byte opacity = (byte)(transparency*255);
1684 COLORREF clrRef = new COLORREF();
1685 if (key != Color.Empty) {
1689 lwa = (LayeredWindowAttributes)( (int)lwa | (int)LayeredWindowAttributes.LWA_COLORKEY );
1694 Win32SetLayeredWindowAttributes(handle, clrRef, opacity, lwa);
1697 TransparencySupport support;
1698 bool queried_transparency_support;
1699 internal override TransparencySupport SupportsTransparency() {
1700 if (queried_transparency_support)
1704 support = TransparencySupport.None;
1708 Win32SetLayeredWindowAttributes (IntPtr.Zero, new COLORREF (), 255, LayeredWindowAttributes.LWA_ALPHA);
1710 catch (EntryPointNotFoundException) { flag = false; }
1711 catch { /* swallow everything else */ }
1713 if (flag) support |= TransparencySupport.Set;
1717 LayeredWindowAttributes lwa;
1721 Win32GetLayeredWindowAttributes (IntPtr.Zero, out clrRef, out alpha, out lwa);
1723 catch (EntryPointNotFoundException) { flag = false; }
1724 catch { /* swallow everything else */ }
1726 if (flag) support |= TransparencySupport.Get;
1728 queried_transparency_support = true;
1732 internal override void UpdateWindow(IntPtr handle) {
1733 Win32UpdateWindow(handle);
1736 internal override PaintEventArgs PaintEventStart(IntPtr handle, bool client) {
1739 PaintEventArgs paint_event;
1741 Rectangle clip_rect;
1744 clip_rect = new Rectangle();
1746 ps = new PAINTSTRUCT();
1748 hwnd = Hwnd.ObjectFromHandle(handle);
1751 if (Win32GetUpdateRect(handle, ref rect, false)) {
1752 hdc = Win32BeginPaint(handle, ref ps);
1754 hwnd.drawing_stack.Push (ps);
1756 clip_rect = new Rectangle(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right-ps.rcPaint.left, ps.rcPaint.bottom-ps.rcPaint.top);
1758 hdc = Win32GetDC(handle);
1759 // FIXME: Add the DC to internal list
1761 hwnd.drawing_stack.Push (null);
1763 clip_rect = new Rectangle(rect.top, rect.left, rect.right-rect.left, rect.bottom-rect.top);
1766 hdc = Win32GetWindowDC (handle);
1768 hwnd.drawing_stack.Push (hdc);
1770 // HACK this in for now
1771 Win32GetWindowRect (handle, out rect);
1772 clip_rect = new Rectangle(0, 0, rect.right-rect.left, rect.bottom-rect.top);
1775 Graphics dc = Graphics.FromHdc(hdc);
1776 hwnd.drawing_stack.Push (dc);
1778 paint_event = new PaintEventArgs(dc, clip_rect);
1783 internal override void PaintEventEnd(IntPtr handle, bool client) {
1786 hwnd = Hwnd.ObjectFromHandle(handle);
1788 Graphics dc = (Graphics)hwnd.drawing_stack.Pop();
1792 object o = hwnd.drawing_stack.Pop();
1794 PAINTSTRUCT ps = (PAINTSTRUCT)o;
1795 Win32EndPaint(handle, ref ps);
1798 IntPtr hdc = (IntPtr)hwnd.drawing_stack.Pop();
1799 Win32ReleaseDC(handle, hdc);
1804 internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
1805 Win32MoveWindow(handle, x, y, width, height, true);
1809 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) {
1814 Win32GetWindowRect(handle, out rect);
1815 width = rect.right - rect.left;
1816 height = rect.bottom - rect.top;
1821 parent = Win32GetAncestor (handle, AncestorType.GA_PARENT);
1822 if (parent != IntPtr.Zero && parent != Win32GetDesktopWindow ())
1823 Win32ScreenToClient(parent, ref pt);
1828 Win32GetClientRect(handle, out rect);
1829 client_width = rect.right - rect.left;
1830 client_height = rect.bottom - rect.top;
1834 internal override void Activate(IntPtr handle) {
1835 Win32SetActiveWindow(handle);
1838 internal override void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
1843 rect.right=rc.Right;
1844 rect.bottom=rc.Bottom;
1845 Win32InvalidateRect(handle, ref rect, clear);
1849 internal override void InvalidateNC (IntPtr handle)
1851 // found this gem at
1852 // http://www.dotnet247.com/247reference/msgs/58/292037.aspx
1853 Win32SetWindowPos(handle, IntPtr.Zero,
1855 SetWindowPosFlags.SWP_NOMOVE |
1856 SetWindowPosFlags.SWP_NOSIZE |
1857 SetWindowPosFlags.SWP_NOZORDER |
1858 SetWindowPosFlags.SWP_NOACTIVATE |
1859 SetWindowPosFlags.SWP_DRAWFRAME);
1862 private IntPtr InternalWndProc (IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam)
1864 if (HwndCreating != null && HwndCreating.ClientWindow == IntPtr.Zero)
1865 HwndCreating.ClientWindow = hWnd;
1866 return NativeWindow.WndProc (hWnd, msg, wParam, lParam);
1869 internal override IntPtr DefWndProc(ref Message msg) {
1870 msg.Result=Win32DefWindowProc(msg.HWnd, (Msg)msg.Msg, msg.WParam, msg.LParam);
1874 internal override void HandleException(Exception e) {
1875 StackTrace st = new StackTrace(e);
1876 Win32MessageBox(IntPtr.Zero, e.Message+st.ToString(), "Exception", 0);
1877 Console.WriteLine("{0}{1}", e.Message, st.ToString());
1880 internal override void DoEvents() {
1881 MSG msg = new MSG();
1883 if (override_cursor != IntPtr.Zero) {
1884 Cursor.Current = null;
1887 while (GetMessage(ref msg, IntPtr.Zero, 0, 0, false)) {
1888 XplatUI.TranslateMessage(ref msg);
1889 XplatUI.DispatchMessage(ref msg);
1893 internal override bool PeekMessage(Object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
1894 return Win32PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
1897 internal override void PostQuitMessage(int exitCode) {
1898 Win32PostQuitMessage(exitCode);
1901 internal override void RequestAdditionalWM_NCMessages(IntPtr hwnd, bool hover, bool leave)
1903 if (wm_nc_registered == null)
1904 wm_nc_registered = new Hashtable ();
1906 TMEFlags flags = TMEFlags.TME_NONCLIENT;
1908 flags |= TMEFlags.TME_HOVER;
1910 flags |= TMEFlags.TME_LEAVE;
1912 if (flags == TMEFlags.TME_NONCLIENT) {
1913 if (wm_nc_registered.Contains (hwnd)) {
1914 wm_nc_registered.Remove (hwnd);
1917 if (!wm_nc_registered.Contains (hwnd)) {
1918 wm_nc_registered.Add (hwnd, flags);
1920 wm_nc_registered [hwnd] = flags;
1925 internal override void RequestNCRecalc(IntPtr handle) {
1926 Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOOWNERZORDER | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE);
1929 internal override void ResetMouseHover(IntPtr handle) {
1930 TRACKMOUSEEVENT tme;
1932 tme = new TRACKMOUSEEVENT();
1933 tme.size = Marshal.SizeOf(tme);
1935 tme.dwFlags = TMEFlags.TME_LEAVE | TMEFlags.TME_HOVER;
1936 Win32TrackMouseEvent(ref tme);
1940 internal override bool GetMessage(Object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
1941 return GetMessage(ref msg, hWnd, wFilterMin, wFilterMax, true);
1944 private bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, bool blocking) {
1948 if (RetrieveMessage(ref msg)) {
1953 result = Win32GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
1955 result = Win32PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, (uint)PeekMessageFlags.PM_REMOVE);
1961 // We need to fake WM_MOUSE_ENTER
1962 switch (msg.message) {
1963 case Msg.WM_LBUTTONDOWN: {
1964 mouse_state |= MouseButtons.Left;
1968 case Msg.WM_MBUTTONDOWN: {
1969 mouse_state |= MouseButtons.Middle;
1973 case Msg.WM_RBUTTONDOWN: {
1974 mouse_state |= MouseButtons.Right;
1978 case Msg.WM_LBUTTONUP: {
1979 mouse_state &= ~MouseButtons.Left;
1983 case Msg.WM_MBUTTONUP: {
1984 mouse_state &= ~MouseButtons.Middle;
1988 case Msg.WM_RBUTTONUP: {
1989 mouse_state &= ~MouseButtons.Right;
1993 case Msg.WM_ASYNC_MESSAGE: {
1994 XplatUIDriverSupport.ExecuteClientMessage((GCHandle)msg.lParam);
1998 case Msg.WM_MOUSEMOVE: {
1999 if (msg.hwnd != prev_mouse_hwnd) {
2000 TRACKMOUSEEVENT tme;
2002 // The current message will be sent out next time around
2003 StoreMessage(ref msg);
2005 // This is the message we want to send at this point
2006 msg.message = Msg.WM_MOUSE_ENTER;
2008 prev_mouse_hwnd = msg.hwnd;
2010 tme = new TRACKMOUSEEVENT();
2011 tme.size = Marshal.SizeOf(tme);
2012 tme.hWnd = msg.hwnd;
2013 tme.dwFlags = TMEFlags.TME_LEAVE | TMEFlags.TME_HOVER;
2014 Win32TrackMouseEvent(ref tme);
2020 case Msg.WM_NCMOUSEMOVE: {
2021 if (wm_nc_registered == null || !wm_nc_registered.Contains (msg.hwnd))
2024 TRACKMOUSEEVENT tme;
2026 tme = new TRACKMOUSEEVENT ();
2027 tme.size = Marshal.SizeOf(tme);
2028 tme.hWnd = msg.hwnd;
2029 tme.dwFlags = (TMEFlags)wm_nc_registered[msg.hwnd];
2030 Win32TrackMouseEvent (ref tme);
2034 case Msg.WM_DROPFILES: {
2035 return Win32DnD.HandleWMDropFiles(ref msg);
2038 case Msg.WM_MOUSELEAVE: {
2039 prev_mouse_hwnd = IntPtr.Zero;
2043 case Msg.WM_TIMER: {
2044 Timer timer=(Timer)timer_list[(int)msg.wParam];
2046 if (timer != null) {
2056 internal override bool TranslateMessage(ref MSG msg) {
2057 return Win32TranslateMessage(ref msg);
2060 internal override IntPtr DispatchMessage(ref MSG msg) {
2061 return Win32DispatchMessage(ref msg);
2064 internal override bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
2066 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOP, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
2068 } else if (!Bottom) {
2069 Win32SetWindowPos(hWnd, AfterhWnd, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
2071 Win32SetWindowPos(hWnd, (IntPtr)SetWindowPosZOrder.HWND_BOTTOM, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
2077 internal override bool SetTopmost(IntPtr hWnd, bool Enabled) {
2079 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE);
2082 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_NOTOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE);
2087 internal override bool SetOwner(IntPtr hWnd, IntPtr hWndOwner) {
2088 Win32SetWindowLong(hWnd, WindowLong.GWL_HWNDPARENT, (uint) hWndOwner);
2092 internal override bool Text(IntPtr handle, string text) {
2093 Win32SetWindowText(handle, text);
2097 internal override bool GetText(IntPtr handle, out string text) {
2100 sb = new StringBuilder(256);
2101 Win32GetWindowText(handle, sb, sb.Capacity);
2102 text = sb.ToString();
2106 internal override bool SetVisible (IntPtr handle, bool visible, bool activate)
2109 Control c = Control.FromHandle (handle);
2113 f = (Form)Control.FromHandle (handle);
2114 WindowPlacementFlags flags = WindowPlacementFlags.SW_SHOWNORMAL;
2115 switch (f.WindowState) {
2116 case FormWindowState.Normal: flags = WindowPlacementFlags.SW_SHOWNORMAL; break;
2117 case FormWindowState.Minimized: flags = WindowPlacementFlags.SW_MINIMIZE; break;
2118 case FormWindowState.Maximized: flags = WindowPlacementFlags.SW_MAXIMIZE; break;
2121 if (!f.ActivateOnShow)
2122 flags = WindowPlacementFlags.SW_SHOWNOACTIVATE;
2124 Win32ShowWindow (handle, flags);
2127 if (c.ActivateOnShow)
2128 Win32ShowWindow (handle, WindowPlacementFlags.SW_SHOWNORMAL);
2130 Win32ShowWindow (handle, WindowPlacementFlags.SW_SHOWNOACTIVATE);
2134 Win32ShowWindow (handle, WindowPlacementFlags.SW_HIDE);
2139 internal override bool IsEnabled(IntPtr handle) {
2140 return IsWindowEnabled (handle);
2143 internal override bool IsVisible(IntPtr handle) {
2144 return IsWindowVisible (handle);
2147 internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
2148 Control c = Control.FromHandle (handle);
2149 if (parent == IntPtr.Zero) {
2151 Win32ShowWindow(handle, WindowPlacementFlags.SW_HIDE);
2155 SetVisible (handle, c.is_visible, true);
2158 // The Win32SetParent is lame, it can very well move the window
2159 // ref: http://groups.google.com/group/microsoft.public.vb.winapi/browse_thread/thread/1b82ccc54231ecee/afa82835bfc0422a%23afa82835bfc0422a
2160 // Here we save the position before changing the parent, and if it has changed afterwards restore it.
2161 // Another possibility would be to intercept WM_WINDOWPOSCHANGING and restore the coords there, but this would require plumbing in weird places
2162 // (either inside Control or add handling to InternalWndProc)
2163 // We also need to remove WS_CHILD if making the window parent-less, and add it if we're parenting it.
2166 WindowStyles style, new_style;
2168 Win32GetWindowRect (handle, out rect);
2169 style = (WindowStyles) Win32GetWindowLong (handle, WindowLong.GWL_STYLE);
2171 if (parent == IntPtr.Zero) {
2172 new_style = style & ~WindowStyles.WS_CHILD;
2173 result = Win32SetParent (handle, FosterParent);
2175 new_style = style | WindowStyles.WS_CHILD;
2176 result = Win32SetParent (handle, parent);
2178 if (style != new_style && c is Form) {
2179 Win32SetWindowLong (handle, WindowLong.GWL_STYLE, (uint) new_style);
2181 Win32GetWindowRect (handle, out rect2);
2182 if (rect.top != rect2.top && rect.left != rect2.left && c is Form) {
2183 Win32SetWindowPos (handle, IntPtr.Zero, rect.top, rect.left, rect.Width, rect.Height, SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOREDRAW | SetWindowPosFlags.SWP_NOOWNERZORDER | SetWindowPosFlags.SWP_NOENDSCHANGING | SetWindowPosFlags.SWP_NOACTIVATE);
2188 // If we ever start using this, we should probably replace FosterParent with IntPtr.Zero
2189 internal override IntPtr GetParent(IntPtr handle) {
2190 return Win32GetParent(handle);
2193 internal override void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
2195 Win32SetCapture(hWnd);
2197 if (ConfineToHwnd != IntPtr.Zero) {
2199 Win32GetWindowRect (ConfineToHwnd, out window_rect);
2200 Win32GetClipCursor (out clipped_cursor_rect);
2201 Win32ClipCursor (ref window_rect);
2205 internal override void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
2207 GrabConfined = grab_confined;
2208 GrabArea = grab_area;
2211 internal override void UngrabWindow(IntPtr hWnd) {
2212 if (!(clipped_cursor_rect.top == 0 && clipped_cursor_rect.bottom == 0 && clipped_cursor_rect.left == 0 && clipped_cursor_rect.right == 0)) {
2213 Win32ClipCursor (ref clipped_cursor_rect);
2214 clipped_cursor_rect = new RECT ();
2217 Win32ReleaseCapture();
2218 grab_hwnd = IntPtr.Zero;
2221 internal override bool CalculateWindowRect(ref Rectangle ClientRect, CreateParams cp, Menu menu, out Rectangle WindowRect) {
2224 rect.left=ClientRect.Left;
2225 rect.top=ClientRect.Top;
2226 rect.right=ClientRect.Right;
2227 rect.bottom=ClientRect.Bottom;
2229 if (!Win32AdjustWindowRectEx(ref rect, cp.Style, menu != null, cp.ExStyle)) {
2230 WindowRect = new Rectangle(ClientRect.Left, ClientRect.Top, ClientRect.Width, ClientRect.Height);
2234 WindowRect = new Rectangle(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
2238 internal override void SetCursor(IntPtr window, IntPtr cursor) {
2239 Win32SetCursor(cursor);
2243 internal override void ShowCursor(bool show) {
2244 Win32ShowCursor(show);
2247 internal override void OverrideCursor(IntPtr cursor) {
2248 Win32SetCursor(cursor);
2251 internal override IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
2253 Bitmap cursor_bitmap;
2261 // Win32 only allows creation cursors of a certain size
2262 if ((bitmap.Width != Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)) || (bitmap.Width != Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR))) {
2263 cursor_bitmap = new Bitmap(bitmap, new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)));
2264 cursor_mask = new Bitmap(mask, new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)));
2266 cursor_bitmap = bitmap;
2270 width = cursor_bitmap.Width;
2271 height = cursor_bitmap.Height;
2273 cursor_bits = new Byte[(width / 8) * height];
2274 mask_bits = new Byte[(width / 8) * height];
2276 for (int y = 0; y < height; y++) {
2277 for (int x = 0; x < width; x++) {
2278 pixel = cursor_bitmap.GetPixel(x, y);
2280 if (pixel == cursor_pixel) {
2281 cursor_bits[y * width / 8 + x / 8] |= (byte)(0x80 >> (x % 8));
2284 pixel = cursor_mask.GetPixel(x, y);
2286 if (pixel == mask_pixel) {
2287 mask_bits[y * width / 8 + x / 8] |= (byte)(0x80 >> (x % 8));
2292 cursor = Win32CreateCursor(IntPtr.Zero, xHotSpot, yHotSpot, width, height, mask_bits, cursor_bits);
2297 internal override Bitmap DefineStdCursorBitmap (StdCursor id)
2299 // We load the cursor, create a bitmap, draw the cursor onto the bitmap and return the bitmap.
2300 IntPtr cursor = DefineStdCursor (id);
2301 // Windows only have one possible cursor size!
2302 int width = Win32GetSystemMetrics (SystemMetrics.SM_CXCURSOR);
2303 int height = Win32GetSystemMetrics (SystemMetrics.SM_CYCURSOR);
2304 Bitmap bmp = new Bitmap (width, height);
2305 Graphics gc = Graphics.FromImage (bmp);
2306 IntPtr hdc = gc.GetHdc ();
2307 Win32DrawIcon (hdc, 0, 0, cursor);
2308 gc.ReleaseHdc (hdc);
2313 [MonoTODO("Define the missing cursors")]
2314 internal override IntPtr DefineStdCursor(StdCursor id) {
2316 case StdCursor.AppStarting: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_APPSTARTING);
2317 case StdCursor.Arrow: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
2318 case StdCursor.Cross: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_CROSS);
2319 case StdCursor.Default: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
2320 case StdCursor.Hand: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_HAND);
2321 case StdCursor.Help: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_HELP);
2322 case StdCursor.HSplit: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2323 case StdCursor.IBeam: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_IBEAM);
2324 case StdCursor.No: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_NO);
2325 case StdCursor.NoMove2D: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2326 case StdCursor.NoMoveHoriz: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2327 case StdCursor.NoMoveVert: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2328 case StdCursor.PanEast: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2329 case StdCursor.PanNE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2330 case StdCursor.PanNorth: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2331 case StdCursor.PanNW: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2332 case StdCursor.PanSE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2333 case StdCursor.PanSouth: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2334 case StdCursor.PanSW: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2335 case StdCursor.PanWest: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2336 case StdCursor.SizeAll: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZEALL);
2337 case StdCursor.SizeNESW: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENESW);
2338 case StdCursor.SizeNS: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENS);
2339 case StdCursor.SizeNWSE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENWSE);
2340 case StdCursor.SizeWE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZEWE);
2341 case StdCursor.UpArrow: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_UPARROW);
2342 case StdCursor.VSplit: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
2343 case StdCursor.WaitCursor: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_WAIT);
2345 throw new NotImplementedException ();
2348 internal override void DestroyCursor(IntPtr cursor) {
2349 if ((cursor.ToInt32() < (int)LoadCursorType.First) || (cursor.ToInt32() > (int)LoadCursorType.Last)) {
2350 Win32DestroyCursor(cursor);
2355 internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
2362 internal override void SetCursorPos(IntPtr handle, int x, int y) {
2363 Win32SetCursorPos(x, y);
2366 internal override Region GetClipRegion(IntPtr hwnd) {
2369 region = new Region();
2371 Win32GetWindowRgn(hwnd, region.GetHrgn(Graphics.FromHwnd(hwnd)));
2376 internal override void SetClipRegion(IntPtr hwnd, Region region) {
2377 Win32SetWindowRgn(hwnd, region.GetHrgn(Graphics.FromHwnd(hwnd)), true);
2380 internal override void EnableWindow(IntPtr handle, bool Enable) {
2381 Win32EnableWindow(handle, Enable);
2384 internal override void EndLoop(System.Threading.Thread thread) {
2388 internal override object StartLoop(System.Threading.Thread thread) {
2392 internal override void SetModal(IntPtr handle, bool Modal) {
2393 // we do nothing on Win32
2396 internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
2399 Win32GetCursorPos(out pt);
2401 if (handle!=IntPtr.Zero) {
2402 Win32ScreenToClient(handle, ref pt);
2409 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y)
2411 POINT pnt = new POINT();
2415 Win32ScreenToClient (handle, ref pnt);
2421 internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) {
2422 POINT pnt = new POINT();
2427 Win32ClientToScreen(handle, ref pnt);
2433 internal override void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
2436 Win32GetWindowRect(handle, out rect);
2437 x -= rect.left + SystemInformation.FrameBorderSize.Width;
2438 y -= rect.top + SystemInformation.FrameBorderSize.Height;
2440 WindowStyles style = (WindowStyles) Win32GetWindowLong (handle, WindowLong.GWL_STYLE);
2441 if (CreateParams.IsSet (style, WindowStyles.WS_CAPTION)) {
2442 y -= ThemeEngine.Current.CaptionHeight;
2446 internal override void MenuToScreen(IntPtr handle, ref int x, ref int y) {
2449 Win32GetWindowRect(handle, out rect);
2450 x += rect.left + SystemInformation.FrameBorderSize.Width;
2451 y += rect.top + SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight;
2455 internal override void SendAsyncMethod (AsyncMethodData method)
2457 Win32PostMessage(FosterParent, Msg.WM_ASYNC_MESSAGE, IntPtr.Zero, (IntPtr)GCHandle.Alloc (method));
2460 internal override void SetTimer (Timer timer)
2464 index = timer.GetHashCode();
2467 timer_list[index]=timer;
2470 Win32SetTimer(FosterParent, index, (uint)timer.Interval, IntPtr.Zero);
2473 internal override void KillTimer (Timer timer)
2477 index = timer.GetHashCode();
2479 Win32KillTimer(FosterParent, index);
2482 timer_list.Remove(index);
2486 internal override void CreateCaret(IntPtr hwnd, int width, int height) {
2487 Win32CreateCaret(hwnd, IntPtr.Zero, width, height);
2488 caret_visible = false;
2491 internal override void DestroyCaret(IntPtr hwnd) {
2492 Win32DestroyCaret();
2495 internal override void SetCaretPos(IntPtr hwnd, int x, int y) {
2496 Win32SetCaretPos(x, y);
2499 internal override void CaretVisible(IntPtr hwnd, bool visible) {
2501 if (!caret_visible) {
2502 Win32ShowCaret(hwnd);
2503 caret_visible = true;
2506 if (caret_visible) {
2507 Win32HideCaret(hwnd);
2508 caret_visible = false;
2513 internal override IntPtr GetFocus() {
2514 return Win32GetFocus();
2517 internal override void SetFocus(IntPtr hwnd) {
2518 Win32SetFocus(hwnd);
2521 internal override IntPtr GetActive() {
2522 return Win32GetActiveWindow();
2525 internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
2530 tm = new TEXTMETRIC();
2532 dc = Win32GetDC (IntPtr.Zero);
2533 prevobj = Win32SelectObject (dc, font.ToHfont ());
2535 if (Win32GetTextMetrics (dc, ref tm) == false) {
2536 prevobj = Win32SelectObject (dc, prevobj);
2537 Win32DeleteObject (prevobj);
2538 Win32ReleaseDC (IntPtr.Zero, dc);
2543 prevobj = Win32SelectObject (dc, prevobj);
2544 Win32DeleteObject (prevobj);
2545 Win32ReleaseDC (IntPtr.Zero, dc);
2547 ascent = tm.tmAscent;
2548 descent = tm.tmDescent;
2553 internal override void ScrollWindow(IntPtr hwnd, Rectangle rectangle, int XAmount, int YAmount, bool with_children) {
2557 rect.left = rectangle.X;
2558 rect.top = rectangle.Y;
2559 rect.right = rectangle.Right;
2560 rect.bottom = rectangle.Bottom;
2562 Win32ScrollWindowEx(hwnd, XAmount, YAmount, IntPtr.Zero, ref rect, IntPtr.Zero, IntPtr.Zero, ScrollWindowExFlags.SW_INVALIDATE | ScrollWindowExFlags.SW_ERASE | (with_children ? ScrollWindowExFlags.SW_SCROLLCHILDREN : ScrollWindowExFlags.SW_NONE));
2563 Win32UpdateWindow(hwnd);
2566 internal override void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount, bool with_children) {
2567 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));
2570 internal override bool SystrayAdd(IntPtr hwnd, string tip, Icon icon, out ToolTip tt) {
2573 nid = new NOTIFYICONDATA();
2575 nid.cbSize = (uint)Marshal.SizeOf(nid);
2578 nid.uCallbackMessage = (uint)Msg.WM_USER;
2579 nid.uFlags = NotifyIconFlags.NIF_MESSAGE;
2583 nid.uFlags |= NotifyIconFlags.NIF_TIP;
2587 nid.hIcon = icon.Handle;
2588 nid.uFlags |= NotifyIconFlags.NIF_ICON;
2593 return Win32Shell_NotifyIcon(NotifyIconMessage.NIM_ADD, ref nid);
2596 internal override bool SystrayChange(IntPtr hwnd, string tip, Icon icon, ref ToolTip tt) {
2599 nid = new NOTIFYICONDATA();
2601 nid.cbSize = (uint)Marshal.SizeOf(nid);
2602 nid.hIcon = icon.Handle;
2605 nid.uCallbackMessage = (uint)Msg.WM_USER;
2606 nid.uFlags = NotifyIconFlags.NIF_MESSAGE;
2610 nid.uFlags |= NotifyIconFlags.NIF_TIP;
2614 nid.hIcon = icon.Handle;
2615 nid.uFlags |= NotifyIconFlags.NIF_ICON;
2618 return Win32Shell_NotifyIcon(NotifyIconMessage.NIM_MODIFY, ref nid);
2621 internal override void SystrayRemove(IntPtr hwnd, ref ToolTip tt) {
2624 nid = new NOTIFYICONDATA();
2626 nid.cbSize = (uint)Marshal.SizeOf(nid);
2631 Win32Shell_NotifyIcon(NotifyIconMessage.NIM_DELETE, ref nid);
2635 internal override void SystrayBalloon(IntPtr hwnd, int timeout, string title, string text, ToolTipIcon icon)
2639 nid = new NOTIFYICONDATA();
2641 nid.cbSize = (uint)Marshal.SizeOf(nid);
2644 nid.uFlags = NotifyIconFlags.NIF_INFO;
2645 nid.uTimeoutOrVersion = timeout;
2646 nid.szInfoTitle = title;
2648 nid.dwInfoFlags = icon;
2650 Win32Shell_NotifyIcon(NotifyIconMessage.NIM_MODIFY, ref nid);
2654 internal override void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
2655 // Nothing to do on Win32
2658 internal override void SetMenu(IntPtr handle, Menu menu) {
2659 // Trigger WM_NCCALC
2660 Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
2663 internal override Point GetMenuOrigin(IntPtr handle) {
2664 Form form = Control.FromHandle (handle) as Form;
2666 Hwnd.Borders borders = Hwnd.GetBorders (form.GetCreateParams (), null);
2667 return new Point(borders.left, borders.top);
2669 return new Point(SystemInformation.FrameBorderSize.Width, SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight);
2672 internal override void SetIcon(IntPtr hwnd, Icon icon) {
2673 Win32SendMessage(hwnd, Msg.WM_SETICON, (IntPtr)1, icon == null ? IntPtr.Zero : icon.Handle); // 1 = large icon (0 would be small)
2676 internal override void ClipboardClose(IntPtr handle) {
2677 if (handle != clip_magic) {
2678 throw new ArgumentException("handle is not a valid clipboard handle");
2680 Win32CloseClipboard();
2683 internal override int ClipboardGetID(IntPtr handle, string format) {
2684 if (handle != clip_magic) {
2685 throw new ArgumentException("handle is not a valid clipboard handle");
2687 if (format == "Text" ) return 1;
2688 else if (format == "Bitmap" ) return 2;
2689 else if (format == "MetaFilePict" ) return 3;
2690 else if (format == "SymbolicLink" ) return 4;
2691 else if (format == "DataInterchangeFormat" ) return 5;
2692 else if (format == "Tiff" ) return 6;
2693 else if (format == "OEMText" ) return 7;
2694 else if (format == "DeviceIndependentBitmap" ) return 8;
2695 else if (format == "Palette" ) return 9;
2696 else if (format == "PenData" ) return 10;
2697 else if (format == "RiffAudio" ) return 11;
2698 else if (format == "WaveAudio" ) return 12;
2699 else if (format == "UnicodeText" ) return 13;
2700 else if (format == "EnhancedMetafile" ) return 14;
2701 else if (format == "FileDrop" ) return 15;
2702 else if (format == "Locale" ) return 16;
2704 return (int)Win32RegisterClipboardFormat(format);
2707 internal override IntPtr ClipboardOpen(bool primary_selection) {
2708 // Win32 does not have primary selection
2709 Win32OpenClipboard(FosterParent);
2713 internal override int[] ClipboardAvailableFormats(IntPtr handle) {
2718 if (handle != clip_magic) {
2726 format = Win32EnumClipboardFormats(format);
2730 } while (format != 0);
2733 result = new int[count];
2737 format = Win32EnumClipboardFormats(format);
2739 result[count++] = (int)format;
2741 } while (format != 0);
2747 internal override object ClipboardRetrieve(IntPtr handle, int type, XplatUI.ClipboardToObject converter) {
2752 if (handle != clip_magic) {
2753 throw new ArgumentException("handle is not a valid clipboard handle");
2756 hmem = Win32GetClipboardData((uint)type);
2757 if (hmem == IntPtr.Zero) {
2761 data = Win32GlobalLock(hmem);
2762 if (data == IntPtr.Zero) {
2763 uint error = Win32GetLastError();
2764 Console.WriteLine("Error: {0}", error);
2770 if (type == DataFormats.GetFormat(DataFormats.Rtf).Id) {
2771 obj = AnsiToString(data);
2772 } else switch ((ClipboardFormats)type) {
2773 case ClipboardFormats.CF_TEXT: {
2774 obj = AnsiToString(data);
2778 case ClipboardFormats.CF_DIB: {
2779 obj = DIBtoImage(data);
2783 case ClipboardFormats.CF_UNICODETEXT: {
2784 obj = UnicodeToString(data);
2789 if (converter != null && !converter(type, data, out obj)) {
2795 Win32GlobalUnlock(hmem);
2801 internal override void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
2806 if (handle != clip_magic) {
2807 throw new ArgumentException("handle is not a valid clipboard handle");
2812 if (!Win32EmptyClipboard())
2813 throw new ExternalException("Win32EmptyClipboard");
2818 if (obj is string) {
2819 type = (int)ClipboardFormats.CF_UNICODETEXT;
2820 } else if (obj is Image) {
2821 type = (int)ClipboardFormats.CF_DIB;
2825 if (type == DataFormats.GetFormat(DataFormats.Rtf).Id) {
2826 hmem = Marshal.StringToHGlobalAnsi((string)obj);
2827 if (Win32SetClipboardData((uint)type, hmem) == IntPtr.Zero )
2828 throw new ExternalException("Win32SetClipboardData");
2830 } else switch((ClipboardFormats)type) {
2831 case ClipboardFormats.CF_UNICODETEXT: {
2832 hmem = Marshal.StringToHGlobalUni((string)obj);
2833 if (Win32SetClipboardData((uint)type, hmem) == IntPtr.Zero)
2834 throw new ExternalException("Win32SetClipboardData");
2838 case ClipboardFormats.CF_TEXT: {
2839 hmem = Marshal.StringToHGlobalAnsi((string)obj);
2840 if (Win32SetClipboardData((uint)type, hmem) == IntPtr.Zero)
2841 throw new ExternalException("Win32SetClipboardData");
2845 case ClipboardFormats.CF_BITMAP:
2846 case ClipboardFormats.CF_DIB: {
2847 data = ImageToDIB((Image)obj);
2849 hmem = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
2850 hmem_ptr = Win32GlobalLock(hmem);
2851 Marshal.Copy(data, 0, hmem_ptr, data.Length);
2852 Win32GlobalUnlock(hmem);
2853 if (Win32SetClipboardData((uint)ClipboardFormats.CF_DIB, hmem) == IntPtr.Zero)
2854 throw new ExternalException("Win32SetClipboardData");
2859 if (converter != null && converter(ref type, obj, out data)) {
2860 hmem = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
2861 hmem_ptr = Win32GlobalLock(hmem);
2862 Marshal.Copy(data, 0, hmem_ptr, data.Length);
2863 Win32GlobalUnlock(hmem);
2864 if (Win32SetClipboardData((uint)type, hmem) == IntPtr.Zero)
2865 throw new ExternalException("Win32SetClipboardData");
2872 internal override void SetAllowDrop(IntPtr hwnd, bool allowed) {
2874 Win32DnD.RegisterDropTarget(hwnd);
2876 Win32DnD.UnregisterDropTarget(hwnd);
2880 internal override DragDropEffects StartDrag(IntPtr hwnd, object data, DragDropEffects allowedEffects) {
2881 return Win32DnD.StartDrag(hwnd, data, allowedEffects);
2884 // XXX this doesn't work at all for FrameStyle.Dashed - it draws like Thick, and in the Thick case
2885 // the corners are drawn incorrectly.
2886 internal override void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
2890 COLORREF clrRef = new COLORREF();
2892 // If we want the standard hatch pattern we would
2893 // need to create a brush
2895 clrRef.R = backColor.R;
2896 clrRef.G = backColor.G;
2897 clrRef.B = backColor.B;
2900 pen = Win32CreatePen (style == FrameStyle.Thick ? PenStyle.PS_SOLID : PenStyle.PS_DASH,
2901 style == FrameStyle.Thick ? 4 : 2, ref clrRef);
2903 hdc = Win32GetDC(IntPtr.Zero);
2904 Win32SetROP2(hdc, ROP2DrawMode.R2_NOT);
2905 oldpen = Win32SelectObject(hdc, pen);
2907 Win32MoveToEx(hdc, rectangle.Left, rectangle.Top, IntPtr.Zero);
2908 if ((rectangle.Width > 0) && (rectangle.Height > 0)) {
2909 Win32LineTo(hdc, rectangle.Right, rectangle.Top);
2910 Win32LineTo(hdc, rectangle.Right, rectangle.Bottom);
2911 Win32LineTo(hdc, rectangle.Left, rectangle.Bottom);
2912 Win32LineTo(hdc, rectangle.Left, rectangle.Top);
2914 if (rectangle.Width > 0) {
2915 Win32LineTo(hdc, rectangle.Right, rectangle.Top);
2917 Win32LineTo(hdc, rectangle.Left, rectangle.Bottom);
2921 Win32SelectObject(hdc, oldpen);
2922 Win32DeleteObject(pen);
2924 Win32ReleaseDC(IntPtr.Zero, hdc);
2927 internal override void DrawReversibleLine(Point start, Point end, Color backColor) {
2932 COLORREF clrRef = new COLORREF();
2937 Win32ClientToScreen(IntPtr.Zero, ref pt);
2939 // If we want the standard hatch pattern we would
2940 // need to create a brush
2942 clrRef.R = backColor.R;
2943 clrRef.G = backColor.G;
2944 clrRef.B = backColor.B;
2947 pen = Win32CreatePen(PenStyle.PS_SOLID, 1, ref clrRef);
2949 hdc = Win32GetDC(IntPtr.Zero);
2950 Win32SetROP2(hdc, ROP2DrawMode.R2_NOT);
2951 oldpen = Win32SelectObject(hdc, pen);
2953 Win32MoveToEx(hdc, pt.x + start.X, pt.y + start.Y, IntPtr.Zero);
2954 Win32LineTo(hdc, pt.x + end.X, pt.y + end.Y);
2956 Win32SelectObject(hdc, oldpen);
2957 Win32DeleteObject(pen);
2959 Win32ReleaseDC(IntPtr.Zero, hdc);
2962 internal override void FillReversibleRectangle (Rectangle rectangle, Color backColor)
2967 rect.left = rectangle.Left;
2968 rect.top = rectangle.Top;
2969 rect.right = rectangle.Right;
2970 rect.bottom = rectangle.Bottom;
2975 COLORREF clrRef = new COLORREF();
2977 clrRef.R = backColor.R;
2978 clrRef.G = backColor.G;
2979 clrRef.B = backColor.B;
2982 brush = Win32CreateSolidBrush (clrRef);
2984 hdc = Win32GetDC(IntPtr.Zero);
2985 oldbrush = Win32SelectObject(hdc, brush);
2987 Win32PatBlt (hdc, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, PatBltRop.DSTINVERT);
2989 Win32SelectObject(hdc, oldbrush);
2990 Win32DeleteObject(brush);
2992 Win32ReleaseDC(IntPtr.Zero, hdc);
2995 internal override void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
3004 Win32ClientToScreen(handle, ref pt);
3006 // If we want the standard hatch pattern we would
3007 // need to create a brush
3010 pen = Win32CreatePen(PenStyle.PS_SOLID, line_width, IntPtr.Zero);
3012 hdc = Win32GetDC(IntPtr.Zero);
3013 Win32SetROP2(hdc, ROP2DrawMode.R2_NOT);
3014 oldpen = Win32SelectObject(hdc, pen);
3016 Control c = Control.FromHandle (handle);
3019 Win32GetWindowRect (c.Handle, out window_rect);
3020 Region r = new Region (new Rectangle(window_rect.left, window_rect.top, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top));
3021 Win32ExtSelectClipRgn(hdc, r.GetHrgn (Graphics.FromHdc (hdc)), (int) ClipCombineMode.RGN_AND);
3024 Win32MoveToEx(hdc, pt.x + rect.Left, pt.y + rect.Top, IntPtr.Zero);
3025 if ((rect.Width > 0) && (rect.Height > 0)) {
3026 Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Top);
3027 Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Bottom);
3028 Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Bottom);
3029 Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Top);
3031 if (rect.Width > 0) {
3032 Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Top);
3034 Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Bottom);
3038 Win32SelectObject(hdc, oldpen);
3039 Win32DeleteObject(pen);
3041 Win32ExtSelectClipRgn(hdc, IntPtr.Zero, (int) ClipCombineMode.RGN_COPY);
3043 Win32ReleaseDC(IntPtr.Zero, hdc);
3046 internal override SizeF GetAutoScaleSize(Font font) {
3049 string magic_string = "The quick brown fox jumped over the lazy dog.";
3050 double magic_number = 44.549996948242189;
3052 g = Graphics.FromHwnd(FosterParent);
3054 width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
3055 return new SizeF(width, font.Height);
3058 internal override IntPtr SendMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
3059 return Win32SendMessage(hwnd, message, wParam, lParam);
3062 internal override bool PostMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
3063 return Win32PostMessage(hwnd, message, wParam, lParam);
3066 internal override int SendInput (IntPtr hwnd, Queue keys) {
3067 INPUT[] inputs = new INPUT[keys.Count];
3068 const Int32 INPUT_KEYBOARD = 1;
3071 while (keys.Count > 0) {
3072 MSG msg = (MSG)keys.Dequeue();
3075 inputs[i].ki.wScan = 0;
3076 inputs[i].ki.time = 0;
3077 inputs[i].ki.dwFlags = (Int32)(msg.message == Msg.WM_KEYUP ? InputFlags.KEYEVENTF_KEYUP : 0);
3078 inputs[i].ki.wVk = (short)msg.wParam.ToInt32();
3079 inputs[i].type = INPUT_KEYBOARD;
3082 returns = Win32SendInput((UInt32)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
3084 return (int) returns;
3087 internal override int KeyboardSpeed {
3090 Win32SystemParametersInfo(SPIAction.SPI_GETKEYBOARDSPEED, 0, ref speed, 0);
3092 // Return values range from 0 to 31 which map to 2.5 to 30 repetitions per second.
3098 internal override int KeyboardDelay {
3101 Win32SystemParametersInfo(SPIAction.SPI_GETKEYBOARDDELAY, 0, ref delay, 0);
3103 // Return values must range from 0 to 4, 0 meaning 250ms,
3104 // and 4 meaning 1000 ms.
3110 private class WinBuffer
3113 public IntPtr bitmap;
3115 public WinBuffer (IntPtr hdc, IntPtr bitmap)
3118 this.bitmap = bitmap;
3122 internal override void CreateOffscreenDrawable (IntPtr handle, int width, int height, out object offscreen_drawable)
3124 Graphics destG = Graphics.FromHwnd (handle);
3125 IntPtr destHdc = destG.GetHdc ();
3127 IntPtr srcHdc = Win32CreateCompatibleDC (destHdc);
3128 IntPtr srcBmp = Win32CreateCompatibleBitmap (destHdc, width, height);
3129 Win32SelectObject (srcHdc, srcBmp);
3131 offscreen_drawable = new WinBuffer (srcHdc, srcBmp);
3133 destG.ReleaseHdc (destHdc);
3136 internal override Graphics GetOffscreenGraphics (object offscreen_drawable)
3138 return Graphics.FromHdc (((WinBuffer)offscreen_drawable).hdc);
3141 internal override void BlitFromOffscreen (IntPtr dest_handle, Graphics dest_dc, object offscreen_drawable, Graphics offscreen_dc, Rectangle r)
3143 WinBuffer wb = (WinBuffer)offscreen_drawable;
3145 IntPtr destHdc = dest_dc.GetHdc ();
3146 Win32BitBlt (destHdc, r.Left, r.Top, r.Width, r.Height, wb.hdc, r.Left, r.Top, TernaryRasterOperations.SRCCOPY);
3147 dest_dc.ReleaseHdc (destHdc);
3150 internal override void DestroyOffscreenDrawable (object offscreen_drawable)
3152 WinBuffer wb = (WinBuffer)offscreen_drawable;
3154 Win32DeleteObject (wb.bitmap);
3155 Win32DeleteDC (wb.hdc);
3158 internal override event EventHandler Idle;
3159 #endregion // Public Static Methods
3161 #region Win32 Imports
3162 [DllImport ("kernel32.dll", EntryPoint="GetLastError", CallingConvention=CallingConvention.StdCall)]
3163 private extern static uint Win32GetLastError();
3165 [DllImport ("user32.dll", EntryPoint="CreateWindowExW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3166 internal extern static IntPtr Win32CreateWindow(WindowExStyles dwExStyle, string lpClassName, string lpWindowName, WindowStyles dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lParam);
3168 [DllImport ("user32.dll", EntryPoint="DestroyWindow", CallingConvention=CallingConvention.StdCall)]
3169 internal extern static bool Win32DestroyWindow(IntPtr hWnd);
3171 [DllImport ("user32.dll", EntryPoint="PeekMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3172 internal extern static bool Win32PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags);
3174 [DllImport ("user32.dll", EntryPoint="GetMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3175 internal extern static bool Win32GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax);
3177 [DllImport ("user32.dll", EntryPoint="TranslateMessage", CallingConvention=CallingConvention.StdCall)]
3178 internal extern static bool Win32TranslateMessage(ref MSG msg);
3180 [DllImport ("user32.dll", EntryPoint="DispatchMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3181 internal extern static IntPtr Win32DispatchMessage(ref MSG msg);
3183 [DllImport ("user32.dll", EntryPoint="MoveWindow", CallingConvention=CallingConvention.StdCall)]
3184 internal extern static bool Win32MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
3186 [DllImport ("user32.dll", EntryPoint="SetWindowPos", CallingConvention=CallingConvention.StdCall)]
3187 internal extern static bool Win32SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SetWindowPosFlags Flags);
3189 [DllImport ("user32.dll", EntryPoint="SetWindowPos", CallingConvention=CallingConvention.StdCall)]
3190 internal extern static bool Win32SetWindowPos(IntPtr hWnd, SetWindowPosZOrder pos, int x, int y, int cx, int cy, SetWindowPosFlags Flags);
3192 [DllImport ("user32.dll", EntryPoint="SetWindowTextW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3193 internal extern static bool Win32SetWindowText(IntPtr hWnd, string lpString);
3195 [DllImport ("user32.dll", EntryPoint="GetWindowTextW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3196 internal extern static bool Win32GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
3198 [DllImport ("user32.dll", EntryPoint="SetParent", CallingConvention=CallingConvention.StdCall)]
3199 internal extern static IntPtr Win32SetParent(IntPtr hWnd, IntPtr hParent);
3201 [DllImport ("user32.dll", EntryPoint="RegisterClassW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3202 private extern static bool Win32RegisterClass(ref WNDCLASS wndClass);
3204 [DllImport ("user32.dll", EntryPoint="LoadCursorW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3205 private extern static IntPtr Win32LoadCursor(IntPtr hInstance, LoadCursorType type);
3207 [DllImport ("user32.dll", EntryPoint="ShowCursor", CallingConvention=CallingConvention.StdCall)]
3208 private extern static IntPtr Win32ShowCursor(bool bShow);
3210 [DllImport ("user32.dll", EntryPoint="SetCursor", CallingConvention=CallingConvention.StdCall)]
3211 private extern static IntPtr Win32SetCursor(IntPtr hCursor);
3213 [DllImport ("user32.dll", EntryPoint="CreateCursor", CallingConvention=CallingConvention.StdCall)]
3214 private extern static IntPtr Win32CreateCursor(IntPtr hInstance, int xHotSpot, int yHotSpot, int nWidth, int nHeight, Byte[] pvANDPlane, Byte[] pvORPlane);
3216 [DllImport ("user32.dll", EntryPoint="DestroyCursor", CallingConvention=CallingConvention.StdCall)]
3217 private extern static bool Win32DestroyCursor(IntPtr hCursor);
3219 [DllImport ("user32.dll", EntryPoint = "DrawIcon", CallingConvention = CallingConvention.StdCall)]
3220 private extern static bool Win32DrawIcon (IntPtr hDC, int X, int Y, IntPtr hIcon);
3222 [DllImport ("user32.dll", EntryPoint="DefWindowProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3223 private extern static IntPtr Win32DefWindowProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
3225 //[DllImport ("user32.dll", EntryPoint="DefDlgProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3226 //private extern static IntPtr Win32DefDlgProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
3228 [DllImport ("user32.dll", EntryPoint="PostQuitMessage", CallingConvention=CallingConvention.StdCall)]
3229 private extern static IntPtr Win32PostQuitMessage(int nExitCode);
3231 [DllImport ("user32.dll", EntryPoint="UpdateWindow", CallingConvention=CallingConvention.StdCall)]
3232 private extern static IntPtr Win32UpdateWindow(IntPtr hWnd);
3234 [DllImport ("user32.dll", EntryPoint="GetUpdateRect", CallingConvention=CallingConvention.StdCall)]
3235 private extern static bool Win32GetUpdateRect(IntPtr hWnd, ref RECT rect, bool erase);
3237 [DllImport ("user32.dll", EntryPoint="BeginPaint", CallingConvention=CallingConvention.StdCall)]
3238 private extern static IntPtr Win32BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
3240 [DllImport ("user32.dll", EntryPoint="EndPaint", CallingConvention=CallingConvention.StdCall)]
3241 private extern static bool Win32EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
3243 [DllImport ("user32.dll", EntryPoint="GetDC", CallingConvention=CallingConvention.StdCall)]
3244 private extern static IntPtr Win32GetDC(IntPtr hWnd);
3246 [DllImport ("user32.dll", EntryPoint="GetWindowDC", CallingConvention=CallingConvention.StdCall)]
3247 private extern static IntPtr Win32GetWindowDC(IntPtr hWnd);
3249 //[DllImport ("user32.dll", EntryPoint="GetDCEx", CallingConvention=CallingConvention.StdCall)]
3250 //private extern static IntPtr Win32GetDCEx(IntPtr hWnd, IntPtr hRgn, DCExFlags flags);
3252 [DllImport ("user32.dll", EntryPoint="ReleaseDC", CallingConvention=CallingConvention.StdCall)]
3253 private extern static IntPtr Win32ReleaseDC(IntPtr hWnd, IntPtr hDC);
3255 [DllImport ("user32.dll", EntryPoint="MessageBoxW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3256 private extern static IntPtr Win32MessageBox(IntPtr hParent, string pText, string pCaption, uint uType);
3258 [DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
3259 private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, ref RECT lpRect, bool bErase);
3261 //[DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
3262 //private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
3264 [DllImport ("user32.dll", EntryPoint="SetCapture", CallingConvention=CallingConvention.StdCall)]
3265 private extern static IntPtr Win32SetCapture(IntPtr hWnd);
3267 [DllImport ("user32.dll", EntryPoint="ReleaseCapture", CallingConvention=CallingConvention.StdCall)]
3268 private extern static IntPtr Win32ReleaseCapture();
3270 [DllImport ("user32.dll", EntryPoint="GetWindowRect", CallingConvention=CallingConvention.StdCall)]
3271 private extern static IntPtr Win32GetWindowRect(IntPtr hWnd, out RECT rect);
3273 [DllImport ("user32.dll", EntryPoint="GetClientRect", CallingConvention=CallingConvention.StdCall)]
3274 private extern static IntPtr Win32GetClientRect(IntPtr hWnd, out RECT rect);
3276 [DllImport ("user32.dll", EntryPoint="ScreenToClient", CallingConvention=CallingConvention.StdCall)]
3277 private extern static bool Win32ScreenToClient(IntPtr hWnd, ref POINT pt);
3279 [DllImport ("user32.dll", EntryPoint="ClientToScreen", CallingConvention=CallingConvention.StdCall)]
3280 private extern static bool Win32ClientToScreen(IntPtr hWnd, ref POINT pt);
3282 // This function returns the parent OR THE OWNER!
3283 // Use GetAncestor to only get the parent.
3284 [DllImport ("user32.dll", EntryPoint="GetParent", CallingConvention=CallingConvention.StdCall)]
3285 private extern static IntPtr Win32GetParent(IntPtr hWnd);
3287 [DllImport ("user32.dll", EntryPoint = "GetAncestor", CallingConvention = CallingConvention.StdCall)]
3288 private extern static IntPtr Win32GetAncestor (IntPtr hWnd, AncestorType flags);
3290 [DllImport ("user32.dll", EntryPoint="SetActiveWindow", CallingConvention=CallingConvention.StdCall)]
3291 private extern static IntPtr Win32SetActiveWindow(IntPtr hWnd);
3293 [DllImport ("user32.dll", EntryPoint="AdjustWindowRectEx", CallingConvention=CallingConvention.StdCall)]
3294 private extern static bool Win32AdjustWindowRectEx(ref RECT lpRect, int dwStyle, bool bMenu, int dwExStyle);
3296 [DllImport ("user32.dll", EntryPoint="GetCursorPos", CallingConvention=CallingConvention.StdCall)]
3297 private extern static bool Win32GetCursorPos(out POINT lpPoint);
3299 [DllImport ("user32.dll", EntryPoint="SetCursorPos", CallingConvention=CallingConvention.StdCall)]
3300 private extern static bool Win32SetCursorPos(int x, int y);
3302 //[DllImport ("user32.dll", EntryPoint="GetWindowPlacement", CallingConvention=CallingConvention.StdCall)]
3303 //private extern static bool Win32GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
3305 [DllImport ("user32.dll", EntryPoint="TrackMouseEvent", CallingConvention=CallingConvention.StdCall)]
3306 private extern static bool Win32TrackMouseEvent(ref TRACKMOUSEEVENT tme);
3308 //[DllImport ("gdi32.dll", EntryPoint="CreateBrushIndirect", CallingConvention=CallingConvention.StdCall)]
3309 //private extern static IntPtr Win32CreateBrushIndirect(ref LOGBRUSH lb);
3311 [DllImport ("gdi32.dll", EntryPoint="CreateSolidBrush", CallingConvention=CallingConvention.StdCall)]
3312 private extern static IntPtr Win32CreateSolidBrush(COLORREF clrRef);
3314 [DllImport ("gdi32.dll", EntryPoint="PatBlt", CallingConvention=CallingConvention.StdCall)]
3315 private extern static int Win32PatBlt(IntPtr hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, PatBltRop dwRop);
3317 [DllImport ("user32.dll", EntryPoint="SetWindowLong", CallingConvention=CallingConvention.StdCall)]
3318 private extern static uint Win32SetWindowLong(IntPtr hwnd, WindowLong index, uint value);
3320 [DllImport ("user32.dll", EntryPoint="GetWindowLong", CallingConvention=CallingConvention.StdCall)]
3321 private extern static uint Win32GetWindowLong(IntPtr hwnd, WindowLong index);
3323 [DllImport ("user32.dll", EntryPoint="SetLayeredWindowAttributes", CallingConvention=CallingConvention.StdCall)]
3324 private extern static uint Win32SetLayeredWindowAttributes (IntPtr hwnd, COLORREF crKey, byte bAlpha, LayeredWindowAttributes dwFlags);
3326 [DllImport ("user32.dll", EntryPoint="GetLayeredWindowAttributes", CallingConvention=CallingConvention.StdCall)]
3327 private extern static uint Win32GetLayeredWindowAttributes (IntPtr hwnd, out COLORREF pcrKey, out byte pbAlpha, out LayeredWindowAttributes pwdFlags);
3329 [DllImport ("gdi32.dll", EntryPoint="DeleteObject", CallingConvention=CallingConvention.StdCall)]
3330 private extern static bool Win32DeleteObject(IntPtr o);
3332 [DllImport ("user32.dll", EntryPoint="GetKeyState", CallingConvention=CallingConvention.StdCall)]
3333 private extern static short Win32GetKeyState(VirtualKeys nVirtKey);
3335 [DllImport ("user32.dll", EntryPoint="GetDesktopWindow", CallingConvention=CallingConvention.StdCall)]
3336 private extern static IntPtr Win32GetDesktopWindow();
3338 [DllImport ("user32.dll", EntryPoint="SetTimer", CallingConvention=CallingConvention.StdCall)]
3339 private extern static IntPtr Win32SetTimer(IntPtr hwnd, int nIDEvent, uint uElapse, IntPtr timerProc);
3341 [DllImport ("user32.dll", EntryPoint="KillTimer", CallingConvention=CallingConvention.StdCall)]
3342 private extern static IntPtr Win32KillTimer(IntPtr hwnd, int nIDEvent);
3344 [DllImport ("user32.dll", EntryPoint="ShowWindow", CallingConvention=CallingConvention.StdCall)]
3345 private extern static IntPtr Win32ShowWindow(IntPtr hwnd, WindowPlacementFlags nCmdShow);
3347 [DllImport ("user32.dll", EntryPoint="EnableWindow", CallingConvention=CallingConvention.StdCall)]
3348 private extern static IntPtr Win32EnableWindow(IntPtr hwnd, bool Enabled);
3350 [DllImport ("user32.dll", EntryPoint="SetFocus", CallingConvention=CallingConvention.StdCall)]
3351 internal extern static IntPtr Win32SetFocus(IntPtr hwnd);
3353 [DllImport ("user32.dll", EntryPoint="GetFocus", CallingConvention=CallingConvention.StdCall)]
3354 internal extern static IntPtr Win32GetFocus();
3356 [DllImport ("user32.dll", EntryPoint="CreateCaret", CallingConvention=CallingConvention.StdCall)]
3357 internal extern static bool Win32CreateCaret(IntPtr hwnd, IntPtr hBitmap, int nWidth, int nHeight);
3359 [DllImport ("user32.dll", EntryPoint="DestroyCaret", CallingConvention=CallingConvention.StdCall)]
3360 private extern static bool Win32DestroyCaret();
3362 [DllImport ("user32.dll", EntryPoint="ShowCaret", CallingConvention=CallingConvention.StdCall)]
3363 private extern static bool Win32ShowCaret(IntPtr hwnd);
3365 [DllImport ("user32.dll", EntryPoint="HideCaret", CallingConvention=CallingConvention.StdCall)]
3366 private extern static bool Win32HideCaret(IntPtr hwnd);
3368 [DllImport ("user32.dll", EntryPoint="SetCaretPos", CallingConvention=CallingConvention.StdCall)]
3369 private extern static bool Win32SetCaretPos(int X, int Y);
3371 //[DllImport ("user32.dll", EntryPoint="GetCaretBlinkTime", CallingConvention=CallingConvention.StdCall)]
3372 //private extern static uint Win32GetCaretBlinkTime();
3374 [DllImport ("gdi32.dll", EntryPoint="GetTextMetricsW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3375 internal extern static bool Win32GetTextMetrics(IntPtr hdc, ref TEXTMETRIC tm);
3377 [DllImport ("gdi32.dll", EntryPoint="SelectObject", CallingConvention=CallingConvention.StdCall)]
3378 internal extern static IntPtr Win32SelectObject(IntPtr hdc, IntPtr hgdiobject);
3380 //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
3381 //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
3383 //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
3384 //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
3386 //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
3387 //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
3389 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
3390 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
3392 //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
3393 //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
3395 //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
3396 //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
3398 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
3399 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
3401 [DllImport ("user32.dll", EntryPoint="GetActiveWindow", CallingConvention=CallingConvention.StdCall)]
3402 private extern static IntPtr Win32GetActiveWindow();
3404 [DllImport ("user32.dll", EntryPoint="GetSystemMetrics", CallingConvention=CallingConvention.StdCall)]
3405 private extern static int Win32GetSystemMetrics(SystemMetrics nIndex);
3407 [DllImport ("shell32.dll", EntryPoint="Shell_NotifyIconW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3408 private extern static bool Win32Shell_NotifyIcon(NotifyIconMessage dwMessage, ref NOTIFYICONDATA lpData);
3410 [DllImport ("gdi32.dll", EntryPoint="CreateRectRgn", CallingConvention=CallingConvention.StdCall)]
3411 internal extern static IntPtr Win32CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
3413 [DllImport ("user32.dll", EntryPoint="IsWindowEnabled", CallingConvention=CallingConvention.StdCall)]
3414 private extern static bool IsWindowEnabled(IntPtr hwnd);
3416 [DllImport ("user32.dll", EntryPoint="IsWindowVisible", CallingConvention=CallingConvention.StdCall)]
3417 private extern static bool IsWindowVisible(IntPtr hwnd);
3419 //[DllImport ("user32.dll", EntryPoint="SetClassLong", CallingConvention=CallingConvention.StdCall)]
3420 //private extern static bool Win32SetClassLong(IntPtr hwnd, ClassLong nIndex, IntPtr dwNewLong);
3422 [DllImport ("user32.dll", EntryPoint="SendMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3423 private extern static IntPtr Win32SendMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
3425 [DllImport ("user32.dll", EntryPoint="PostMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3426 private extern static bool Win32PostMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
3428 [DllImport ("user32.dll", EntryPoint="SendInput", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3429 private extern static UInt32 Win32SendInput(UInt32 nInputs, [MarshalAs(UnmanagedType.LPArray)] INPUT[] inputs, Int32 cbSize);
3431 [DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3432 private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref RECT rect, uint fWinIni);
3434 //[DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3435 //private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref uint value, uint fWinIni);
3437 [DllImport ("user32.dll", EntryPoint = "SystemParametersInfoW", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
3438 private extern static bool Win32SystemParametersInfo (SPIAction uiAction, uint uiParam, ref int value, uint fWinIni);
3440 [DllImport ("user32.dll", EntryPoint = "SystemParametersInfoW", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
3441 private extern static bool Win32SystemParametersInfo (SPIAction uiAction, uint uiParam, ref bool value, uint fWinIni);
3443 [DllImport ("user32.dll", EntryPoint = "SystemParametersInfoW", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
3444 private extern static bool Win32SystemParametersInfo (SPIAction uiAction, uint uiParam, ref ANIMATIONINFO value, uint fWinIni);
3446 [DllImport ("user32.dll", EntryPoint="OpenClipboard", CallingConvention=CallingConvention.StdCall)]
3447 private extern static bool Win32OpenClipboard(IntPtr hwnd);
3449 [DllImport ("user32.dll", EntryPoint="EmptyClipboard", CallingConvention=CallingConvention.StdCall)]
3450 private extern static bool Win32EmptyClipboard();
3452 [DllImport ("user32.dll", EntryPoint="RegisterClipboardFormatW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3453 private extern static uint Win32RegisterClipboardFormat(string format);
3455 [DllImport ("user32.dll", EntryPoint="CloseClipboard", CallingConvention=CallingConvention.StdCall)]
3456 private extern static bool Win32CloseClipboard();
3458 [DllImport ("user32.dll", EntryPoint="EnumClipboardFormats", CallingConvention=CallingConvention.StdCall)]
3459 private extern static uint Win32EnumClipboardFormats(uint format);
3461 [DllImport ("user32.dll", EntryPoint="GetClipboardData", CallingConvention=CallingConvention.StdCall)]
3462 private extern static IntPtr Win32GetClipboardData(uint format);
3464 [DllImport ("user32.dll", EntryPoint="SetClipboardData", CallingConvention=CallingConvention.StdCall)]
3465 private extern static IntPtr Win32SetClipboardData(uint format, IntPtr handle);
3467 [DllImport ("kernel32.dll", EntryPoint="GlobalAlloc", CallingConvention=CallingConvention.StdCall)]
3468 internal extern static IntPtr Win32GlobalAlloc(GAllocFlags Flags, int dwBytes);
3470 [DllImport ("kernel32.dll", EntryPoint="CopyMemory", CallingConvention=CallingConvention.StdCall)]
3471 internal extern static void Win32CopyMemory(IntPtr Destination, IntPtr Source, int length);
3473 [DllImport ("kernel32.dll", EntryPoint="GlobalFree", CallingConvention=CallingConvention.StdCall)]
3474 internal extern static IntPtr Win32GlobalFree(IntPtr hMem);
3476 [DllImport ("kernel32.dll", EntryPoint="GlobalSize", CallingConvention=CallingConvention.StdCall)]
3477 internal extern static uint Win32GlobalSize(IntPtr hMem);
3479 [DllImport ("kernel32.dll", EntryPoint="GlobalLock", CallingConvention=CallingConvention.StdCall)]
3480 internal extern static IntPtr Win32GlobalLock(IntPtr hMem);
3482 [DllImport ("kernel32.dll", EntryPoint="GlobalUnlock", CallingConvention=CallingConvention.StdCall)]
3483 internal extern static IntPtr Win32GlobalUnlock(IntPtr hMem);
3485 [DllImport ("gdi32.dll", EntryPoint="SetROP2", CallingConvention=CallingConvention.StdCall)]
3486 internal extern static int Win32SetROP2(IntPtr hdc, ROP2DrawMode fnDrawMode);
3488 [DllImport ("gdi32.dll", EntryPoint="MoveToEx", CallingConvention=CallingConvention.StdCall)]
3489 internal extern static bool Win32MoveToEx(IntPtr hdc, int x, int y, ref POINT lpPoint);
3491 [DllImport ("gdi32.dll", EntryPoint="MoveToEx", CallingConvention=CallingConvention.StdCall)]
3492 internal extern static bool Win32MoveToEx(IntPtr hdc, int x, int y, IntPtr lpPoint);
3494 [DllImport ("gdi32.dll", EntryPoint="LineTo", CallingConvention=CallingConvention.StdCall)]
3495 internal extern static bool Win32LineTo(IntPtr hdc, int x, int y);
3497 [DllImport ("gdi32.dll", EntryPoint="CreatePen", CallingConvention=CallingConvention.StdCall)]
3498 internal extern static IntPtr Win32CreatePen(PenStyle fnPenStyle, int nWidth, ref COLORREF color);
3500 [DllImport ("gdi32.dll", EntryPoint="CreatePen", CallingConvention=CallingConvention.StdCall)]
3501 internal extern static IntPtr Win32CreatePen(PenStyle fnPenStyle, int nWidth, IntPtr color);
3503 [DllImport ("gdi32.dll", EntryPoint="GetStockObject", CallingConvention=CallingConvention.StdCall)]
3504 internal extern static IntPtr Win32GetStockObject(StockObject fnObject);
3506 [DllImport ("gdi32.dll", EntryPoint="CreateHatchBrush", CallingConvention=CallingConvention.StdCall)]
3507 internal extern static IntPtr Win32CreateHatchBrush(HatchStyle fnStyle, IntPtr color);
3509 [DllImport ("gdi32.dll", EntryPoint="CreateHatchBrush", CallingConvention=CallingConvention.StdCall)]
3510 internal extern static IntPtr Win32CreateHatchBrush(HatchStyle fnStyle, ref COLORREF color);
3512 [DllImport("gdi32.dll", EntryPoint = "ExcludeClipRect", CallingConvention = CallingConvention.StdCall)]
3513 internal extern static int Win32ExcludeClipRect (IntPtr hdc, int left, int top, int right, int bottom);
3515 [DllImport ("gdi32.dll", EntryPoint="ExtSelectClipRgn", CallingConvention=CallingConvention.StdCall)]
3516 internal extern static int Win32ExtSelectClipRgn(IntPtr hdc, IntPtr hrgn, int mode);
3518 [DllImport ("winmm.dll", EntryPoint="PlaySoundW", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
3519 internal extern static IntPtr Win32PlaySound(string pszSound, IntPtr hmod, SndFlags fdwSound);
3521 [DllImport ("user32.dll", EntryPoint="GetDoubleClickTime", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
3522 private extern static int Win32GetDoubleClickTime ();
3524 [DllImport ("user32.dll", EntryPoint="SetWindowRgn", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
3525 internal extern static int Win32SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
3527 [DllImport ("user32.dll", EntryPoint="GetWindowRgn", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
3528 internal extern static IntPtr Win32GetWindowRgn(IntPtr hWnd, IntPtr hRgn);
3530 [DllImport ("user32.dll", EntryPoint="ClipCursor", CallingConvention=CallingConvention.StdCall)]
3531 internal extern static bool Win32ClipCursor (ref RECT lpRect);
3533 [DllImport ("user32.dll", EntryPoint="GetClipCursor", CallingConvention=CallingConvention.StdCall)]
3534 internal extern static bool Win32GetClipCursor (out RECT lpRect);
3536 [DllImport ("gdi32.dll", EntryPoint="BitBlt", CallingConvention=CallingConvention.StdCall)]
3537 internal static extern bool Win32BitBlt (IntPtr hObject, int nXDest, int nYDest, int nWidth,
3538 int nHeight, IntPtr hObjSource, int nXSrc, int nYSrc, TernaryRasterOperations dwRop);
3540 [DllImport ("gdi32.dll", EntryPoint="CreateCompatibleDC", CallingConvention=CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
3541 internal static extern IntPtr Win32CreateCompatibleDC (IntPtr hdc);
3543 [DllImport ("gdi32.dll", EntryPoint="DeleteDC", CallingConvention=CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
3544 internal static extern bool Win32DeleteDC (IntPtr hdc);
3546 [DllImport ("gdi32.dll", EntryPoint="CreateCompatibleBitmap", CallingConvention=CallingConvention.StdCall)]
3547 internal static extern IntPtr Win32CreateCompatibleBitmap (IntPtr hdc, int nWidth, int nHeight);
3549 [DllImport ("kernel32.dll", EntryPoint = "GetSystemPowerStatus", CallingConvention = CallingConvention.StdCall)]
3550 internal static extern Boolean Win32GetSystemPowerStatus (SYSTEMPOWERSTATUS sps);