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;
65 private static Win32DnD DnD;
66 #endregion // Local Variables
68 #region Private Structs
69 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
70 private struct WNDCLASS {
72 internal WndProc lpfnWndProc;
73 internal int cbClsExtra;
74 internal int cbWndExtra;
75 internal IntPtr hInstance;
76 internal IntPtr hIcon;
77 internal IntPtr hCursor;
78 internal IntPtr hbrBackground;
79 [MarshalAs(UnmanagedType.LPWStr)]
80 internal string lpszMenuName;
81 [MarshalAs(UnmanagedType.LPWStr)]
82 internal string lpszClassName;
85 [StructLayout(LayoutKind.Sequential)]
86 internal struct RECT {
91 public override string ToString() {
92 return String.Format("RECT left={0}, top={1}, right={2}, bottom={3}, width={4}, height={5}", left, top, right, bottom, right-left, bottom-top);
97 [StructLayout(LayoutKind.Sequential)]
98 internal struct POINT {
103 internal enum SPIAction {
104 SPI_GETWORKAREA = 0x0030,
105 SPI_GETMOUSEHOVERWIDTH = 0x0062,
106 SPI_GETMOUSEHOVERHEIGHT = 0x0064,
107 SPI_GETMOUSEHOVERTIME = 0x0066,
110 internal enum WindowPlacementFlags {
114 SW_SHOWMINIMIZED = 2,
115 SW_SHOWMAXIMIZED = 3,
117 SW_SHOWNOACTIVATE = 4,
120 SW_SHOWMINNOACTIVE = 7,
124 SW_FORCEMINIMIZE = 11,
128 [StructLayout(LayoutKind.Sequential)]
129 private struct WINDOWPLACEMENT {
130 internal uint length;
132 internal WindowPlacementFlags showCmd;
133 internal POINT ptMinPosition;
134 internal POINT ptMaxPosition;
135 internal RECT rcNormalPosition;
138 [StructLayout(LayoutKind.Sequential)]
139 internal struct NCCALCSIZE_PARAMS {
143 internal IntPtr lppos;
147 private enum TMEFlags {
148 TME_HOVER = 0x00000001,
149 TME_LEAVE = 0x00000002,
150 TME_QUERY = unchecked((int)0x40000000),
151 TME_CANCEL = unchecked((int)0x80000000)
154 [StructLayout(LayoutKind.Sequential)]
155 private struct TRACKMOUSEEVENT {
157 internal TMEFlags dwFlags;
158 internal IntPtr hWnd;
159 internal int dwHoverTime;
162 [StructLayout(LayoutKind.Sequential)]
163 private struct PAINTSTRUCT {
166 internal RECT rcPaint;
167 internal int fRestore;
168 internal int fIncUpdate;
169 internal int Reserved1;
170 internal int Reserved2;
171 internal int Reserved3;
172 internal int Reserved4;
173 internal int Reserved5;
174 internal int Reserved6;
175 internal int Reserved7;
176 internal int Reserved8;
179 internal enum ClassStyle {
180 CS_VREDRAW = 0x00000001,
181 CS_HREDRAW = 0x00000002,
182 CS_KEYCVTWINDOW = 0x00000004,
183 CS_DBLCLKS = 0x00000008,
184 CS_OWNDC = 0x00000020,
185 CS_CLASSDC = 0x00000040,
186 CS_PARENTDC = 0x00000080,
187 CS_NOKEYCVT = 0x00000100,
188 CS_NOCLOSE = 0x00000200,
189 CS_SAVEBITS = 0x00000800,
190 CS_BYTEALIGNCLIENT = 0x00001000,
191 CS_BYTEALIGNWINDOW = 0x00002000,
192 CS_GLOBALCLASS = 0x00004000,
196 internal enum SetWindowPosZOrder {
204 internal enum SetWindowPosFlags {
205 SWP_ASYNCWINDOWPOS = 0x4000,
206 SWP_DEFERERASE = 0x2000,
207 SWP_DRAWFRAME = 0x0020,
208 SWP_FRAMECHANGED = 0x0020,
209 SWP_HIDEWINDOW = 0x0080,
210 SWP_NOACTIVATE = 0x0010,
211 SWP_NOCOPYBITS = 0x0100,
213 SWP_NOOWNERZORDER = 0x0200,
214 SWP_NOREDRAW = 0x0008,
215 SWP_NOREPOSITION = 0x0200,
216 SWP_NOENDSCHANGING = 0x0400,
218 SWP_NOZORDER = 0x0004,
219 SWP_SHOWWINDOW = 0x0040
222 internal enum GetSysColorIndex {
224 COLOR_BACKGROUND = 1,
225 COLOR_ACTIVECAPTION = 2,
226 COLOR_INACTIVECAPTION = 3,
229 COLOR_WINDOWFRAME = 6,
231 COLOR_WINDOWTEXT = 8,
232 COLOR_CAPTIONTEXT = 9,
233 COLOR_ACTIVEBORDER = 10,
234 COLOR_INACTIVEBORDER = 11,
235 COLOR_APPWORKSPACE = 12,
236 COLOR_HIGHLIGHT = 13,
237 COLOR_HIGHLIGHTTEXT = 14,
239 COLOR_BTNSHADOW = 16,
242 COLOR_INACTIVECAPTIONTEXT = 19,
243 COLOR_BTNHIGHLIGHT = 20,
244 COLOR_3DDKSHADOW = 21,
250 COLOR_GRADIENTACTIVECAPTION = 27,
251 COLOR_GRADIENTINACTIVECAPTION = 28,
252 COLOR_MENUHIGHLIGHT = 29,
258 COLOR_3DHIGHLIGHT = 20,
259 COLOR_3DHILIGHT = 20,
260 COLOR_BTNHILIGHT = 20,
261 COLOR_MAXVALUE = 24,/* Maximum value */
264 private enum LoadCursorType {
273 IDC_SIZENWSE = 32642,
274 IDC_SIZENESW = 32643,
280 IDC_APPSTARTING = 32650,
286 private enum WindowLong {
297 private enum LogBrushStyle {
306 BS_DIBPATTERN8X8 = 8,
311 private enum LogBrushHatch {
312 HS_HORIZONTAL = 0, /* ----- */
313 HS_VERTICAL = 1, /* ||||| */
314 HS_FDIAGONAL = 2, /* \\\\\ */
315 HS_BDIAGONAL = 3, /* ///// */
316 HS_CROSS = 4, /* +++++ */
317 HS_DIAGCROSS = 5, /* xxxxx */
320 internal struct COLORREF {
327 [StructLayout(LayoutKind.Sequential)]
328 private struct LOGBRUSH {
329 internal LogBrushStyle lbStyle;
330 internal COLORREF lbColor;
331 internal LogBrushHatch lbHatch;
334 [StructLayout(LayoutKind.Sequential)]
335 internal struct TEXTMETRIC {
336 internal int tmHeight;
337 internal int tmAscent;
338 internal int tmDescent;
339 internal int tmInternalLeading;
340 internal int tmExternalLeading;
341 internal int tmAveCharWidth;
342 internal int tmMaxCharWidth;
343 internal int tmWeight;
344 internal int tmOverhang;
345 internal int tmDigitizedAspectX;
346 internal int tmDigitizedAspectY;
347 internal short tmFirstChar;
348 internal short tmLastChar;
349 internal short tmDefaultChar;
350 internal short tmBreakChar;
351 internal byte tmItalic;
352 internal byte tmUnderlined;
353 internal byte tmStruckOut;
354 internal byte tmPitchAndFamily;
355 internal byte tmCharSet;
359 private enum ScrollWindowExFlags {
361 SW_SCROLLCHILDREN = 0x0001,
362 SW_INVALIDATE = 0x0002,
364 SW_SMOOTHSCROLL = 0x0010
367 internal enum SystemMetrics {
384 SM_CXFULLSCREEN = 16,
385 SM_CYFULLSCREEN = 17,
386 SM_CYKANJIWINDOW = 18,
387 SM_MOUSEPRESENT = 19,
406 SM_CXICONSPACING = 38,
407 SM_CYICONSPACING = 39,
408 SM_MENUDROPALIGNMENT = 40,
411 SM_CMOUSEBUTTONS = 43,
412 SM_CXFIXEDFRAME = SM_CXDLGFRAME,
413 SM_CYFIXEDFRAME = SM_CYDLGFRAME,
414 SM_CXSIZEFRAME = SM_CXFRAME,
415 SM_CYSIZEFRAME = SM_CYFRAME,
419 SM_CXMINSPACING = 47,
420 SM_CYMINSPACING = 48,
443 SM_MIDEASTENABLED = 74,
444 SM_MOUSEWHEELPRESENT = 75,
445 SM_XVIRTUALSCREEN = 76,
446 SM_YVIRTUALSCREEN = 77,
447 SM_CXVIRTUALSCREEN = 78,
448 SM_CYVIRTUALSCREEN = 79,
450 SM_SAMEDISPLAYFORMAT = 81,
452 SM_CXFOCUSBORDER = 83,
453 SM_CYFOCUSBORDER = 84,
459 // We'll only support _WIN32_IE < 0x0500 for now
460 internal enum NotifyIconMessage {
461 NIM_ADD = 0x00000000,
462 NIM_MODIFY = 0x00000001,
463 NIM_DELETE = 0x00000002,
467 internal enum NotifyIconFlags {
468 NIF_MESSAGE = 0x00000001,
469 NIF_ICON = 0x00000002,
470 NIF_TIP = 0x00000004,
473 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
474 internal struct NOTIFYICONDATA {
475 internal uint cbSize;
476 internal IntPtr hWnd;
478 internal NotifyIconFlags uFlags;
479 internal uint uCallbackMessage;
480 internal IntPtr hIcon;
481 [MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)]
482 internal string szTip;
486 internal enum DCExFlags {
487 DCX_WINDOW = 0x00000001,
488 DCX_CACHE = 0x00000002,
489 DCX_NORESETATTRS = 0x00000004,
490 DCX_CLIPCHILDREN = 0x00000008,
491 DCX_CLIPSIBLINGS = 0x00000010,
492 DCX_PARENTCLIP = 0x00000020,
493 DCX_EXCLUDERGN = 0x00000040,
494 DCX_INTERSECTRGN = 0x00000080,
495 DCX_EXCLUDEUPDATE = 0x00000100,
496 DCX_INTERSECTUPDATE = 0x00000200,
497 DCX_LOCKWINDOWUPDATE = 0x00000400,
498 DCX_USESTYLE = 0x00010000,
499 DCX_VALIDATE = 0x00200000
502 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
503 internal struct CLIENTCREATESTRUCT {
504 internal IntPtr hWindowMenu;
505 internal uint idFirstChild;
508 private enum ClassLong : int {
510 GCL_HBRBACKGROUND = -10,
514 GCL_CBWNDEXTRA = -18,
515 GCL_CBCLSEXTRA = -20,
523 internal enum GAllocFlags : uint {
525 GMEM_MOVEABLE = 0x0002,
526 GMEM_NOCOMPACT = 0x0010,
527 GMEM_NODISCARD = 0x0020,
528 GMEM_ZEROINIT = 0x0040,
529 GMEM_MODIFY = 0x0080,
530 GMEM_DISCARDABLE = 0x0100,
531 GMEM_NOT_BANKED = 0x1000,
533 GMEM_DDESHARE = 0x2000,
534 GMEM_NOTIFY = 0x4000,
535 GMEM_LOWER = GMEM_NOT_BANKED,
536 GMEM_VALID_FLAGS = 0x7F72,
537 GMEM_INVALID_HANDLE = 0x8000,
538 GHND = (GMEM_MOVEABLE | GMEM_ZEROINIT),
539 GPTR = (GMEM_FIXED | GMEM_ZEROINIT)
542 internal enum ROP2DrawMode : int {
562 internal enum PenStyle : int {
574 internal enum StockObject : int {
581 HOLLOW_BRUSH = NULL_BRUSH,
586 ANSI_FIXED_FONT = 11,
589 DEVICE_DEFAULT_FONT = 14,
590 DEFAULT_PALETTE = 15,
591 SYSTEM_FIXED_FONT = 16
594 internal enum HatchStyle : int {
604 internal enum SndFlags : int {
607 SND_NODEFAULT = 0x0002,
611 SND_NOWAIT = 0x00002000,
612 SND_ALIAS = 0x00010000,
613 SND_ALIAS_ID = 0x00110000,
614 SND_FILENAME = 0x00020000,
615 SND_RESOURCE = 0x00040004,
617 SND_APPLICATION = 0x0080,
621 internal enum LayeredWindowAttributes : int {
629 #region Constructor & Destructor
630 private XplatUIWin32() {
634 // Handle singleton stuff first
637 DnD = new Win32DnD();
639 mouse_state = MouseButtons.None;
640 mouse_position = Point.Empty;
642 message_queue = new Queue();
644 themes_enabled = false;
646 // Prepare 'our' window class
647 wnd_proc = new WndProc(NativeWindow.WndProc);
648 wndClass.style = (int)(ClassStyle.CS_OWNDC | ClassStyle.CS_DBLCLKS);
649 wndClass.lpfnWndProc = wnd_proc;
650 wndClass.cbClsExtra = 0;
651 wndClass.cbWndExtra = 0;
652 wndClass.hbrBackground = IntPtr.Zero;
653 wndClass.hCursor = Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
654 wndClass.hIcon = IntPtr.Zero;
655 wndClass.hInstance = IntPtr.Zero;
656 wndClass.lpszClassName = XplatUI.DefaultClassName;
657 wndClass.lpszMenuName = "";
659 result=Win32RegisterClass(ref wndClass);
661 Win32MessageBox(IntPtr.Zero, "Could not register the "+XplatUI.DefaultClassName+" window class, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
664 FosterParent=Win32CreateWindow((int)WindowExStyles.WS_EX_TOOLWINDOW, "static", "Foster Parent Window", (int)WindowStyles.WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
666 if (FosterParent==IntPtr.Zero) {
667 Win32MessageBox(IntPtr.Zero, "Could not create foster window, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
670 scroll_height = Win32GetSystemMetrics(SystemMetrics.SM_CYHSCROLL);
671 scroll_width = Win32GetSystemMetrics(SystemMetrics.SM_CXVSCROLL);
673 timer_list = new Hashtable ();
675 #endregion // Constructor & Destructor
677 #region Private Support Methods
678 private static IntPtr DefWndProc(IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) {
679 return Win32DefWindowProc(hWnd, msg, wParam, lParam);
682 private static bool MessageWaiting {
684 if (message_queue.Count == 0) {
691 private static bool RetrieveMessage(ref MSG msg) {
694 if (message_queue.Count == 0) {
698 message = (MSG)message_queue.Dequeue();
704 private static bool StoreMessage(ref MSG msg) {
705 MSG message = new MSG();
708 message_queue.Enqueue(message);
713 internal static String AnsiToString(IntPtr ansi_data) {
714 return (string)Marshal.PtrToStringAnsi(ansi_data);
717 internal static String UnicodeToString(IntPtr unicode_data) {
718 return (string)Marshal.PtrToStringUni(unicode_data);
721 internal static Image DIBtoImage(IntPtr dib_data) {
722 BITMAPINFOHEADER bmi;
733 bmi = (BITMAPINFOHEADER)Marshal.PtrToStructure(dib_data, typeof(BITMAPINFOHEADER));
735 ncolors = (int)bmi.biClrUsed;
737 if (bmi.biBitCount < 24) {
738 ncolors = (int)(1 << bmi.biBitCount);
741 //palettesize = ncolors * 4;
743 imagesize = (int)bmi.biSizeImage;
744 if (imagesize == 0) {
745 imagesize = (int)(((((bmi.biWidth * bmi.biBitCount) + 31) & ~31) >> 3) * bmi.biHeight);
748 switch(bmi.biBitCount) {
749 case 1: { // Monochrome
750 bmp = new Bitmap(bmi.biWidth, bmi.biHeight, PixelFormat.Format1bppIndexed);
751 palette = new int[2];
756 bmp = new Bitmap(bmi.biWidth, bmi.biHeight, PixelFormat.Format4bppIndexed);
757 palette = new int[16];
762 bmp = new Bitmap(bmi.biWidth, bmi.biHeight, PixelFormat.Format8bppIndexed);
763 palette = new int[256];
769 bmp = new Bitmap(bmi.biWidth, bmi.biHeight, PixelFormat.Format32bppArgb);
770 palette = new int[0];
775 throw new Exception("Unexpected number of bits:" + bmi.biBitCount.ToString());
779 if (bmi.biBitCount < 24) {
780 pal = bmp.Palette; // Managed palette
781 Marshal.Copy((IntPtr)((int)dib_data + Marshal.SizeOf(typeof(BITMAPINFOHEADER))), palette, 0, palette.Length);
783 for (int i = 0; i < ncolors; i++) {
784 pal.Entries[i] = Color.FromArgb(palette[i] | unchecked((int)0xff000000));
789 bytesPerLine = (int)((((bmi.biWidth * bmi.biBitCount) + 31) & ~31) >> 3);
790 bits = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
792 imagebits = new byte[bytesPerLine];
794 for (int y = 0; y < bmi.biHeight; y++) {
795 // Copy from source to managed
796 Marshal.Copy((IntPtr)((int)dib_data + Marshal.SizeOf(typeof(BITMAPINFOHEADER)) + palette.Length * 4 + bytesPerLine * y), imagebits, 0, bytesPerLine);
798 // Copy from managed to dest
799 Marshal.Copy(imagebits, 0, (IntPtr)((int)bits.Scan0 + bits.Stride * (bmi.biHeight - 1 - y)), imagebits.Length);
802 bmp.UnlockBits(bits);
807 internal static byte[] ImageToDIB(Image image) {
812 ms = new MemoryStream();
813 image.Save(ms, ImageFormat.Bmp);
814 buffer = ms.GetBuffer();
816 // Filter out the file header
817 retbuf = new byte[buffer.Length];
818 Array.Copy(buffer, 14, retbuf, 0, buffer.Length - 14);
822 internal static IntPtr DupGlobalMem(IntPtr mem) {
828 len = Win32GlobalSize(mem);
829 mem_ptr = Win32GlobalLock(mem);
831 dup = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE, (int)len);
832 dup_ptr = Win32GlobalLock(dup);
834 Win32CopyMemory(dup_ptr, mem_ptr, (int)len);
836 Win32GlobalUnlock(mem);
837 Win32GlobalUnlock(dup);
841 #endregion // Private Support Methods
843 #region Static Properties
844 internal override Keys ModifierKeys {
849 key_state = Keys.None;
851 state = Win32GetKeyState(VirtualKeys.VK_SHIFT);
852 if ((state & 0x8000) != 0) {
853 key_state |= Keys.Shift;
855 state = Win32GetKeyState(VirtualKeys.VK_CONTROL);
856 if ((state & 0x8000) != 0) {
857 key_state |= Keys.Control;
860 state = Win32GetKeyState(VirtualKeys.VK_MENU);
861 if ((state & 0x8000) != 0) {
862 key_state |= Keys.Alt;
869 internal override MouseButtons MouseButtons {
875 internal override Point MousePosition {
877 return mouse_position;
881 internal override Size MouseHoverSize {
886 Win32SystemParametersInfo(SPIAction.SPI_GETMOUSEHOVERWIDTH, 0, ref width, 0);
887 Win32SystemParametersInfo(SPIAction.SPI_GETMOUSEHOVERWIDTH, 0, ref height, 0);
888 return new Size(width, height);
892 internal override int MouseHoverTime {
896 Win32SystemParametersInfo(SPIAction.SPI_GETMOUSEHOVERTIME, 0, ref time, 0);
901 internal override int HorizontalScrollBarHeight {
903 return scroll_height;
907 internal override bool UserClipWontExposeParent {
914 internal override int VerticalScrollBarWidth {
920 internal override int MenuHeight {
922 return Win32GetSystemMetrics(SystemMetrics.SM_CYMENU);
926 internal override bool DropTarget {
933 //throw new NotImplementedException("Need to figure out D'n'D for Win32");
938 internal override int Caption {
940 return Win32GetSystemMetrics(SystemMetrics.SM_CYCAPTION);
944 internal override Size CursorSize {
946 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CYCURSOR));
950 internal override bool DragFullWindows {
956 internal override Size DragSize {
958 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXDRAG), Win32GetSystemMetrics(SystemMetrics.SM_CYDRAG));
962 internal override Size FrameBorderSize {
964 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXFRAME), Win32GetSystemMetrics(SystemMetrics.SM_CYFRAME));
968 internal override Size IconSize {
970 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXICON), Win32GetSystemMetrics(SystemMetrics.SM_CYICON));
974 internal override Size MaxWindowTrackSize {
976 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMAXTRACK), Win32GetSystemMetrics(SystemMetrics.SM_CYMAXTRACK));
980 internal override Size MinimizedWindowSize {
982 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINIMIZED), Win32GetSystemMetrics(SystemMetrics.SM_CYMINIMIZED));
986 internal override Size MinimizedWindowSpacingSize {
988 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINSPACING), Win32GetSystemMetrics(SystemMetrics.SM_CYMINSPACING));
992 internal override Size MinimumWindowSize {
994 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMIN), Win32GetSystemMetrics(SystemMetrics.SM_CYMIN));
998 internal override Size MinWindowTrackSize {
1000 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINTRACK), Win32GetSystemMetrics(SystemMetrics.SM_CYMINTRACK));
1004 internal override Size SmallIconSize {
1006 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXSMICON), Win32GetSystemMetrics(SystemMetrics.SM_CYSMICON));
1010 internal override int MouseButtonCount {
1012 return Win32GetSystemMetrics(SystemMetrics.SM_CMOUSEBUTTONS);
1016 internal override bool MouseButtonsSwapped {
1018 return Win32GetSystemMetrics(SystemMetrics.SM_SWAPBUTTON) != 0;
1022 internal override bool MouseWheelPresent {
1024 return Win32GetSystemMetrics(SystemMetrics.SM_MOUSEWHEELPRESENT) != 0;
1028 internal override Rectangle VirtualScreen {
1030 return new Rectangle( Win32GetSystemMetrics(SystemMetrics.SM_XVIRTUALSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_YVIRTUALSCREEN),
1031 Win32GetSystemMetrics(SystemMetrics.SM_CXVIRTUALSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_CYVIRTUALSCREEN));
1035 internal override Rectangle WorkingArea {
1040 Win32SystemParametersInfo(SPIAction.SPI_GETWORKAREA, 0, ref rect, 0);
1041 return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
1042 //return new Rectangle(0, 0, Win32GetSystemMetrics(SystemMetrics.SM.SM_CXSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_CYSCREEN));
1046 internal override bool ThemesEnabled {
1048 return XplatUIWin32.themes_enabled;
1053 #endregion // Static Properties
1055 #region Singleton Specific Code
1056 public static XplatUIWin32 GetInstance() {
1057 if (instance==null) {
1058 instance=new XplatUIWin32();
1064 public int Reference {
1071 #region Public Static Methods
1072 internal override IntPtr InitializeDriver() {
1076 internal override void ShutdownDriver(IntPtr token) {
1077 Console.WriteLine("XplatUIWin32 ShutdownDriver called");
1081 internal void Version() {
1082 Console.WriteLine("Xplat version $revision: $");
1085 internal override void AudibleAlert() {
1086 Win32PlaySound("Default", IntPtr.Zero, SndFlags.SND_ALIAS | SndFlags.SND_ASYNC | SndFlags.SND_NOSTOP | SndFlags.SND_NOWAIT);
1089 internal override void GetDisplaySize(out Size size) {
1092 Win32GetWindowRect(Win32GetDesktopWindow(), out rect);
1094 size = new Size(rect.right - rect.left, rect.bottom - rect.top);
1097 internal override void EnableThemes() {
1098 themes_enabled=true;
1101 internal override IntPtr CreateWindow(CreateParams cp) {
1102 IntPtr WindowHandle;
1103 IntPtr ParentHandle;
1108 ParentHandle=cp.Parent;
1110 if ((ParentHandle==IntPtr.Zero) && (cp.Style & (int)(WindowStyles.WS_CHILD))!=0) {
1111 // We need to use our foster parent window until this poor child gets it's parent assigned
1112 ParentHandle = FosterParent;
1115 if ( ((cp.Style & (int)(WindowStyles.WS_CHILD | WindowStyles.WS_POPUP))==0) && ((cp.ExStyle & (int)WindowExStyles.WS_EX_APPWINDOW) == 0)) {
1116 // If we want to be hidden from the taskbar we need to be 'owned' by
1117 // something not on the taskbar. FosterParent is just that
1118 ParentHandle = FosterParent;
1121 // Since we fake MDI dont tell Windows that this is a real MDI window
1122 if ((cp.ExStyle & (int) WindowExStyles.WS_EX_MDICHILD) != 0) {
1126 WindowHandle = Win32CreateWindow((uint)cp.ExStyle, cp.ClassName, cp.Caption, (uint)cp.Style, cp.X, cp.Y, cp.Width, cp.Height, ParentHandle, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
1128 if (WindowHandle==IntPtr.Zero) {
1129 uint error = Win32GetLastError();
1131 Win32MessageBox(IntPtr.Zero, "Error : " + error.ToString(), "Failed to create window, class '"+cp.ClassName+"'", 0);
1134 hwnd.ClientWindow = WindowHandle;
1136 Win32SetWindowLong(WindowHandle, WindowLong.GWL_USERDATA, (uint)ThemeEngine.Current.DefaultControlBackColor.ToArgb());
1138 return WindowHandle;
1141 internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
1142 CreateParams create_params = new CreateParams();
1144 create_params.Caption = "";
1145 create_params.X = X;
1146 create_params.Y = Y;
1147 create_params.Width = Width;
1148 create_params.Height = Height;
1150 create_params.ClassName=XplatUI.DefaultClassName;
1151 create_params.ClassStyle = 0;
1152 create_params.ExStyle=0;
1153 create_params.Parent=IntPtr.Zero;
1154 create_params.Param=0;
1156 return CreateWindow(create_params);
1159 internal override void DestroyWindow(IntPtr handle) {
1162 hwnd = Hwnd.ObjectFromHandle(handle);
1163 Win32DestroyWindow(handle);
1168 internal override void SetWindowMinMax(IntPtr handle, Rectangle maximized, Size min, Size max) {
1169 // We do nothing, Form has to handle WM_GETMINMAXINFO
1173 internal override FormWindowState GetWindowState(IntPtr handle) {
1176 style = Win32GetWindowLong(handle, WindowLong.GWL_STYLE);
1177 if ((style & (uint)WindowStyles.WS_MAXIMIZE) != 0) {
1178 return FormWindowState.Maximized;
1179 } else if ((style & (uint)WindowStyles.WS_MINIMIZE) != 0) {
1180 return FormWindowState.Minimized;
1182 return FormWindowState.Normal;
1185 internal override void SetWindowState(IntPtr hwnd, FormWindowState state) {
1187 case FormWindowState.Normal: {
1188 Win32ShowWindow(hwnd, WindowPlacementFlags.SW_RESTORE);
1192 case FormWindowState.Minimized: {
1193 Win32ShowWindow(hwnd, WindowPlacementFlags.SW_MINIMIZE);
1197 case FormWindowState.Maximized: {
1198 Win32ShowWindow(hwnd, WindowPlacementFlags.SW_MAXIMIZE);
1204 internal override void SetWindowStyle(IntPtr handle, CreateParams cp) {
1206 if ((cp.ExStyle & (int) WindowExStyles.WS_EX_MDICHILD) != 0) {
1210 Win32SetWindowLong(handle, WindowLong.GWL_STYLE, (uint)cp.Style);
1211 Win32SetWindowLong(handle, WindowLong.GWL_EXSTYLE, (uint)cp.ExStyle);
1215 internal override void SetWindowTransparency(IntPtr handle, double transparency, Color key) {
1216 LayeredWindowAttributes lwa = LayeredWindowAttributes.LWA_ALPHA;
1217 byte opacity = (byte)(transparency*255);
1218 COLORREF clrRef = new COLORREF();
1219 if (key != Color.Empty) {
1223 lwa = (LayeredWindowAttributes)( (int)lwa | (int)LayeredWindowAttributes.LWA_COLORKEY );
1228 Win32SetLayeredWindowAttributes(handle, clrRef, opacity, lwa);
1231 internal override bool SupportsTransparency() {
1232 // We might check with the OS, but I think we're only >=W2k
1236 internal override void UpdateWindow(IntPtr handle) {
1237 Win32UpdateWindow(handle);
1240 internal override PaintEventArgs PaintEventStart(IntPtr handle, bool client) {
1243 PaintEventArgs paint_event;
1245 Rectangle clip_rect;
1248 clip_rect = new Rectangle();
1250 ps = new PAINTSTRUCT();
1252 hwnd = Hwnd.ObjectFromHandle(handle);
1255 if (Win32GetUpdateRect(handle, ref rect, false)) {
1256 hdc = Win32BeginPaint(handle, ref ps);
1258 hwnd.drawing_stack.Push (ps);
1260 clip_rect = new Rectangle(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right-ps.rcPaint.left, ps.rcPaint.bottom-ps.rcPaint.top);
1262 hdc = Win32GetDC(handle);
1263 // FIXME: Add the DC to internal list
1265 hwnd.drawing_stack.Push (null);
1267 clip_rect = new Rectangle(rect.top, rect.left, rect.right-rect.left, rect.bottom-rect.top);
1270 hdc = Win32GetWindowDC (handle);
1272 hwnd.drawing_stack.Push (hdc);
1274 // HACK this in for now
1275 Win32GetWindowRect (handle, out rect);
1276 clip_rect = new Rectangle(0, 0, rect.right-rect.left, rect.bottom-rect.top);
1279 Graphics dc = Graphics.FromHdc(hdc);
1280 hwnd.drawing_stack.Push (dc);
1282 paint_event = new PaintEventArgs(dc, clip_rect);
1287 internal override void PaintEventEnd(IntPtr handle, bool client) {
1290 hwnd = Hwnd.ObjectFromHandle(handle);
1292 Graphics dc = (Graphics)hwnd.drawing_stack.Pop();
1296 object o = hwnd.drawing_stack.Pop();
1298 PAINTSTRUCT ps = (PAINTSTRUCT)o;
1299 Win32EndPaint(handle, ref ps);
1302 IntPtr hdc = (IntPtr)hwnd.drawing_stack.Pop();
1303 Win32ReleaseDC(handle, hdc);
1308 internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
1309 Win32MoveWindow(handle, x, y, width, height, true);
1313 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) {
1318 Win32GetWindowRect(handle, out rect);
1319 width = rect.right - rect.left;
1320 height = rect.bottom - rect.top;
1325 parent = Win32GetParent(handle);
1326 Win32ScreenToClient(parent, ref pt);
1331 Win32GetClientRect(handle, out rect);
1332 client_width = rect.right - rect.left;
1333 client_height = rect.bottom - rect.top;
1337 internal override void Activate(IntPtr handle) {
1338 Win32SetActiveWindow(handle);
1341 internal override void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
1346 rect.right=rc.Right;
1347 rect.bottom=rc.Bottom;
1348 Win32InvalidateRect(handle, ref rect, clear);
1352 internal override void InvalidateNC (IntPtr handle)
1354 // found this gem at
1355 // http://www.dotnet247.com/247reference/msgs/58/292037.aspx
1356 Win32SetWindowPos(handle, IntPtr.Zero,
1358 SetWindowPosFlags.SWP_NOMOVE |
1359 SetWindowPosFlags.SWP_NOSIZE |
1360 SetWindowPosFlags.SWP_NOZORDER |
1361 SetWindowPosFlags.SWP_NOACTIVATE |
1362 SetWindowPosFlags.SWP_DRAWFRAME);
1365 internal override IntPtr DefWndProc(ref Message msg) {
1366 msg.Result=Win32DefWindowProc(msg.HWnd, (Msg)msg.Msg, msg.WParam, msg.LParam);
1370 internal override void HandleException(Exception e) {
1371 StackTrace st = new StackTrace(e);
1372 Win32MessageBox(IntPtr.Zero, e.Message+st.ToString(), "Exception", 0);
1373 Console.WriteLine("{0}{1}", e.Message, st.ToString());
1376 internal override void DoEvents() {
1377 MSG msg = new MSG();
1379 if (override_cursor != IntPtr.Zero) {
1380 Cursor.Current = null;
1383 while (GetMessage(ref msg, IntPtr.Zero, 0, 0, false)) {
1384 XplatUI.TranslateMessage(ref msg);
1385 XplatUI.DispatchMessage(ref msg);
1389 internal override bool PeekMessage(Object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
1390 return Win32PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
1393 internal override void PostQuitMessage(int exitCode) {
1394 Win32PostQuitMessage(exitCode);
1397 internal override void RequestNCRecalc(IntPtr handle) {
1398 Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOOWNERZORDER | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOMOVE);
1401 internal override void ResetMouseHover(IntPtr handle) {
1402 TRACKMOUSEEVENT tme;
1404 tme = new TRACKMOUSEEVENT();
1405 tme.size = Marshal.SizeOf(tme);
1407 tme.dwFlags = TMEFlags.TME_LEAVE | TMEFlags.TME_HOVER;
1408 Win32TrackMouseEvent(ref tme);
1412 internal override bool GetMessage(Object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
1413 return GetMessage(ref msg, hWnd, wFilterMin, wFilterMax, true);
1416 private bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, bool blocking) {
1419 if (RetrieveMessage(ref msg)) {
1424 result = Win32GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
1426 result = Win32PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, (uint)PeekMessageFlags.PM_REMOVE);
1432 // We need to fake WM_MOUSE_ENTER/WM_MOUSE_LEAVE
1433 switch (msg.message) {
1434 case Msg.WM_LBUTTONDOWN: {
1435 mouse_state |= MouseButtons.Left;
1439 case Msg.WM_MBUTTONDOWN: {
1440 mouse_state |= MouseButtons.Middle;
1444 case Msg.WM_RBUTTONDOWN: {
1445 mouse_state |= MouseButtons.Right;
1449 case Msg.WM_LBUTTONUP: {
1450 mouse_state &= ~MouseButtons.Left;
1454 case Msg.WM_MBUTTONUP: {
1455 mouse_state &= ~MouseButtons.Middle;
1459 case Msg.WM_RBUTTONUP: {
1460 mouse_state &= ~MouseButtons.Right;
1464 case Msg.WM_ASYNC_MESSAGE: {
1465 XplatUIDriverSupport.ExecuteClientMessage((GCHandle)msg.lParam);
1469 case Msg.WM_MOUSEMOVE: {
1470 if (msg.hwnd != prev_mouse_hwnd) {
1471 TRACKMOUSEEVENT tme;
1473 // The current message will be sent out next time around
1474 StoreMessage(ref msg);
1476 // This is the message we want to send at this point
1477 msg.message = Msg.WM_MOUSE_ENTER;
1479 prev_mouse_hwnd = msg.hwnd;
1481 tme = new TRACKMOUSEEVENT();
1482 tme.size = Marshal.SizeOf(tme);
1483 tme.hWnd = msg.hwnd;
1484 tme.dwFlags = TMEFlags.TME_LEAVE | TMEFlags.TME_HOVER;
1485 Win32TrackMouseEvent(ref tme);
1491 case Msg.WM_DROPFILES: {
1492 return Win32DnD.HandleWMDropFiles(ref msg);
1495 case Msg.WM_MOUSELEAVE: {
1496 prev_mouse_hwnd = IntPtr.Zero;
1497 msg.message=Msg.WM_MOUSE_LEAVE;
1501 case Msg.WM_TIMER: {
1502 Timer timer=(Timer)timer_list[(int)msg.wParam];
1504 if (timer != null) {
1514 internal override bool TranslateMessage(ref MSG msg) {
1515 return Win32TranslateMessage(ref msg);
1518 internal override IntPtr DispatchMessage(ref MSG msg) {
1519 return Win32DispatchMessage(ref msg);
1522 internal override bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
1524 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOP, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1526 } else if (!Bottom) {
1527 Win32SetWindowPos(hWnd, AfterhWnd, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1529 Win32SetWindowPos(hWnd, (IntPtr)SetWindowPosZOrder.HWND_BOTTOM, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1535 internal override bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
1537 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1540 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_NOTOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1545 internal override bool Text(IntPtr handle, string text) {
1546 Win32SetWindowText(handle, text);
1550 internal override bool GetText(IntPtr handle, out string text) {
1553 sb = new StringBuilder(256);
1554 Win32GetWindowText(handle, sb, sb.Capacity);
1555 text = sb.ToString();
1559 internal override bool SetVisible (IntPtr handle, bool visible, bool activate)
1562 if (Control.FromHandle (handle) is Form) {
1565 f = (Form)Control.FromHandle (handle);
1566 WindowPlacementFlags flags = WindowPlacementFlags.SW_SHOWNORMAL;
1567 switch (f.WindowState) {
1568 case FormWindowState.Normal: flags = WindowPlacementFlags.SW_SHOWNORMAL; break;
1569 case FormWindowState.Minimized: flags = WindowPlacementFlags.SW_MINIMIZE; break;
1570 case FormWindowState.Maximized: flags = WindowPlacementFlags.SW_MAXIMIZE; break;
1573 if (Hwnd.ObjectFromHandle (handle).no_activate)
1574 flags |= WindowPlacementFlags.SW_SHOWNOACTIVATE;
1576 Win32ShowWindow (handle, flags);
1579 if (Hwnd.ObjectFromHandle (handle).no_activate)
1580 Win32ShowWindow (handle, WindowPlacementFlags.SW_SHOWNOACTIVATE);
1582 Win32ShowWindow (handle, WindowPlacementFlags.SW_SHOWNORMAL);
1586 Win32ShowWindow (handle, WindowPlacementFlags.SW_HIDE);
1591 internal override bool IsEnabled(IntPtr handle) {
1592 return IsWindowEnabled (handle);
1595 internal override bool IsVisible(IntPtr handle) {
1596 return IsWindowVisible (handle);
1599 internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
1600 Control c = Control.FromHandle (handle);
1601 if (parent == IntPtr.Zero) {
1603 Win32ShowWindow(handle, WindowPlacementFlags.SW_HIDE);
1607 SetVisible (handle, c.is_visible, true);
1609 if (parent == IntPtr.Zero)
1610 return Win32SetParent (handle, FosterParent);
1612 return Win32SetParent(handle, parent);
1615 // If we ever start using this, we should probably replace FosterParent with IntPtr.Zero
1616 internal override IntPtr GetParent(IntPtr handle) {
1617 return Win32GetParent(handle);
1620 internal override void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
1622 Win32SetCapture(hWnd);
1625 internal override void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
1627 GrabConfined = grab_confined;
1628 GrabArea = grab_area;
1631 internal override void UngrabWindow(IntPtr hWnd) {
1632 Win32ReleaseCapture();
1633 grab_hwnd = IntPtr.Zero;
1636 internal override bool CalculateWindowRect(ref Rectangle ClientRect, int Style, int ExStyle, Menu menu, out Rectangle WindowRect) {
1639 rect.left=ClientRect.Left;
1640 rect.top=ClientRect.Top;
1641 rect.right=ClientRect.Right;
1642 rect.bottom=ClientRect.Bottom;
1644 if (!Win32AdjustWindowRectEx(ref rect, Style, menu != null, ExStyle)) {
1645 WindowRect = new Rectangle(ClientRect.Left, ClientRect.Top, ClientRect.Width, ClientRect.Height);
1649 WindowRect = new Rectangle(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
1653 internal override void SetCursor(IntPtr window, IntPtr cursor) {
1654 Win32SetCursor(cursor);
1658 internal override void ShowCursor(bool show) {
1659 Win32ShowCursor(show);
1662 internal override void OverrideCursor(IntPtr cursor) {
1663 Win32SetCursor(cursor);
1666 internal override IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
1668 Bitmap cursor_bitmap;
1676 // Win32 only allows creation cursors of a certain size
1677 if ((bitmap.Width != Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)) || (bitmap.Width != Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR))) {
1678 cursor_bitmap = new Bitmap(bitmap, new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)));
1679 cursor_mask = new Bitmap(mask, new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)));
1681 cursor_bitmap = bitmap;
1685 width = cursor_bitmap.Width;
1686 height = cursor_bitmap.Height;
1688 cursor_bits = new Byte[(width / 8) * height];
1689 mask_bits = new Byte[(width / 8) * height];
1691 for (int y = 0; y < height; y++) {
1692 for (int x = 0; x < width; x++) {
1693 pixel = cursor_bitmap.GetPixel(x, y);
1695 if (pixel == cursor_pixel) {
1696 cursor_bits[y * width / 8 + x / 8] |= (byte)(0x80 >> (x % 8));
1699 pixel = cursor_mask.GetPixel(x, y);
1701 if (pixel == mask_pixel) {
1702 mask_bits[y * width / 8 + x / 8] |= (byte)(0x80 >> (x % 8));
1707 cursor = Win32CreateCursor(IntPtr.Zero, xHotSpot, yHotSpot, width, height, mask_bits, cursor_bits);
1712 [MonoTODO("Define the missing cursors")]
1713 internal override IntPtr DefineStdCursor(StdCursor id) {
1715 case StdCursor.AppStarting: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_APPSTARTING);
1716 case StdCursor.Arrow: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
1717 case StdCursor.Cross: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_CROSS);
1718 case StdCursor.Default: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
1719 case StdCursor.Hand: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_HAND);
1720 case StdCursor.Help: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_HELP);
1721 case StdCursor.HSplit: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1722 case StdCursor.IBeam: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_IBEAM);
1723 case StdCursor.No: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_NO);
1724 case StdCursor.NoMove2D: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1725 case StdCursor.NoMoveHoriz: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1726 case StdCursor.NoMoveVert: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1727 case StdCursor.PanEast: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1728 case StdCursor.PanNE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1729 case StdCursor.PanNorth: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1730 case StdCursor.PanNW: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1731 case StdCursor.PanSE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1732 case StdCursor.PanSouth: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1733 case StdCursor.PanSW: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1734 case StdCursor.PanWest: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1735 case StdCursor.SizeAll: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZEALL);
1736 case StdCursor.SizeNESW: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENESW);
1737 case StdCursor.SizeNS: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENS);
1738 case StdCursor.SizeNWSE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENWSE);
1739 case StdCursor.SizeWE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZEWE);
1740 case StdCursor.UpArrow: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_UPARROW);
1741 case StdCursor.VSplit: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1742 case StdCursor.WaitCursor: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_WAIT);
1744 throw new NotImplementedException ();
1747 internal override void DestroyCursor(IntPtr cursor) {
1748 if ((cursor.ToInt32() < (int)LoadCursorType.First) || (cursor.ToInt32() > (int)LoadCursorType.Last)) {
1749 Win32DestroyCursor(cursor);
1754 internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
1761 internal override void SetCursorPos(IntPtr handle, int x, int y) {
1762 Win32SetCursorPos(x, y);
1765 internal override Region GetClipRegion(IntPtr hwnd) {
1768 region = new Region();
1770 Win32GetWindowRgn(hwnd, region.GetHrgn(Graphics.FromHwnd(hwnd)));
1775 internal override void SetClipRegion(IntPtr hwnd, Region region) {
1776 Win32SetWindowRgn(hwnd, region.GetHrgn(Graphics.FromHwnd(hwnd)), true);
1779 internal override void EnableWindow(IntPtr handle, bool Enable) {
1780 Win32EnableWindow(handle, Enable);
1783 internal override void EndLoop(System.Threading.Thread thread) {
1787 internal override object StartLoop(System.Threading.Thread thread) {
1791 internal override void SetModal(IntPtr handle, bool Modal) {
1792 // we do nothing on Win32
1795 internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
1798 Win32GetCursorPos(out pt);
1800 if (handle!=IntPtr.Zero) {
1801 Win32ScreenToClient(handle, ref pt);
1808 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y)
1810 POINT pnt = new POINT();
1814 Win32ScreenToClient (handle, ref pnt);
1820 internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) {
1821 POINT pnt = new POINT();
1826 Win32ClientToScreen(handle, ref pnt);
1832 internal override void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
1835 Win32GetWindowRect(handle, out rect);
1836 x -= rect.left + SystemInformation.FrameBorderSize.Width;
1837 y -= rect.top + SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight;
1841 internal override void MenuToScreen(IntPtr handle, ref int x, ref int y) {
1844 Win32GetWindowRect(handle, out rect);
1845 x += rect.left + SystemInformation.FrameBorderSize.Width;
1846 y += rect.top + SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight;
1850 internal override void SendAsyncMethod (AsyncMethodData method)
1852 Win32PostMessage(FosterParent, Msg.WM_ASYNC_MESSAGE, IntPtr.Zero, (IntPtr)GCHandle.Alloc (method));
1855 internal override void SetTimer (Timer timer)
1859 index = timer.GetHashCode();
1862 timer_list[index]=timer;
1865 Win32SetTimer(FosterParent, index, (uint)timer.Interval, IntPtr.Zero);
1868 internal override void KillTimer (Timer timer)
1872 index = timer.GetHashCode();
1874 Win32KillTimer(FosterParent, index);
1877 timer_list.Remove(index);
1882 private void CaretCallback(object sender, EventArgs e) {
1883 Console.WriteLine("CaretCallback hit");
1886 private void SetMdiStyles (CreateParams cp)
1888 cp.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
1892 internal override void CreateCaret(IntPtr hwnd, int width, int height) {
1893 Win32CreateCaret(hwnd, IntPtr.Zero, width, height);
1894 caret_visible = false;
1897 internal override void DestroyCaret(IntPtr hwnd) {
1898 Win32DestroyCaret();
1901 internal override void SetCaretPos(IntPtr hwnd, int x, int y) {
1902 Win32SetCaretPos(x, y);
1905 internal override void CaretVisible(IntPtr hwnd, bool visible) {
1907 if (!caret_visible) {
1908 Win32ShowCaret(hwnd);
1909 caret_visible = true;
1912 if (caret_visible) {
1913 Win32HideCaret(hwnd);
1914 caret_visible = false;
1919 internal override IntPtr GetFocus() {
1920 return Win32GetFocus();
1923 internal override void SetFocus(IntPtr hwnd) {
1924 Win32SetFocus(hwnd);
1927 internal override IntPtr GetActive() {
1928 return Win32GetActiveWindow();
1931 internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
1935 tm = new TEXTMETRIC();
1937 dc = Win32GetDC(IntPtr.Zero);
1938 Win32SelectObject(dc, font.ToHfont());
1939 if (Win32GetTextMetrics(dc, ref tm) == false) {
1940 Win32ReleaseDC(IntPtr.Zero, dc);
1945 Win32ReleaseDC(IntPtr.Zero, dc);
1947 ascent = tm.tmAscent;
1948 descent = tm.tmDescent;
1953 internal override void ScrollWindow(IntPtr hwnd, Rectangle rectangle, int XAmount, int YAmount, bool with_children) {
1957 rect.left = rectangle.X;
1958 rect.top = rectangle.Y;
1959 rect.right = rectangle.Right;
1960 rect.bottom = rectangle.Bottom;
1962 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));
1963 Win32UpdateWindow(hwnd);
1966 internal override void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount, bool with_children) {
1967 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));
1970 internal override bool SystrayAdd(IntPtr hwnd, string tip, Icon icon, out ToolTip tt) {
1973 nid = new NOTIFYICONDATA();
1975 nid.cbSize = (uint)Marshal.SizeOf(nid);
1978 nid.uCallbackMessage = (uint)Msg.WM_USER;
1979 nid.uFlags = NotifyIconFlags.NIF_MESSAGE;
1983 nid.uFlags |= NotifyIconFlags.NIF_TIP;
1987 nid.hIcon = icon.Handle;
1988 nid.uFlags |= NotifyIconFlags.NIF_ICON;
1993 return Win32Shell_NotifyIcon(NotifyIconMessage.NIM_ADD, ref nid);
1996 internal override bool SystrayChange(IntPtr hwnd, string tip, Icon icon, ref ToolTip tt) {
1999 nid = new NOTIFYICONDATA();
2001 nid.cbSize = (uint)Marshal.SizeOf(nid);
2002 nid.hIcon = icon.Handle;
2005 nid.uCallbackMessage = (uint)Msg.WM_USER;
2006 nid.uFlags = NotifyIconFlags.NIF_MESSAGE;
2010 nid.uFlags |= NotifyIconFlags.NIF_TIP;
2014 nid.hIcon = icon.Handle;
2015 nid.uFlags |= NotifyIconFlags.NIF_ICON;
2018 return Win32Shell_NotifyIcon(NotifyIconMessage.NIM_MODIFY, ref nid);
2021 internal override void SystrayRemove(IntPtr hwnd, ref ToolTip tt) {
2024 nid = new NOTIFYICONDATA();
2026 nid.cbSize = (uint)Marshal.SizeOf(nid);
2031 Win32Shell_NotifyIcon(NotifyIconMessage.NIM_DELETE, ref nid);
2035 internal override void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
2039 style = Win32GetWindowLong(handle, WindowLong.GWL_STYLE);
2040 exstyle = Win32GetWindowLong(handle, WindowLong.GWL_EXSTYLE);
2043 switch (border_style) {
2044 case FormBorderStyle.None: {
2045 style &= ~(uint)WindowStyles.WS_BORDER;
2046 exstyle &= ~(uint)WindowExStyles.WS_EX_CLIENTEDGE;
2050 case FormBorderStyle.FixedSingle: {
2051 style |= (uint)WindowStyles.WS_BORDER;
2052 exstyle &= ~(uint)WindowExStyles.WS_EX_CLIENTEDGE;
2056 case FormBorderStyle.Fixed3D: {
2057 style &= ~(uint)WindowStyles.WS_BORDER;
2058 exstyle |= (uint)WindowExStyles.WS_EX_CLIENTEDGE;
2063 Win32SetWindowLong(handle, WindowLong.GWL_STYLE, style);
2064 Win32SetWindowLong(handle, WindowLong.GWL_EXSTYLE, exstyle);
2066 Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0,
2067 SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE | SetWindowPosFlags.SWP_NOOWNERZORDER | SetWindowPosFlags.SWP_NOZORDER);
2070 internal override void SetMenu(IntPtr handle, Menu menu) {
2071 // Trigger WM_NCCALC
2072 Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
2076 internal override Point GetMenuOrigin(IntPtr handle) {
2077 return new Point(SystemInformation.FrameBorderSize.Width, SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight);
2080 internal override void SetIcon(IntPtr hwnd, Icon icon) {
2081 Win32SendMessage(hwnd, Msg.WM_SETICON, (IntPtr)1, icon.Handle); // 1 = large icon (0 would be small)
2084 internal override void ClipboardClose(IntPtr handle) {
2085 if (handle != clip_magic) {
2086 throw new ArgumentException("handle is not a valid clipboard handle");
2088 Win32CloseClipboard();
2091 internal override int ClipboardGetID(IntPtr handle, string format) {
2092 if (handle != clip_magic) {
2093 throw new ArgumentException("handle is not a valid clipboard handle");
2095 if (format == "Text" ) return 1;
2096 else if (format == "Bitmap" ) return 2;
2097 else if (format == "MetaFilePict" ) return 3;
2098 else if (format == "SymbolicLink" ) return 4;
2099 else if (format == "DataInterchangeFormat" ) return 5;
2100 else if (format == "Tiff" ) return 6;
2101 else if (format == "OEMText" ) return 7;
2102 else if (format == "DeviceIndependentBitmap" ) return 8;
2103 else if (format == "Palette" ) return 9;
2104 else if (format == "PenData" ) return 10;
2105 else if (format == "RiffAudio" ) return 11;
2106 else if (format == "WaveAudio" ) return 12;
2107 else if (format == "UnicodeText" ) return 13;
2108 else if (format == "EnhancedMetafile" ) return 14;
2109 else if (format == "FileDrop" ) return 15;
2110 else if (format == "Locale" ) return 16;
2112 return (int)Win32RegisterClipboardFormat(format);
2115 internal override IntPtr ClipboardOpen(bool primary_selection) {
2116 // Win32 does not have primary selection
2117 Win32OpenClipboard(FosterParent);
2121 internal override int[] ClipboardAvailableFormats(IntPtr handle) {
2126 if (handle != clip_magic) {
2134 format = Win32EnumClipboardFormats(format);
2138 } while (format != 0);
2141 result = new int[count];
2145 format = Win32EnumClipboardFormats(format);
2147 result[count++] = (int)format;
2149 } while (format != 0);
2155 internal override object ClipboardRetrieve(IntPtr handle, int type, XplatUI.ClipboardToObject converter) {
2160 if (handle != clip_magic) {
2161 throw new ArgumentException("handle is not a valid clipboard handle");
2164 hmem = Win32GetClipboardData((uint)type);
2165 if (hmem == IntPtr.Zero) {
2169 data = Win32GlobalLock(hmem);
2170 if (data == IntPtr.Zero) {
2171 uint error = Win32GetLastError();
2172 Console.WriteLine("Error: {0}", error);
2178 if (type == DataFormats.GetFormat(DataFormats.Rtf).Id) {
2179 obj = AnsiToString(data);
2180 } else switch ((ClipboardFormats)type) {
2181 case ClipboardFormats.CF_TEXT: {
2182 obj = AnsiToString(data);
2186 case ClipboardFormats.CF_DIB: {
2187 obj = DIBtoImage(data);
2191 case ClipboardFormats.CF_UNICODETEXT: {
2192 obj = UnicodeToString(data);
2197 if (converter != null && !converter(type, data, out obj)) {
2203 Win32GlobalUnlock(hmem);
2209 internal override void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
2214 if (handle != clip_magic) {
2215 throw new ArgumentException("handle is not a valid clipboard handle");
2220 Win32EmptyClipboard();
2225 if (obj is string) {
2226 type = (int)ClipboardFormats.CF_UNICODETEXT;
2227 } else if (obj is Image) {
2228 type = (int)ClipboardFormats.CF_DIB;
2232 if (type == DataFormats.GetFormat(DataFormats.Rtf).Id) {
2233 hmem = Marshal.StringToHGlobalAnsi((string)obj);
2234 Win32SetClipboardData((uint)type, hmem);
2236 } else switch((ClipboardFormats)type) {
2237 case ClipboardFormats.CF_UNICODETEXT: {
2238 hmem = Marshal.StringToHGlobalUni((string)obj);
2239 Win32SetClipboardData((uint)type, hmem);
2243 case ClipboardFormats.CF_TEXT: {
2244 hmem = Marshal.StringToHGlobalAnsi((string)obj);
2245 Win32SetClipboardData((uint)type, hmem);
2249 case ClipboardFormats.CF_BITMAP:
2250 case ClipboardFormats.CF_DIB: {
2251 data = ImageToDIB((Image)obj);
2253 hmem = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
2254 hmem_ptr = Win32GlobalLock(hmem);
2255 Marshal.Copy(data, 0, hmem_ptr, data.Length);
2256 Win32GlobalUnlock(hmem);
2257 Win32SetClipboardData((uint)ClipboardFormats.CF_DIB, hmem);
2262 if (converter != null && converter(ref type, obj, out data)) {
2263 hmem = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
2264 hmem_ptr = Win32GlobalLock(hmem);
2265 Marshal.Copy(data, 0, hmem_ptr, data.Length);
2266 Win32GlobalUnlock(hmem);
2267 Win32SetClipboardData((uint)type, hmem);
2274 internal override void SetAllowDrop(IntPtr hwnd, bool allowed) {
2276 Win32DnD.RegisterDropTarget(hwnd);
2278 Win32DnD.UnregisterDropTarget(hwnd);
2282 internal override DragDropEffects StartDrag(IntPtr hwnd, object data, DragDropEffects allowedEffects) {
2283 return Win32DnD.StartDrag(hwnd, data, allowedEffects);
2286 internal override void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
2295 Win32ClientToScreen(handle, ref pt);
2297 // If we want the standard hatch pattern we would
2298 // need to create a brush
2301 pen = Win32CreatePen(PenStyle.PS_SOLID, line_width, IntPtr.Zero);
2303 hdc = Win32GetDC(IntPtr.Zero);
2304 Win32SetROP2(hdc, ROP2DrawMode.R2_NOT);
2305 oldpen = Win32SelectObject(hdc, pen);
2307 Control c = Control.FromHandle (handle);
2309 Region r = new Region(new Rectangle(c.PointToScreen (c.Location), c.Size));
2311 Win32ExtSelectClipRgn(hdc, r.GetHrgn (Graphics.FromHdc (hdc)), (int) ClipCombineMode.RGN_AND);
2314 Win32MoveToEx(hdc, pt.x + rect.Left, pt.y + rect.Top, IntPtr.Zero);
2315 if ((rect.Width > 0) && (rect.Height > 0)) {
2316 Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Top);
2317 Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Bottom);
2318 Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Bottom);
2319 Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Top);
2321 if (rect.Width > 0) {
2322 Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Top);
2324 Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Bottom);
2328 Win32SelectObject(hdc, oldpen);
2329 Win32DeleteObject(pen);
2331 Win32ExtSelectClipRgn(hdc, IntPtr.Zero, (int) ClipCombineMode.RGN_COPY);
2333 Win32ReleaseDC(IntPtr.Zero, hdc);
2336 internal override SizeF GetAutoScaleSize(Font font) {
2339 string magic_string = "The quick brown fox jumped over the lazy dog.";
2340 double magic_number = 44.549996948242189;
2342 g = Graphics.FromHwnd(FosterParent);
2344 width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
2345 return new SizeF(width, font.Height);
2348 internal override IntPtr SendMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
2349 return Win32SendMessage(hwnd, message, wParam, lParam);
2352 internal override bool PostMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
2353 return Win32PostMessage(hwnd, message, wParam, lParam);
2356 internal override int KeyboardSpeed {
2358 Console.WriteLine ("KeyboardSpeed: need to query Windows");
2361 // Return values range from 0 to 31 which map to 2.5 to 30 repetitions per second.
2367 internal override int KeyboardDelay {
2369 Console.WriteLine ("KeyboardDelay: need to query Windows");
2372 // Return values must range from 0 to 4, 0 meaning 250ms,
2373 // and 4 meaning 1000 ms.
2379 internal override event EventHandler Idle;
2381 // Santa's little helper
2382 static void Where() {
2383 Console.WriteLine("Here: {0}", new StackTrace().ToString());
2385 #endregion // Public Static Methods
2387 #region Win32 Imports
2388 [DllImport ("kernel32.dll", EntryPoint="GetLastError", CallingConvention=CallingConvention.StdCall)]
2389 private extern static uint Win32GetLastError();
2391 [DllImport ("user32.dll", EntryPoint="CreateWindowExW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2392 internal extern static IntPtr Win32CreateWindow(uint dwExStyle, string lpClassName, string lpWindowName, uint dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lParam);
2394 [DllImport ("user32.dll", EntryPoint="DestroyWindow", CallingConvention=CallingConvention.StdCall)]
2395 internal extern static bool Win32DestroyWindow(IntPtr hWnd);
2397 [DllImport ("user32.dll", EntryPoint="PeekMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2398 internal extern static bool Win32PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags);
2400 [DllImport ("user32.dll", EntryPoint="GetMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2401 internal extern static bool Win32GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax);
2403 [DllImport ("user32.dll", EntryPoint="TranslateMessage", CallingConvention=CallingConvention.StdCall)]
2404 internal extern static bool Win32TranslateMessage(ref MSG msg);
2406 [DllImport ("user32.dll", EntryPoint="DispatchMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2407 internal extern static IntPtr Win32DispatchMessage(ref MSG msg);
2409 [DllImport ("user32.dll", EntryPoint="MoveWindow", CallingConvention=CallingConvention.StdCall)]
2410 internal extern static bool Win32MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
2412 [DllImport ("user32.dll", EntryPoint="SetWindowPos", CallingConvention=CallingConvention.StdCall)]
2413 internal extern static bool Win32SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SetWindowPosFlags Flags);
2415 [DllImport ("user32.dll", EntryPoint="SetWindowPos", CallingConvention=CallingConvention.StdCall)]
2416 internal extern static bool Win32SetWindowPos(IntPtr hWnd, SetWindowPosZOrder pos, int x, int y, int cx, int cy, SetWindowPosFlags Flags);
2418 [DllImport ("user32.dll", EntryPoint="SetWindowTextW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2419 internal extern static bool Win32SetWindowText(IntPtr hWnd, string lpString);
2421 [DllImport ("user32.dll", EntryPoint="GetWindowTextW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2422 internal extern static bool Win32GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
2424 [DllImport ("user32.dll", EntryPoint="SetParent", CallingConvention=CallingConvention.StdCall)]
2425 internal extern static IntPtr Win32SetParent(IntPtr hWnd, IntPtr hParent);
2427 [DllImport ("user32.dll", EntryPoint="RegisterClassW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2428 private extern static bool Win32RegisterClass(ref WNDCLASS wndClass);
2430 [DllImport ("user32.dll", EntryPoint="LoadCursorW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2431 private extern static IntPtr Win32LoadCursor(IntPtr hInstance, LoadCursorType type);
2433 [DllImport ("user32.dll", EntryPoint="ShowCursor", CallingConvention=CallingConvention.StdCall)]
2434 private extern static IntPtr Win32ShowCursor(bool bShow);
2436 [DllImport ("user32.dll", EntryPoint="SetCursor", CallingConvention=CallingConvention.StdCall)]
2437 private extern static IntPtr Win32SetCursor(IntPtr hCursor);
2439 [DllImport ("user32.dll", EntryPoint="CreateCursor", CallingConvention=CallingConvention.StdCall)]
2440 private extern static IntPtr Win32CreateCursor(IntPtr hInstance, int xHotSpot, int yHotSpot, int nWidth, int nHeight, Byte[] pvANDPlane, Byte[] pvORPlane);
2442 [DllImport ("user32.dll", EntryPoint="DestroyCursor", CallingConvention=CallingConvention.StdCall)]
2443 private extern static bool Win32DestroyCursor(IntPtr hCursor);
2445 [DllImport ("user32.dll", EntryPoint="DefWindowProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2446 private extern static IntPtr Win32DefWindowProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
2448 [DllImport ("user32.dll", EntryPoint="DefDlgProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2449 private extern static IntPtr Win32DefDlgProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
2451 [DllImport ("user32.dll", EntryPoint="PostQuitMessage", CallingConvention=CallingConvention.StdCall)]
2452 private extern static IntPtr Win32PostQuitMessage(int nExitCode);
2454 [DllImport ("user32.dll", EntryPoint="UpdateWindow", CallingConvention=CallingConvention.StdCall)]
2455 private extern static IntPtr Win32UpdateWindow(IntPtr hWnd);
2457 [DllImport ("user32.dll", EntryPoint="GetUpdateRect", CallingConvention=CallingConvention.StdCall)]
2458 private extern static bool Win32GetUpdateRect(IntPtr hWnd, ref RECT rect, bool erase);
2460 [DllImport ("user32.dll", EntryPoint="BeginPaint", CallingConvention=CallingConvention.StdCall)]
2461 private extern static IntPtr Win32BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
2463 [DllImport ("user32.dll", EntryPoint="EndPaint", CallingConvention=CallingConvention.StdCall)]
2464 private extern static bool Win32EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
2466 [DllImport ("user32.dll", EntryPoint="GetDC", CallingConvention=CallingConvention.StdCall)]
2467 private extern static IntPtr Win32GetDC(IntPtr hWnd);
2469 [DllImport ("user32.dll", EntryPoint="GetWindowDC", CallingConvention=CallingConvention.StdCall)]
2470 private extern static IntPtr Win32GetWindowDC(IntPtr hWnd);
2472 [DllImport ("user32.dll", EntryPoint="GetDCEx", CallingConvention=CallingConvention.StdCall)]
2473 private extern static IntPtr Win32GetDCEx(IntPtr hWnd, IntPtr hRgn, DCExFlags flags);
2475 [DllImport ("user32.dll", EntryPoint="ReleaseDC", CallingConvention=CallingConvention.StdCall)]
2476 private extern static IntPtr Win32ReleaseDC(IntPtr hWnd, IntPtr hDC);
2478 [DllImport ("user32.dll", EntryPoint="MessageBoxW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2479 private extern static IntPtr Win32MessageBox(IntPtr hParent, string pText, string pCaption, uint uType);
2481 [DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
2482 private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, ref RECT lpRect, bool bErase);
2484 [DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
2485 private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
2487 [DllImport ("user32.dll", EntryPoint="SetCapture", CallingConvention=CallingConvention.StdCall)]
2488 private extern static IntPtr Win32SetCapture(IntPtr hWnd);
2490 [DllImport ("user32.dll", EntryPoint="ReleaseCapture", CallingConvention=CallingConvention.StdCall)]
2491 private extern static IntPtr Win32ReleaseCapture();
2493 [DllImport ("user32.dll", EntryPoint="GetWindowRect", CallingConvention=CallingConvention.StdCall)]
2494 private extern static IntPtr Win32GetWindowRect(IntPtr hWnd, out RECT rect);
2496 [DllImport ("user32.dll", EntryPoint="GetClientRect", CallingConvention=CallingConvention.StdCall)]
2497 private extern static IntPtr Win32GetClientRect(IntPtr hWnd, out RECT rect);
2499 [DllImport ("user32.dll", EntryPoint="ScreenToClient", CallingConvention=CallingConvention.StdCall)]
2500 private extern static bool Win32ScreenToClient(IntPtr hWnd, ref POINT pt);
2502 [DllImport ("user32.dll", EntryPoint="ClientToScreen", CallingConvention=CallingConvention.StdCall)]
2503 private extern static bool Win32ClientToScreen(IntPtr hWnd, ref POINT pt);
2505 [DllImport ("user32.dll", EntryPoint="GetParent", CallingConvention=CallingConvention.StdCall)]
2506 private extern static IntPtr Win32GetParent(IntPtr hWnd);
2508 [DllImport ("user32.dll", EntryPoint="SetActiveWindow", CallingConvention=CallingConvention.StdCall)]
2509 private extern static IntPtr Win32SetActiveWindow(IntPtr hWnd);
2511 [DllImport ("user32.dll", EntryPoint="AdjustWindowRectEx", CallingConvention=CallingConvention.StdCall)]
2512 private extern static bool Win32AdjustWindowRectEx(ref RECT lpRect, int dwStyle, bool bMenu, int dwExStyle);
2514 [DllImport ("user32.dll", EntryPoint="GetCursorPos", CallingConvention=CallingConvention.StdCall)]
2515 private extern static bool Win32GetCursorPos(out POINT lpPoint);
2517 [DllImport ("user32.dll", EntryPoint="SetCursorPos", CallingConvention=CallingConvention.StdCall)]
2518 private extern static bool Win32SetCursorPos(int x, int y);
2520 [DllImport ("user32.dll", EntryPoint="GetWindowPlacement", CallingConvention=CallingConvention.StdCall)]
2521 private extern static bool Win32GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
2523 [DllImport ("user32.dll", EntryPoint="TrackMouseEvent", CallingConvention=CallingConvention.StdCall)]
2524 private extern static bool Win32TrackMouseEvent(ref TRACKMOUSEEVENT tme);
2526 [DllImport ("gdi32.dll", EntryPoint="CreateBrushIndirect", CallingConvention=CallingConvention.StdCall)]
2527 private extern static IntPtr Win32CreateBrushIndirect(ref LOGBRUSH lb);
2529 [DllImport ("user32.dll", EntryPoint="FillRect", CallingConvention=CallingConvention.StdCall)]
2530 private extern static int Win32FillRect(IntPtr hdc, ref RECT rect, IntPtr hbr);
2532 [DllImport ("user32.dll", EntryPoint="SetWindowLong", CallingConvention=CallingConvention.StdCall)]
2533 private extern static uint Win32SetWindowLong(IntPtr hwnd, WindowLong index, uint value);
2535 [DllImport ("user32.dll", EntryPoint="GetWindowLong", CallingConvention=CallingConvention.StdCall)]
2536 private extern static uint Win32GetWindowLong(IntPtr hwnd, WindowLong index);
2538 [DllImport ("user32.dll", EntryPoint="SetLayeredWindowAttributes", CallingConvention=CallingConvention.StdCall)]
2539 private extern static uint Win32SetLayeredWindowAttributes (IntPtr hwnd, COLORREF crKey, byte bAlpha, LayeredWindowAttributes dwFlags);
2541 [DllImport ("gdi32.dll", EntryPoint="DeleteObject", CallingConvention=CallingConvention.StdCall)]
2542 private extern static bool Win32DeleteObject(IntPtr o);
2544 [DllImport ("user32.dll", EntryPoint="GetKeyState", CallingConvention=CallingConvention.StdCall)]
2545 private extern static short Win32GetKeyState(VirtualKeys nVirtKey);
2547 [DllImport ("user32.dll", EntryPoint="GetDesktopWindow", CallingConvention=CallingConvention.StdCall)]
2548 private extern static IntPtr Win32GetDesktopWindow();
2550 [DllImport ("user32.dll", EntryPoint="SetTimer", CallingConvention=CallingConvention.StdCall)]
2551 private extern static IntPtr Win32SetTimer(IntPtr hwnd, int nIDEvent, uint uElapse, IntPtr timerProc);
2553 [DllImport ("user32.dll", EntryPoint="KillTimer", CallingConvention=CallingConvention.StdCall)]
2554 private extern static IntPtr Win32KillTimer(IntPtr hwnd, int nIDEvent);
2556 [DllImport ("user32.dll", EntryPoint="ShowWindow", CallingConvention=CallingConvention.StdCall)]
2557 private extern static IntPtr Win32ShowWindow(IntPtr hwnd, WindowPlacementFlags nCmdShow);
2559 [DllImport ("user32.dll", EntryPoint="EnableWindow", CallingConvention=CallingConvention.StdCall)]
2560 private extern static IntPtr Win32EnableWindow(IntPtr hwnd, bool Enabled);
2562 [DllImport ("user32.dll", EntryPoint="SetFocus", CallingConvention=CallingConvention.StdCall)]
2563 internal extern static IntPtr Win32SetFocus(IntPtr hwnd);
2565 [DllImport ("user32.dll", EntryPoint="GetFocus", CallingConvention=CallingConvention.StdCall)]
2566 internal extern static IntPtr Win32GetFocus();
2568 [DllImport ("user32.dll", EntryPoint="CreateCaret", CallingConvention=CallingConvention.StdCall)]
2569 internal extern static bool Win32CreateCaret(IntPtr hwnd, IntPtr hBitmap, int nWidth, int nHeight);
2571 [DllImport ("user32.dll", EntryPoint="DestroyCaret", CallingConvention=CallingConvention.StdCall)]
2572 private extern static bool Win32DestroyCaret();
2574 [DllImport ("user32.dll", EntryPoint="ShowCaret", CallingConvention=CallingConvention.StdCall)]
2575 private extern static bool Win32ShowCaret(IntPtr hwnd);
2577 [DllImport ("user32.dll", EntryPoint="HideCaret", CallingConvention=CallingConvention.StdCall)]
2578 private extern static bool Win32HideCaret(IntPtr hwnd);
2580 [DllImport ("user32.dll", EntryPoint="SetCaretPos", CallingConvention=CallingConvention.StdCall)]
2581 private extern static bool Win32SetCaretPos(int X, int Y);
2583 [DllImport ("user32.dll", EntryPoint="GetCaretBlinkTime", CallingConvention=CallingConvention.StdCall)]
2584 private extern static uint Win32GetCaretBlinkTime();
2586 [DllImport ("gdi32.dll", EntryPoint="GetTextMetricsW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2587 internal extern static bool Win32GetTextMetrics(IntPtr hdc, ref TEXTMETRIC tm);
2589 [DllImport ("gdi32.dll", EntryPoint="SelectObject", CallingConvention=CallingConvention.StdCall)]
2590 internal extern static IntPtr Win32SelectObject(IntPtr hdc, IntPtr hgdiobject);
2592 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2593 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
2595 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2596 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
2598 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2599 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
2601 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2602 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2604 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2605 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2607 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2608 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2610 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2611 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2613 [DllImport ("user32.dll", EntryPoint="GetActiveWindow", CallingConvention=CallingConvention.StdCall)]
2614 private extern static IntPtr Win32GetActiveWindow();
2616 [DllImport ("user32.dll", EntryPoint="GetSystemMetrics", CallingConvention=CallingConvention.StdCall)]
2617 private extern static int Win32GetSystemMetrics(SystemMetrics nIndex);
2619 [DllImport ("shell32.dll", EntryPoint="Shell_NotifyIconW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2620 private extern static bool Win32Shell_NotifyIcon(NotifyIconMessage dwMessage, ref NOTIFYICONDATA lpData);
2622 [DllImport ("gdi32.dll", EntryPoint="CreateRectRgn", CallingConvention=CallingConvention.StdCall)]
2623 internal extern static IntPtr Win32CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
2625 [DllImport ("user32.dll", EntryPoint="IsWindowEnabled", CallingConvention=CallingConvention.StdCall)]
2626 private extern static bool IsWindowEnabled(IntPtr hwnd);
2628 [DllImport ("user32.dll", EntryPoint="IsWindowVisible", CallingConvention=CallingConvention.StdCall)]
2629 private extern static bool IsWindowVisible(IntPtr hwnd);
2631 [DllImport ("user32.dll", EntryPoint="SetClassLong", CallingConvention=CallingConvention.StdCall)]
2632 private extern static bool Win32SetClassLong(IntPtr hwnd, ClassLong nIndex, IntPtr dwNewLong);
2634 [DllImport ("user32.dll", EntryPoint="SendMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2635 private extern static IntPtr Win32SendMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
2637 [DllImport ("user32.dll", EntryPoint="PostMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2638 private extern static bool Win32PostMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
2640 [DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2641 private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref RECT rect, uint fWinIni);
2643 [DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2644 private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref uint value, uint fWinIni);
2646 [DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2647 private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref int value, uint fWinIni);
2649 [DllImport ("user32.dll", EntryPoint="OpenClipboard", CallingConvention=CallingConvention.StdCall)]
2650 private extern static bool Win32OpenClipboard(IntPtr hwnd);
2652 [DllImport ("user32.dll", EntryPoint="EmptyClipboard", CallingConvention=CallingConvention.StdCall)]
2653 private extern static bool Win32EmptyClipboard();
2655 [DllImport ("user32.dll", EntryPoint="RegisterClipboardFormatW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2656 private extern static uint Win32RegisterClipboardFormat(string format);
2658 [DllImport ("user32.dll", EntryPoint="CloseClipboard", CallingConvention=CallingConvention.StdCall)]
2659 private extern static bool Win32CloseClipboard();
2661 [DllImport ("user32.dll", EntryPoint="EnumClipboardFormats", CallingConvention=CallingConvention.StdCall)]
2662 private extern static uint Win32EnumClipboardFormats(uint format);
2664 [DllImport ("user32.dll", EntryPoint="GetClipboardData", CallingConvention=CallingConvention.StdCall)]
2665 private extern static IntPtr Win32GetClipboardData(uint format);
2667 [DllImport ("user32.dll", EntryPoint="SetClipboardData", CallingConvention=CallingConvention.StdCall)]
2668 private extern static IntPtr Win32SetClipboardData(uint format, IntPtr handle);
2670 [DllImport ("kernel32.dll", EntryPoint="GlobalAlloc", CallingConvention=CallingConvention.StdCall)]
2671 internal extern static IntPtr Win32GlobalAlloc(GAllocFlags Flags, int dwBytes);
2673 [DllImport ("kernel32.dll", EntryPoint="CopyMemory", CallingConvention=CallingConvention.StdCall)]
2674 internal extern static void Win32CopyMemory(IntPtr Destination, IntPtr Source, int length);
2676 [DllImport ("kernel32.dll", EntryPoint="GlobalFree", CallingConvention=CallingConvention.StdCall)]
2677 internal extern static IntPtr Win32GlobalFree(IntPtr hMem);
2679 [DllImport ("kernel32.dll", EntryPoint="GlobalSize", CallingConvention=CallingConvention.StdCall)]
2680 internal extern static uint Win32GlobalSize(IntPtr hMem);
2682 [DllImport ("kernel32.dll", EntryPoint="GlobalLock", CallingConvention=CallingConvention.StdCall)]
2683 internal extern static IntPtr Win32GlobalLock(IntPtr hMem);
2685 [DllImport ("kernel32.dll", EntryPoint="GlobalUnlock", CallingConvention=CallingConvention.StdCall)]
2686 internal extern static IntPtr Win32GlobalUnlock(IntPtr hMem);
2688 [DllImport ("gdi32.dll", EntryPoint="SetROP2", CallingConvention=CallingConvention.StdCall)]
2689 internal extern static int Win32SetROP2(IntPtr hdc, ROP2DrawMode fnDrawMode);
2691 [DllImport ("gdi32.dll", EntryPoint="MoveToEx", CallingConvention=CallingConvention.StdCall)]
2692 internal extern static bool Win32MoveToEx(IntPtr hdc, int x, int y, ref POINT lpPoint);
2694 [DllImport ("gdi32.dll", EntryPoint="MoveToEx", CallingConvention=CallingConvention.StdCall)]
2695 internal extern static bool Win32MoveToEx(IntPtr hdc, int x, int y, IntPtr lpPoint);
2697 [DllImport ("gdi32.dll", EntryPoint="LineTo", CallingConvention=CallingConvention.StdCall)]
2698 internal extern static bool Win32LineTo(IntPtr hdc, int x, int y);
2700 [DllImport ("gdi32.dll", EntryPoint="CreatePen", CallingConvention=CallingConvention.StdCall)]
2701 internal extern static IntPtr Win32CreatePen(PenStyle fnPenStyle, int nWidth, ref COLORREF color);
2703 [DllImport ("gdi32.dll", EntryPoint="CreatePen", CallingConvention=CallingConvention.StdCall)]
2704 internal extern static IntPtr Win32CreatePen(PenStyle fnPenStyle, int nWidth, IntPtr color);
2706 [DllImport ("gdi32.dll", EntryPoint="GetStockObject", CallingConvention=CallingConvention.StdCall)]
2707 internal extern static IntPtr Win32GetStockObject(StockObject fnObject);
2709 [DllImport ("gdi32.dll", EntryPoint="CreateHatchBrush", CallingConvention=CallingConvention.StdCall)]
2710 internal extern static IntPtr Win32CreateHatchBrush(HatchStyle fnStyle, IntPtr color);
2712 [DllImport ("gdi32.dll", EntryPoint="CreateHatchBrush", CallingConvention=CallingConvention.StdCall)]
2713 internal extern static IntPtr Win32CreateHatchBrush(HatchStyle fnStyle, ref COLORREF color);
2715 [DllImport("gdi32.dll", EntryPoint = "ExcludeClipRect", CallingConvention = CallingConvention.StdCall)]
2716 internal extern static int Win32ExcludeClipRect (IntPtr hdc, int left, int top, int right, int bottom);
2718 [DllImport ("gdi32.dll", EntryPoint="ExtSelectClipRgn", CallingConvention=CallingConvention.StdCall)]
2719 internal extern static int Win32ExtSelectClipRgn(IntPtr hdc, IntPtr hrgn, int mode);
2721 [DllImport ("winmm.dll", EntryPoint="PlaySoundW", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
2722 internal extern static IntPtr Win32PlaySound(string pszSound, IntPtr hmod, SndFlags fdwSound);
2724 [DllImport ("user32.dll", EntryPoint="SetWindowRgn", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
2725 internal extern static int Win32SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
2727 [DllImport ("user32.dll", EntryPoint="GetWindowRgn", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
2728 internal extern static IntPtr Win32GetWindowRgn(IntPtr hWnd, IntPtr hRgn);