1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
31 using System.Drawing.Imaging;
32 using System.ComponentModel;
33 using System.Collections;
34 using System.Diagnostics;
36 using System.Reflection;
37 using System.Reflection.Emit;
38 using System.Runtime.InteropServices;
43 namespace System.Windows.Forms {
44 internal class XplatUIWin32 : XplatUIDriver {
45 #region Local Variables
46 private static XplatUIWin32 instance;
47 private static int ref_count;
48 private static IntPtr FosterParent;
50 internal static MouseButtons mouse_state;
51 internal static Point mouse_position;
52 internal static bool grab_confined;
53 internal static IntPtr grab_hwnd;
54 internal static Rectangle grab_area;
55 internal static WndProc wnd_proc;
56 internal static IntPtr prev_mouse_hwnd;
57 internal static IntPtr override_cursor;
59 internal static bool themes_enabled;
60 private Hashtable timer_list;
61 private static Queue message_queue;
62 private static IntPtr clip_magic = new IntPtr(27051977);
64 // References to DnD delegates for unmanaged land
66 private static MethodInfo IDataObjectGetDataMethod;
67 private static object[] GetDataArgs;
69 private static QueryInterfaceDelegate QueryInterface;
70 private static AddRefDelegate AddRef;
71 private static ReleaseDelegate Release;
72 private static DragEnterDelegate DragEnter;
73 private static DragOverDelegate DragOver;
74 private static DragLeaveDelegate DragLeave;
75 private static DropDelegate Drop;
76 private static DragEventArgs DragDropEventArgs;
77 #endregion // Local Variables
79 #region Private Structs
80 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
81 private struct WNDCLASS {
83 internal WndProc lpfnWndProc;
84 internal int cbClsExtra;
85 internal int cbWndExtra;
86 internal IntPtr hInstance;
87 internal IntPtr hIcon;
88 internal IntPtr hCursor;
89 internal IntPtr hbrBackground;
90 [MarshalAs(UnmanagedType.LPWStr)]
91 internal string lpszMenuName;
92 [MarshalAs(UnmanagedType.LPWStr)]
93 internal string lpszClassName;
96 [StructLayout(LayoutKind.Sequential)]
97 internal struct RECT {
104 [StructLayout(LayoutKind.Sequential)]
105 internal struct POINT {
110 internal enum SPIAction {
111 SPI_GETWORKAREA = 0x0030
114 internal enum WindowPlacementFlags {
118 SW_SHOWMINIMIZED = 2,
119 SW_SHOWMAXIMIZED = 3,
121 SW_SHOWNOACTIVATE = 4,
124 SW_SHOWMINNOACTIVE = 7,
128 SW_FORCEMINIMIZE = 11,
132 [StructLayout(LayoutKind.Sequential)]
133 private struct WINDOWPLACEMENT {
134 internal uint length;
136 internal WindowPlacementFlags showCmd;
137 internal POINT ptMinPosition;
138 internal POINT ptMaxPosition;
139 internal RECT rcNormalPosition;
142 [StructLayout(LayoutKind.Sequential)]
143 internal struct NCCALCSIZE_PARAMS {
147 internal IntPtr lppos;
151 private enum TMEFlags {
152 TME_HOVER = 0x00000001,
153 TME_LEAVE = 0x00000002,
154 TME_QUERY = unchecked((int)0x40000000),
155 TME_CANCEL = unchecked((int)0x80000000)
158 [StructLayout(LayoutKind.Sequential)]
159 private struct TRACKMOUSEEVENT {
161 internal TMEFlags dwFlags;
162 internal IntPtr hWnd;
163 internal int dwHoverTime;
166 [StructLayout(LayoutKind.Sequential)]
167 private struct PAINTSTRUCT {
170 internal RECT rcPaint;
171 internal int fRestore;
172 internal int fIncUpdate;
173 internal int Reserved1;
174 internal int Reserved2;
175 internal int Reserved3;
176 internal int Reserved4;
177 internal int Reserved5;
178 internal int Reserved6;
179 internal int Reserved7;
180 internal int Reserved8;
183 internal enum ClassStyle {
184 CS_VREDRAW = 0x00000001,
185 CS_HREDRAW = 0x00000002,
186 CS_KEYCVTWINDOW = 0x00000004,
187 CS_DBLCLKS = 0x00000008,
188 CS_OWNDC = 0x00000020,
189 CS_CLASSDC = 0x00000040,
190 CS_PARENTDC = 0x00000080,
191 CS_NOKEYCVT = 0x00000100,
192 CS_NOCLOSE = 0x00000200,
193 CS_SAVEBITS = 0x00000800,
194 CS_BYTEALIGNCLIENT = 0x00001000,
195 CS_BYTEALIGNWINDOW = 0x00002000,
196 CS_GLOBALCLASS = 0x00004000,
200 internal enum SetWindowPosZOrder {
208 internal enum SetWindowPosFlags {
209 SWP_ASYNCWINDOWPOS = 0x4000,
210 SWP_DEFERERASE = 0x2000,
211 SWP_DRAWFRAME = 0x0020,
212 SWP_FRAMECHANGED = 0x0020,
213 SWP_HIDEWINDOW = 0x0080,
214 SWP_NOACTIVATE = 0x0010,
215 SWP_NOCOPYBITS = 0x0100,
217 SWP_NOOWNERZORDER = 0x0200,
218 SWP_NOREDRAW = 0x0008,
219 SWP_NOREPOSITION = 0x0200,
220 SWP_NOENDSCHANGING = 0x0400,
222 SWP_NOZORDER = 0x0004,
223 SWP_SHOWWINDOW = 0x0040
226 internal enum GetSysColorIndex {
229 COLOR_ACTIVECAPTION =2,
230 COLOR_INACTIVECAPTION =3,
233 COLOR_WINDOWFRAME =6,
236 COLOR_CAPTIONTEXT =9,
237 COLOR_ACTIVEBORDER =10,
238 COLOR_INACTIVEBORDER =11,
239 COLOR_APPWORKSPACE =12,
241 COLOR_HIGHLIGHTTEXT =14,
246 COLOR_INACTIVECAPTIONTEXT =19,
247 COLOR_BTNHIGHLIGHT =20,
248 COLOR_3DDKSHADOW =21,
255 COLOR_3DHIGHLIGHT =20,
257 COLOR_BTNHILIGHT =20,
258 COLOR_MAXVALUE =24,/* Maximum value */
261 private enum LoadCursorType {
270 IDC_SIZENWSE = 32642,
271 IDC_SIZENESW = 32643,
277 IDC_APPSTARTING = 32650,
283 private enum WindowLong {
294 private enum LogBrushStyle {
303 BS_DIBPATTERN8X8 = 8,
308 private enum LogBrushHatch {
309 HS_HORIZONTAL = 0, /* ----- */
310 HS_VERTICAL = 1, /* ||||| */
311 HS_FDIAGONAL = 2, /* \\\\\ */
312 HS_BDIAGONAL = 3, /* ///// */
313 HS_CROSS = 4, /* +++++ */
314 HS_DIAGCROSS = 5, /* xxxxx */
317 private struct COLORREF {
324 [StructLayout(LayoutKind.Sequential)]
325 private struct LOGBRUSH {
326 internal LogBrushStyle lbStyle;
327 internal COLORREF lbColor;
328 internal LogBrushHatch lbHatch;
331 [StructLayout(LayoutKind.Sequential)]
332 internal struct TEXTMETRIC {
333 internal int tmHeight;
334 internal int tmAscent;
335 internal int tmDescent;
336 internal int tmInternalLeading;
337 internal int tmExternalLeading;
338 internal int tmAveCharWidth;
339 internal int tmMaxCharWidth;
340 internal int tmWeight;
341 internal int tmOverhang;
342 internal int tmDigitizedAspectX;
343 internal int tmDigitizedAspectY;
344 internal byte tmFirstChar;
345 internal byte tmLastChar;
346 internal byte tmDefaultChar;
347 internal byte tmBreakChar;
348 internal byte tmItalic;
349 internal byte tmUnderlined;
350 internal byte tmStruckOut;
351 internal byte tmPitchAndFamily;
352 internal byte tmCharSet;
356 private enum ScrollWindowExFlags {
358 SW_SCROLLCHILDREN = 0x0001,
359 SW_INVALIDATE = 0x0002,
361 SW_SMOOTHSCROLL = 0x0010
364 internal enum SystemMetrics {
381 SM_CXFULLSCREEN = 16,
382 SM_CYFULLSCREEN = 17,
383 SM_CYKANJIWINDOW = 18,
384 SM_MOUSEPRESENT = 19,
403 SM_CXICONSPACING = 38,
404 SM_CYICONSPACING = 39,
405 SM_MENUDROPALIGNMENT = 40,
408 SM_CMOUSEBUTTONS = 43,
409 SM_CXFIXEDFRAME = SM_CXDLGFRAME,
410 SM_CYFIXEDFRAME = SM_CYDLGFRAME,
411 SM_CXSIZEFRAME = SM_CXFRAME,
412 SM_CYSIZEFRAME = SM_CYFRAME,
416 SM_CXMINSPACING = 47,
417 SM_CYMINSPACING = 48,
440 SM_MIDEASTENABLED = 74,
441 SM_MOUSEWHEELPRESENT = 75,
442 SM_XVIRTUALSCREEN = 76,
443 SM_YVIRTUALSCREEN = 77,
444 SM_CXVIRTUALSCREEN = 78,
445 SM_CYVIRTUALSCREEN = 79,
447 SM_SAMEDISPLAYFORMAT = 81,
449 SM_CXFOCUSBORDER = 83,
450 SM_CYFOCUSBORDER = 84,
456 // We'll only support _WIN32_IE < 0x0500 for now
457 internal enum NotifyIconMessage {
458 NIM_ADD = 0x00000000,
459 NIM_MODIFY = 0x00000001,
460 NIM_DELETE = 0x00000002,
464 internal enum NotifyIconFlags {
465 NIF_MESSAGE = 0x00000001,
466 NIF_ICON = 0x00000002,
467 NIF_TIP = 0x00000004,
470 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
471 internal struct NOTIFYICONDATA {
472 internal uint cbSize;
473 internal IntPtr hWnd;
475 internal NotifyIconFlags uFlags;
476 internal uint uCallbackMessage;
477 internal IntPtr hIcon;
478 [MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)]
479 internal string szTip;
483 internal enum DCExFlags {
484 DCX_WINDOW = 0x00000001,
485 DCX_CACHE = 0x00000002,
486 DCX_NORESETATTRS = 0x00000004,
487 DCX_CLIPCHILDREN = 0x00000008,
488 DCX_CLIPSIBLINGS = 0x00000010,
489 DCX_PARENTCLIP = 0x00000020,
490 DCX_EXCLUDERGN = 0x00000040,
491 DCX_INTERSECTRGN = 0x00000080,
492 DCX_EXCLUDEUPDATE = 0x00000100,
493 DCX_INTERSECTUPDATE = 0x00000200,
494 DCX_LOCKWINDOWUPDATE = 0x00000400,
495 DCX_USESTYLE = 0x00010000,
496 DCX_VALIDATE = 0x00200000
499 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
500 internal struct CLIENTCREATESTRUCT {
501 internal IntPtr hWindowMenu;
502 internal uint idFirstChild;
505 private enum ClassLong : int {
507 GCL_HBRBACKGROUND = -10,
511 GCL_CBWNDEXTRA = -18,
512 GCL_CBCLSEXTRA = -20,
519 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
520 internal struct MINMAXINFO {
521 internal POINT ptReserved;
522 internal POINT ptMaxSize;
523 internal POINT ptMaxPosition;
524 internal POINT ptMinTrackSize;
525 internal POINT ptMaxTrackSize;
529 private enum GAllocFlags : uint {
531 GMEM_MOVEABLE = 0x0002,
532 GMEM_NOCOMPACT = 0x0010,
533 GMEM_NODISCARD = 0x0020,
534 GMEM_ZEROINIT = 0x0040,
535 GMEM_MODIFY = 0x0080,
536 GMEM_DISCARDABLE = 0x0100,
537 GMEM_NOT_BANKED = 0x1000,
539 GMEM_DDESHARE = 0x2000,
540 GMEM_NOTIFY = 0x4000,
541 GMEM_LOWER = GMEM_NOT_BANKED,
542 GMEM_VALID_FLAGS = 0x7F72,
543 GMEM_INVALID_HANDLE = 0x8000,
544 GHND = (GMEM_MOVEABLE | GMEM_ZEROINIT),
545 GPTR = (GMEM_FIXED | GMEM_ZEROINIT)
549 internal delegate IntPtr QueryInterfaceDelegate(IntPtr this_, IntPtr riid, IntPtr ppvObject);
550 internal delegate uint AddRefDelegate(IntPtr this_);
551 internal delegate uint ReleaseDelegate(IntPtr this_);
552 internal delegate IntPtr DragEnterDelegate(IntPtr this_, IntPtr pDataObj, IntPtr grfkeyState, IntPtr pt_x, IntPtr pt_y, IntPtr pdwEffect);
553 internal delegate IntPtr DragOverDelegate(IntPtr this_, IntPtr grfkeyState, IntPtr pt_x, IntPtr pt_y, IntPtr pdwEffect);
554 internal delegate IntPtr DragLeaveDelegate(IntPtr this_);
555 internal delegate IntPtr DropDelegate(IntPtr this_, IntPtr pDataObj, uint grfkeyState, IntPtr pt_x, IntPtr pt_y, IntPtr pdwEffect);
557 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
558 internal struct IDropTargetVtbl {
559 internal QueryInterfaceDelegate QueryInterface;
560 internal AddRefDelegate AddRef;
561 internal ReleaseDelegate Release;
562 internal DragEnterDelegate DragEnter;
563 internal DragOverDelegate DragOver;
564 internal DragLeaveDelegate DragLeave;
565 internal DropDelegate Drop;
568 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
569 internal struct IDropTarget {
570 internal IntPtr vtbl;
571 internal IntPtr window;
574 internal delegate IntPtr GetDataDelegate(IntPtr this_, ref FORMATETC pformatetcIn, ref STGMEDIUM pmedium);
575 internal delegate IntPtr GetDataHereDelegate(IntPtr this_, IntPtr pformatetc, IntPtr pmedium);
576 internal delegate IntPtr QueryGetDataDelegate(IntPtr this_, IntPtr pformatetc);
577 internal delegate IntPtr GetCanonicalFormatEtcDelegate(IntPtr this_, IntPtr pformatetcIn, IntPtr pformatetcOut);
578 internal delegate IntPtr SetDataDelegate(IntPtr this_, IntPtr pformatetc, IntPtr pmedium, bool release);
579 internal delegate IntPtr EnumFormatEtcDelegate(IntPtr this_, IntPtr direction, IntPtr ppenumFormatEtc);
580 internal delegate IntPtr DAdviseDelegate(IntPtr this_, IntPtr pformatetc, IntPtr advf, IntPtr pAdvSink, IntPtr pdwConnection);
581 internal delegate IntPtr DUnadviseDelegate(IntPtr this_, IntPtr pdwConnection);
582 internal delegate IntPtr EnumAdviseDelegate(IntPtr this_, IntPtr ppenumAdvise);
584 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
585 internal struct IDataObjectVtbl {
586 internal IntPtr QueryInterface;
587 internal IntPtr AddRef;
588 internal IntPtr Release;
589 internal IntPtr GetData;
590 internal IntPtr GetDataHere;
591 internal IntPtr QueryGetData;
592 internal IntPtr GetCanonicalFormatEtc;
593 internal IntPtr SetData;
594 internal IntPtr EnumFormatEtc;
595 internal IntPtr DAdvise;
596 internal IntPtr DUnadvise;
597 internal IntPtr EnumAdvise;
600 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
601 internal struct IDataObject {
602 internal IntPtr vtbl;
605 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
606 internal struct FORMATETC {
607 internal ClipboardFormats cfFormat;
608 internal IntPtr ptd; // Pointer to target device
609 internal DVASPECT dwAspect;
611 internal TYMED tymed;
614 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
615 internal struct STGMEDIUM {
617 internal IntPtr hHandle; // This is usually a union of various handle types
618 internal IntPtr pUnkForRelease;
621 internal enum DVASPECT {
\r
622 DVASPECT_CONTENT = 1,
\r
623 DVASPECT_THUMBNAIL = 2,
\r
625 DVASPECT_DOCPRINT = 8
\r
628 internal enum TYMED {
\r
632 TYMED_ISTORAGE = 8,
\r
639 internal static IntPtr QueryInterfaceMethod(IntPtr this_, IntPtr riid, IntPtr ppvObject) {
643 internal static uint AddRefMethod(IntPtr this_) {
647 internal static uint ReleaseMethod(IntPtr this_) {
651 internal static IntPtr DragEnterMethod(IntPtr this_, IntPtr pDataObj, IntPtr grfkeyState, IntPtr pt_x, IntPtr pt_y, IntPtr pdwEffect) {
655 window = Marshal.ReadIntPtr(this_, Marshal.SizeOf(typeof(IntPtr)));
657 DragDropEventArgs.x = pt_x.ToInt32();
658 DragDropEventArgs.y = pt_y.ToInt32();
659 DragDropEventArgs.allowed_effect = (DragDropEffects)Marshal.ReadIntPtr(pdwEffect).ToInt32();
660 DragDropEventArgs.current_effect = DragDropEventArgs.AllowedEffect;
661 DragDropEventArgs.keystate = grfkeyState.ToInt32();
663 Control.FromHandle(window).DndEnter(DragDropEventArgs);
665 Marshal.WriteInt32(pdwEffect, (int)DragDropEventArgs.Effect);
670 internal static IntPtr DragOverMethod(IntPtr this_, IntPtr grfkeyState, IntPtr pt_x, IntPtr pt_y, IntPtr pdwEffect) {
673 window = Marshal.ReadIntPtr(this_, Marshal.SizeOf(typeof(IntPtr)));
675 DragDropEventArgs.x = pt_x.ToInt32();
676 DragDropEventArgs.y = pt_y.ToInt32();
677 DragDropEventArgs.allowed_effect = (DragDropEffects)Marshal.ReadIntPtr(pdwEffect).ToInt32();
678 DragDropEventArgs.current_effect = DragDropEventArgs.AllowedEffect;
679 DragDropEventArgs.keystate = grfkeyState.ToInt32();
681 Control.FromHandle(window).DndOver(DragDropEventArgs);
683 Marshal.WriteInt32(pdwEffect, (int)DragDropEventArgs.Effect);
688 internal static IntPtr DragLeaveMethod(IntPtr this_) {
691 window = Marshal.ReadIntPtr(this_, Marshal.SizeOf(typeof(IntPtr)));
693 Control.FromHandle(window).DndLeave(EventArgs.Empty);
698 internal static IntPtr DropMethod(IntPtr this_, IntPtr pDataObj, uint grfkeyState, IntPtr pt_x, IntPtr pt_y, IntPtr pdwEffect) {
710 throw new Exception("Yeah Baby, give me WM_DROPFILES");
713 window = Marshal.ReadIntPtr(this_, Marshal.SizeOf(typeof(IntPtr)));
715 Console.WriteLine("Drop called, window {0:X}", window.ToInt32());
717 format = new FORMATETC();
718 format.cfFormat = ClipboardFormats.CF_HDROP;
\r
719 format.ptd = IntPtr.Zero;
\r
720 format.dwAspect=DVASPECT.DVASPECT_CONTENT;
\r
722 format.tymed=TYMED.TYMED_HGLOBAL;
\r
724 medium = new STGMEDIUM();
726 format_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(format));
727 Marshal.StructureToPtr(format, format_ptr, false);
729 medium_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(medium));
730 Marshal.StructureToPtr(medium, medium_ptr, false);
732 GetDataArgs[0] = Marshal.ReadIntPtr(Marshal.ReadIntPtr(pDataObj), 12);
733 GetDataArgs[1] = pDataObj;
734 GetDataArgs[2] = format_ptr;
735 GetDataArgs[3] = medium_ptr;
740 result = (int)IDataObjectGetDataMethod.Invoke(null, GetDataArgs);
743 catch (Exception e) {
744 Console.WriteLine("Exception", e.Message);
747 Console.WriteLine("GetData returnd {0:X}", result);
753 internal static bool RegisterDropTarget(IntPtr Window) {
\r
754 IDropTarget DropTarget;
\r
755 IntPtr DropTargetPtr;
\r
756 IDropTargetVtbl OLEDropObject;
\r
757 IntPtr OLEDropObjectPtr;
\r
760 DropTarget = new IDropTarget();
\r
761 OLEDropObject = new IDropTargetVtbl();
\r
762 OLEDropObject.QueryInterface = QueryInterface;
\r
763 OLEDropObject.AddRef = AddRef;
\r
764 OLEDropObject.Release = Release;
\r
765 OLEDropObject.DragEnter = DragEnter;
\r
766 OLEDropObject.DragOver = DragOver;
\r
767 OLEDropObject.DragLeave = DragLeave;
\r
768 OLEDropObject.Drop = Drop;
\r
770 hwnd = Hwnd.ObjectFromHandle(Window);
772 OLEDropObjectPtr = Marshal.AllocHGlobal(Marshal.SizeOf(OLEDropObject));
\r
773 Marshal.StructureToPtr(OLEDropObject, OLEDropObjectPtr, false);
\r
774 hwnd.marshal_free_list.Add(OLEDropObjectPtr);
\r
776 DropTargetPtr = Marshal.AllocHGlobal(Marshal.SizeOf(DropTarget));
\r
777 hwnd.marshal_free_list.Add(DropTargetPtr);
\r
778 DropTarget.vtbl = OLEDropObjectPtr;
\r
779 DropTarget.window = Window;
\r
780 Marshal.StructureToPtr(DropTarget, DropTargetPtr, false);
\r
782 int result = Win32RegisterDragDrop(Window, DropTargetPtr);
\r
788 static MethodInfo CreateIDataObjectGetDataMethod () {
\r
789 AssemblyName aname = new AssemblyName ();
\r
790 aname.Name = "XplatUIWin32.GetData";
\r
791 AssemblyBuilder ass = AppDomain.CurrentDomain.DefineDynamicAssembly (
\r
792 aname, AssemblyBuilderAccess.Run);
\r
794 ModuleBuilder mb = ass.DefineDynamicModule ("XplatUIWin32.GetData");
\r
796 TypeBuilder tb = mb.DefineType ("XplatUIWin32.GetData", TypeAttributes.Public);
\r
798 Type ret_type = typeof (int);
\r
799 Type[] param_types = new Type[] { typeof (IntPtr), typeof (IntPtr), typeof (IntPtr), typeof (IntPtr) };
\r
800 Type[] c_param_types = new Type[] { typeof (IntPtr), typeof (IntPtr), typeof (IntPtr) };
\r
802 MethodBuilder method = tb.DefineMethod (
\r
803 "GetData", MethodAttributes.Static | MethodAttributes.Public,
\r
804 ret_type, param_types);
\r
806 ILGenerator ig = method.GetILGenerator ();
\r
807 ig.Emit (OpCodes.Ldarg_3);
\r
808 ig.Emit (OpCodes.Ldarg_2);
\r
809 ig.Emit (OpCodes.Ldarg_1);
\r
810 ig.Emit (OpCodes.Ldarg_0);
\r
811 ig.EmitCalli (OpCodes.Calli, CallingConvention.StdCall, ret_type, c_param_types);
\r
812 ig.Emit (OpCodes.Ret);
\r
814 Type t = tb.CreateType ();
\r
815 MethodInfo m = t.GetMethod ("GetData");
\r
823 #region Constructor & Destructor
824 private XplatUIWin32() {
828 // Handle singleton stuff first
831 // Now regular initialization
832 Win32OleInitialize(IntPtr.Zero);
835 // To callback IDataObject methods
836 IDataObjectGetDataMethod = CreateIDataObjectGetDataMethod();
837 GetDataArgs = new object[4];
839 DragDropEventArgs = new DragEventArgs(new DataObject(DataFormats.FileDrop, new string[0]), 0, 0, 0, DragDropEffects.None, DragDropEffects.None);
841 mouse_state = MouseButtons.None;
842 mouse_position = Point.Empty;
844 message_queue = new Queue();
846 themes_enabled = false;
848 // Prepare 'our' window class
849 wnd_proc = new WndProc(NativeWindow.WndProc);
850 wndClass.style = (int)(ClassStyle.CS_OWNDC | ClassStyle.CS_DBLCLKS);
851 wndClass.lpfnWndProc = wnd_proc;
852 wndClass.cbClsExtra = 0;
853 wndClass.cbWndExtra = 0;
854 wndClass.hbrBackground = IntPtr.Zero;
855 wndClass.hCursor = Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
856 wndClass.hIcon = IntPtr.Zero;
857 wndClass.hInstance = IntPtr.Zero;
858 wndClass.lpszClassName = XplatUI.DefaultClassName;
859 wndClass.lpszMenuName = "";
861 result=Win32RegisterClass(ref wndClass);
863 Win32MessageBox(IntPtr.Zero, "Could not register the "+XplatUI.DefaultClassName+" window class, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
866 FosterParent=Win32CreateWindow(0, "static", "Foster Parent Window", (int)WindowStyles.WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
868 if (FosterParent==IntPtr.Zero) {
869 Win32MessageBox(IntPtr.Zero, "Could not create foster window, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
872 timer_list = new Hashtable ();
874 // Setup our delegates
\r
875 QueryInterface = new QueryInterfaceDelegate(QueryInterfaceMethod);
\r
876 AddRef = new AddRefDelegate(AddRefMethod);
\r
877 Release = new ReleaseDelegate(ReleaseMethod);
\r
878 DragEnter = new DragEnterDelegate(DragEnterMethod);
\r
879 DragOver = new DragOverDelegate(DragOverMethod);
\r
880 DragLeave = new DragLeaveDelegate(DragLeaveMethod);
\r
881 Drop = new DropDelegate(DropMethod);
\r
883 #endregion // Constructor & Destructor
885 #region Private Support Methods
886 private static IntPtr DefWndProc(IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) {
887 return Win32DefWindowProc(hWnd, msg, wParam, lParam);
890 private static bool MessageWaiting {
892 if (message_queue.Count == 0) {
899 private static bool RetrieveMessage(ref MSG msg) {
902 if (message_queue.Count == 0) {
906 message = (MSG)message_queue.Dequeue();
912 private static bool StoreMessage(ref MSG msg) {
913 MSG message = new MSG();
916 message_queue.Enqueue(message);
921 private static String AnsiToString(IntPtr ansi_data) {
922 return (string)Marshal.PtrToStringAnsi(ansi_data);
925 private static String UnicodeToString(IntPtr unicode_data) {
926 return (string)Marshal.PtrToStringUni(unicode_data);
929 private static Image DIBtoImage(IntPtr dib_data) {
934 BITMAPINFOHEADER bmi;
941 header = new byte[54]; // Size of a BMP file header, without palette
943 header[0] = (byte)'B';
944 header[1] = (byte)'M';
945 // 2, 3, 4 and 5 = unsigned int size
946 // 6, 7, 8 and 9 = reserved
947 // 10, 11, 12 and 13 = offset to image data
949 // Create a fake BMP header
950 bmi = (BITMAPINFOHEADER)Marshal.PtrToStructure(dib_data, typeof(BITMAPINFOHEADER));
952 ncolors = (int)bmi.biClrUsed;
954 if (bmi.biBitCount != 24) {
955 ncolors = (int)(1 << bmi.biBitCount);
958 palettesize = ncolors * 4;
960 imagesize = (int)bmi.biSizeImage;
961 if (imagesize == 0) {
962 imagesize = (int)(((((bmi.biWidth * bmi.biBitCount) + 31) & ~31) >> 3) * bmi.biHeight);
965 size = 54 + palettesize + imagesize;
966 offset = 54 + palettesize;
967 buffer = new byte[size];
969 // Copy the fake BMP file header
970 header[2] = (byte)size;
971 header[3] = (byte)(size >> 8);
972 header[4] = (byte)(size >> 16);
973 header[5] = (byte)(size >> 24);
975 header[10] = (byte)offset;
976 header[11] = (byte)(offset >> 8);
977 header[12] = (byte)(offset >> 16);
978 header[13] = (byte)(offset >> 24);
980 Array.Copy(header, 0, buffer, 0, 14);
982 for (int i = 14; i < size; i++) {
983 buffer[i] = Marshal.ReadByte(dib_data, i - 14);
986 ms = new MemoryStream(buffer, 0, size, false);
987 bmp = new Bitmap(ms);
992 private static byte[] ImageToDIB(Image image) {
997 ms = new MemoryStream();
998 image.Save(ms, ImageFormat.Bmp);
999 buffer = ms.GetBuffer();
1001 // Filter out the file header
1002 retbuf = new byte[buffer.Length];
1003 Array.Copy(buffer, 14, retbuf, 0, buffer.Length - 14);
1006 #endregion // Private Support Methods
1008 #region Static Properties
1009 internal override Keys ModifierKeys {
1014 key_state = Keys.None;
1016 state = Win32GetKeyState(VirtualKeys.VK_SHIFT);
1017 if ((state & 0x8000) != 0) {
1018 key_state |= Keys.Shift;
1020 state = Win32GetKeyState(VirtualKeys.VK_CONTROL);
1021 if ((state & 0x8000) != 0) {
1022 key_state |= Keys.Control;
1025 state = Win32GetKeyState(VirtualKeys.VK_MENU);
1026 if ((state & 0x8000) != 0) {
1027 key_state |= Keys.Alt;
1034 internal override MouseButtons MouseButtons {
1040 internal override Point MousePosition {
1042 return mouse_position;
1046 internal override bool DropTarget {
1053 //throw new NotImplementedException("Need to figure out D'n'D for Win32");
1058 internal override int Caption {
1060 return Win32GetSystemMetrics(SystemMetrics.SM_CYCAPTION);
1064 internal override Size CursorSize {
1066 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CYCURSOR));
1070 internal override bool DragFullWindows {
1076 internal override Size DragSize {
1078 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXDRAG), Win32GetSystemMetrics(SystemMetrics.SM_CYDRAG));
1082 internal override Size FrameBorderSize {
1084 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXFRAME), Win32GetSystemMetrics(SystemMetrics.SM_CYFRAME));
1088 internal override Size IconSize {
1090 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXICON), Win32GetSystemMetrics(SystemMetrics.SM_CYICON));
1094 internal override Size MaxWindowTrackSize {
1096 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMAXTRACK), Win32GetSystemMetrics(SystemMetrics.SM_CYMAXTRACK));
1100 internal override Size MinimizedWindowSize {
1102 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINIMIZED), Win32GetSystemMetrics(SystemMetrics.SM_CYMINIMIZED));
1106 internal override Size MinimizedWindowSpacingSize {
1108 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINSPACING), Win32GetSystemMetrics(SystemMetrics.SM_CYMINSPACING));
1112 internal override Size MinimumWindowSize {
1114 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMIN), Win32GetSystemMetrics(SystemMetrics.SM_CYMIN));
1118 internal override Size MinWindowTrackSize {
1120 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINTRACK), Win32GetSystemMetrics(SystemMetrics.SM_CYMINTRACK));
1124 internal override Size SmallIconSize {
1126 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXSMICON), Win32GetSystemMetrics(SystemMetrics.SM_CYSMICON));
1130 internal override int MouseButtonCount {
1132 return Win32GetSystemMetrics(SystemMetrics.SM_CMOUSEBUTTONS);
1136 internal override bool MouseButtonsSwapped {
1138 return Win32GetSystemMetrics(SystemMetrics.SM_SWAPBUTTON) != 0;
1142 internal override bool MouseWheelPresent {
1144 return Win32GetSystemMetrics(SystemMetrics.SM_MOUSEWHEELPRESENT) != 0;
1148 internal override Rectangle VirtualScreen {
1150 return new Rectangle( Win32GetSystemMetrics(SystemMetrics.SM_XVIRTUALSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_YVIRTUALSCREEN),
1151 Win32GetSystemMetrics(SystemMetrics.SM_CXVIRTUALSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_CYVIRTUALSCREEN));
1155 internal override Rectangle WorkingArea {
1160 Win32SystemParametersInfo(SPIAction.SPI_GETWORKAREA, 0, ref rect, 0);
1161 return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
1162 //return new Rectangle(0, 0, Win32GetSystemMetrics(SystemMetrics.SM.SM_CXSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_CYSCREEN));
1165 #endregion // Static Properties
1167 #region Singleton Specific Code
1168 public static XplatUIWin32 GetInstance() {
1169 if (instance==null) {
1170 instance=new XplatUIWin32();
1176 public int Reference {
1183 #region Public Static Methods
1184 internal override IntPtr InitializeDriver() {
1188 internal override void ShutdownDriver(IntPtr token) {
1189 Console.WriteLine("XplatUIWin32 ShutdownDriver called");
1193 internal void Version() {
1194 Console.WriteLine("Xplat version $revision: $");
1197 internal override void Exit() {
1198 Win32PostQuitMessage(0);
1201 internal override void GetDisplaySize(out Size size) {
1204 Win32GetWindowRect(Win32GetDesktopWindow(), out rect);
1206 size = new Size(rect.right - rect.left, rect.bottom - rect.top);
1209 internal override void EnableThemes() {
1210 themes_enabled=true;
1213 internal override IntPtr CreateWindow(CreateParams cp) {
1214 IntPtr WindowHandle;
1215 IntPtr ParentHandle;
1221 ParentHandle=cp.Parent;
1223 if ((ParentHandle==IntPtr.Zero) && (cp.Style & (int)(WindowStyles.WS_CHILD))!=0) {
1224 // We need to use our foster parent window until this poor child gets it's parent assigned
1225 ParentHandle=FosterParent;
1228 lParam = IntPtr.Zero;
1229 if (cp.Param != null && cp.Param is CLIENTCREATESTRUCT) {
1230 lParam = Marshal.AllocHGlobal(Marshal.SizeOf(cp.Param));
1231 Marshal.StructureToPtr(cp.Param, lParam, false);
1234 WindowHandle = Win32CreateWindow((uint)cp.ExStyle, cp.ClassName, cp.Caption, (uint)cp.Style, cp.X, cp.Y, cp.Width, cp.Height, ParentHandle, IntPtr.Zero, IntPtr.Zero, lParam);
1236 if (lParam != IntPtr.Zero) {
1237 Marshal.FreeHGlobal(lParam);
1240 if (WindowHandle==IntPtr.Zero) {
1241 uint error = Win32GetLastError();
1243 Win32MessageBox(IntPtr.Zero, "Error : " + error.ToString(), "Failed to create window, class '"+cp.ClassName+"'", 0);
1246 hwnd.ClientWindow = WindowHandle;
1248 Win32SetWindowLong(WindowHandle, WindowLong.GWL_USERDATA, (IntPtr)ThemeEngine.Current.DefaultControlBackColor.ToArgb());
1250 return WindowHandle;
1253 internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
1254 CreateParams create_params = new CreateParams();
1256 create_params.Caption = "";
1257 create_params.X = X;
1258 create_params.Y = Y;
1259 create_params.Width = Width;
1260 create_params.Height = Height;
1262 create_params.ClassName=XplatUI.DefaultClassName;
1263 create_params.ClassStyle = 0;
1264 create_params.ExStyle=0;
1265 create_params.Parent=IntPtr.Zero;
1266 create_params.Param=0;
1268 return CreateWindow(create_params);
1271 internal override void DestroyWindow(IntPtr handle) {
1274 hwnd = Hwnd.ObjectFromHandle(handle);
1275 Win32DestroyWindow(handle);
1280 internal override FormWindowState GetWindowState(IntPtr handle) {
1283 style = Win32GetWindowLong(handle, WindowLong.GWL_STYLE);
1284 if ((style & (uint)WindowStyles.WS_MAXIMIZE) != 0) {
1285 return FormWindowState.Maximized;
1286 } else if ((style & (uint)WindowStyles.WS_MINIMIZE) != 0) {
1287 return FormWindowState.Minimized;
1289 return FormWindowState.Normal;
1292 internal override void SetWindowState(IntPtr hwnd, FormWindowState state) {
1294 case FormWindowState.Normal: {
1295 Win32ShowWindow(hwnd, WindowPlacementFlags.SW_SHOWNORMAL);
1299 case FormWindowState.Minimized: {
1300 Win32ShowWindow(hwnd, WindowPlacementFlags.SW_SHOWMINIMIZED);
1304 case FormWindowState.Maximized: {
1305 Win32ShowWindow(hwnd, WindowPlacementFlags.SW_SHOWMAXIMIZED);
1311 internal override void SetWindowStyle(IntPtr handle, CreateParams cp) {
1312 Win32SetWindowLong(handle, WindowLong.GWL_STYLE, (IntPtr)cp.Style);
1313 Win32SetWindowLong(handle, WindowLong.GWL_EXSTYLE, (IntPtr)cp.ExStyle);
1316 internal override void UpdateWindow(IntPtr handle) {
1317 Win32UpdateWindow(handle);
1320 internal override void SetWindowBackground(IntPtr handle, Color color) {
1321 Win32SetWindowLong(handle, WindowLong.GWL_USERDATA, (IntPtr)color.ToArgb());
1324 [MonoTODO("Add support for internal table of windows/DCs for cleanup")]
1325 internal override PaintEventArgs PaintEventStart(IntPtr handle) {
1328 PaintEventArgs paint_event;
1330 Rectangle clip_rect;
1333 clip_rect = new Rectangle();
1335 ps = new PAINTSTRUCT();
1337 hwnd = Hwnd.ObjectFromHandle(handle);
1339 if (Win32GetUpdateRect(handle, ref rect, false)) {
1340 hdc = Win32BeginPaint(handle, ref ps);
1342 hwnd.user_data = (object)ps;
1344 // FIXME: Figure out why the rectangle is always 0 size
1345 clip_rect = new Rectangle(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right-ps.rcPaint.left, ps.rcPaint.bottom-ps.rcPaint.top);
1346 // clip_rect = new Rectangle(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
1348 if (ps.fErase != 0) {
1349 Console.WriteLine("Hit Clear background");
1350 EraseWindowBackground(handle, hdc);
1353 hdc = Win32GetDC(handle);
1354 // FIXME: Add the DC to internal list
1355 clip_rect = new Rectangle(rect.top, rect.left, rect.right-rect.left, rect.bottom-rect.top);
1358 hwnd.client_dc = Graphics.FromHdc(hdc);
1359 paint_event = new PaintEventArgs(hwnd.client_dc, clip_rect);
1364 internal override void PaintEventEnd(IntPtr handle) {
1368 hwnd = Hwnd.ObjectFromHandle(handle);
1369 hwnd.client_dc.Dispose();
1371 if (hwnd.user_data != null) {
1372 ps = (PAINTSTRUCT)hwnd.user_data;
1373 Win32EndPaint(handle, ref ps);
1378 internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
1379 Win32MoveWindow(handle, x, y, width, height, true);
1383 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) {
1387 Win32GetWindowRect(handle, out rect);
1388 width = rect.right - rect.left;
1389 height = rect.bottom - rect.top;
1393 Win32ScreenToClient(Win32GetParent(handle), ref pt);
1397 Win32GetClientRect(handle, out rect);
1398 client_width = rect.right - rect.left;
1399 client_height = rect.bottom - rect.top;
1403 internal override void Activate(IntPtr handle) {
1404 Win32SetActiveWindow(handle);
1407 internal override void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
1412 rect.right=rc.Right;
1413 rect.bottom=rc.Bottom;
1414 Win32InvalidateRect(handle, ref rect, clear);
1417 internal override IntPtr DefWndProc(ref Message msg) {
1418 msg.Result=Win32DefWindowProc(msg.HWnd, (Msg)msg.Msg, msg.WParam, msg.LParam);
1422 internal override void HandleException(Exception e) {
1423 StackTrace st = new StackTrace(e);
1424 Win32MessageBox(IntPtr.Zero, e.Message+st.ToString(), "Exception", 0);
1425 Console.WriteLine("{0}{1}", e.Message, st.ToString());
1428 internal override void DoEvents() {
1429 MSG msg = new MSG();
1431 if (override_cursor != IntPtr.Zero) {
1432 Cursor.Current = null;
1435 while (Win32PeekMessage(ref msg, IntPtr.Zero, 0, 0, (uint)PeekMessageFlags.PM_REMOVE)!=true) {
1436 if (msg.message==Msg.WM_PAINT) {
1437 XplatUI.TranslateMessage(ref msg);
1438 XplatUI.DispatchMessage(ref msg);
1443 internal override bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
1444 return Win32PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
1447 internal override bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
1450 if (RetrieveMessage(ref msg)) {
1454 result = Win32GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
1456 // We need to fake WM_MOUSE_ENTER/WM_MOUSE_LEAVE
1457 switch (msg.message) {
1458 case Msg.WM_LBUTTONDOWN: {
1459 mouse_state |= MouseButtons.Left;
1463 case Msg.WM_MBUTTONDOWN: {
1464 mouse_state |= MouseButtons.Middle;
1468 case Msg.WM_RBUTTONDOWN: {
1469 mouse_state |= MouseButtons.Right;
1473 case Msg.WM_LBUTTONUP: {
1474 mouse_state &= ~MouseButtons.Left;
1478 case Msg.WM_MBUTTONUP: {
1479 mouse_state &= ~MouseButtons.Middle;
1483 case Msg.WM_RBUTTONUP: {
1484 mouse_state &= ~MouseButtons.Right;
1488 case Msg.WM_ASYNC_MESSAGE: {
1489 XplatUIDriverSupport.ExecuteClientMessage((GCHandle)msg.lParam);
1493 case Msg.WM_MOUSEMOVE: {
1494 if (msg.hwnd != prev_mouse_hwnd) {
1495 TRACKMOUSEEVENT tme;
1497 // The current message will be sent out next time around
1498 StoreMessage(ref msg);
1500 // This is the message we want to send at this point
1501 msg.message = Msg.WM_MOUSE_ENTER;
1503 prev_mouse_hwnd = msg.hwnd;
1505 tme = new TRACKMOUSEEVENT();
1506 tme.size = Marshal.SizeOf(tme);
1507 tme.hWnd = msg.hwnd;
1508 tme.dwFlags = TMEFlags.TME_LEAVE | TMEFlags.TME_HOVER;
1509 Win32TrackMouseEvent(ref tme);
1515 case Msg.WM_DROPFILES: {
1522 count = Win32DragQueryFile(hDrop, -1, IntPtr.Zero, 0);
1524 dropfiles = new string[count];
1526 sb = new StringBuilder(256);
1527 for (int i = 0; i < count; i++) {
1528 Win32DragQueryFile(hDrop, i, sb, sb.Capacity);
1529 dropfiles[i] = sb.ToString();
1532 DragDropEventArgs.Data.SetData(DataFormats.FileDrop, dropfiles);
1534 Control.FromHandle(msg.hwnd).DndDrop(DragDropEventArgs);
1539 case Msg.WM_MOUSELEAVE: {
1540 prev_mouse_hwnd = IntPtr.Zero;
1541 msg.message=Msg.WM_MOUSE_LEAVE;
1545 case Msg.WM_TIMER: {
1546 Timer timer=(Timer)timer_list[(int)msg.wParam];
1548 if (timer != null) {
1558 internal override bool TranslateMessage(ref MSG msg) {
1559 return Win32TranslateMessage(ref msg);
1562 internal override IntPtr DispatchMessage(ref MSG msg) {
1563 return Win32DispatchMessage(ref msg);
1566 internal override bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
1568 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOP, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1570 } else if (!Bottom) {
1571 Win32SetWindowPos(hWnd, AfterhWnd, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1573 Win32SetWindowPos(hWnd, (IntPtr)SetWindowPosZOrder.HWND_BOTTOM, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1579 internal override bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
1581 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1584 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_NOTOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1589 internal override bool Text(IntPtr handle, string text) {
1590 Win32SetWindowText(handle, text);
1594 internal override bool GetText(IntPtr handle, out string text) {
1597 sb = new StringBuilder(256);
1598 Win32GetWindowText(handle, sb, sb.Capacity);
1599 text = sb.ToString();
1603 internal override bool SetVisible(IntPtr handle, bool visible) {
1605 Win32ShowWindow(handle, WindowPlacementFlags.SW_SHOWNORMAL);
1607 Win32ShowWindow(handle, WindowPlacementFlags.SW_HIDE);
1612 internal override bool IsVisible(IntPtr handle) {
1613 return IsWindowVisible (handle);
1616 internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
1617 return Win32SetParent(handle, parent);
1620 internal override IntPtr GetParent(IntPtr handle) {
1621 return Win32GetParent(handle);
1624 internal override void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
1626 Win32SetCapture(hWnd);
1629 internal override void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
1631 GrabConfined = grab_confined;
1632 GrabArea = grab_area;
1635 internal override void UngrabWindow(IntPtr hWnd) {
1636 Win32ReleaseCapture();
1637 grab_hwnd = IntPtr.Zero;
1640 internal override bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, int ExStyle, IntPtr MenuHandle, out Rectangle WindowRect) {
1643 rect.left=ClientRect.Left;
1644 rect.top=ClientRect.Top;
1645 rect.right=ClientRect.Right;
1646 rect.bottom=ClientRect.Bottom;
1648 if (!Win32AdjustWindowRectEx(ref rect, Style, MenuHandle != IntPtr.Zero, ExStyle)) {
1649 WindowRect = new Rectangle(ClientRect.Left, ClientRect.Top, ClientRect.Width, ClientRect.Height);
1653 WindowRect = new Rectangle(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
1657 internal override void SetCursor(IntPtr window, IntPtr cursor) {
1658 if (override_cursor == IntPtr.Zero) {
1659 Win32SetCursor(cursor);
1662 Win32SetCursor(override_cursor);
1665 internal override void ShowCursor(bool show) {
1666 Win32ShowCursor(show);
1669 internal override void OverrideCursor(IntPtr cursor) {
1670 override_cursor = cursor;
1673 internal override IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
1675 Bitmap cursor_bitmap;
1683 // Win32 only allows creation cursors of a certain size
1684 if ((bitmap.Width != Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)) || (bitmap.Width != Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR))) {
1685 cursor_bitmap = new Bitmap(bitmap, new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)));
1686 cursor_mask = new Bitmap(mask, new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)));
1688 cursor_bitmap = bitmap;
1692 width = cursor_bitmap.Width;
1693 height = cursor_bitmap.Height;
1695 cursor_bits = new Byte[(width / 8) * height];
1696 mask_bits = new Byte[(width / 8) * height];
1698 for (int y = 0; y < height; y++) {
1699 for (int x = 0; x < width; x++) {
1700 pixel = cursor_bitmap.GetPixel(x, y);
1702 if (pixel == cursor_pixel) {
1703 cursor_bits[y * width / 8 + x / 8] |= (byte)(0x80 >> (x % 8));
1706 pixel = cursor_mask.GetPixel(x, y);
1708 if (pixel == mask_pixel) {
1709 mask_bits[y * width / 8 + x / 8] |= (byte)(0x80 >> (x % 8));
1714 cursor = Win32CreateCursor(IntPtr.Zero, xHotSpot, yHotSpot, width, height, mask_bits, cursor_bits);
1719 [MonoTODO("Define the missing cursors")]
1720 internal override IntPtr DefineStdCursor(StdCursor id) {
1722 case StdCursor.AppStarting: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_APPSTARTING);
1723 case StdCursor.Arrow: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
1724 case StdCursor.Cross: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_CROSS);
1725 case StdCursor.Default: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
1726 case StdCursor.Hand: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_HAND);
1727 case StdCursor.Help: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_HELP);
1728 case StdCursor.HSplit: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1729 case StdCursor.IBeam: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_IBEAM);
1730 case StdCursor.No: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_NO);
1731 case StdCursor.NoMove2D: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1732 case StdCursor.NoMoveHoriz: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1733 case StdCursor.NoMoveVert: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1734 case StdCursor.PanEast: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1735 case StdCursor.PanNE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1736 case StdCursor.PanNorth: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1737 case StdCursor.PanNW: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1738 case StdCursor.PanSE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1739 case StdCursor.PanSouth: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1740 case StdCursor.PanSW: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1741 case StdCursor.PanWest: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1742 case StdCursor.SizeAll: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZEALL);
1743 case StdCursor.SizeNESW: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENESW);
1744 case StdCursor.SizeNS: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENS);
1745 case StdCursor.SizeNWSE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENWSE);
1746 case StdCursor.SizeWE: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZEWE);
1747 case StdCursor.UpArrow: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_UPARROW);
1748 case StdCursor.VSplit: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW); // FIXME
1749 case StdCursor.WaitCursor: return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_WAIT);
1751 throw new NotImplementedException ();
1754 internal override void DestroyCursor(IntPtr cursor) {
1755 if ((cursor.ToInt32() < (int)LoadCursorType.First) || (cursor.ToInt32() > (int)LoadCursorType.Last)) {
1756 Win32DestroyCursor(cursor);
1761 internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
1762 throw new NotImplementedException ();
1765 internal override void SetCursorPos(IntPtr handle, int x, int y) {
1766 Win32SetCursorPos(x, y);
1769 internal override void EnableWindow(IntPtr handle, bool Enable) {
1770 Win32EnableWindow(handle, Enable);
1773 internal override void SetModal(IntPtr handle, bool Modal) {
1774 // we do nothing on Win32; Application.cs simulates modal dialogs by disabling all toplevel windows
1777 internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
1780 Win32GetCursorPos(out pt);
1782 if (handle!=IntPtr.Zero) {
1783 Win32ScreenToClient(handle, ref pt);
1790 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y)
1792 POINT pnt = new POINT();
1796 Win32ScreenToClient (handle, ref pnt);
1802 internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) {
1803 POINT pnt = new POINT();
1808 Win32ClientToScreen(handle, ref pnt);
1814 internal override void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
1815 ScreenToClient(handle, ref x, ref y);
1818 internal override void MenuToScreen(IntPtr handle, ref int x, ref int y) {
1819 ClientToScreen(handle, ref x, ref y);
1822 internal override void SendAsyncMethod (AsyncMethodData method)
1824 Win32PostMessage(FosterParent, Msg.WM_ASYNC_MESSAGE, IntPtr.Zero, (IntPtr)GCHandle.Alloc (method));
1827 internal override void SetTimer (Timer timer)
1831 index = timer.GetHashCode();
1834 timer_list[index]=timer;
1837 Win32SetTimer(FosterParent, index, (uint)timer.Interval, IntPtr.Zero);
1840 internal override void KillTimer (Timer timer)
1844 index = timer.GetHashCode();
1846 Win32KillTimer(FosterParent, index);
1849 timer_list.Remove(index);
1854 private void CaretCallback(object sender, EventArgs e) {
1855 Console.WriteLine("CaretCallback hit");
1858 internal override void CreateCaret(IntPtr hwnd, int width, int height) {
1859 Win32CreateCaret(hwnd, IntPtr.Zero, width, height);
1862 internal override void DestroyCaret(IntPtr hwnd) {
1863 Win32DestroyCaret();
1866 internal override void SetCaretPos(IntPtr hwnd, int x, int y) {
1867 Win32SetCaretPos(x, y);
1870 internal override void CaretVisible(IntPtr hwnd, bool visible) {
1872 Win32ShowCaret(hwnd);
1874 Win32HideCaret(hwnd);
1878 internal override void SetFocus(IntPtr hwnd) {
1879 Win32SetFocus(hwnd);
1882 internal override IntPtr GetActive() {
1883 return Win32GetActiveWindow();
1886 internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
1890 tm = new TEXTMETRIC();
1892 dc = Win32GetDC(IntPtr.Zero);
1893 Win32SelectObject(dc, font.ToHfont());
1894 if (Win32GetTextMetrics(dc, ref tm) == false) {
1895 Win32ReleaseDC(IntPtr.Zero, dc);
1900 Win32ReleaseDC(IntPtr.Zero, dc);
1902 ascent = tm.tmAscent;
1903 descent = tm.tmDescent;
1908 internal override void ScrollWindow(IntPtr hwnd, Rectangle rectangle, int XAmount, int YAmount, bool with_children) {
1912 rect.left = rectangle.X;
1913 rect.top = rectangle.Y;
1914 rect.right = rectangle.Right;
1915 rect.bottom = rectangle.Bottom;
1917 Win32ScrollWindowEx(hwnd, XAmount, YAmount, ref rect, ref rect, IntPtr.Zero, IntPtr.Zero, ScrollWindowExFlags.SW_INVALIDATE | ScrollWindowExFlags.SW_ERASE | (with_children ? ScrollWindowExFlags.SW_SCROLLCHILDREN : ScrollWindowExFlags.SW_NONE));
1918 Win32UpdateWindow(hwnd);
1921 internal override void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount, bool with_children) {
1922 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));
1925 internal override bool SystrayAdd(IntPtr hwnd, string tip, Icon icon, out ToolTip tt) {
1928 nid = new NOTIFYICONDATA();
1930 nid.cbSize = (uint)Marshal.SizeOf(nid);
1931 nid.hIcon = icon.Handle;
1934 nid.uCallbackMessage = (uint)Msg.WM_USER;
1935 nid.uFlags = NotifyIconFlags.NIF_MESSAGE;
1939 nid.uFlags |= NotifyIconFlags.NIF_TIP;
1943 nid.hIcon = icon.Handle;
1944 nid.uFlags |= NotifyIconFlags.NIF_ICON;
1949 return Win32Shell_NotifyIcon(NotifyIconMessage.NIM_ADD, ref nid);
1952 internal override bool SystrayChange(IntPtr hwnd, string tip, Icon icon, ref ToolTip tt) {
1955 nid = new NOTIFYICONDATA();
1957 nid.cbSize = (uint)Marshal.SizeOf(nid);
1958 nid.hIcon = icon.Handle;
1961 nid.uCallbackMessage = (uint)Msg.WM_USER;
1962 nid.uFlags = NotifyIconFlags.NIF_MESSAGE;
1966 nid.uFlags |= NotifyIconFlags.NIF_TIP;
1970 nid.hIcon = icon.Handle;
1971 nid.uFlags |= NotifyIconFlags.NIF_ICON;
1974 return Win32Shell_NotifyIcon(NotifyIconMessage.NIM_MODIFY, ref nid);
1977 internal override void SystrayRemove(IntPtr hwnd, ref ToolTip tt) {
1980 nid = new NOTIFYICONDATA();
1982 nid.cbSize = (uint)Marshal.SizeOf(nid);
1987 Win32Shell_NotifyIcon(NotifyIconMessage.NIM_DELETE, ref nid);
1991 internal override void SetBorderStyle(IntPtr handle, BorderStyle border_style) {
\r
1992 Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0,
\r
1993 SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE);
\r
1996 internal override void SetMenu(IntPtr handle, IntPtr menu_handle) {
1997 // Trigger WM_NCCALC
1998 Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
2002 internal override Graphics GetMenuDC(IntPtr hwnd, IntPtr ncpaint_region) {
2007 // hdc = Win32GetDCEx(hwnd, ncpaint_region, DCExFlags.DCX_WINDOW | DCExFlags.DCX_INTERSECTRGN | DCExFlags.DCX_USESTYLE);
2008 hdc = Win32GetDCEx(hwnd, ncpaint_region, DCExFlags.DCX_WINDOW);
2010 g = Graphics.FromHdc(hdc);
2012 Win32ReleaseDC(hwnd, hdc);
2017 internal override Point GetMenuOrigin(IntPtr handle) {
2018 return new Point(SystemInformation.FrameBorderSize.Width, SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight);
2022 internal override void ReleaseMenuDC(IntPtr hwnd, Graphics dc) {
2026 internal override void SetIcon(IntPtr hwnd, Icon icon) {
2027 Win32SendMessage(hwnd, Msg.WM_SETICON, (IntPtr)1, icon.Handle); // 1 = large icon (0 would be small)
2030 internal override void EraseWindowBackground(IntPtr hWnd, IntPtr hDc) {
2037 argb = Win32GetWindowLong(hWnd, WindowLong.GWL_USERDATA);
2038 lb = new LOGBRUSH();
2040 lb.lbColor.B = (byte)((argb & 0xff0000)>>16);
2041 lb.lbColor.G = (byte)((argb & 0xff00)>>8);
2042 lb.lbColor.R = (byte)(argb & 0xff);
2044 lb.lbStyle = LogBrushStyle.BS_SOLID;
2045 hbr = Win32CreateBrushIndirect(ref lb);
2046 Win32GetClientRect(hWnd, out rect);
2047 Win32FillRect(hDc, ref rect, hbr);
2048 Win32DeleteObject(hbr);
2051 internal override void ClipboardClose(IntPtr handle) {
2052 if (handle != clip_magic) {
2053 throw new ArgumentException("handle is not a valid clipboard handle");
2055 Win32CloseClipboard();
2058 internal override int ClipboardGetID(IntPtr handle, string format) {
2059 if (handle != clip_magic) {
2060 throw new ArgumentException("handle is not a valid clipboard handle");
2062 if (format == "Text" ) return 1;
2063 else if (format == "Bitmap" ) return 2;
2064 else if (format == "MetaFilePict" ) return 3;
2065 else if (format == "SymbolicLink" ) return 4;
2066 else if (format == "DataInterchangeFormat" ) return 5;
2067 else if (format == "Tiff" ) return 6;
2068 else if (format == "OEMText" ) return 7;
2069 else if (format == "DeviceIndependentBitmap" ) return 8;
2070 else if (format == "Palette" ) return 9;
2071 else if (format == "PenData" ) return 10;
2072 else if (format == "RiffAudio" ) return 11;
2073 else if (format == "WaveAudio" ) return 12;
2074 else if (format == "UnicodeText" ) return 13;
2075 else if (format == "EnhancedMetafile" ) return 14;
2076 else if (format == "FileDrop" ) return 15;
2077 else if (format == "Locale" ) return 16;
2079 return (int)Win32RegisterClipboardFormat(format);
2082 internal override IntPtr ClipboardOpen() {
2083 Win32OpenClipboard(FosterParent);
2087 internal override int[] ClipboardAvailableFormats(IntPtr handle) {
2092 if (handle != clip_magic) {
2100 format = Win32EnumClipboardFormats(format);
2104 } while (format != 0);
2107 result = new int[count];
2111 format = Win32EnumClipboardFormats(format);
2113 result[count++] = (int)format;
2115 } while (format != 0);
2121 internal override object ClipboardRetrieve(IntPtr handle, int type, XplatUI.ClipboardToObject converter) {
2126 if (handle != clip_magic) {
2127 throw new ArgumentException("handle is not a valid clipboard handle");
2130 hmem = Win32GetClipboardData((uint)type);
2131 if (hmem == IntPtr.Zero) {
2135 data = Win32GlobalLock(hmem);
2136 if (data == IntPtr.Zero) {
2137 uint error = Win32GetLastError();
2138 Console.WriteLine("Error: {0}", error);
2144 switch ((ClipboardFormats)type) {
2145 case ClipboardFormats.CF_TEXT: {
2146 obj = AnsiToString(data);
2150 case ClipboardFormats.CF_DIB: {
2151 obj = DIBtoImage(data);
2155 case ClipboardFormats.CF_UNICODETEXT: {
2156 obj = UnicodeToString(data);
2161 if (converter != null && !converter(type, data, out obj)) {
2167 Win32GlobalUnlock(hmem);
2173 internal override void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
2178 if (handle != clip_magic) {
2179 throw new ArgumentException("handle is not a valid clipboard handle");
2184 Win32EmptyClipboard();
2189 if (obj is string) {
2190 type = (int)ClipboardFormats.CF_UNICODETEXT;
2191 } else if (obj is Image) {
2192 type = (int)ClipboardFormats.CF_DIB;
2196 switch((ClipboardFormats)type) {
2197 case ClipboardFormats.CF_UNICODETEXT: {
2198 hmem = Marshal.StringToHGlobalUni((string)obj);
2199 Win32EmptyClipboard();
2200 Win32SetClipboardData((uint)type, hmem);
2204 case ClipboardFormats.CF_DIB: {
2205 data = ImageToDIB((Image)obj);
2207 hmem = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
2208 hmem_ptr = Win32GlobalLock(hmem);
2209 Marshal.Copy(data, 0, hmem_ptr, data.Length);
2210 Win32GlobalUnlock(hmem);
2211 Win32EmptyClipboard();
2212 Win32SetClipboardData((uint)type, hmem);
2217 if (converter != null && converter(ref type, obj, out data)) {
2218 hmem = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
2219 hmem_ptr = Win32GlobalLock(hmem);
2220 Marshal.Copy(data, 0, hmem_ptr, data.Length);
2221 Win32GlobalUnlock(hmem);
2222 Win32EmptyClipboard();
2223 Win32SetClipboardData((uint)type, hmem);
2230 internal override void SetAllowDrop(IntPtr hwnd, bool allowed) {
2232 RegisterDropTarget(hwnd);
2234 Win32RevokeDragDrop(hwnd);
2238 internal override int KeyboardSpeed {
2240 Console.WriteLine ("KeyboardSpeed: need to query Windows");
2243 // Return values range from 0 to 31 which map to 2.5 to 30 repetitions per second.
2249 internal override int KeyboardDelay {
2251 Console.WriteLine ("KeyboardDelay: need to query Windows");
2254 // Return values must range from 0 to 4, 0 meaning 250ms,
2255 // and 4 meaning 1000 ms.
2261 internal override event EventHandler Idle;
2263 // Santa's little helper
2264 static void Where() {
2265 Console.WriteLine("Here: {0}", new StackTrace().ToString());
2267 #endregion // Public Static Methods
2269 #region Win32 Imports
2270 [DllImport ("kernel32.dll", EntryPoint="GetLastError", CallingConvention=CallingConvention.StdCall)]
2271 private extern static uint Win32GetLastError();
2273 [DllImport ("user32.dll", EntryPoint="CreateWindowExW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2274 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);
2276 [DllImport ("user32.dll", EntryPoint="DestroyWindow", CallingConvention=CallingConvention.StdCall)]
2277 internal extern static bool Win32DestroyWindow(IntPtr hWnd);
2279 [DllImport ("user32.dll", EntryPoint="PeekMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2280 internal extern static bool Win32PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags);
2282 [DllImport ("user32.dll", EntryPoint="GetMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2283 internal extern static bool Win32GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax);
2285 [DllImport ("user32.dll", EntryPoint="TranslateMessage", CallingConvention=CallingConvention.StdCall)]
2286 internal extern static bool Win32TranslateMessage(ref MSG msg);
2288 [DllImport ("user32.dll", EntryPoint="DispatchMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2289 internal extern static IntPtr Win32DispatchMessage(ref MSG msg);
2291 [DllImport ("user32.dll", EntryPoint="MoveWindow", CallingConvention=CallingConvention.StdCall)]
2292 internal extern static bool Win32MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
2294 [DllImport ("user32.dll", EntryPoint="SetWindowPos", CallingConvention=CallingConvention.StdCall)]
2295 internal extern static bool Win32SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SetWindowPosFlags Flags);
2297 [DllImport ("user32.dll", EntryPoint="SetWindowPos", CallingConvention=CallingConvention.StdCall)]
2298 internal extern static bool Win32SetWindowPos(IntPtr hWnd, SetWindowPosZOrder pos, int x, int y, int cx, int cy, SetWindowPosFlags Flags);
2300 [DllImport ("user32.dll", EntryPoint="SetWindowTextW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2301 internal extern static bool Win32SetWindowText(IntPtr hWnd, string lpString);
2303 [DllImport ("user32.dll", EntryPoint="GetWindowTextW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2304 internal extern static bool Win32GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
2306 [DllImport ("user32.dll", EntryPoint="SetParent", CallingConvention=CallingConvention.StdCall)]
2307 internal extern static IntPtr Win32SetParent(IntPtr hWnd, IntPtr hParent);
2309 [DllImport ("user32.dll", EntryPoint="RegisterClassW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2310 private extern static bool Win32RegisterClass(ref WNDCLASS wndClass);
2312 [DllImport ("user32.dll", EntryPoint="LoadCursorW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2313 private extern static IntPtr Win32LoadCursor(IntPtr hInstance, LoadCursorType type);
2315 [DllImport ("user32.dll", EntryPoint="ShowCursor", CallingConvention=CallingConvention.StdCall)]
2316 private extern static IntPtr Win32ShowCursor(bool bShow);
2318 [DllImport ("user32.dll", EntryPoint="SetCursor", CallingConvention=CallingConvention.StdCall)]
2319 private extern static IntPtr Win32SetCursor(IntPtr hCursor);
2321 [DllImport ("user32.dll", EntryPoint="CreateCursor", CallingConvention=CallingConvention.StdCall)]
2322 private extern static IntPtr Win32CreateCursor(IntPtr hInstance, int xHotSpot, int yHotSpot, int nWidth, int nHeight, Byte[] pvANDPlane, Byte[] pvORPlane);
2324 [DllImport ("user32.dll", EntryPoint="DestroyCursor", CallingConvention=CallingConvention.StdCall)]
2325 private extern static bool Win32DestroyCursor(IntPtr hCursor);
2327 [DllImport ("user32.dll", EntryPoint="DefWindowProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2328 private extern static IntPtr Win32DefWindowProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
2330 [DllImport ("user32.dll", EntryPoint="DefDlgProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2331 private extern static IntPtr Win32DefDlgProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
2333 [DllImport ("user32.dll", EntryPoint="PostQuitMessage", CallingConvention=CallingConvention.StdCall)]
2334 private extern static IntPtr Win32PostQuitMessage(int nExitCode);
2336 [DllImport ("user32.dll", EntryPoint="UpdateWindow", CallingConvention=CallingConvention.StdCall)]
2337 private extern static IntPtr Win32UpdateWindow(IntPtr hWnd);
2339 [DllImport ("user32.dll", EntryPoint="GetUpdateRect", CallingConvention=CallingConvention.StdCall)]
2340 private extern static bool Win32GetUpdateRect(IntPtr hWnd, ref RECT rect, bool erase);
2342 [DllImport ("user32.dll", EntryPoint="BeginPaint", CallingConvention=CallingConvention.StdCall)]
2343 private extern static IntPtr Win32BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
2345 [DllImport ("user32.dll", EntryPoint="EndPaint", CallingConvention=CallingConvention.StdCall)]
2346 private extern static bool Win32EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
2348 [DllImport ("user32.dll", EntryPoint="GetDC", CallingConvention=CallingConvention.StdCall)]
2349 private extern static IntPtr Win32GetDC(IntPtr hWnd);
2351 [DllImport ("user32.dll", EntryPoint="GetDCEx", CallingConvention=CallingConvention.StdCall)]
2352 private extern static IntPtr Win32GetDCEx(IntPtr hWnd, IntPtr hRgn, DCExFlags flags);
2354 [DllImport ("user32.dll", EntryPoint="ReleaseDC", CallingConvention=CallingConvention.StdCall)]
2355 private extern static IntPtr Win32ReleaseDC(IntPtr hWnd, IntPtr hDC);
2357 [DllImport ("user32.dll", EntryPoint="MessageBoxW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2358 private extern static IntPtr Win32MessageBox(IntPtr hParent, string pText, string pCaption, uint uType);
2360 [DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
2361 private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, ref RECT lpRect, bool bErase);
2363 [DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
2364 private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
2366 [DllImport ("user32.dll", EntryPoint="SetCapture", CallingConvention=CallingConvention.StdCall)]
2367 private extern static IntPtr Win32SetCapture(IntPtr hWnd);
2369 [DllImport ("user32.dll", EntryPoint="ReleaseCapture", CallingConvention=CallingConvention.StdCall)]
2370 private extern static IntPtr Win32ReleaseCapture();
2372 [DllImport ("user32.dll", EntryPoint="GetWindowRect", CallingConvention=CallingConvention.StdCall)]
2373 private extern static IntPtr Win32GetWindowRect(IntPtr hWnd, out RECT rect);
2375 [DllImport ("user32.dll", EntryPoint="GetClientRect", CallingConvention=CallingConvention.StdCall)]
2376 private extern static IntPtr Win32GetClientRect(IntPtr hWnd, out RECT rect);
2378 [DllImport ("user32.dll", EntryPoint="ScreenToClient", CallingConvention=CallingConvention.StdCall)]
2379 private extern static bool Win32ScreenToClient(IntPtr hWnd, ref POINT pt);
2381 [DllImport ("user32.dll", EntryPoint="ClientToScreen", CallingConvention=CallingConvention.StdCall)]
2382 private extern static bool Win32ClientToScreen(IntPtr hWnd, ref POINT pt);
2384 [DllImport ("user32.dll", EntryPoint="GetParent", CallingConvention=CallingConvention.StdCall)]
2385 private extern static IntPtr Win32GetParent(IntPtr hWnd);
2387 [DllImport ("user32.dll", EntryPoint="SetActiveWindow", CallingConvention=CallingConvention.StdCall)]
2388 private extern static IntPtr Win32SetActiveWindow(IntPtr hWnd);
2390 [DllImport ("user32.dll", EntryPoint="PostQuitMessage", CallingConvention=CallingConvention.StdCall)]
2391 private extern static IntPtr Win32PostQuitMessage(IntPtr hWnd);
2393 [DllImport ("user32.dll", EntryPoint="AdjustWindowRectEx", CallingConvention=CallingConvention.StdCall)]
2394 private extern static bool Win32AdjustWindowRectEx(ref RECT lpRect, int dwStyle, bool bMenu, int dwExStyle);
2396 [DllImport ("user32.dll", EntryPoint="GetCursorPos", CallingConvention=CallingConvention.StdCall)]
2397 private extern static bool Win32GetCursorPos(out POINT lpPoint);
2399 [DllImport ("user32.dll", EntryPoint="SetCursorPos", CallingConvention=CallingConvention.StdCall)]
2400 private extern static bool Win32SetCursorPos(int x, int y);
2402 [DllImport ("user32.dll", EntryPoint="GetWindowPlacement", CallingConvention=CallingConvention.StdCall)]
2403 private extern static bool Win32GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
2405 [DllImport ("user32.dll", EntryPoint="TrackMouseEvent", CallingConvention=CallingConvention.StdCall)]
2406 private extern static bool Win32TrackMouseEvent(ref TRACKMOUSEEVENT tme);
2408 [DllImport ("gdi32.dll", EntryPoint="CreateBrushIndirect", CallingConvention=CallingConvention.StdCall)]
2409 private extern static IntPtr Win32CreateBrushIndirect(ref LOGBRUSH lb);
2411 [DllImport ("user32.dll", EntryPoint="FillRect", CallingConvention=CallingConvention.StdCall)]
2412 private extern static int Win32FillRect(IntPtr hdc, ref RECT rect, IntPtr hbr);
2414 [DllImport ("user32.dll", EntryPoint="SetWindowLong", CallingConvention=CallingConvention.StdCall)]
2415 private extern static IntPtr Win32SetWindowLong(IntPtr hwnd, WindowLong index, IntPtr value);
2417 [DllImport ("user32.dll", EntryPoint="GetWindowLong", CallingConvention=CallingConvention.StdCall)]
2418 private extern static uint Win32GetWindowLong(IntPtr hwnd, WindowLong index);
2420 [DllImport ("gdi32.dll", EntryPoint="DeleteObject", CallingConvention=CallingConvention.StdCall)]
2421 private extern static bool Win32DeleteObject(IntPtr o);
2423 [DllImport ("user32.dll", EntryPoint="PostMessage", CallingConvention=CallingConvention.StdCall)]
2424 private extern static bool Win32PostMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
2426 [DllImport ("user32.dll", EntryPoint="GetKeyState", CallingConvention=CallingConvention.StdCall)]
2427 private extern static short Win32GetKeyState(VirtualKeys nVirtKey);
2429 [DllImport ("user32.dll", EntryPoint="GetDesktopWindow", CallingConvention=CallingConvention.StdCall)]
2430 private extern static IntPtr Win32GetDesktopWindow();
2432 [DllImport ("user32.dll", EntryPoint="SetTimer", CallingConvention=CallingConvention.StdCall)]
2433 private extern static IntPtr Win32SetTimer(IntPtr hwnd, int nIDEvent, uint uElapse, IntPtr timerProc);
2435 [DllImport ("user32.dll", EntryPoint="KillTimer", CallingConvention=CallingConvention.StdCall)]
2436 private extern static IntPtr Win32KillTimer(IntPtr hwnd, int nIDEvent);
2438 [DllImport ("user32.dll", EntryPoint="ShowWindow", CallingConvention=CallingConvention.StdCall)]
2439 private extern static IntPtr Win32ShowWindow(IntPtr hwnd, WindowPlacementFlags nCmdShow);
2441 [DllImport ("user32.dll", EntryPoint="EnableWindow", CallingConvention=CallingConvention.StdCall)]
2442 private extern static IntPtr Win32EnableWindow(IntPtr hwnd, bool Enabled);
2444 [DllImport ("user32.dll", EntryPoint="SetFocus", CallingConvention=CallingConvention.StdCall)]
2445 internal extern static IntPtr Win32SetFocus(IntPtr hwnd);
2447 [DllImport ("user32.dll", EntryPoint="CreateCaret", CallingConvention=CallingConvention.StdCall)]
2448 internal extern static bool Win32CreateCaret(IntPtr hwnd, IntPtr hBitmap, int nWidth, int nHeight);
2450 [DllImport ("user32.dll", EntryPoint="DestroyCaret", CallingConvention=CallingConvention.StdCall)]
2451 private extern static bool Win32DestroyCaret();
2453 [DllImport ("user32.dll", EntryPoint="ShowCaret", CallingConvention=CallingConvention.StdCall)]
2454 private extern static bool Win32ShowCaret(IntPtr hwnd);
2456 [DllImport ("user32.dll", EntryPoint="HideCaret", CallingConvention=CallingConvention.StdCall)]
2457 private extern static bool Win32HideCaret(IntPtr hwnd);
2459 [DllImport ("user32.dll", EntryPoint="SetCaretPos", CallingConvention=CallingConvention.StdCall)]
2460 private extern static bool Win32SetCaretPos(int X, int Y);
2462 [DllImport ("user32.dll", EntryPoint="GetCaretBlinkTime", CallingConvention=CallingConvention.StdCall)]
2463 private extern static uint Win32GetCaretBlinkTime();
2465 [DllImport ("gdi32.dll", EntryPoint="GetTextMetricsW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2466 internal extern static bool Win32GetTextMetrics(IntPtr hdc, ref TEXTMETRIC tm);
2468 [DllImport ("gdi32.dll", EntryPoint="SelectObject", CallingConvention=CallingConvention.StdCall)]
2469 internal extern static bool Win32SelectObject(IntPtr hdc, IntPtr hgdiobject);
2471 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2472 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
2474 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2475 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2477 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2478 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2480 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2481 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2483 [DllImport ("user32.dll", EntryPoint="GetActiveWindow", CallingConvention=CallingConvention.StdCall)]
2484 private extern static IntPtr Win32GetActiveWindow();
2486 [DllImport ("user32.dll", EntryPoint="GetSystemMetrics", CallingConvention=CallingConvention.StdCall)]
2487 private extern static int Win32GetSystemMetrics(SystemMetrics nIndex);
2489 [DllImport ("shell32.dll", EntryPoint="Shell_NotifyIconW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2490 private extern static bool Win32Shell_NotifyIcon(NotifyIconMessage dwMessage, ref NOTIFYICONDATA lpData);
2492 [DllImport ("gdi32.dll", EntryPoint="CreateRectRgn", CallingConvention=CallingConvention.StdCall)]
2493 internal extern static IntPtr Win32CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
2495 [DllImport ("user32.dll", EntryPoint="IsWindowVisible", CallingConvention=CallingConvention.StdCall)]
2496 private extern static bool IsWindowVisible(IntPtr hwnd);
2498 [DllImport ("user32.dll", EntryPoint="SetClassLong", CallingConvention=CallingConvention.StdCall)]
2499 private extern static bool Win32SetClassLong(IntPtr hwnd, ClassLong nIndex, IntPtr dwNewLong);
2501 [DllImport ("user32.dll", EntryPoint="SendMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2502 private extern static bool Win32SendMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
2504 [DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2505 private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref RECT rect, uint fWinIni);
2507 [DllImport ("user32.dll", EntryPoint="OpenClipboard", CallingConvention=CallingConvention.StdCall)]
2508 private extern static bool Win32OpenClipboard(IntPtr hwnd);
2510 [DllImport ("user32.dll", EntryPoint="EmptyClipboard", CallingConvention=CallingConvention.StdCall)]
2511 private extern static bool Win32EmptyClipboard();
2513 [DllImport ("user32.dll", EntryPoint="RegisterClipboardFormatW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2514 private extern static uint Win32RegisterClipboardFormat(string format);
2516 [DllImport ("user32.dll", EntryPoint="CloseClipboard", CallingConvention=CallingConvention.StdCall)]
2517 private extern static bool Win32CloseClipboard();
2519 [DllImport ("user32.dll", EntryPoint="EnumClipboardFormats", CallingConvention=CallingConvention.StdCall)]
2520 private extern static uint Win32EnumClipboardFormats(uint format);
2522 [DllImport ("user32.dll", EntryPoint="GetClipboardData", CallingConvention=CallingConvention.StdCall)]
2523 private extern static IntPtr Win32GetClipboardData(uint format);
2525 [DllImport ("user32.dll", EntryPoint="SetClipboardData", CallingConvention=CallingConvention.StdCall)]
2526 private extern static IntPtr Win32SetClipboardData(uint format, IntPtr handle);
2528 [DllImport ("kernel32.dll", EntryPoint="GlobalAlloc", CallingConvention=CallingConvention.StdCall)]
2529 private extern static IntPtr Win32GlobalAlloc(GAllocFlags Flags, int dwBytes);
2531 [DllImport ("kernel32.dll", EntryPoint="GlobalFree", CallingConvention=CallingConvention.StdCall)]
2532 private extern static IntPtr Win32GlobalFree(IntPtr hMem);
2534 [DllImport ("kernel32.dll", EntryPoint="GlobalLock", CallingConvention=CallingConvention.StdCall)]
2535 private extern static IntPtr Win32GlobalLock(IntPtr hMem);
2537 [DllImport ("kernel32.dll", EntryPoint="GlobalUnlock", CallingConvention=CallingConvention.StdCall)]
2538 private extern static bool Win32GlobalUnlock(IntPtr hMem);
2540 [DllImport ("kernel32.dll", EntryPoint="CopyMemory", CallingConvention=CallingConvention.StdCall)]
2541 private extern static bool Win32CopyMemory(IntPtr destination, IntPtr source, int length);
2543 [DllImport ("ole32.dll", EntryPoint="RegisterDragDrop", CallingConvention=CallingConvention.StdCall)]
2544 private extern static int Win32RegisterDragDrop(IntPtr Window, IntPtr pDropTarget);
2546 [DllImport ("ole32.dll", EntryPoint="RevokeDragDrop", CallingConvention=CallingConvention.StdCall)]
2547 private extern static int Win32RevokeDragDrop(IntPtr Window);
2549 [DllImport ("shell32.dll", EntryPoint="DragAcceptFiles", CallingConvention=CallingConvention.StdCall)]
2550 private extern static int Win32DragAcceptFiles(IntPtr Window, bool fAccept);
2552 [DllImport ("ole32.dll", EntryPoint="OleInitialize", CallingConvention=CallingConvention.StdCall)]
2553 private extern static int Win32OleInitialize(IntPtr pvReserved);
2555 [DllImport ("shell32.dll", EntryPoint="DragQueryFileW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2556 private extern static int Win32DragQueryFile(IntPtr hDrop, int iFile, IntPtr lpszFile, int cch);
2558 [DllImport ("shell32.dll", EntryPoint="DragQueryFileW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2559 private extern static int Win32DragQueryFile(IntPtr hDrop, int iFile, StringBuilder lpszFile, int cch);