fixed tests
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / XplatUIWin32.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2004-2006 Novell, Inc.
21 //
22 // Authors:
23 //      Peter Bartok    pbartok@novell.com
24 //
25 //
26
27 // NOT COMPLETE
28
29 using System;
30 using System.Drawing;
31 using System.Drawing.Imaging;
32 using System.ComponentModel;
33 using System.Collections;
34 using System.Diagnostics;
35 using System.IO;
36 using System.Runtime.InteropServices;
37 using System.Text;
38
39
40 /// Win32 Version
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;
47
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;
57
58                 internal static bool            themes_enabled;
59                 private Hashtable               timer_list;
60                 private static Queue            message_queue;
61                 private static IntPtr           clip_magic = new IntPtr(27051977);
62                 private static int              scroll_width;
63                 private static int              scroll_height;
64                 private static Hashtable        wm_nc_registered;
65                 private static RECT             clipped_cursor_rect;
66
67                 #endregion      // Local Variables
68
69                 #region Private Structs
70                 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
71                 private struct WNDCLASS {
72                         internal int            style;
73                         internal WndProc        lpfnWndProc;
74                         internal int            cbClsExtra;
75                         internal int            cbWndExtra;
76                         internal IntPtr         hInstance;
77                         internal IntPtr         hIcon;
78                         internal IntPtr         hCursor;
79                         internal IntPtr         hbrBackground;
80                         [MarshalAs(UnmanagedType.LPWStr)]
81                         internal string         lpszMenuName;
82                         [MarshalAs(UnmanagedType.LPWStr)]
83                         internal string         lpszClassName;
84                 }
85
86                 [StructLayout(LayoutKind.Sequential)]
87                 internal struct RECT {
88                         internal int            left;
89                         internal int            top;
90                         internal int            right;
91                         internal int            bottom;
92
93                         public RECT (int left, int top, int right, int bottom)
94                         {
95                                 this.left = left;
96                                 this.top = top;
97                                 this.right = right;
98                                 this.bottom = bottom;
99                         }
100
101                         #region Instance Properties
102                         public int Height { get { return bottom - top + 1; } }
103                         public int Width { get { return right - left + 1; } }
104                         public Size Size { get { return new Size (Width, Height); } }
105                         public Point Location { get { return new Point (left, top); } }
106                         #endregion
107
108                         #region Instance Methods
109                         public Rectangle ToRectangle ()
110                         {
111                                 return Rectangle.FromLTRB (left, top, right, bottom);
112                         }
113
114                         public static RECT FromRectangle (Rectangle rectangle)
115                         {
116                                 return new RECT (rectangle.Left, rectangle.Top, rectangle.Right, rectangle.Bottom);
117                         }
118
119                         public override int GetHashCode ()
120                         {
121                                 return left ^ ((top << 13) | (top >> 0x13))
122                                   ^ ((Width << 0x1a) | (Width >> 6))
123                                   ^ ((Height << 7) | (Height >> 0x19));
124                         }
125                         
126                         public override string ToString ()
127                         {
128                                 return String.Format("RECT left={0}, top={1}, right={2}, bottom={3}, width={4}, height={5}", left, top, right, bottom, right-left, bottom-top);
129                         }
130                         #endregion
131
132                         #region Operator overloads
133                         public static implicit operator Rectangle (RECT rect)
134                         {
135                                 return Rectangle.FromLTRB (rect.left, rect.top, rect.right, rect.bottom);
136                         }
137
138                         public static implicit operator RECT (Rectangle rect)
139                         {
140                                 return new RECT (rect.Left, rect.Top, rect.Right, rect.Bottom);
141                         }
142                         #endregion
143                 }
144
145                 internal enum SPIAction {
146                         SPI_GETWORKAREA         = 0x0030,
147                         SPI_GETMOUSEHOVERWIDTH  = 0x0062,
148                         SPI_GETMOUSEHOVERHEIGHT = 0x0064,
149                         SPI_GETMOUSEHOVERTIME   = 0x0066,
150                 }
151
152                 internal enum WindowPlacementFlags {
153                         SW_HIDE                 = 0,
154                         SW_SHOWNORMAL           = 1,
155                         SW_NORMAL               = 1,
156                         SW_SHOWMINIMIZED        = 2,
157                         SW_SHOWMAXIMIZED        = 3,
158                         SW_MAXIMIZE             = 3,
159                         SW_SHOWNOACTIVATE       = 4,
160                         SW_SHOW                 = 5,
161                         SW_MINIMIZE             = 6,
162                         SW_SHOWMINNOACTIVE      = 7,
163                         SW_SHOWNA               = 8,
164                         SW_RESTORE              = 9,
165                         SW_SHOWDEFAULT          = 10,
166                         SW_FORCEMINIMIZE        = 11,
167                         SW_MAX                  = 11
168                 }
169
170                 [StructLayout(LayoutKind.Sequential)]
171                 private struct WINDOWPLACEMENT {
172                         internal uint                   length;
173                         internal uint                   flags;
174                         internal WindowPlacementFlags   showCmd;
175                         internal POINT                  ptMinPosition;
176                         internal POINT                  ptMaxPosition;
177                         internal RECT                   rcNormalPosition;
178                 }
179
180                 [StructLayout(LayoutKind.Sequential)]
181                 internal struct NCCALCSIZE_PARAMS {
182                         internal RECT           rgrc1;
183                         internal RECT           rgrc2;
184                         internal RECT           rgrc3;
185                         internal IntPtr         lppos;
186                 }
187
188                 [Flags]
189                 private enum TMEFlags {
190                         TME_HOVER               = 0x00000001,
191                         TME_LEAVE               = 0x00000002,
192                         TME_NONCLIENT           = 0x00000010,
193                         TME_QUERY               = unchecked((int)0x40000000),
194                         TME_CANCEL              = unchecked((int)0x80000000)
195                 }
196
197                 [StructLayout(LayoutKind.Sequential)]
198                 private struct TRACKMOUSEEVENT {
199                         internal int            size;
200                         internal TMEFlags       dwFlags;
201                         internal IntPtr         hWnd;
202                         internal int            dwHoverTime;
203                 }
204
205                 [StructLayout(LayoutKind.Sequential)]
206                 private struct PAINTSTRUCT {
207                         internal IntPtr         hdc;
208                         internal int            fErase;
209                         internal RECT           rcPaint;
210                         internal int            fRestore;
211                         internal int            fIncUpdate;
212                         internal int            Reserved1;
213                         internal int            Reserved2;
214                         internal int            Reserved3;
215                         internal int            Reserved4;
216                         internal int            Reserved5;
217                         internal int            Reserved6;
218                         internal int            Reserved7;
219                         internal int            Reserved8;
220                 }
221
222                 [StructLayout(LayoutKind.Sequential)]
223                 internal struct KEYBDINPUT {
224                         internal short wVk;
225                         internal short wScan;
226                         internal Int32 dwFlags;
227                         internal Int32 time;
228                         internal UIntPtr dwExtraInfo;
229                 }
230
231                 [StructLayout(LayoutKind.Sequential)]
232                 internal struct MOUSEINPUT {
233                         internal Int32 dx;
234                         internal Int32 dy;
235                         internal Int32 mouseData;
236                         internal Int32 dwFlags;
237                         internal Int32 time;
238                         internal UIntPtr dwExtraInfo;
239                 }
240
241                 [StructLayout(LayoutKind.Sequential)]
242                 internal struct HARDWAREINPUT {
243                         internal Int32 uMsg;
244                         internal short wParamL;
245                         internal short wParamH;
246                 }
247
248                 [StructLayout(LayoutKind.Explicit)]
249                 internal struct INPUT {
250                         [FieldOffset(0)]
251                         internal Int32 type;
252
253                         [FieldOffset(4)]
254                         internal MOUSEINPUT mi;
255
256                         [FieldOffset(4)]
257                         internal KEYBDINPUT ki;
258
259                         [FieldOffset(4)]
260                         internal HARDWAREINPUT hi;
261                 }
262
263
264                 internal enum InputFlags {
265                         KEYEVENTF_EXTENDEDKEY   = 0x0001,
266                         KEYEVENTF_KEYUP                 = 0x0002,
267                         KEYEVENTF_SCANCODE              = 0x0003,
268                         KEYEVENTF_UNICODE               = 0x0004,
269                 }
270
271                 internal enum ClassStyle {
272                         CS_VREDRAW                      = 0x00000001,
273                         CS_HREDRAW                      = 0x00000002,
274                         CS_KEYCVTWINDOW                 = 0x00000004,
275                         CS_DBLCLKS                      = 0x00000008,
276                         CS_OWNDC                        = 0x00000020,
277                         CS_CLASSDC                      = 0x00000040,
278                         CS_PARENTDC                     = 0x00000080,
279                         CS_NOKEYCVT                     = 0x00000100,
280                         CS_NOCLOSE                      = 0x00000200,
281                         CS_SAVEBITS                     = 0x00000800,
282                         CS_BYTEALIGNCLIENT              = 0x00001000,
283                         CS_BYTEALIGNWINDOW              = 0x00002000,
284                         CS_GLOBALCLASS                  = 0x00004000,
285                         CS_IME                          = 0x00010000
286                 }
287
288                 internal enum SetWindowPosZOrder {
289                         HWND_TOP                        = 0,
290                         HWND_BOTTOM                     = 1,
291                         HWND_TOPMOST                    = -1,
292                         HWND_NOTOPMOST                  = -2
293                 }
294
295                 [Flags]
296                 internal enum SetWindowPosFlags {
297                         SWP_ASYNCWINDOWPOS              = 0x4000, 
298                         SWP_DEFERERASE                  = 0x2000,
299                         SWP_DRAWFRAME                   = 0x0020,
300                         SWP_FRAMECHANGED                = 0x0020,
301                         SWP_HIDEWINDOW                  = 0x0080,
302                         SWP_NOACTIVATE                  = 0x0010,
303                         SWP_NOCOPYBITS                  = 0x0100,
304                         SWP_NOMOVE                      = 0x0002,
305                         SWP_NOOWNERZORDER               = 0x0200,
306                         SWP_NOREDRAW                    = 0x0008,
307                         SWP_NOREPOSITION                = 0x0200,
308                         SWP_NOENDSCHANGING              = 0x0400,
309                         SWP_NOSIZE                      = 0x0001,
310                         SWP_NOZORDER                    = 0x0004,
311                         SWP_SHOWWINDOW                  = 0x0040
312                 }
313
314                 internal enum GetSysColorIndex {
315                         COLOR_SCROLLBAR                 = 0,
316                         COLOR_BACKGROUND                = 1,
317                         COLOR_ACTIVECAPTION             = 2,
318                         COLOR_INACTIVECAPTION           = 3,
319                         COLOR_MENU                      = 4,
320                         COLOR_WINDOW                    = 5,
321                         COLOR_WINDOWFRAME               = 6,
322                         COLOR_MENUTEXT                  = 7,
323                         COLOR_WINDOWTEXT                = 8,
324                         COLOR_CAPTIONTEXT               = 9,
325                         COLOR_ACTIVEBORDER              = 10,
326                         COLOR_INACTIVEBORDER            = 11,
327                         COLOR_APPWORKSPACE              = 12,
328                         COLOR_HIGHLIGHT                 = 13,
329                         COLOR_HIGHLIGHTTEXT             = 14,
330                         COLOR_BTNFACE                   = 15,
331                         COLOR_BTNSHADOW                 = 16,
332                         COLOR_GRAYTEXT                  = 17,
333                         COLOR_BTNTEXT                   = 18,
334                         COLOR_INACTIVECAPTIONTEXT       = 19,
335                         COLOR_BTNHIGHLIGHT              = 20,
336                         COLOR_3DDKSHADOW                = 21,
337                         COLOR_3DLIGHT                   = 22,
338                         COLOR_INFOTEXT                  = 23,
339                         COLOR_INFOBK                    = 24,
340                         
341                         COLOR_HOTLIGHT                  = 26,
342                         COLOR_GRADIENTACTIVECAPTION     = 27,
343                         COLOR_GRADIENTINACTIVECAPTION   = 28,
344                         COLOR_MENUHIGHLIGHT             = 29,
345                         COLOR_MENUBAR                   = 30,
346
347                         COLOR_DESKTOP                   = 1,
348                         COLOR_3DFACE                    = 16,
349                         COLOR_3DSHADOW                  = 16,
350                         COLOR_3DHIGHLIGHT               = 20,
351                         COLOR_3DHILIGHT                 = 20,
352                         COLOR_BTNHILIGHT                = 20,
353                         COLOR_MAXVALUE                  = 24,/* Maximum value */
354                 }       
355
356                 private enum LoadCursorType {
357                         First                           = 32512,
358                         IDC_ARROW                       = 32512,
359                         IDC_IBEAM                       = 32513,
360                         IDC_WAIT                        = 32514,
361                         IDC_CROSS                       = 32515,
362                         IDC_UPARROW                     = 32516,
363                         IDC_SIZE                        = 32640,
364                         IDC_ICON                        = 32641,
365                         IDC_SIZENWSE                    = 32642,
366                         IDC_SIZENESW                    = 32643,
367                         IDC_SIZEWE                      = 32644,
368                         IDC_SIZENS                      = 32645,
369                         IDC_SIZEALL                     = 32646,
370                         IDC_NO                          = 32648,
371                         IDC_HAND                        = 32649,
372                         IDC_APPSTARTING                 = 32650,
373                         IDC_HELP                        = 32651,
374                         Last                            = 32651
375                 }
376
377                 [Flags]
378                 private enum WindowLong {
379                         GWL_WNDPROC                     = -4,
380                         GWL_HINSTANCE                   = -6,
381                         GWL_HWNDPARENT                  = -8,
382                         GWL_STYLE                       = -16,
383                         GWL_EXSTYLE                     = -20,
384                         GWL_USERDATA                    = -21,
385                         GWL_ID                          = -12
386                 }
387
388                 [Flags]
389                 private enum LogBrushStyle {
390                         BS_SOLID                        = 0,
391                         BS_NULL                         = 1,
392                         BS_HATCHED                      = 2,
393                         BS_PATTERN                      = 3,
394                         BS_INDEXED                      = 4,
395                         BS_DIBPATTERN                   = 5,
396                         BS_DIBPATTERNPT                 = 6,
397                         BS_PATTERN8X8                   = 7,
398                         BS_DIBPATTERN8X8                = 8,
399                         BS_MONOPATTERN                  = 9
400                 }
401
402                 [Flags]
403                 private enum LogBrushHatch {
404                         HS_HORIZONTAL                   = 0,       /* ----- */
405                         HS_VERTICAL                     = 1,       /* ||||| */
406                         HS_FDIAGONAL                    = 2,       /* \\\\\ */
407                         HS_BDIAGONAL                    = 3,       /* ///// */
408                         HS_CROSS                        = 4,       /* +++++ */
409                         HS_DIAGCROSS                    = 5,       /* xxxxx */
410                 }
411
412                 internal struct COLORREF {
413                         internal byte                   R;
414                         internal byte                   G;
415                         internal byte                   B;
416                         internal byte                   A;
417                 }
418
419                 [StructLayout(LayoutKind.Sequential)]
420                 private struct LOGBRUSH {
421                         internal LogBrushStyle          lbStyle;
422                         internal COLORREF               lbColor;
423                         internal LogBrushHatch          lbHatch;
424                 }
425
426                 [StructLayout(LayoutKind.Sequential)]
427                 internal struct TEXTMETRIC { 
428                         internal int                    tmHeight;
429                         internal int                    tmAscent;
430                         internal int                    tmDescent;
431                         internal int                    tmInternalLeading;
432                         internal int                    tmExternalLeading;
433                         internal int                    tmAveCharWidth;
434                         internal int                    tmMaxCharWidth;
435                         internal int                    tmWeight;
436                         internal int                    tmOverhang;
437                         internal int                    tmDigitizedAspectX;
438                         internal int                    tmDigitizedAspectY;
439                         internal short                  tmFirstChar; 
440                         internal short                  tmLastChar; 
441                         internal short                  tmDefaultChar; 
442                         internal short                  tmBreakChar; 
443                         internal byte                   tmItalic; 
444                         internal byte                   tmUnderlined; 
445                         internal byte                   tmStruckOut; 
446                         internal byte                   tmPitchAndFamily; 
447                         internal byte                   tmCharSet; 
448                 }
449
450                 public enum TernaryRasterOperations : uint
451                 {
452                         SRCCOPY = 0x00CC0020,
453                         SRCPAINT = 0x00EE0086,
454                         SRCAND = 0x008800C6,
455                         SRCINVERT = 0x00660046,
456                         SRCERASE = 0x00440328,
457                         NOTSRCCOPY = 0x00330008,
458                         NOTSRCERASE = 0x001100A6,
459                         MERGECOPY = 0x00C000CA,
460                         MERGEPAINT = 0x00BB0226,
461                         PATCOPY = 0x00F00021,
462                         PATPAINT = 0x00FB0A09,
463                         PATINVERT = 0x005A0049,
464                         DSTINVERT = 0x00550009,
465                         BLACKNESS = 0x00000042,
466                         WHITENESS = 0x00FF0062
467                 }
468
469                 [Flags]
470                 private enum ScrollWindowExFlags {
471                         SW_NONE                         = 0x0000,
472                         SW_SCROLLCHILDREN               = 0x0001,
473                         SW_INVALIDATE                   = 0x0002,
474                         SW_ERASE                        = 0x0004,
475                         SW_SMOOTHSCROLL                 = 0x0010
476                 }
477
478                 internal enum SystemMetrics {
479                         SM_CXSCREEN                     = 0,
480                         SM_CYSCREEN                     = 1,
481                         SM_CXVSCROLL                    = 2,
482                         SM_CYHSCROLL                    = 3,
483                         SM_CYCAPTION                    = 4,
484                         SM_CXBORDER                     = 5,
485                         SM_CYBORDER                     = 6,
486                         SM_CXDLGFRAME                   = 7,
487                         SM_CYDLGFRAME                   = 8,
488                         SM_CYVTHUMB                     = 9,
489                         SM_CXHTHUMB                     = 10,
490                         SM_CXICON                       = 11,
491                         SM_CYICON                       = 12,
492                         SM_CXCURSOR                     = 13,
493                         SM_CYCURSOR                     = 14,
494                         SM_CYMENU                       = 15,
495                         SM_CXFULLSCREEN                 = 16,
496                         SM_CYFULLSCREEN                 = 17,
497                         SM_CYKANJIWINDOW                = 18,
498                         SM_MOUSEPRESENT                 = 19,
499                         SM_CYVSCROLL                    = 20,
500                         SM_CXHSCROLL                    = 21,
501                         SM_DEBUG                        = 22,
502                         SM_SWAPBUTTON                   = 23,
503                         SM_RESERVED1                    = 24,
504                         SM_RESERVED2                    = 25,
505                         SM_RESERVED3                    = 26,
506                         SM_RESERVED4                    = 27,
507                         SM_CXMIN                        = 28,
508                         SM_CYMIN                        = 29,
509                         SM_CXSIZE                       = 30,
510                         SM_CYSIZE                       = 31,
511                         SM_CXFRAME                      = 32,
512                         SM_CYFRAME                      = 33,
513                         SM_CXMINTRACK                   = 34,
514                         SM_CYMINTRACK                   = 35,
515                         SM_CXDOUBLECLK                  = 36,
516                         SM_CYDOUBLECLK                  = 37,
517                         SM_CXICONSPACING                = 38,
518                         SM_CYICONSPACING                = 39,
519                         SM_MENUDROPALIGNMENT            = 40,
520                         SM_PENWINDOWS                   = 41,
521                         SM_DBCSENABLED                  = 42,
522                         SM_CMOUSEBUTTONS                = 43,
523                         SM_CXFIXEDFRAME                 = SM_CXDLGFRAME,
524                         SM_CYFIXEDFRAME                 = SM_CYDLGFRAME,
525                         SM_CXSIZEFRAME                  = SM_CXFRAME,
526                         SM_CYSIZEFRAME                  = SM_CYFRAME,
527                         SM_SECURE                       = 44,
528                         SM_CXEDGE                       = 45,
529                         SM_CYEDGE                       = 46,
530                         SM_CXMINSPACING                 = 47,
531                         SM_CYMINSPACING                 = 48,
532                         SM_CXSMICON                     = 49,
533                         SM_CYSMICON                     = 50,
534                         SM_CYSMCAPTION                  = 51,
535                         SM_CXSMSIZE                     = 52,
536                         SM_CYSMSIZE                     = 53,
537                         SM_CXMENUSIZE                   = 54,
538                         SM_CYMENUSIZE                   = 55,
539                         SM_ARRANGE                      = 56,
540                         SM_CXMINIMIZED                  = 57,
541                         SM_CYMINIMIZED                  = 58,
542                         SM_CXMAXTRACK                   = 59,
543                         SM_CYMAXTRACK                   = 60,
544                         SM_CXMAXIMIZED                  = 61,
545                         SM_CYMAXIMIZED                  = 62,
546                         SM_NETWORK                      = 63,
547                         SM_CLEANBOOT                    = 67,
548                         SM_CXDRAG                       = 68,
549                         SM_CYDRAG                       = 69,
550                         SM_SHOWSOUNDS                   = 70,
551                         SM_CXMENUCHECK                  = 71,
552                         SM_CYMENUCHECK                  = 72,
553                         SM_SLOWMACHINE                  = 73,
554                         SM_MIDEASTENABLED               = 74,
555                         SM_MOUSEWHEELPRESENT            = 75,
556                         SM_XVIRTUALSCREEN               = 76,
557                         SM_YVIRTUALSCREEN               = 77,
558                         SM_CXVIRTUALSCREEN              = 78,
559                         SM_CYVIRTUALSCREEN              = 79,
560                         SM_CMONITORS                    = 80,
561                         SM_SAMEDISPLAYFORMAT            = 81,
562                         SM_IMMENABLED                   = 82,
563                         SM_CXFOCUSBORDER                = 83,
564                         SM_CYFOCUSBORDER                = 84,
565                         SM_TABLETPC                     = 86,
566                         SM_MEDIACENTER                  = 87,
567                         SM_CMETRICS                     = 88
568                 }
569
570                 // We'll only support _WIN32_IE < 0x0500 for now
571                 internal enum NotifyIconMessage {
572                         NIM_ADD                         = 0x00000000,
573                         NIM_MODIFY                      = 0x00000001,
574                         NIM_DELETE                      = 0x00000002,
575                 }
576
577                 [Flags]
578                 internal enum NotifyIconFlags {
579                         NIF_MESSAGE                     = 0x00000001,
580                         NIF_ICON                        = 0x00000002,
581                         NIF_TIP                         = 0x00000004,
582                 }
583
584                 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
585                 internal struct NOTIFYICONDATA {
586                         internal uint                   cbSize;
587                         internal IntPtr                 hWnd;
588                         internal uint                   uID;
589                         internal NotifyIconFlags        uFlags;
590                         internal uint                   uCallbackMessage;
591                         internal IntPtr                 hIcon;
592                         [MarshalAs(UnmanagedType.ByValTStr, SizeConst=64)]
593                         internal string                 szTip;
594                 }
595
596                 [Flags]
597                 internal enum DCExFlags {
598                         DCX_WINDOW                      = 0x00000001,
599                         DCX_CACHE                       = 0x00000002,
600                         DCX_NORESETATTRS                = 0x00000004,
601                         DCX_CLIPCHILDREN                = 0x00000008,
602                         DCX_CLIPSIBLINGS                = 0x00000010,
603                         DCX_PARENTCLIP                  = 0x00000020,
604                         DCX_EXCLUDERGN                  = 0x00000040,
605                         DCX_INTERSECTRGN                = 0x00000080,
606                         DCX_EXCLUDEUPDATE               = 0x00000100,
607                         DCX_INTERSECTUPDATE             = 0x00000200,
608                         DCX_LOCKWINDOWUPDATE            = 0x00000400,
609                         DCX_USESTYLE                    = 0x00010000,
610                         DCX_VALIDATE                    = 0x00200000
611                 }
612
613                 [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
614                 internal struct CLIENTCREATESTRUCT {
615                         internal IntPtr                 hWindowMenu;
616                         internal uint                   idFirstChild;
617                 }
618
619                 private enum ClassLong : int {
620                         GCL_MENUNAME                    = -8,
621                         GCL_HBRBACKGROUND               = -10,
622                         GCL_HCURSOR                     = -12,
623                         GCL_HICON                       = -14,
624                         GCL_HMODULE                     = -16,
625                         GCL_CBWNDEXTRA                  = -18,
626                         GCL_CBCLSEXTRA                  = -20,
627                         GCL_WNDPROC                     = -24,
628                         GCL_STYLE                       = -26,
629                         GCW_ATOM                        = -32,
630                         GCL_HICONSM                     = -34
631                 }
632
633                 [Flags]
634                 internal enum GAllocFlags : uint {
635                         GMEM_FIXED                      = 0x0000,
636                         GMEM_MOVEABLE                   = 0x0002,
637                         GMEM_NOCOMPACT                  = 0x0010,
638                         GMEM_NODISCARD                  = 0x0020,
639                         GMEM_ZEROINIT                   = 0x0040,
640                         GMEM_MODIFY                     = 0x0080,
641                         GMEM_DISCARDABLE                = 0x0100,
642                         GMEM_NOT_BANKED                 = 0x1000,
643                         GMEM_SHARE                      = 0x2000,
644                         GMEM_DDESHARE                   = 0x2000,
645                         GMEM_NOTIFY                     = 0x4000,
646                         GMEM_LOWER                      = GMEM_NOT_BANKED,
647                         GMEM_VALID_FLAGS                = 0x7F72,
648                         GMEM_INVALID_HANDLE             = 0x8000,
649                         GHND                            = (GMEM_MOVEABLE | GMEM_ZEROINIT),
650                         GPTR                            = (GMEM_FIXED | GMEM_ZEROINIT)
651                 }
652
653                 internal enum ROP2DrawMode : int {
654                         R2_BLACK                        = 1,
655                         R2_NOTMERGEPEN                  = 2,
656                         R2_MASKNOTPEN                   = 3,
657                         R2_NOTCOPYPEN                   = 4,
658                         R2_MASKPENNOT                   = 5,
659                         R2_NOT                          = 6,
660                         R2_XORPEN                       = 7,
661                         R2_NOTMASKPEN                   = 8,
662                         R2_MASKPEN                      = 9,
663                         R2_NOTXORPEN                    = 10,
664                         R2_NOP                          = 11,
665                         R2_MERGENOTPEN                  = 12,
666                         R2_COPYPEN                      = 13,
667                         R2_MERGEPENNOT                  = 14,
668                         R2_MERGEPEN                     = 15,
669                         R2_WHITE                        = 16,
670                         R2_LAST                         = 16
671                 }
672
673                 internal enum PenStyle : int {
674                         PS_SOLID                        = 0,
675                         PS_DASH                         = 1,
676                         PS_DOT                          = 2,
677                         PS_DASHDOT                      = 3,
678                         PS_DASHDOTDOT                   = 4,
679                         PS_NULL                         = 5,
680                         PS_INSIDEFRAME                  = 6,
681                         PS_USERSTYLE                    = 7,
682                         PS_ALTERNATE                    = 8
683                 }
684
685                 internal enum PatBltRop : int {
686                         PATCOPY   = 0xf00021,
687                         PATINVERT = 0x5a0049,
688                         DSTINVERT = 0x550009,
689                         BLACKNESS = 0x000042,
690                         WHITENESS = 0xff0062,
691                 }
692
693                 internal enum StockObject : int {
694                         WHITE_BRUSH                     = 0,
695                         LTGRAY_BRUSH                    = 1,
696                         GRAY_BRUSH                      = 2,
697                         DKGRAY_BRUSH                    = 3,
698                         BLACK_BRUSH                     = 4,
699                         NULL_BRUSH                      = 5,
700                         HOLLOW_BRUSH                    = NULL_BRUSH,
701                         WHITE_PEN                       = 6,
702                         BLACK_PEN                       = 7,
703                         NULL_PEN                        = 8,
704                         OEM_FIXED_FONT                  = 10,
705                         ANSI_FIXED_FONT                 = 11,
706                         ANSI_VAR_FONT                   = 12,
707                         SYSTEM_FONT                     = 13,
708                         DEVICE_DEFAULT_FONT             = 14,
709                         DEFAULT_PALETTE                 = 15,
710                         SYSTEM_FIXED_FONT               = 16
711                 }
712
713                 internal enum HatchStyle : int {
714                         HS_HORIZONTAL                   = 0,
715                         HS_VERTICAL                     = 1,
716                         HS_FDIAGONAL                    = 2,
717                         HS_BDIAGONAL                    = 3,
718                         HS_CROSS                        = 4,
719                         HS_DIAGCROSS                    = 5
720                 }
721
722                 [Flags]
723                 internal enum SndFlags : int {
724                         SND_SYNC                        = 0x0000,
725                         SND_ASYNC                       = 0x0001,
726                         SND_NODEFAULT                   = 0x0002,
727                         SND_MEMORY                      = 0x0004,
728                         SND_LOOP                        = 0x0008,
729                         SND_NOSTOP                      = 0x0010,
730                         SND_NOWAIT                      = 0x00002000,
731                         SND_ALIAS                       = 0x00010000,
732                         SND_ALIAS_ID                    = 0x00110000,
733                         SND_FILENAME                    = 0x00020000,
734                         SND_RESOURCE                    = 0x00040004,
735                         SND_PURGE                       = 0x0040,
736                         SND_APPLICATION                 = 0x0080,
737                 }
738
739                 [Flags]
740                 internal enum LayeredWindowAttributes : int {
741                         LWA_COLORKEY            = 0x1,
742                         LWA_ALPHA                       = 0x2,
743                 }
744
745                 
746                 #endregion
747
748                 #region Constructor & Destructor
749                 private XplatUIWin32() {
750                         WNDCLASS        wndClass;
751                         bool            result;
752
753                         // Handle singleton stuff first
754                         ref_count=0;
755
756                         mouse_state = MouseButtons.None;
757                         mouse_position = Point.Empty;
758
759                         message_queue = new Queue();
760
761                         themes_enabled = false;
762
763                         // Prepare 'our' window class
764                         wnd_proc = new WndProc(NativeWindow.WndProc);
765                         wndClass.style = (int)(ClassStyle.CS_OWNDC | ClassStyle.CS_DBLCLKS);
766                         wndClass.lpfnWndProc = wnd_proc;
767                         wndClass.cbClsExtra = 0;
768                         wndClass.cbWndExtra = 0;
769                         wndClass.hbrBackground = IntPtr.Zero;
770                         wndClass.hCursor = Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
771                         wndClass.hIcon = IntPtr.Zero;
772                         wndClass.hInstance = IntPtr.Zero;
773                         wndClass.lpszClassName = XplatUI.DefaultClassName;
774                         wndClass.lpszMenuName = "";
775
776                         result=Win32RegisterClass(ref wndClass);
777                         if (result==false) {
778                                 Win32MessageBox(IntPtr.Zero, "Could not register the "+XplatUI.DefaultClassName+" window class, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
779                         }
780
781                         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);
782
783                         if (FosterParent==IntPtr.Zero) {
784                                 Win32MessageBox(IntPtr.Zero, "Could not create foster window, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
785                         }
786
787                         scroll_height = Win32GetSystemMetrics(SystemMetrics.SM_CYHSCROLL);
788                         scroll_width = Win32GetSystemMetrics(SystemMetrics.SM_CXVSCROLL);
789
790                         timer_list = new Hashtable ();
791                 }
792                 #endregion      // Constructor & Destructor
793
794                 #region Private Support Methods
795
796                 private static bool RetrieveMessage(ref MSG msg) {
797                         MSG     message;
798
799                         if (message_queue.Count == 0) {
800                                 return false;
801                         }
802
803                         message = (MSG)message_queue.Dequeue();
804                         msg = message;
805
806                         return true;
807                 }
808
809                 private static bool StoreMessage(ref MSG msg) {
810                         MSG message = new MSG();
811
812                         message = msg;
813                         message_queue.Enqueue(message);
814
815                         return true;
816                 }
817
818                 internal static String AnsiToString(IntPtr ansi_data) {
819                         return (string)Marshal.PtrToStringAnsi(ansi_data);
820                 }
821
822                 internal static String UnicodeToString(IntPtr unicode_data) {
823                         return (string)Marshal.PtrToStringUni(unicode_data);
824                 }
825
826                 internal static Image DIBtoImage(IntPtr dib_data) {
827                         BITMAPINFOHEADER        bmi;
828                         int                     ncolors;
829                         int                     imagesize;
830                         //int                   palettesize;
831                         Bitmap                  bmp;
832                         BitmapData              bits;
833                         ColorPalette            pal;
834                         int[]                   palette;
835                         byte[]                  imagebits;
836                         int                     bytesPerLine;
837
838                         bmi = (BITMAPINFOHEADER)Marshal.PtrToStructure(dib_data, typeof(BITMAPINFOHEADER));
839
840                         ncolors = (int)bmi.biClrUsed;
841                         if (ncolors == 0) {
842                                 if (bmi.biBitCount < 24) {
843                                         ncolors = (int)(1 << bmi.biBitCount);
844                                 }
845                         }
846                         //palettesize = ncolors * 4;
847
848                         imagesize = (int)bmi.biSizeImage;
849                         if (imagesize == 0) {
850                                 imagesize = (int)(((((bmi.biWidth * bmi.biBitCount) + 31) & ~31) >> 3) * bmi.biHeight);
851                         }
852
853                         switch(bmi.biBitCount) {
854                                 case 1: {       // Monochrome
855                                         bmp = new Bitmap(bmi.biWidth, bmi.biHeight, PixelFormat.Format1bppIndexed);
856                                         palette = new int[2];
857                                         break;
858                                 }
859
860                                 case 4: {       // 4bpp
861                                         bmp = new Bitmap(bmi.biWidth, bmi.biHeight, PixelFormat.Format4bppIndexed);
862                                         palette = new int[16];
863                                         break;
864                                 }
865
866                                 case 8: {       // 8bpp
867                                         bmp = new Bitmap(bmi.biWidth, bmi.biHeight, PixelFormat.Format8bppIndexed);
868                                         palette = new int[256];
869                                         break;
870                                 }
871
872                                 case 24:
873                                 case 32: {      // 32bpp
874                                         bmp = new Bitmap(bmi.biWidth, bmi.biHeight, PixelFormat.Format32bppArgb);
875                                         palette = new int[0];
876                                         break;
877                                 }
878
879                                 default: {
880                                         throw new Exception("Unexpected number of bits:" + bmi.biBitCount.ToString());
881                                 }
882                         }
883
884                         if (bmi.biBitCount < 24) {
885                                 pal = bmp.Palette;                              // Managed palette
886                                 Marshal.Copy((IntPtr)((int)dib_data + Marshal.SizeOf(typeof(BITMAPINFOHEADER))), palette, 0, palette.Length);
887
888                                 for (int i = 0; i < ncolors; i++) {
889                                         pal.Entries[i] = Color.FromArgb(palette[i] | unchecked((int)0xff000000));
890                                 }
891                                 bmp.Palette = pal;
892                         }
893
894                         bytesPerLine = (int)((((bmi.biWidth * bmi.biBitCount) + 31) & ~31) >> 3);
895                         bits = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
896
897                         imagebits = new byte[bytesPerLine];
898
899                         for (int y = 0; y < bmi.biHeight; y++) {
900                                 // Copy from source to managed
901                                 Marshal.Copy((IntPtr)((int)dib_data + Marshal.SizeOf(typeof(BITMAPINFOHEADER)) + palette.Length * 4 + bytesPerLine * y), imagebits, 0, bytesPerLine);
902
903                                 // Copy from managed to dest
904                                 Marshal.Copy(imagebits, 0, (IntPtr)((int)bits.Scan0 + bits.Stride * (bmi.biHeight - 1 - y)), imagebits.Length);
905                         }
906
907                         bmp.UnlockBits(bits);
908
909                         return bmp;
910                 }
911
912                 internal static byte[] ImageToDIB(Image image) {
913                         MemoryStream    ms;
914                         byte[]          buffer;
915                         byte[]          retbuf;
916
917                         ms = new MemoryStream();
918                         image.Save(ms, ImageFormat.Bmp);
919                         buffer = ms.GetBuffer();
920
921                         // Filter out the file header
922                         retbuf = new byte[buffer.Length];
923                         Array.Copy(buffer, 14, retbuf, 0, buffer.Length - 14);
924                         return retbuf;
925                 }
926
927                 internal static IntPtr DupGlobalMem(IntPtr mem) {
928                         IntPtr  dup;
929                         IntPtr  dup_ptr;
930                         IntPtr  mem_ptr;
931                         uint    len;
932
933                         len = Win32GlobalSize(mem);
934                         mem_ptr = Win32GlobalLock(mem);
935
936                         dup = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE, (int)len);
937                         dup_ptr = Win32GlobalLock(dup);
938
939                         Win32CopyMemory(dup_ptr, mem_ptr, (int)len);
940
941                         Win32GlobalUnlock(mem);
942                         Win32GlobalUnlock(dup);
943
944                         return dup;
945                 }
946                 #endregion      // Private Support Methods
947
948                 #region Static Properties
949                 internal override Keys ModifierKeys {
950                         get {
951                                 short   state;
952                                 Keys    key_state;
953
954                                 key_state = Keys.None;
955
956                                 state = Win32GetKeyState(VirtualKeys.VK_SHIFT);
957                                 if ((state & 0x8000) != 0) {
958                                         key_state |= Keys.Shift;
959                                 }
960                                 state = Win32GetKeyState(VirtualKeys.VK_CONTROL);
961                                 if ((state & 0x8000) != 0) {
962                                         key_state |= Keys.Control;
963                                 }
964
965                                 state = Win32GetKeyState(VirtualKeys.VK_MENU);
966                                 if ((state & 0x8000) != 0) {
967                                         key_state |= Keys.Alt;
968                                 }
969
970                                 return key_state;
971                         }
972                 }
973
974                 internal override MouseButtons MouseButtons {
975                         get {
976                                 return mouse_state;
977                         }
978                 }
979
980                 internal override Point MousePosition {
981                         get {
982                                 return mouse_position;
983                         }
984                 }
985
986                 internal override Size MouseHoverSize {
987                         get {
988                                 int     width = 4;
989                                 int     height = 4;
990
991                                 Win32SystemParametersInfo(SPIAction.SPI_GETMOUSEHOVERWIDTH, 0, ref width, 0);
992                                 Win32SystemParametersInfo(SPIAction.SPI_GETMOUSEHOVERWIDTH, 0, ref height, 0);
993                                 return new Size(width, height);
994                         }
995                 }
996
997                 internal override int MouseHoverTime {
998                         get {
999                                 int time = 500;
1000
1001                                 Win32SystemParametersInfo(SPIAction.SPI_GETMOUSEHOVERTIME, 0, ref time, 0);
1002                                 return time;
1003                         }
1004                 }
1005
1006                 internal override int HorizontalScrollBarHeight {
1007                         get {
1008                                 return scroll_height;
1009                         }
1010                 }
1011
1012                 internal override bool UserClipWontExposeParent {
1013                         get {
1014                                 return false;
1015                         }
1016                 }
1017
1018
1019                 internal override int VerticalScrollBarWidth {
1020                         get {
1021                                 return scroll_width;
1022                         }
1023                 }
1024
1025                 internal override int MenuHeight {
1026                         get {
1027                                 return Win32GetSystemMetrics(SystemMetrics.SM_CYMENU);
1028                         }
1029                 }
1030
1031                 internal override bool DropTarget {
1032                         get {
1033                                 return false;
1034                         }
1035
1036                         set {
1037                                 if (value) {
1038                                         //throw new NotImplementedException("Need to figure out D'n'D for Win32");
1039                                 }
1040                         }
1041                 }
1042
1043                 internal override int Caption {
1044                         get {
1045                                 return Win32GetSystemMetrics(SystemMetrics.SM_CYCAPTION);
1046                         }
1047                 }
1048
1049                 internal override Size CursorSize {
1050                         get {
1051                                 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CYCURSOR));
1052                         }
1053                 }
1054
1055                 internal override bool DragFullWindows {
1056                         get {
1057                                 return true;
1058                         }
1059                 }
1060
1061                 internal override Size DragSize {
1062                         get {
1063                                 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXDRAG), Win32GetSystemMetrics(SystemMetrics.SM_CYDRAG));
1064                         }
1065                 }
1066
1067                 internal override Size FrameBorderSize { 
1068                         get {
1069                                 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXFRAME), Win32GetSystemMetrics(SystemMetrics.SM_CYFRAME));
1070                         }
1071                 }
1072
1073                 internal override Size IconSize {
1074                         get {
1075                                 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXICON), Win32GetSystemMetrics(SystemMetrics.SM_CYICON));
1076                         }
1077                 }
1078
1079                 internal override Size MaxWindowTrackSize {
1080                         get {
1081                                 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMAXTRACK), Win32GetSystemMetrics(SystemMetrics.SM_CYMAXTRACK));
1082                         }
1083                 }
1084
1085                 internal override Size MinimizedWindowSize {
1086                         get {
1087                                 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINIMIZED), Win32GetSystemMetrics(SystemMetrics.SM_CYMINIMIZED));
1088                         }
1089                 }
1090
1091                 internal override Size MinimizedWindowSpacingSize {
1092                         get {
1093                                 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINSPACING), Win32GetSystemMetrics(SystemMetrics.SM_CYMINSPACING));
1094                         }
1095                 }
1096
1097                 internal override Size MinimumWindowSize {
1098                         get {
1099                                 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMIN), Win32GetSystemMetrics(SystemMetrics.SM_CYMIN));
1100                         }
1101                 }
1102
1103                 internal override Size MinWindowTrackSize {
1104                         get {
1105                                 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXMINTRACK), Win32GetSystemMetrics(SystemMetrics.SM_CYMINTRACK));
1106                         }
1107                 }
1108
1109                 internal override Size SmallIconSize {
1110                         get {
1111                                 return new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXSMICON), Win32GetSystemMetrics(SystemMetrics.SM_CYSMICON));
1112                         }
1113                 }
1114
1115                 internal override int MouseButtonCount {
1116                         get {
1117                                 return Win32GetSystemMetrics(SystemMetrics.SM_CMOUSEBUTTONS);
1118                         }
1119                 }
1120
1121                 internal override bool MouseButtonsSwapped {
1122                         get {
1123                                 return Win32GetSystemMetrics(SystemMetrics.SM_SWAPBUTTON) != 0;
1124                         }
1125                 }
1126
1127                 internal override bool MouseWheelPresent {
1128                         get {
1129                                 return Win32GetSystemMetrics(SystemMetrics.SM_MOUSEWHEELPRESENT) != 0;
1130                         }
1131                 }
1132
1133                 internal override Rectangle VirtualScreen {
1134                         get {
1135                                 return new Rectangle(   Win32GetSystemMetrics(SystemMetrics.SM_XVIRTUALSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_YVIRTUALSCREEN),
1136                                                         Win32GetSystemMetrics(SystemMetrics.SM_CXVIRTUALSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_CYVIRTUALSCREEN));
1137                         }
1138                 }
1139
1140                 internal override Rectangle WorkingArea {
1141                         get {
1142                                 RECT    rect;
1143
1144                                 rect = new RECT();
1145                                 Win32SystemParametersInfo(SPIAction.SPI_GETWORKAREA, 0, ref rect, 0);
1146                                 return new Rectangle(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top);
1147                                 //return new Rectangle(0, 0, Win32GetSystemMetrics(SystemMetrics.SM.SM_CXSCREEN), Win32GetSystemMetrics(SystemMetrics.SM_CYSCREEN));
1148                         }
1149                 }
1150
1151                 internal override bool ThemesEnabled {
1152                         get {
1153                                 return XplatUIWin32.themes_enabled;
1154                         }
1155                 }
1156  
1157
1158                 #endregion      // Static Properties
1159
1160                 #region Singleton Specific Code
1161                 public static XplatUIWin32 GetInstance() {
1162                         if (instance==null) {
1163                                 instance=new XplatUIWin32();
1164                         }
1165                         ref_count++;
1166                         return instance;
1167                 }
1168
1169                 public int Reference {
1170                         get {
1171                                 return ref_count;
1172                         }
1173                 }
1174                 #endregion
1175
1176                 #region Public Static Methods
1177                 internal override IntPtr InitializeDriver() {
1178                         return IntPtr.Zero;
1179                 }
1180
1181                 internal override void ShutdownDriver(IntPtr token) {
1182                         Console.WriteLine("XplatUIWin32 ShutdownDriver called");
1183                 }
1184
1185
1186                 internal void Version() {
1187                         Console.WriteLine("Xplat version $revision: $");
1188                 }
1189
1190                 internal override void AudibleAlert() {
1191                         Win32PlaySound("Default", IntPtr.Zero, SndFlags.SND_ALIAS | SndFlags.SND_ASYNC | SndFlags.SND_NOSTOP | SndFlags.SND_NOWAIT);
1192                 }
1193
1194                 internal override void GetDisplaySize(out Size size) {
1195                         RECT    rect;
1196
1197                         Win32GetWindowRect(Win32GetDesktopWindow(), out rect);
1198
1199                         size = new Size(rect.right - rect.left, rect.bottom - rect.top);
1200                 }
1201
1202                 internal override void EnableThemes() {
1203                         themes_enabled=true;
1204                 }
1205
1206                 internal override IntPtr CreateWindow(CreateParams cp) {
1207                         IntPtr  WindowHandle;
1208                         IntPtr  ParentHandle;
1209                         Hwnd    hwnd;
1210
1211                         hwnd = new Hwnd();
1212
1213                         ParentHandle=cp.Parent;
1214
1215                         if ((ParentHandle==IntPtr.Zero) && (cp.Style & (int)(WindowStyles.WS_CHILD))!=0) {
1216                                 // We need to use our foster parent window until this poor child gets it's parent assigned
1217                                 ParentHandle = FosterParent;
1218                         }
1219
1220                         if ( ((cp.Style & (int)(WindowStyles.WS_CHILD | WindowStyles.WS_POPUP))==0) && ((cp.ExStyle & (int)WindowExStyles.WS_EX_APPWINDOW) == 0)) {
1221                                 // If we want to be hidden from the taskbar we need to be 'owned' by 
1222                                 // something not on the taskbar. FosterParent is just that
1223                                 ParentHandle = FosterParent;
1224                         }
1225
1226                         // Since we fake MDI dont tell Windows that this is a real MDI window
1227                         if ((cp.ExStyle & (int) WindowExStyles.WS_EX_MDICHILD) != 0) {
1228                                 SetMdiStyles (cp);
1229                         }
1230
1231                         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);
1232
1233                         if (WindowHandle==IntPtr.Zero) {
1234                                 uint error = Win32GetLastError();
1235
1236                                 Win32MessageBox(IntPtr.Zero, "Error : " + error.ToString(), "Failed to create window, class '"+cp.ClassName+"'", 0);
1237                         }
1238
1239                         hwnd.ClientWindow = WindowHandle;
1240
1241                         Win32SetWindowLong(WindowHandle, WindowLong.GWL_USERDATA, (uint)ThemeEngine.Current.DefaultControlBackColor.ToArgb());
1242
1243                         return WindowHandle;
1244                 }
1245
1246                 internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
1247                         CreateParams create_params = new CreateParams();
1248
1249                         create_params.Caption = "";
1250                         create_params.X = X;
1251                         create_params.Y = Y;
1252                         create_params.Width = Width;
1253                         create_params.Height = Height;
1254
1255                         create_params.ClassName=XplatUI.DefaultClassName;
1256                         create_params.ClassStyle = 0;
1257                         create_params.ExStyle=0;
1258                         create_params.Parent=IntPtr.Zero;
1259                         create_params.Param=0;
1260
1261                         return CreateWindow(create_params);
1262                 }
1263
1264                 internal override void DestroyWindow(IntPtr handle) {
1265                         Hwnd    hwnd;
1266
1267                         hwnd = Hwnd.ObjectFromHandle(handle);
1268                         Win32DestroyWindow(handle);
1269                         hwnd.Dispose();
1270                         return;
1271                 }
1272
1273                 internal override void SetWindowMinMax(IntPtr handle, Rectangle maximized, Size min, Size max) {
1274                         // We do nothing, Form has to handle WM_GETMINMAXINFO
1275                 }
1276
1277
1278                 internal override FormWindowState GetWindowState(IntPtr handle) {
1279                         uint style;
1280
1281                         style = Win32GetWindowLong(handle, WindowLong.GWL_STYLE);
1282                         if ((style & (uint)WindowStyles.WS_MAXIMIZE) != 0) {
1283                                 return FormWindowState.Maximized;
1284                         } else if ((style & (uint)WindowStyles.WS_MINIMIZE) != 0) {
1285                                 return FormWindowState.Minimized;
1286                         }
1287                         return FormWindowState.Normal;
1288                 }
1289
1290                 internal override void SetWindowState(IntPtr hwnd, FormWindowState state) {
1291                         switch(state) {
1292                                 case FormWindowState.Normal: {
1293                                         Win32ShowWindow(hwnd, WindowPlacementFlags.SW_RESTORE);
1294                                         return;
1295                                 }
1296
1297                                 case FormWindowState.Minimized: {
1298                                         Win32ShowWindow(hwnd, WindowPlacementFlags.SW_MINIMIZE);
1299                                         return;
1300                                 }
1301
1302                                 case FormWindowState.Maximized: {
1303                                         Win32ShowWindow(hwnd, WindowPlacementFlags.SW_MAXIMIZE);
1304                                         return;
1305                                 }
1306                         }
1307                 }
1308
1309                 internal override void SetWindowStyle(IntPtr handle, CreateParams cp) {
1310
1311                         if ((cp.ExStyle & (int) WindowExStyles.WS_EX_MDICHILD) != 0) {
1312                                 SetMdiStyles (cp);
1313                         }
1314
1315                         Win32SetWindowLong(handle, WindowLong.GWL_STYLE, (uint)cp.Style);
1316                         Win32SetWindowLong(handle, WindowLong.GWL_EXSTYLE, (uint)cp.ExStyle);
1317
1318                         if ((cp.ExStyle & (int) WindowExStyles.WS_EX_TOOLWINDOW) > 0)
1319                                 XplatUI.RequestNCRecalc (handle);
1320                 }
1321
1322                 internal override double GetWindowTransparency(IntPtr handle)
1323                 {
1324                         LayeredWindowAttributes lwa;
1325                         COLORREF clrRef;
1326                         byte alpha;
1327
1328                         if (0 == Win32GetLayeredWindowAttributes (handle, out clrRef, out alpha, out lwa))
1329                                 return 1.0;
1330
1331                         return ((double)alpha) / 255.0;
1332                 }
1333
1334                 internal override void SetWindowTransparency(IntPtr handle, double transparency, Color key) {
1335                         LayeredWindowAttributes lwa = LayeredWindowAttributes.LWA_ALPHA;
1336                         byte opacity = (byte)(transparency*255);
1337                         COLORREF clrRef = new COLORREF();
1338                         if (key != Color.Empty) {
1339                                 clrRef.R = key.R;
1340                                 clrRef.G = key.G;
1341                                 clrRef.B = key.B;
1342                                 lwa = (LayeredWindowAttributes)( (int)lwa | (int)LayeredWindowAttributes.LWA_COLORKEY );
1343                         }
1344                         RECT rc;
1345                         rc.right = 1000;
1346                         rc.bottom = 1000;
1347                         Win32SetLayeredWindowAttributes(handle, clrRef, opacity, lwa);
1348                 }
1349
1350                 TransparencySupport support;
1351                 bool queried_transparency_support;
1352                 internal override TransparencySupport SupportsTransparency() {
1353                         if (queried_transparency_support)
1354                                 return support;
1355
1356                         bool flag;
1357                         support = TransparencySupport.None;
1358
1359                         flag = true;
1360                         try {
1361                                 Win32SetLayeredWindowAttributes (IntPtr.Zero, new COLORREF (), 255, LayeredWindowAttributes.LWA_ALPHA);
1362                         }
1363                         catch (EntryPointNotFoundException) { flag = false; }
1364                         catch { /* swallow everything else */ }
1365
1366                         if (flag) support |= TransparencySupport.Set;
1367
1368                         flag = true;
1369                         try {
1370                                 LayeredWindowAttributes lwa;
1371                                 COLORREF clrRef;
1372                                 byte alpha;
1373
1374                                 Win32GetLayeredWindowAttributes (IntPtr.Zero, out clrRef, out alpha, out lwa);
1375                         }
1376                         catch (EntryPointNotFoundException) { flag = false; }
1377                         catch { /* swallow everything else */ }
1378
1379                         if (flag) support |= TransparencySupport.Get;
1380
1381                         queried_transparency_support = true;
1382                         return support;
1383                 }
1384
1385                 internal override void UpdateWindow(IntPtr handle) {
1386                         Win32UpdateWindow(handle);
1387                 }
1388
1389                 internal override PaintEventArgs PaintEventStart(IntPtr handle, bool client) {
1390                         IntPtr          hdc;
1391                         PAINTSTRUCT     ps;
1392                         PaintEventArgs  paint_event;
1393                         RECT            rect;
1394                         Rectangle       clip_rect;
1395                         Hwnd            hwnd;
1396
1397                         clip_rect = new Rectangle();
1398                         rect = new RECT();
1399                         ps = new PAINTSTRUCT();
1400
1401                         hwnd = Hwnd.ObjectFromHandle(handle);
1402
1403                         if (client) {
1404                                 if (Win32GetUpdateRect(handle, ref rect, false)) {
1405                                         hdc = Win32BeginPaint(handle, ref ps);
1406
1407                                         hwnd.drawing_stack.Push (ps);
1408
1409                                         clip_rect = new Rectangle(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right-ps.rcPaint.left, ps.rcPaint.bottom-ps.rcPaint.top);
1410                                 } else {
1411                                         hdc = Win32GetDC(handle);
1412                                         // FIXME: Add the DC to internal list
1413
1414                                         hwnd.drawing_stack.Push (null);
1415
1416                                         clip_rect = new Rectangle(rect.top, rect.left, rect.right-rect.left, rect.bottom-rect.top);
1417                                 }
1418                         } else {
1419                                 hdc = Win32GetWindowDC (handle);
1420
1421                                 hwnd.drawing_stack.Push (hdc);
1422
1423                                 // HACK this in for now
1424                                 Win32GetWindowRect (handle, out rect);
1425                                 clip_rect = new Rectangle(0, 0, rect.right-rect.left, rect.bottom-rect.top);
1426                         }
1427
1428                         Graphics dc = Graphics.FromHdc(hdc);
1429                         hwnd.drawing_stack.Push (dc);
1430
1431                         paint_event = new PaintEventArgs(dc, clip_rect);
1432
1433                         return paint_event;
1434                 }
1435
1436                 internal override void PaintEventEnd(IntPtr handle, bool client) {
1437                         Hwnd            hwnd;
1438
1439                         hwnd = Hwnd.ObjectFromHandle(handle);
1440
1441                         Graphics dc = (Graphics)hwnd.drawing_stack.Pop();
1442                         dc.Dispose ();
1443
1444                         if (client) {
1445                                 object o = hwnd.drawing_stack.Pop();
1446                                 if (o != null) {
1447                                         PAINTSTRUCT ps = (PAINTSTRUCT)o;
1448                                         Win32EndPaint(handle, ref ps);
1449                                 }
1450                         } else {
1451                                 IntPtr hdc = (IntPtr)hwnd.drawing_stack.Pop();
1452                                 Win32ReleaseDC(handle, hdc);
1453                         }
1454                 }
1455
1456
1457                 internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
1458                         Win32MoveWindow(handle, x, y, width, height, true);
1459                         return;
1460                 }
1461
1462                 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) {
1463                         IntPtr  parent;
1464                         RECT    rect;
1465                         POINT   pt;
1466
1467                         Win32GetWindowRect(handle, out rect);
1468                         width = rect.right - rect.left;
1469                         height = rect.bottom - rect.top;
1470
1471                         pt.x=rect.left;
1472                         pt.y=rect.top;
1473
1474                         parent = Win32GetParent(handle);
1475                         Win32ScreenToClient(parent, ref pt);
1476
1477                         x = pt.x;
1478                         y = pt.y;
1479
1480                         Win32GetClientRect(handle, out rect);
1481                         client_width = rect.right - rect.left;
1482                         client_height = rect.bottom - rect.top;
1483                         return;
1484                 }
1485
1486                 internal override void Activate(IntPtr handle) {
1487                         Win32SetActiveWindow(handle);
1488                 }
1489
1490                 internal override void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
1491                         RECT rect;
1492
1493                         rect.left=rc.Left;
1494                         rect.top=rc.Top;
1495                         rect.right=rc.Right;
1496                         rect.bottom=rc.Bottom;
1497                         Win32InvalidateRect(handle, ref rect, clear);
1498                 }
1499
1500
1501                 internal override void InvalidateNC (IntPtr handle)
1502                 {
1503                         // found this gem at
1504                         // http://www.dotnet247.com/247reference/msgs/58/292037.aspx
1505                         Win32SetWindowPos(handle, IntPtr.Zero,
1506                                           0, 0, 0, 0,
1507                                           SetWindowPosFlags.SWP_NOMOVE |
1508                                           SetWindowPosFlags.SWP_NOSIZE |
1509                                           SetWindowPosFlags.SWP_NOZORDER |
1510                                           SetWindowPosFlags.SWP_NOACTIVATE |
1511                                           SetWindowPosFlags.SWP_DRAWFRAME);
1512                 }
1513
1514                 internal override IntPtr DefWndProc(ref Message msg) {
1515                         msg.Result=Win32DefWindowProc(msg.HWnd, (Msg)msg.Msg, msg.WParam, msg.LParam);
1516                         return msg.Result;
1517                 }
1518
1519                 internal override void HandleException(Exception e) {
1520                         StackTrace st = new StackTrace(e);
1521                         Win32MessageBox(IntPtr.Zero, e.Message+st.ToString(), "Exception", 0);
1522                         Console.WriteLine("{0}{1}", e.Message, st.ToString());
1523                 }
1524
1525                 internal override void DoEvents() {
1526                         MSG msg = new MSG();
1527
1528                         if (override_cursor != IntPtr.Zero) {
1529                                 Cursor.Current = null;
1530                         }
1531
1532                         while (GetMessage(ref msg, IntPtr.Zero, 0, 0, false)) {
1533                                 XplatUI.TranslateMessage(ref msg);
1534                                 XplatUI.DispatchMessage(ref msg);
1535                         }
1536                 }
1537
1538                 internal override bool PeekMessage(Object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
1539                         return Win32PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
1540                 }
1541
1542                 internal override void PostQuitMessage(int exitCode) {
1543                         Win32PostQuitMessage(exitCode);
1544                 }
1545
1546                 internal override void RequestAdditionalWM_NCMessages(IntPtr hwnd, bool hover, bool leave)
1547                 {
1548                         if (wm_nc_registered == null)
1549                                 wm_nc_registered = new Hashtable ();
1550                                 
1551                         TMEFlags flags = TMEFlags.TME_NONCLIENT;
1552                         if (hover)
1553                                 flags |= TMEFlags.TME_HOVER;
1554                         if (leave)
1555                                 flags |= TMEFlags.TME_LEAVE;
1556
1557                         if (flags == TMEFlags.TME_NONCLIENT) {
1558                                 if (wm_nc_registered.Contains (hwnd)) {
1559                                         wm_nc_registered.Remove (hwnd);
1560                                 }
1561                         } else {
1562                                 if (!wm_nc_registered.Contains (hwnd)) {
1563                                         wm_nc_registered.Add (hwnd, flags);
1564                                 } else {
1565                                         wm_nc_registered [hwnd] = flags;
1566                                 }
1567                         }
1568                 }
1569
1570                 internal override void RequestNCRecalc(IntPtr handle) {
1571                         Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOOWNERZORDER | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE);
1572                 }
1573
1574                 internal override void ResetMouseHover(IntPtr handle) {
1575                         TRACKMOUSEEVENT tme;
1576
1577                         tme = new TRACKMOUSEEVENT();
1578                         tme.size = Marshal.SizeOf(tme);
1579                         tme.hWnd = handle;
1580                         tme.dwFlags = TMEFlags.TME_LEAVE | TMEFlags.TME_HOVER;
1581                         Win32TrackMouseEvent(ref tme);
1582                 }
1583
1584
1585                 internal override bool GetMessage(Object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
1586                         return GetMessage(ref msg, hWnd, wFilterMin, wFilterMax, true);
1587                 }
1588
1589                 private bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, bool blocking) {
1590                         bool            result;
1591
1592                         msg.refobject = 0;
1593                         if (RetrieveMessage(ref msg)) {
1594                                 return true;
1595                         }
1596
1597                         if (blocking) {
1598                                 result = Win32GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
1599                         } else {
1600                                 result = Win32PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, (uint)PeekMessageFlags.PM_REMOVE);
1601                                 if (!result) {
1602                                         return false;
1603                                 }
1604                         }
1605
1606                         // We need to fake WM_MOUSE_ENTER/WM_MOUSE_LEAVE
1607                         switch (msg.message) {
1608                                 case Msg.WM_LBUTTONDOWN: {
1609                                         mouse_state |= MouseButtons.Left;
1610                                         break;
1611                                 }
1612
1613                                 case Msg.WM_MBUTTONDOWN: {
1614                                         mouse_state |= MouseButtons.Middle;
1615                                         break;
1616                                 }
1617
1618                                 case Msg.WM_RBUTTONDOWN: {
1619                                         mouse_state |= MouseButtons.Right;
1620                                         break;
1621                                 }
1622
1623                                 case Msg.WM_LBUTTONUP: {
1624                                         mouse_state &= ~MouseButtons.Left;
1625                                         break;
1626                                 }
1627
1628                                 case Msg.WM_MBUTTONUP: {
1629                                         mouse_state &= ~MouseButtons.Middle;
1630                                         break;
1631                                 }
1632
1633                                 case Msg.WM_RBUTTONUP: {
1634                                         mouse_state &= ~MouseButtons.Right;
1635                                         break;
1636                                 }
1637
1638                                 case Msg.WM_ASYNC_MESSAGE: {
1639                                         XplatUIDriverSupport.ExecuteClientMessage((GCHandle)msg.lParam);
1640                                         break;
1641                                 }
1642
1643                                 case Msg.WM_MOUSEMOVE: {
1644                                         if (msg.hwnd != prev_mouse_hwnd) {
1645                                                 TRACKMOUSEEVENT tme;
1646
1647                                                 // The current message will be sent out next time around
1648                                                 StoreMessage(ref msg);
1649
1650                                                 // This is the message we want to send at this point
1651                                                 msg.message = Msg.WM_MOUSE_ENTER;
1652
1653                                                 prev_mouse_hwnd = msg.hwnd;
1654
1655                                                 tme = new TRACKMOUSEEVENT();
1656                                                 tme.size = Marshal.SizeOf(tme);
1657                                                 tme.hWnd = msg.hwnd;
1658                                                 tme.dwFlags = TMEFlags.TME_LEAVE | TMEFlags.TME_HOVER;
1659                                                 Win32TrackMouseEvent(ref tme);
1660                                                 return result;
1661                                         }
1662                                         break;
1663                                 }
1664
1665                                 case Msg.WM_NCMOUSEMOVE: {
1666                                         if (wm_nc_registered == null || !wm_nc_registered.Contains (msg.hwnd))
1667                                                 break;
1668                                                 
1669                                         TRACKMOUSEEVENT tme;
1670
1671                                         tme = new TRACKMOUSEEVENT ();
1672                                         tme.size = Marshal.SizeOf(tme);
1673                                         tme.hWnd = msg.hwnd;
1674                                         tme.dwFlags = (TMEFlags)wm_nc_registered[msg.hwnd];
1675                                         Win32TrackMouseEvent (ref tme);
1676                                         return result;
1677                                 }
1678
1679                                 case Msg.WM_DROPFILES: {
1680                                         return Win32DnD.HandleWMDropFiles(ref msg);
1681                                 }
1682
1683                                 case Msg.WM_MOUSELEAVE: {
1684                                         prev_mouse_hwnd = IntPtr.Zero;
1685                                         msg.message=Msg.WM_MOUSE_LEAVE;
1686                                         break;
1687                                 }
1688
1689                                 case Msg.WM_TIMER: {
1690                                         Timer timer=(Timer)timer_list[(int)msg.wParam];
1691
1692                                         if (timer != null) {
1693                                                 timer.FireTick();
1694                                         }
1695                                         break;
1696                                 }
1697                         }
1698
1699                         return result;
1700                 }
1701
1702                 internal override bool TranslateMessage(ref MSG msg) {
1703                         return Win32TranslateMessage(ref msg);
1704                 }
1705
1706                 internal override IntPtr DispatchMessage(ref MSG msg) {
1707                         return Win32DispatchMessage(ref msg);
1708                 }
1709
1710                 internal override bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
1711                         if (Top) {
1712                                 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOP, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1713                                 return true;
1714                         } else if (!Bottom) {
1715                                 Win32SetWindowPos(hWnd, AfterhWnd, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1716                         } else {
1717                                 Win32SetWindowPos(hWnd, (IntPtr)SetWindowPosZOrder.HWND_BOTTOM, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
1718                                 return true;
1719                         }
1720                         return false;
1721                 }
1722
1723                 internal override bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
1724                         if (Enabled) {
1725                                 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE);
1726                                 return true;
1727                         } else {
1728                                 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_NOTOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE);
1729                                 return true;
1730                         }
1731                 }
1732
1733                 internal override bool Text(IntPtr handle, string text) {
1734                         Win32SetWindowText(handle, text);
1735                         return true;
1736                 }
1737
1738                 internal override bool GetText(IntPtr handle, out string text) {
1739                         StringBuilder sb;
1740
1741                         sb = new StringBuilder(256);
1742                         Win32GetWindowText(handle, sb, sb.Capacity);
1743                         text = sb.ToString();
1744                         return true;
1745                 }
1746
1747                 internal override bool SetVisible (IntPtr handle, bool visible, bool activate)
1748                 {
1749                         if (visible) {
1750                                 if (Control.FromHandle (handle) is Form) {
1751                                         Form f;
1752
1753                                         f = (Form)Control.FromHandle (handle);
1754                                         WindowPlacementFlags flags = WindowPlacementFlags.SW_SHOWNORMAL;
1755                                         switch (f.WindowState) {
1756                                                 case FormWindowState.Normal: flags = WindowPlacementFlags.SW_SHOWNORMAL; break;
1757                                                 case FormWindowState.Minimized: flags = WindowPlacementFlags.SW_MINIMIZE; break;
1758                                                 case FormWindowState.Maximized: flags = WindowPlacementFlags.SW_MAXIMIZE; break;
1759                                         }
1760                                         
1761                                         if (Hwnd.ObjectFromHandle (handle).no_activate)
1762                                                 flags = WindowPlacementFlags.SW_SHOWNOACTIVATE;
1763                                                 
1764                                         Win32ShowWindow (handle, flags);
1765                                 }
1766                                 else {
1767                                         if (Hwnd.ObjectFromHandle (handle).no_activate)
1768                                                 Win32ShowWindow (handle, WindowPlacementFlags.SW_SHOWNOACTIVATE);
1769                                         else
1770                                                 Win32ShowWindow (handle, WindowPlacementFlags.SW_SHOWNORMAL);
1771                                 }
1772                         }
1773                         else {
1774                                 Win32ShowWindow (handle, WindowPlacementFlags.SW_HIDE);
1775                         }
1776                         return true;
1777                 }
1778
1779                 internal override bool IsEnabled(IntPtr handle) {
1780                         return IsWindowEnabled (handle);
1781                 }
1782                 
1783                 internal override bool IsVisible(IntPtr handle) {
1784                         return IsWindowVisible (handle);
1785                 }
1786
1787                 internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
1788                         Control c = Control.FromHandle (handle);
1789                         if (parent == IntPtr.Zero) {
1790                                 if (!(c is Form)) {
1791                                         Win32ShowWindow(handle, WindowPlacementFlags.SW_HIDE);
1792                                 }
1793                         }
1794                         else
1795                                 SetVisible (handle, c.is_visible, true);
1796                                 
1797                         if (parent == IntPtr.Zero)
1798                                 return Win32SetParent (handle, FosterParent);
1799                         else
1800                                 return Win32SetParent(handle, parent);
1801                 }
1802
1803                 // If we ever start using this, we should probably replace FosterParent with IntPtr.Zero
1804                 internal override IntPtr GetParent(IntPtr handle) {
1805                         return Win32GetParent(handle);
1806                 }
1807
1808                 internal override void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
1809                         grab_hwnd = hWnd;
1810                         Win32SetCapture(hWnd);
1811                         
1812                         if (ConfineToHwnd != IntPtr.Zero) {
1813                                 RECT window_rect;
1814                                 Win32GetWindowRect (ConfineToHwnd, out window_rect);
1815                                 Win32GetClipCursor (out clipped_cursor_rect);
1816                                 Win32ClipCursor (ref window_rect);
1817                         }
1818                 }
1819
1820                 internal override void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
1821                         hWnd = grab_hwnd;
1822                         GrabConfined = grab_confined;
1823                         GrabArea = grab_area;
1824                 }
1825
1826                 internal override void UngrabWindow(IntPtr hWnd) {
1827                         if (!(clipped_cursor_rect.top == 0 && clipped_cursor_rect.bottom == 0 && clipped_cursor_rect.left == 0 && clipped_cursor_rect.right == 0)) {
1828                                 Win32ClipCursor (ref clipped_cursor_rect);
1829                                 clipped_cursor_rect = new RECT ();
1830                         }
1831                         
1832                         Win32ReleaseCapture();
1833                         grab_hwnd = IntPtr.Zero;
1834                 }
1835
1836                 internal override bool CalculateWindowRect(ref Rectangle ClientRect, int Style, int ExStyle, Menu menu, out Rectangle WindowRect) {
1837                         RECT    rect;
1838
1839                         rect.left=ClientRect.Left;
1840                         rect.top=ClientRect.Top;
1841                         rect.right=ClientRect.Right;
1842                         rect.bottom=ClientRect.Bottom;
1843
1844                         if (!Win32AdjustWindowRectEx(ref rect, Style, menu != null, ExStyle)) {
1845                                 WindowRect = new Rectangle(ClientRect.Left, ClientRect.Top, ClientRect.Width, ClientRect.Height);
1846                                 return false;
1847                         }
1848
1849                         WindowRect = new Rectangle(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
1850                         return true;
1851                 }
1852
1853                 internal override void SetCursor(IntPtr window, IntPtr cursor) {
1854                         Win32SetCursor(cursor);
1855                         return;
1856                 }
1857
1858                 internal override void ShowCursor(bool show) {
1859                         Win32ShowCursor(show);
1860                 }
1861
1862                 internal override void OverrideCursor(IntPtr cursor) {
1863                         Win32SetCursor(cursor);
1864                 }
1865
1866                 internal override IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
1867                         IntPtr  cursor;
1868                         Bitmap  cursor_bitmap;
1869                         Bitmap  cursor_mask;
1870                         Byte[]  cursor_bits;
1871                         Byte[]  mask_bits;
1872                         Color   pixel;
1873                         int     width;
1874                         int     height;
1875
1876                         // Win32 only allows creation cursors of a certain size
1877                         if ((bitmap.Width != Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)) || (bitmap.Width != Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR))) {
1878                                 cursor_bitmap = new Bitmap(bitmap, new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)));
1879                                 cursor_mask = new Bitmap(mask, new Size(Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR), Win32GetSystemMetrics(SystemMetrics.SM_CXCURSOR)));
1880                         } else {
1881                                 cursor_bitmap = bitmap;
1882                                 cursor_mask = mask;
1883                         }
1884
1885                         width = cursor_bitmap.Width;
1886                         height = cursor_bitmap.Height;
1887
1888                         cursor_bits = new Byte[(width / 8) * height];
1889                         mask_bits = new Byte[(width / 8) * height];
1890
1891                         for (int y = 0; y < height; y++) {
1892                                 for (int x = 0; x < width; x++) {
1893                                         pixel = cursor_bitmap.GetPixel(x, y);
1894
1895                                         if (pixel == cursor_pixel) {
1896                                                 cursor_bits[y * width / 8 + x / 8] |= (byte)(0x80 >> (x % 8));
1897                                         }
1898
1899                                         pixel = cursor_mask.GetPixel(x, y);
1900
1901                                         if (pixel == mask_pixel) {
1902                                                 mask_bits[y * width / 8 + x / 8] |= (byte)(0x80 >> (x % 8));
1903                                         }
1904                                 }
1905                         }
1906
1907                         cursor = Win32CreateCursor(IntPtr.Zero, xHotSpot, yHotSpot, width, height, mask_bits, cursor_bits);
1908
1909                         return cursor;
1910                 }
1911
1912                 [MonoTODO("Define the missing cursors")]
1913                 internal override IntPtr DefineStdCursor(StdCursor id) {
1914                         switch(id) {
1915                                 case StdCursor.AppStarting:     return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_APPSTARTING);
1916                                 case StdCursor.Arrow:           return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
1917                                 case StdCursor.Cross:           return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_CROSS);
1918                                 case StdCursor.Default:         return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
1919                                 case StdCursor.Hand:            return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_HAND);
1920                                 case StdCursor.Help:            return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_HELP);
1921                                 case StdCursor.HSplit:          return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1922                                 case StdCursor.IBeam:           return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_IBEAM);
1923                                 case StdCursor.No:              return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_NO);
1924                                 case StdCursor.NoMove2D:        return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1925                                 case StdCursor.NoMoveHoriz:     return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1926                                 case StdCursor.NoMoveVert:      return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1927                                 case StdCursor.PanEast:         return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1928                                 case StdCursor.PanNE:           return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1929                                 case StdCursor.PanNorth:        return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1930                                 case StdCursor.PanNW:           return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1931                                 case StdCursor.PanSE:           return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1932                                 case StdCursor.PanSouth:        return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1933                                 case StdCursor.PanSW:           return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1934                                 case StdCursor.PanWest:         return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1935                                 case StdCursor.SizeAll:         return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZEALL);
1936                                 case StdCursor.SizeNESW:        return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENESW);
1937                                 case StdCursor.SizeNS:          return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENS);
1938                                 case StdCursor.SizeNWSE:        return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZENWSE);
1939                                 case StdCursor.SizeWE:          return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_SIZEWE);
1940                                 case StdCursor.UpArrow:         return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_UPARROW);
1941                                 case StdCursor.VSplit:          return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);          // FIXME
1942                                 case StdCursor.WaitCursor:      return Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_WAIT);
1943                         }
1944                         throw new NotImplementedException ();
1945                 }
1946
1947                 internal override void DestroyCursor(IntPtr cursor) {
1948                         if ((cursor.ToInt32() < (int)LoadCursorType.First) || (cursor.ToInt32() > (int)LoadCursorType.Last)) {
1949                                 Win32DestroyCursor(cursor);
1950                         }
1951                 }
1952
1953                 [MonoTODO]
1954                 internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
1955                         width = 20;
1956                         height = 20;
1957                         hotspot_x = 0;
1958                         hotspot_y = 0;
1959                 }
1960
1961                 internal override void SetCursorPos(IntPtr handle, int x, int y) {
1962                         Win32SetCursorPos(x, y);
1963                 }
1964
1965                 internal override Region GetClipRegion(IntPtr hwnd) {
1966                         Region region;
1967
1968                         region = new Region();
1969
1970                         Win32GetWindowRgn(hwnd, region.GetHrgn(Graphics.FromHwnd(hwnd)));
1971
1972                         return region;
1973                 }
1974
1975                 internal override void SetClipRegion(IntPtr hwnd, Region region) {
1976                         Win32SetWindowRgn(hwnd, region.GetHrgn(Graphics.FromHwnd(hwnd)), true);
1977                 }
1978
1979                 internal override void EnableWindow(IntPtr handle, bool Enable) {
1980                         Win32EnableWindow(handle, Enable);
1981                 }
1982
1983                 internal override void EndLoop(System.Threading.Thread thread) {
1984                         // Nothing to do
1985                 }
1986
1987                 internal override object StartLoop(System.Threading.Thread thread) {
1988                         return null;
1989                 }
1990
1991                 internal override void SetModal(IntPtr handle, bool Modal) {
1992                         // we do nothing on Win32
1993                 }
1994
1995                 internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
1996                         POINT   pt;
1997
1998                         Win32GetCursorPos(out pt);
1999
2000                         if (handle!=IntPtr.Zero) {
2001                                 Win32ScreenToClient(handle, ref pt);
2002                         }
2003
2004                         x=pt.x;
2005                         y=pt.y;
2006                 }
2007
2008                 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y)
2009                 {
2010                         POINT pnt = new POINT();                        
2011
2012                         pnt.x = x;
2013                         pnt.y = y;
2014                         Win32ScreenToClient (handle, ref pnt);
2015
2016                         x = pnt.x;
2017                         y = pnt.y;
2018                 }
2019
2020                 internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) {                    
2021                         POINT   pnt = new POINT();                      
2022
2023                         pnt.x = x;
2024                         pnt.y = y;
2025
2026                         Win32ClientToScreen(handle, ref pnt);
2027
2028                         x = pnt.x;
2029                         y = pnt.y;
2030                 }
2031
2032                 internal override void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
2033                         RECT    rect;
2034  
2035                         Win32GetWindowRect(handle, out rect);
2036                         x -= rect.left + SystemInformation.FrameBorderSize.Width;
2037                         y -= rect.top + SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight;
2038                         return;
2039                 }
2040   
2041                 internal override void MenuToScreen(IntPtr handle, ref int x, ref int y) {                      
2042                         RECT    rect;
2043  
2044                         Win32GetWindowRect(handle, out rect);
2045                         x += rect.left + SystemInformation.FrameBorderSize.Width;
2046                         y += rect.top + SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight;
2047                         return;
2048                 }
2049   
2050                 internal override void SendAsyncMethod (AsyncMethodData method)
2051                 {
2052                         Win32PostMessage(FosterParent, Msg.WM_ASYNC_MESSAGE, IntPtr.Zero, (IntPtr)GCHandle.Alloc (method));
2053                 }
2054
2055                 internal override void SetTimer (Timer timer)
2056                 {
2057                         int     index;
2058
2059                         index = timer.GetHashCode();
2060
2061                         lock (timer_list) {
2062                                 timer_list[index]=timer;
2063                         }
2064
2065                         Win32SetTimer(FosterParent, index, (uint)timer.Interval, IntPtr.Zero);
2066                 }
2067
2068                 internal override void KillTimer (Timer timer)
2069                 {
2070                         int     index;
2071
2072                         index = timer.GetHashCode();
2073
2074                         Win32KillTimer(FosterParent, index);
2075
2076                         lock (timer_list) {
2077                                 timer_list.Remove(index);
2078                         }
2079                 }
2080
2081                 private void SetMdiStyles (CreateParams cp)
2082                 {
2083                         cp.Style = (int)WindowStyles.WS_CHILD | (int)WindowStyles.WS_CLIPCHILDREN | (int)WindowStyles.WS_CLIPSIBLINGS;
2084                         cp.ExStyle = 0;
2085                 }
2086         
2087                 internal override void CreateCaret(IntPtr hwnd, int width, int height) {
2088                         Win32CreateCaret(hwnd, IntPtr.Zero, width, height);
2089                         caret_visible = false;
2090                 }
2091
2092                 internal override void DestroyCaret(IntPtr hwnd) {
2093                         Win32DestroyCaret();
2094                 }
2095
2096                 internal override void SetCaretPos(IntPtr hwnd, int x, int y) {
2097                         Win32SetCaretPos(x, y);
2098                 }
2099
2100                 internal override void CaretVisible(IntPtr hwnd, bool visible) {
2101                         if (visible) {
2102                                 if (!caret_visible) {
2103                                         Win32ShowCaret(hwnd);
2104                                         caret_visible = true;
2105                                 }
2106                         } else {
2107                                 if (caret_visible) {
2108                                         Win32HideCaret(hwnd);
2109                                         caret_visible = false;
2110                                 }
2111                         }
2112                 }
2113
2114                 internal override IntPtr GetFocus() {
2115                         return Win32GetFocus();
2116                 }
2117
2118                 internal override void SetFocus(IntPtr hwnd) {
2119                         Win32SetFocus(hwnd);
2120                 }
2121
2122                 internal override IntPtr GetActive() {
2123                         return Win32GetActiveWindow();
2124                 }
2125
2126                 internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
2127                         IntPtr          dc;
2128                         TEXTMETRIC      tm;
2129
2130                         tm = new TEXTMETRIC();
2131
2132                         dc = Win32GetDC(IntPtr.Zero);
2133                         Win32SelectObject(dc, font.ToHfont());
2134                         if (Win32GetTextMetrics(dc, ref tm) == false) {
2135                                 Win32ReleaseDC(IntPtr.Zero, dc);
2136                                 ascent = 0;
2137                                 descent = 0;
2138                                 return false;
2139                         }
2140                         Win32ReleaseDC(IntPtr.Zero, dc);
2141
2142                         ascent = tm.tmAscent;
2143                         descent = tm.tmDescent;
2144
2145                         return true;
2146                 }
2147
2148                 internal override void ScrollWindow(IntPtr hwnd, Rectangle rectangle, int XAmount, int YAmount, bool with_children) {
2149                         RECT    rect;
2150
2151                         rect = new RECT();
2152                         rect.left = rectangle.X;
2153                         rect.top = rectangle.Y;
2154                         rect.right = rectangle.Right;
2155                         rect.bottom = rectangle.Bottom;
2156
2157                         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));
2158                         Win32UpdateWindow(hwnd);
2159                 }
2160
2161                 internal override void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount, bool with_children) {
2162                         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));
2163                 }
2164
2165                 internal override bool SystrayAdd(IntPtr hwnd, string tip, Icon icon, out ToolTip tt) {
2166                         NOTIFYICONDATA  nid;
2167
2168                         nid = new NOTIFYICONDATA();
2169
2170                         nid.cbSize = (uint)Marshal.SizeOf(nid);
2171                         nid.hWnd = hwnd;
2172                         nid.uID = 1;
2173                         nid.uCallbackMessage = (uint)Msg.WM_USER;
2174                         nid.uFlags = NotifyIconFlags.NIF_MESSAGE;
2175
2176                         if (tip != null) {       
2177                                 nid.szTip = tip;
2178                                 nid.uFlags |= NotifyIconFlags.NIF_TIP;
2179                         }
2180
2181                         if (icon != null) {
2182                                 nid.hIcon = icon.Handle;
2183                                 nid.uFlags |= NotifyIconFlags.NIF_ICON;
2184                         }
2185
2186                         tt = null;
2187
2188                         return Win32Shell_NotifyIcon(NotifyIconMessage.NIM_ADD, ref nid);
2189                 }
2190
2191                 internal override bool SystrayChange(IntPtr hwnd, string tip, Icon icon, ref ToolTip tt) {
2192                         NOTIFYICONDATA  nid;
2193
2194                         nid = new NOTIFYICONDATA();
2195
2196                         nid.cbSize = (uint)Marshal.SizeOf(nid);
2197                         nid.hIcon = icon.Handle;
2198                         nid.hWnd = hwnd;
2199                         nid.uID = 1;
2200                         nid.uCallbackMessage = (uint)Msg.WM_USER;
2201                         nid.uFlags = NotifyIconFlags.NIF_MESSAGE;
2202
2203                         if (tip != null) {
2204                                 nid.szTip = tip;
2205                                 nid.uFlags |= NotifyIconFlags.NIF_TIP;
2206                         }
2207
2208                         if (icon != null) {
2209                                 nid.hIcon = icon.Handle;
2210                                 nid.uFlags |= NotifyIconFlags.NIF_ICON;
2211                         }
2212
2213                         return Win32Shell_NotifyIcon(NotifyIconMessage.NIM_MODIFY, ref nid);
2214                 }
2215
2216                 internal override void SystrayRemove(IntPtr hwnd, ref ToolTip tt) {
2217                         NOTIFYICONDATA  nid;
2218
2219                         nid = new NOTIFYICONDATA();
2220
2221                         nid.cbSize = (uint)Marshal.SizeOf(nid);
2222                         nid.hWnd = hwnd;
2223                         nid.uID = 1;
2224                         nid.uFlags = 0;
2225
2226                         Win32Shell_NotifyIcon(NotifyIconMessage.NIM_DELETE, ref nid);
2227                 }
2228
2229
2230                 internal override void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
2231                         // Nothing to do on Win32
2232                 }
2233
2234                 internal override void SetMenu(IntPtr handle, Menu menu) {
2235                         // Trigger WM_NCCALC
2236                         Win32SetWindowPos(handle, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_FRAMECHANGED | SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
2237                 }
2238
2239                 internal override Point GetMenuOrigin(IntPtr handle) {
2240                         return new Point(SystemInformation.FrameBorderSize.Width, SystemInformation.FrameBorderSize.Height + ThemeEngine.Current.CaptionHeight);
2241                 }
2242
2243                 internal override void SetIcon(IntPtr hwnd, Icon icon) {
2244                         Win32SendMessage(hwnd, Msg.WM_SETICON, (IntPtr)1, icon == null ? IntPtr.Zero : icon.Handle);    // 1 = large icon (0 would be small)
2245                 }
2246
2247                 internal override void ClipboardClose(IntPtr handle) {
2248                         if (handle != clip_magic) {
2249                                 throw new ArgumentException("handle is not a valid clipboard handle");
2250                         }
2251                         Win32CloseClipboard();
2252                 }
2253
2254                 internal override int ClipboardGetID(IntPtr handle, string format) {
2255                         if (handle != clip_magic) {
2256                                 throw new ArgumentException("handle is not a valid clipboard handle");
2257                         }
2258                         if (format == "Text" ) return 1;
2259                         else if (format == "Bitmap" ) return 2;
2260                         else if (format == "MetaFilePict" ) return 3;
2261                         else if (format == "SymbolicLink" ) return 4;
2262                         else if (format == "DataInterchangeFormat" ) return 5;
2263                         else if (format == "Tiff" ) return 6;
2264                         else if (format == "OEMText" ) return 7;
2265                         else if (format == "DeviceIndependentBitmap" ) return 8;
2266                         else if (format == "Palette" ) return 9;
2267                         else if (format == "PenData" ) return 10;
2268                         else if (format == "RiffAudio" ) return 11;
2269                         else if (format == "WaveAudio" ) return 12;
2270                         else if (format == "UnicodeText" ) return 13;
2271                         else if (format == "EnhancedMetafile" ) return 14;
2272                         else if (format == "FileDrop" ) return 15;
2273                         else if (format == "Locale" ) return 16;
2274
2275                         return (int)Win32RegisterClipboardFormat(format);
2276                 }
2277
2278                 internal override IntPtr ClipboardOpen(bool primary_selection) {
2279                         // Win32 does not have primary selection
2280                         Win32OpenClipboard(FosterParent);
2281                         return clip_magic;
2282                 }
2283
2284                 internal override int[] ClipboardAvailableFormats(IntPtr handle) {
2285                         uint    format;
2286                         int[]   result;
2287                         int     count;
2288
2289                         if (handle != clip_magic) {
2290                                 return null;
2291                         }
2292
2293                         // Count first
2294                         count = 0;
2295                         format = 0;
2296                         do {
2297                                 format = Win32EnumClipboardFormats(format);
2298                                 if (format != 0) {
2299                                         count++;
2300                                 }
2301                         } while (format != 0);
2302
2303                         // Now assign
2304                         result = new int[count];
2305                         count = 0;
2306                         format = 0;
2307                         do {
2308                                 format = Win32EnumClipboardFormats(format);
2309                                 if (format != 0) {
2310                                         result[count++] = (int)format;
2311                                 }
2312                         } while (format != 0);
2313
2314                         return result;
2315                 }
2316
2317
2318                 internal override object ClipboardRetrieve(IntPtr handle, int type, XplatUI.ClipboardToObject converter) {
2319                         IntPtr  hmem;
2320                         IntPtr  data;
2321                         object  obj;
2322
2323                         if (handle != clip_magic) {
2324                                 throw new ArgumentException("handle is not a valid clipboard handle");
2325                         }
2326
2327                         hmem = Win32GetClipboardData((uint)type);
2328                         if (hmem == IntPtr.Zero) {
2329                                 return null;
2330                         }
2331
2332                         data = Win32GlobalLock(hmem);
2333                         if (data == IntPtr.Zero) {
2334                                 uint error = Win32GetLastError();
2335                                 Console.WriteLine("Error: {0}", error);
2336                                 return null;
2337                         }
2338
2339                         obj = null;
2340
2341                         if (type == DataFormats.GetFormat(DataFormats.Rtf).Id) {
2342                                 obj = AnsiToString(data);
2343                         } else switch ((ClipboardFormats)type) {
2344                                 case ClipboardFormats.CF_TEXT: {
2345                                         obj = AnsiToString(data);
2346                                         break;
2347                                 }
2348
2349                                 case ClipboardFormats.CF_DIB: {
2350                                         obj = DIBtoImage(data);
2351                                         break;
2352                                 }
2353
2354                                 case ClipboardFormats.CF_UNICODETEXT: {
2355                                         obj = UnicodeToString(data);
2356                                         break;
2357                                 }
2358
2359                                 default: {
2360                                         if (converter != null && !converter(type, data, out obj)) {
2361                                                 obj = null;
2362                                         }
2363                                         break;
2364                                 }
2365                         }
2366                         Win32GlobalUnlock(hmem);
2367
2368                         return obj;
2369
2370                 }
2371
2372                 internal override void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
2373                         byte[]  data;
2374                         IntPtr  hmem;
2375                         IntPtr  hmem_ptr;
2376
2377                         if (handle != clip_magic) {
2378                                 throw new ArgumentException("handle is not a valid clipboard handle");
2379                         }
2380
2381                         if (obj == null) {
2382                                 // Just clear it
2383                                 Win32EmptyClipboard();
2384                                 return;
2385                         }
2386
2387                         if (type == -1) {
2388                                 if (obj is string) {
2389                                         type = (int)ClipboardFormats.CF_UNICODETEXT;
2390                                 } else if (obj is Image) {
2391                                         type = (int)ClipboardFormats.CF_DIB;
2392                                 }
2393                         }
2394
2395                         if (type == DataFormats.GetFormat(DataFormats.Rtf).Id) {
2396                                 hmem = Marshal.StringToHGlobalAnsi((string)obj);
2397                                 Win32SetClipboardData((uint)type, hmem);
2398                                 return;
2399                         } else switch((ClipboardFormats)type) {
2400                                 case ClipboardFormats.CF_UNICODETEXT: {
2401                                         hmem = Marshal.StringToHGlobalUni((string)obj);
2402                                         Win32SetClipboardData((uint)type, hmem);
2403                                         return;
2404                                 }
2405
2406                                 case ClipboardFormats.CF_TEXT: {
2407                                         hmem = Marshal.StringToHGlobalAnsi((string)obj);
2408                                         Win32SetClipboardData((uint)type, hmem);
2409                                         return;
2410                                 }
2411
2412                                 case ClipboardFormats.CF_BITMAP:
2413                                 case ClipboardFormats.CF_DIB: {
2414                                         data = ImageToDIB((Image)obj);
2415
2416                                         hmem = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
2417                                         hmem_ptr = Win32GlobalLock(hmem);
2418                                         Marshal.Copy(data, 0, hmem_ptr, data.Length);
2419                                         Win32GlobalUnlock(hmem);
2420                                         Win32SetClipboardData((uint)ClipboardFormats.CF_DIB, hmem);
2421                                         return;
2422                                 }
2423
2424                                 default: {
2425                                         if (converter != null && converter(ref type, obj, out data)) {
2426                                                 hmem = Win32GlobalAlloc(GAllocFlags.GMEM_MOVEABLE | GAllocFlags.GMEM_DDESHARE, data.Length);
2427                                                 hmem_ptr = Win32GlobalLock(hmem);
2428                                                 Marshal.Copy(data, 0, hmem_ptr, data.Length);
2429                                                 Win32GlobalUnlock(hmem);
2430                                                 Win32SetClipboardData((uint)type, hmem);
2431                                         }
2432                                         return;
2433                                 }
2434                         }
2435                 }
2436
2437                 internal override void SetAllowDrop(IntPtr hwnd, bool allowed) {
2438                         if (allowed) {
2439                                 Win32DnD.RegisterDropTarget(hwnd);
2440                         } else {
2441                                 Win32DnD.UnregisterDropTarget(hwnd);
2442                         }
2443                 }
2444
2445                 internal override DragDropEffects StartDrag(IntPtr hwnd, object data, DragDropEffects allowedEffects) {
2446                         return Win32DnD.StartDrag(hwnd, data, allowedEffects);
2447                 }
2448
2449                 // XXX this doesn't work at all for FrameStyle.Dashed - it draws like Thick, and in the Thick case
2450                 // the corners are drawn incorrectly.
2451                 internal override void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
2452                         IntPtr          hdc;
2453                         IntPtr          pen;
2454                         IntPtr          oldpen;
2455                         COLORREF        clrRef = new COLORREF();
2456
2457                         // If we want the standard hatch pattern we would
2458                         // need to create a brush
2459
2460                         clrRef.R = backColor.R;
2461                         clrRef.G = backColor.G;
2462                         clrRef.B = backColor.B;
2463
2464                         // Grab a pen
2465                         pen = Win32CreatePen (style == FrameStyle.Thick ? PenStyle.PS_SOLID : PenStyle.PS_DASH,
2466                                               style == FrameStyle.Thick ? 4 : 2, ref clrRef);
2467
2468                         hdc = Win32GetDC(IntPtr.Zero);
2469                         Win32SetROP2(hdc, ROP2DrawMode.R2_NOT);
2470                         oldpen = Win32SelectObject(hdc, pen);
2471
2472                         Win32MoveToEx(hdc, rectangle.Left, rectangle.Top, IntPtr.Zero);
2473                         if ((rectangle.Width > 0) && (rectangle.Height > 0)) {
2474                                 Win32LineTo(hdc, rectangle.Right, rectangle.Top);
2475                                 Win32LineTo(hdc, rectangle.Right, rectangle.Bottom);
2476                                 Win32LineTo(hdc, rectangle.Left, rectangle.Bottom);
2477                                 Win32LineTo(hdc, rectangle.Left, rectangle.Top);
2478                         } else {
2479                                 if (rectangle.Width > 0) {
2480                                         Win32LineTo(hdc, rectangle.Right, rectangle.Top);
2481                                 } else {
2482                                         Win32LineTo(hdc, rectangle.Left, rectangle.Bottom);
2483                                 }
2484                         }
2485
2486                         Win32SelectObject(hdc, oldpen);
2487                         Win32DeleteObject(pen);
2488
2489                         Win32ReleaseDC(IntPtr.Zero, hdc);
2490                 }
2491
2492                 internal override void DrawReversibleLine(Point start, Point end, Color backColor) {
2493                         IntPtr          hdc;
2494                         IntPtr          pen;
2495                         IntPtr          oldpen;
2496                         POINT           pt;
2497                         COLORREF        clrRef = new COLORREF();
2498
2499                         pt = new POINT();
2500                         pt.x = 0;
2501                         pt.y = 0;
2502                         Win32ClientToScreen(IntPtr.Zero, ref pt);
2503
2504                         // If we want the standard hatch pattern we would
2505                         // need to create a brush
2506
2507                         clrRef.R = backColor.R;
2508                         clrRef.G = backColor.G;
2509                         clrRef.B = backColor.B;
2510
2511                         // Grab a pen
2512                         pen = Win32CreatePen(PenStyle.PS_SOLID, 1, ref clrRef);
2513
2514                         hdc = Win32GetDC(IntPtr.Zero);
2515                         Win32SetROP2(hdc, ROP2DrawMode.R2_NOT);
2516                         oldpen = Win32SelectObject(hdc, pen);
2517
2518                         Win32MoveToEx(hdc, pt.x + start.X, pt.y + start.Y, IntPtr.Zero);
2519                         Win32LineTo(hdc, pt.x + end.X, pt.y + end.Y);
2520
2521                         Win32SelectObject(hdc, oldpen);
2522                         Win32DeleteObject(pen);
2523
2524                         Win32ReleaseDC(IntPtr.Zero, hdc);
2525                 }
2526
2527                 internal override void FillReversibleRectangle (Rectangle rectangle, Color backColor)
2528                 {
2529                         RECT    rect;
2530
2531                         rect = new RECT();
2532                         rect.left = rectangle.Left;
2533                         rect.top = rectangle.Top;
2534                         rect.right = rectangle.Right;
2535                         rect.bottom = rectangle.Bottom;
2536
2537                         IntPtr          hdc;
2538                         IntPtr          brush;
2539                         IntPtr          oldbrush;
2540                         COLORREF        clrRef = new COLORREF();
2541
2542                         clrRef.R = backColor.R;
2543                         clrRef.G = backColor.G;
2544                         clrRef.B = backColor.B;
2545
2546                         // Grab a brush
2547                         brush = Win32CreateSolidBrush (clrRef);
2548
2549                         hdc = Win32GetDC(IntPtr.Zero);
2550                         oldbrush = Win32SelectObject(hdc, brush);
2551
2552                         Win32PatBlt (hdc, rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height, PatBltRop.DSTINVERT);
2553
2554                         Win32SelectObject(hdc, oldbrush);
2555                         Win32DeleteObject(brush);
2556
2557                         Win32ReleaseDC(IntPtr.Zero, hdc);
2558                 }
2559
2560                 internal override void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
2561                         IntPtr          hdc;
2562                         IntPtr          pen;
2563                         IntPtr          oldpen;
2564                         POINT           pt;
2565
2566                         pt = new POINT();
2567                         pt.x = 0;
2568                         pt.y = 0;
2569                         Win32ClientToScreen(handle, ref pt);
2570
2571                         // If we want the standard hatch pattern we would
2572                         // need to create a brush
2573
2574                         // Grab a pen
2575                         pen = Win32CreatePen(PenStyle.PS_SOLID, line_width, IntPtr.Zero);
2576
2577                         hdc = Win32GetDC(IntPtr.Zero);
2578                         Win32SetROP2(hdc, ROP2DrawMode.R2_NOT);
2579                         oldpen = Win32SelectObject(hdc, pen);
2580
2581                         Control c = Control.FromHandle (handle);
2582                         if (c != null) {
2583                                 RECT window_rect;
2584                                 Win32GetWindowRect (c.Handle, out window_rect);
2585                                 Region r = new Region (new Rectangle(window_rect.left, window_rect.top, window_rect.right - window_rect.left, window_rect.bottom - window_rect.top));
2586                                 Win32ExtSelectClipRgn(hdc, r.GetHrgn (Graphics.FromHdc (hdc)), (int) ClipCombineMode.RGN_AND);
2587                         }
2588
2589                         Win32MoveToEx(hdc, pt.x + rect.Left, pt.y + rect.Top, IntPtr.Zero);
2590                         if ((rect.Width > 0) && (rect.Height > 0)) {
2591                                 Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Top);
2592                                 Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Bottom);
2593                                 Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Bottom);
2594                                 Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Top);
2595                         } else {
2596                                 if (rect.Width > 0) {
2597                                         Win32LineTo(hdc, pt.x + rect.Right, pt.y + rect.Top);
2598                                 } else {
2599                                         Win32LineTo(hdc, pt.x + rect.Left, pt.y + rect.Bottom);
2600                                 }
2601                         }
2602
2603                         Win32SelectObject(hdc, oldpen);
2604                         Win32DeleteObject(pen);
2605                         if (c != null)
2606                                 Win32ExtSelectClipRgn(hdc, IntPtr.Zero, (int) ClipCombineMode.RGN_COPY);
2607
2608                         Win32ReleaseDC(IntPtr.Zero, hdc);
2609                 }
2610
2611                 internal override SizeF GetAutoScaleSize(Font font) {
2612                         Graphics        g;
2613                         float           width;
2614                         string          magic_string = "The quick brown fox jumped over the lazy dog.";
2615                         double          magic_number = 44.549996948242189;
2616
2617                         g = Graphics.FromHwnd(FosterParent);
2618
2619                         width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
2620                         return new SizeF(width, font.Height);
2621                 }
2622
2623                 internal override IntPtr SendMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
2624                         return Win32SendMessage(hwnd, message, wParam, lParam);
2625                 }
2626
2627                 internal override bool PostMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
2628                         return Win32PostMessage(hwnd, message, wParam, lParam);
2629                 }
2630
2631                 internal override int SendInput (IntPtr hwnd, Queue keys) {
2632                         INPUT[] inputs = new INPUT[keys.Count];
2633                         const Int32 INPUT_KEYBOARD = 1;
2634                         uint returns = 0;
2635                         int i = 0;
2636                         while (keys.Count > 0) {
2637                                 MSG msg = (MSG)keys.Dequeue();
2638
2639                                 
2640                                 inputs[i].ki.wScan = 0;
2641                                 inputs[i].ki.time = 0;
2642                                 inputs[i].ki.dwFlags = (Int32)(msg.message == Msg.WM_KEYUP ? InputFlags.KEYEVENTF_KEYUP : 0);
2643                                 inputs[i].ki.wVk = (short)msg.wParam.ToInt32();
2644                                 inputs[i].type = INPUT_KEYBOARD;
2645                                 i++;
2646                         }
2647                         returns = Win32SendInput((UInt32)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
2648
2649                         return (int) returns;
2650                 }
2651
2652                 internal override int KeyboardSpeed {
2653                         get {
2654                                 Console.WriteLine ("KeyboardSpeed: need to query Windows");
2655
2656                                 //
2657                                 // Return values range from 0 to 31 which map to 2.5 to 30 repetitions per second.
2658                                 //
2659                                 return 0;
2660                         }
2661                 }
2662
2663                 internal override int KeyboardDelay {
2664                         get {
2665                                 Console.WriteLine ("KeyboardDelay: need to query Windows");
2666
2667                                 //
2668                                 // Return values must range from 0 to 4, 0 meaning 250ms,
2669                                 // and 4 meaning 1000 ms.
2670                                 //
2671                                 return 1;
2672                         }
2673                 }
2674
2675                 private class WinBuffer
2676                 {
2677                         public IntPtr hdc;
2678                         public IntPtr bitmap;
2679
2680                         public WinBuffer (IntPtr hdc, IntPtr bitmap)
2681                         {
2682                                 this.hdc = hdc;
2683                                 this.bitmap = bitmap;
2684                         }
2685                 }
2686
2687                 internal override void CreateOffscreenDrawable (IntPtr handle, int width, int height, out object offscreen_drawable)
2688                 {
2689                         Graphics destG = Graphics.FromHwnd (handle);
2690                         IntPtr destHdc = destG.GetHdc ();
2691
2692                         IntPtr srcHdc = Win32CreateCompatibleDC (destHdc);
2693                         IntPtr srcBmp = Win32CreateCompatibleBitmap (destHdc, width, height);
2694                         Win32SelectObject (srcHdc, srcBmp);
2695
2696                         offscreen_drawable = new WinBuffer (srcHdc, srcBmp);
2697
2698                         destG.ReleaseHdc (destHdc);
2699                 }
2700
2701                 internal override Graphics GetOffscreenGraphics (object offscreen_drawable)
2702                 {
2703                         return Graphics.FromHdc (((WinBuffer)offscreen_drawable).hdc);
2704                 }
2705
2706                 internal override void BlitFromOffscreen (IntPtr dest_handle, Graphics dest_dc, object offscreen_drawable, Graphics offscreen_dc, Rectangle r)
2707                 {
2708                         WinBuffer wb = (WinBuffer)offscreen_drawable;
2709
2710                         IntPtr destHdc = dest_dc.GetHdc ();
2711                         Win32BitBlt (destHdc, r.Left, r.Top, r.Width, r.Height, wb.hdc, r.Left, r.Top, TernaryRasterOperations.SRCCOPY);
2712                         dest_dc.ReleaseHdc (destHdc);
2713                 }
2714
2715                 internal override void DestroyOffscreenDrawable (object offscreen_drawable)
2716                 {
2717                         WinBuffer wb = (WinBuffer)offscreen_drawable;
2718
2719                         Win32DeleteObject (wb.bitmap);
2720                         Win32DeleteDC (wb.hdc);
2721                 }
2722
2723                 internal override event EventHandler Idle;
2724                 #endregion      // Public Static Methods
2725
2726                 #region Win32 Imports
2727                 [DllImport ("kernel32.dll", EntryPoint="GetLastError", CallingConvention=CallingConvention.StdCall)]
2728                 private extern static uint Win32GetLastError();
2729
2730                 [DllImport ("user32.dll", EntryPoint="CreateWindowExW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2731                 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);
2732
2733                 [DllImport ("user32.dll", EntryPoint="DestroyWindow", CallingConvention=CallingConvention.StdCall)]
2734                 internal extern static bool Win32DestroyWindow(IntPtr hWnd);
2735
2736                 [DllImport ("user32.dll", EntryPoint="PeekMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2737                 internal extern static bool Win32PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags);
2738
2739                 [DllImport ("user32.dll", EntryPoint="GetMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2740                 internal extern static bool Win32GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax);
2741
2742                 [DllImport ("user32.dll", EntryPoint="TranslateMessage", CallingConvention=CallingConvention.StdCall)]
2743                 internal extern static bool Win32TranslateMessage(ref MSG msg);
2744
2745                 [DllImport ("user32.dll", EntryPoint="DispatchMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2746                 internal extern static IntPtr Win32DispatchMessage(ref MSG msg);
2747
2748                 [DllImport ("user32.dll", EntryPoint="MoveWindow", CallingConvention=CallingConvention.StdCall)]
2749                 internal extern static bool Win32MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
2750
2751                 [DllImport ("user32.dll", EntryPoint="SetWindowPos", CallingConvention=CallingConvention.StdCall)]
2752                 internal extern static bool Win32SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SetWindowPosFlags Flags);
2753
2754                 [DllImport ("user32.dll", EntryPoint="SetWindowPos", CallingConvention=CallingConvention.StdCall)]
2755                 internal extern static bool Win32SetWindowPos(IntPtr hWnd, SetWindowPosZOrder pos, int x, int y, int cx, int cy, SetWindowPosFlags Flags);
2756
2757                 [DllImport ("user32.dll", EntryPoint="SetWindowTextW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2758                 internal extern static bool Win32SetWindowText(IntPtr hWnd, string lpString);
2759
2760                 [DllImport ("user32.dll", EntryPoint="GetWindowTextW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2761                 internal extern static bool Win32GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
2762
2763                 [DllImport ("user32.dll", EntryPoint="SetParent", CallingConvention=CallingConvention.StdCall)]
2764                 internal extern static IntPtr Win32SetParent(IntPtr hWnd, IntPtr hParent);
2765
2766                 [DllImport ("user32.dll", EntryPoint="RegisterClassW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2767                 private extern static bool Win32RegisterClass(ref WNDCLASS wndClass);
2768
2769                 [DllImport ("user32.dll", EntryPoint="LoadCursorW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2770                 private extern static IntPtr Win32LoadCursor(IntPtr hInstance, LoadCursorType type);
2771
2772                 [DllImport ("user32.dll", EntryPoint="ShowCursor", CallingConvention=CallingConvention.StdCall)]
2773                 private extern static IntPtr Win32ShowCursor(bool bShow);
2774
2775                 [DllImport ("user32.dll", EntryPoint="SetCursor", CallingConvention=CallingConvention.StdCall)]
2776                 private extern static IntPtr Win32SetCursor(IntPtr hCursor);
2777
2778                 [DllImport ("user32.dll", EntryPoint="CreateCursor", CallingConvention=CallingConvention.StdCall)]
2779                 private extern static IntPtr Win32CreateCursor(IntPtr hInstance, int xHotSpot, int yHotSpot, int nWidth, int nHeight, Byte[] pvANDPlane, Byte[] pvORPlane);
2780
2781                 [DllImport ("user32.dll", EntryPoint="DestroyCursor", CallingConvention=CallingConvention.StdCall)]
2782                 private extern static bool Win32DestroyCursor(IntPtr hCursor);
2783
2784                 [DllImport ("user32.dll", EntryPoint="DefWindowProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2785                 private extern static IntPtr Win32DefWindowProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
2786
2787                 //[DllImport ("user32.dll", EntryPoint="DefDlgProcW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2788                 //private extern static IntPtr Win32DefDlgProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
2789
2790                 [DllImport ("user32.dll", EntryPoint="PostQuitMessage", CallingConvention=CallingConvention.StdCall)]
2791                 private extern static IntPtr Win32PostQuitMessage(int nExitCode);
2792
2793                 [DllImport ("user32.dll", EntryPoint="UpdateWindow", CallingConvention=CallingConvention.StdCall)]
2794                 private extern static IntPtr Win32UpdateWindow(IntPtr hWnd);
2795
2796                 [DllImport ("user32.dll", EntryPoint="GetUpdateRect", CallingConvention=CallingConvention.StdCall)]
2797                 private extern static bool Win32GetUpdateRect(IntPtr hWnd, ref RECT rect, bool erase);
2798
2799                 [DllImport ("user32.dll", EntryPoint="BeginPaint", CallingConvention=CallingConvention.StdCall)]
2800                 private extern static IntPtr Win32BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
2801
2802                 [DllImport ("user32.dll", EntryPoint="EndPaint", CallingConvention=CallingConvention.StdCall)]
2803                 private extern static bool Win32EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
2804
2805                 [DllImport ("user32.dll", EntryPoint="GetDC", CallingConvention=CallingConvention.StdCall)]
2806                 private extern static IntPtr Win32GetDC(IntPtr hWnd);
2807
2808                 [DllImport ("user32.dll", EntryPoint="GetWindowDC", CallingConvention=CallingConvention.StdCall)]
2809                 private extern static IntPtr Win32GetWindowDC(IntPtr hWnd);
2810
2811                 //[DllImport ("user32.dll", EntryPoint="GetDCEx", CallingConvention=CallingConvention.StdCall)]
2812                 //private extern static IntPtr Win32GetDCEx(IntPtr hWnd, IntPtr hRgn, DCExFlags flags);
2813
2814                 [DllImport ("user32.dll", EntryPoint="ReleaseDC", CallingConvention=CallingConvention.StdCall)]
2815                 private extern static IntPtr Win32ReleaseDC(IntPtr hWnd, IntPtr hDC);
2816
2817                 [DllImport ("user32.dll", EntryPoint="MessageBoxW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2818                 private extern static IntPtr Win32MessageBox(IntPtr hParent, string pText, string pCaption, uint uType);
2819
2820                 [DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
2821                 private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, ref RECT lpRect, bool bErase);
2822
2823                 //[DllImport ("user32.dll", EntryPoint="InvalidateRect", CallingConvention=CallingConvention.StdCall)]
2824                 //private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
2825
2826                 [DllImport ("user32.dll", EntryPoint="SetCapture", CallingConvention=CallingConvention.StdCall)]
2827                 private extern static IntPtr Win32SetCapture(IntPtr hWnd);
2828
2829                 [DllImport ("user32.dll", EntryPoint="ReleaseCapture", CallingConvention=CallingConvention.StdCall)]
2830                 private extern static IntPtr Win32ReleaseCapture();
2831
2832                 [DllImport ("user32.dll", EntryPoint="GetWindowRect", CallingConvention=CallingConvention.StdCall)]
2833                 private extern static IntPtr Win32GetWindowRect(IntPtr hWnd, out RECT rect);
2834
2835                 [DllImport ("user32.dll", EntryPoint="GetClientRect", CallingConvention=CallingConvention.StdCall)]
2836                 private extern static IntPtr Win32GetClientRect(IntPtr hWnd, out RECT rect);
2837
2838                 [DllImport ("user32.dll", EntryPoint="ScreenToClient", CallingConvention=CallingConvention.StdCall)]
2839                 private extern static bool Win32ScreenToClient(IntPtr hWnd, ref POINT pt);
2840
2841                 [DllImport ("user32.dll", EntryPoint="ClientToScreen", CallingConvention=CallingConvention.StdCall)]
2842                 private extern static bool Win32ClientToScreen(IntPtr hWnd, ref POINT pt);
2843
2844                 [DllImport ("user32.dll", EntryPoint="GetParent", CallingConvention=CallingConvention.StdCall)]
2845                 private extern static IntPtr Win32GetParent(IntPtr hWnd);
2846
2847                 [DllImport ("user32.dll", EntryPoint="SetActiveWindow", CallingConvention=CallingConvention.StdCall)]
2848                 private extern static IntPtr Win32SetActiveWindow(IntPtr hWnd);
2849
2850                 [DllImport ("user32.dll", EntryPoint="AdjustWindowRectEx", CallingConvention=CallingConvention.StdCall)]
2851                 private extern static bool Win32AdjustWindowRectEx(ref RECT lpRect, int dwStyle, bool bMenu, int dwExStyle);
2852
2853                 [DllImport ("user32.dll", EntryPoint="GetCursorPos", CallingConvention=CallingConvention.StdCall)]
2854                 private extern static bool Win32GetCursorPos(out POINT lpPoint);
2855
2856                 [DllImport ("user32.dll", EntryPoint="SetCursorPos", CallingConvention=CallingConvention.StdCall)]
2857                 private extern static bool Win32SetCursorPos(int x, int y);
2858
2859                 //[DllImport ("user32.dll", EntryPoint="GetWindowPlacement", CallingConvention=CallingConvention.StdCall)]
2860                 //private extern static bool Win32GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
2861
2862                 [DllImport ("user32.dll", EntryPoint="TrackMouseEvent", CallingConvention=CallingConvention.StdCall)]
2863                 private extern static bool Win32TrackMouseEvent(ref TRACKMOUSEEVENT tme);
2864
2865                 //[DllImport ("gdi32.dll", EntryPoint="CreateBrushIndirect", CallingConvention=CallingConvention.StdCall)]
2866                 //private extern static IntPtr Win32CreateBrushIndirect(ref LOGBRUSH lb);
2867
2868                 [DllImport ("gdi32.dll", EntryPoint="CreateSolidBrush", CallingConvention=CallingConvention.StdCall)]
2869                 private extern static IntPtr Win32CreateSolidBrush(COLORREF clrRef);
2870
2871                 [DllImport ("gdi32.dll", EntryPoint="PatBlt", CallingConvention=CallingConvention.StdCall)]
2872                 private extern static int Win32PatBlt(IntPtr hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, PatBltRop dwRop);
2873
2874                 [DllImport ("user32.dll", EntryPoint="SetWindowLong", CallingConvention=CallingConvention.StdCall)]
2875                 private extern static uint Win32SetWindowLong(IntPtr hwnd, WindowLong index, uint value);
2876
2877                 [DllImport ("user32.dll", EntryPoint="GetWindowLong", CallingConvention=CallingConvention.StdCall)]
2878                 private extern static uint Win32GetWindowLong(IntPtr hwnd, WindowLong index);
2879
2880                 [DllImport ("user32.dll", EntryPoint="SetLayeredWindowAttributes", CallingConvention=CallingConvention.StdCall)]
2881                 private extern static uint Win32SetLayeredWindowAttributes (IntPtr hwnd, COLORREF crKey, byte bAlpha, LayeredWindowAttributes dwFlags);
2882
2883                 [DllImport ("user32.dll", EntryPoint="GetLayeredWindowAttributes", CallingConvention=CallingConvention.StdCall)]
2884                 private extern static uint Win32GetLayeredWindowAttributes (IntPtr hwnd, out COLORREF pcrKey, out byte pbAlpha, out LayeredWindowAttributes pwdFlags);
2885
2886                 [DllImport ("gdi32.dll", EntryPoint="DeleteObject", CallingConvention=CallingConvention.StdCall)]
2887                 private extern static bool Win32DeleteObject(IntPtr o);
2888
2889                 [DllImport ("user32.dll", EntryPoint="GetKeyState", CallingConvention=CallingConvention.StdCall)]
2890                 private extern static short Win32GetKeyState(VirtualKeys nVirtKey);
2891
2892                 [DllImport ("user32.dll", EntryPoint="GetDesktopWindow", CallingConvention=CallingConvention.StdCall)]
2893                 private extern static IntPtr Win32GetDesktopWindow();
2894
2895                 [DllImport ("user32.dll", EntryPoint="SetTimer", CallingConvention=CallingConvention.StdCall)]
2896                 private extern static IntPtr Win32SetTimer(IntPtr hwnd, int nIDEvent, uint uElapse, IntPtr timerProc);
2897
2898                 [DllImport ("user32.dll", EntryPoint="KillTimer", CallingConvention=CallingConvention.StdCall)]
2899                 private extern static IntPtr Win32KillTimer(IntPtr hwnd, int nIDEvent);
2900
2901                 [DllImport ("user32.dll", EntryPoint="ShowWindow", CallingConvention=CallingConvention.StdCall)]
2902                 private extern static IntPtr Win32ShowWindow(IntPtr hwnd, WindowPlacementFlags nCmdShow);
2903
2904                 [DllImport ("user32.dll", EntryPoint="EnableWindow", CallingConvention=CallingConvention.StdCall)]
2905                 private extern static IntPtr Win32EnableWindow(IntPtr hwnd, bool Enabled);
2906
2907                 [DllImport ("user32.dll", EntryPoint="SetFocus", CallingConvention=CallingConvention.StdCall)]
2908                 internal extern static IntPtr Win32SetFocus(IntPtr hwnd);
2909
2910                 [DllImport ("user32.dll", EntryPoint="GetFocus", CallingConvention=CallingConvention.StdCall)]
2911                 internal extern static IntPtr Win32GetFocus();
2912
2913                 [DllImport ("user32.dll", EntryPoint="CreateCaret", CallingConvention=CallingConvention.StdCall)]
2914                 internal extern static bool Win32CreateCaret(IntPtr hwnd, IntPtr hBitmap, int nWidth, int nHeight);
2915
2916                 [DllImport ("user32.dll", EntryPoint="DestroyCaret", CallingConvention=CallingConvention.StdCall)]
2917                 private  extern static bool Win32DestroyCaret();
2918
2919                 [DllImport ("user32.dll", EntryPoint="ShowCaret", CallingConvention=CallingConvention.StdCall)]
2920                 private  extern static bool Win32ShowCaret(IntPtr hwnd);
2921
2922                 [DllImport ("user32.dll", EntryPoint="HideCaret", CallingConvention=CallingConvention.StdCall)]
2923                 private  extern static bool Win32HideCaret(IntPtr hwnd);
2924
2925                 [DllImport ("user32.dll", EntryPoint="SetCaretPos", CallingConvention=CallingConvention.StdCall)]
2926                 private  extern static bool Win32SetCaretPos(int X, int Y);
2927
2928                 //[DllImport ("user32.dll", EntryPoint="GetCaretBlinkTime", CallingConvention=CallingConvention.StdCall)]
2929                 //private  extern static uint Win32GetCaretBlinkTime();
2930
2931                 [DllImport ("gdi32.dll", EntryPoint="GetTextMetricsW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2932                 internal extern static bool Win32GetTextMetrics(IntPtr hdc, ref TEXTMETRIC tm);
2933
2934                 [DllImport ("gdi32.dll", EntryPoint="SelectObject", CallingConvention=CallingConvention.StdCall)]
2935                 internal extern static IntPtr Win32SelectObject(IntPtr hdc, IntPtr hgdiobject);
2936
2937                 //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2938                 //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
2939
2940                 //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2941                 //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
2942
2943                 //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2944                 //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, out RECT prcUpdate, ScrollWindowExFlags flags);
2945
2946                 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2947                 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2948
2949                 //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2950                 //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2951
2952                 //[DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2953                 //private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, ref RECT prcScroll, ref RECT prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2954
2955                 [DllImport ("user32.dll", EntryPoint="ScrollWindowEx", CallingConvention=CallingConvention.StdCall)]
2956                 private extern static bool Win32ScrollWindowEx(IntPtr hwnd, int dx, int dy, IntPtr prcScroll, IntPtr prcClip, IntPtr hrgnUpdate, IntPtr prcUpdate, ScrollWindowExFlags flags);
2957
2958                 [DllImport ("user32.dll", EntryPoint="GetActiveWindow", CallingConvention=CallingConvention.StdCall)]
2959                 private extern static IntPtr Win32GetActiveWindow();
2960
2961                 [DllImport ("user32.dll", EntryPoint="GetSystemMetrics", CallingConvention=CallingConvention.StdCall)]
2962                 private extern static int Win32GetSystemMetrics(SystemMetrics nIndex);
2963
2964                 [DllImport ("shell32.dll", EntryPoint="Shell_NotifyIconW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2965                 private extern static bool Win32Shell_NotifyIcon(NotifyIconMessage dwMessage, ref NOTIFYICONDATA lpData);
2966
2967                 [DllImport ("gdi32.dll", EntryPoint="CreateRectRgn", CallingConvention=CallingConvention.StdCall)]
2968                 internal extern static IntPtr Win32CreateRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect);
2969
2970                 [DllImport ("user32.dll", EntryPoint="IsWindowEnabled", CallingConvention=CallingConvention.StdCall)]
2971                 private extern static bool IsWindowEnabled(IntPtr hwnd);
2972
2973                 [DllImport ("user32.dll", EntryPoint="IsWindowVisible", CallingConvention=CallingConvention.StdCall)]
2974                 private extern static bool IsWindowVisible(IntPtr hwnd);
2975
2976                 //[DllImport ("user32.dll", EntryPoint="SetClassLong", CallingConvention=CallingConvention.StdCall)]
2977                 //private extern static bool Win32SetClassLong(IntPtr hwnd, ClassLong nIndex, IntPtr dwNewLong);
2978
2979                 [DllImport ("user32.dll", EntryPoint="SendMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2980                 private extern static IntPtr Win32SendMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
2981
2982                 [DllImport ("user32.dll", EntryPoint="PostMessageW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2983                 private extern static bool Win32PostMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
2984
2985                 [DllImport ("user32.dll", EntryPoint="SendInput", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2986                 private extern static UInt32 Win32SendInput(UInt32 nInputs, [MarshalAs(UnmanagedType.LPArray)] INPUT[] inputs, Int32 cbSize);
2987
2988                 [DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2989                 private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref RECT rect, uint fWinIni);
2990                 
2991                 //[DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2992                 //private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref uint value, uint fWinIni);
2993
2994                 [DllImport ("user32.dll", EntryPoint="SystemParametersInfoW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
2995                 private extern static bool Win32SystemParametersInfo(SPIAction uiAction, uint uiParam, ref int value, uint fWinIni);
2996
2997                 [DllImport ("user32.dll", EntryPoint="OpenClipboard", CallingConvention=CallingConvention.StdCall)]
2998                 private extern static bool Win32OpenClipboard(IntPtr hwnd);
2999
3000                 [DllImport ("user32.dll", EntryPoint="EmptyClipboard", CallingConvention=CallingConvention.StdCall)]
3001                 private extern static bool Win32EmptyClipboard();
3002
3003                 [DllImport ("user32.dll", EntryPoint="RegisterClipboardFormatW", CharSet=CharSet.Unicode, CallingConvention=CallingConvention.StdCall)]
3004                 private extern static uint Win32RegisterClipboardFormat(string format);
3005
3006                 [DllImport ("user32.dll", EntryPoint="CloseClipboard", CallingConvention=CallingConvention.StdCall)]
3007                 private extern static bool Win32CloseClipboard();
3008
3009                 [DllImport ("user32.dll", EntryPoint="EnumClipboardFormats", CallingConvention=CallingConvention.StdCall)]
3010                 private extern static uint Win32EnumClipboardFormats(uint format);
3011
3012                 [DllImport ("user32.dll", EntryPoint="GetClipboardData", CallingConvention=CallingConvention.StdCall)]
3013                 private extern static IntPtr Win32GetClipboardData(uint format);
3014
3015                 [DllImport ("user32.dll", EntryPoint="SetClipboardData", CallingConvention=CallingConvention.StdCall)]
3016                 private extern static IntPtr Win32SetClipboardData(uint format, IntPtr handle);
3017
3018                 [DllImport ("kernel32.dll", EntryPoint="GlobalAlloc", CallingConvention=CallingConvention.StdCall)]
3019                 internal extern static IntPtr Win32GlobalAlloc(GAllocFlags Flags, int dwBytes);
3020
3021                 [DllImport ("kernel32.dll", EntryPoint="CopyMemory", CallingConvention=CallingConvention.StdCall)]
3022                 internal extern static void Win32CopyMemory(IntPtr Destination, IntPtr Source, int length);
3023
3024                 [DllImport ("kernel32.dll", EntryPoint="GlobalFree", CallingConvention=CallingConvention.StdCall)]
3025                 internal extern static IntPtr Win32GlobalFree(IntPtr hMem);
3026
3027                 [DllImport ("kernel32.dll", EntryPoint="GlobalSize", CallingConvention=CallingConvention.StdCall)]
3028                 internal extern static uint Win32GlobalSize(IntPtr hMem);
3029
3030                 [DllImport ("kernel32.dll", EntryPoint="GlobalLock", CallingConvention=CallingConvention.StdCall)]
3031                 internal extern static IntPtr Win32GlobalLock(IntPtr hMem);
3032
3033                 [DllImport ("kernel32.dll", EntryPoint="GlobalUnlock", CallingConvention=CallingConvention.StdCall)]
3034                 internal extern static IntPtr Win32GlobalUnlock(IntPtr hMem);
3035
3036                 [DllImport ("gdi32.dll", EntryPoint="SetROP2", CallingConvention=CallingConvention.StdCall)]
3037                 internal extern static int Win32SetROP2(IntPtr hdc, ROP2DrawMode fnDrawMode);
3038
3039                 [DllImport ("gdi32.dll", EntryPoint="MoveToEx", CallingConvention=CallingConvention.StdCall)]
3040                 internal extern static bool Win32MoveToEx(IntPtr hdc, int x, int y, ref POINT lpPoint);
3041
3042                 [DllImport ("gdi32.dll", EntryPoint="MoveToEx", CallingConvention=CallingConvention.StdCall)]
3043                 internal extern static bool Win32MoveToEx(IntPtr hdc, int x, int y, IntPtr lpPoint);
3044
3045                 [DllImport ("gdi32.dll", EntryPoint="LineTo", CallingConvention=CallingConvention.StdCall)]
3046                 internal extern static bool Win32LineTo(IntPtr hdc, int x, int y);
3047
3048                 [DllImport ("gdi32.dll", EntryPoint="CreatePen", CallingConvention=CallingConvention.StdCall)]
3049                 internal extern static IntPtr Win32CreatePen(PenStyle fnPenStyle, int nWidth, ref COLORREF color);
3050
3051                 [DllImport ("gdi32.dll", EntryPoint="CreatePen", CallingConvention=CallingConvention.StdCall)]
3052                 internal extern static IntPtr Win32CreatePen(PenStyle fnPenStyle, int nWidth, IntPtr color);
3053
3054                 [DllImport ("gdi32.dll", EntryPoint="GetStockObject", CallingConvention=CallingConvention.StdCall)]
3055                 internal extern static IntPtr Win32GetStockObject(StockObject fnObject);
3056
3057                 [DllImport ("gdi32.dll", EntryPoint="CreateHatchBrush", CallingConvention=CallingConvention.StdCall)]
3058                 internal extern static IntPtr Win32CreateHatchBrush(HatchStyle fnStyle, IntPtr color);
3059
3060                 [DllImport ("gdi32.dll", EntryPoint="CreateHatchBrush", CallingConvention=CallingConvention.StdCall)]
3061                 internal extern static IntPtr Win32CreateHatchBrush(HatchStyle fnStyle, ref COLORREF color);
3062
3063                 [DllImport("gdi32.dll", EntryPoint = "ExcludeClipRect", CallingConvention = CallingConvention.StdCall)]
3064                 internal extern static int Win32ExcludeClipRect (IntPtr hdc, int left, int top,  int right, int bottom);
3065
3066                 [DllImport ("gdi32.dll", EntryPoint="ExtSelectClipRgn", CallingConvention=CallingConvention.StdCall)]
3067                 internal extern static int Win32ExtSelectClipRgn(IntPtr hdc, IntPtr hrgn, int mode);
3068
3069                 [DllImport ("winmm.dll", EntryPoint="PlaySoundW", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
3070                 internal extern static IntPtr Win32PlaySound(string pszSound, IntPtr hmod, SndFlags fdwSound);
3071
3072                 [DllImport ("user32.dll", EntryPoint="SetWindowRgn", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
3073                 internal extern static int Win32SetWindowRgn(IntPtr hWnd, IntPtr hRgn, bool redraw);
3074
3075                 [DllImport ("user32.dll", EntryPoint="GetWindowRgn", CallingConvention=CallingConvention.StdCall, CharSet=CharSet.Unicode)]
3076                 internal extern static IntPtr Win32GetWindowRgn(IntPtr hWnd, IntPtr hRgn);
3077
3078                 [DllImport ("user32.dll", EntryPoint="ClipCursor", CallingConvention=CallingConvention.StdCall)]
3079                 internal extern static bool Win32ClipCursor (ref RECT lpRect);
3080
3081                 [DllImport ("user32.dll", EntryPoint="GetClipCursor", CallingConvention=CallingConvention.StdCall)]
3082                 internal extern static bool Win32GetClipCursor (out RECT lpRect);
3083
3084                 [DllImport ("gdi32.dll", EntryPoint="BitBlt", CallingConvention=CallingConvention.StdCall)]
3085                 internal static extern bool Win32BitBlt (IntPtr hObject, int nXDest, int nYDest, int nWidth,
3086                    int nHeight, IntPtr hObjSource, int nXSrc, int nYSrc, TernaryRasterOperations dwRop);
3087
3088                 [DllImport ("gdi32.dll", EntryPoint="CreateCompatibleDC", CallingConvention=CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
3089                 internal static extern IntPtr Win32CreateCompatibleDC (IntPtr hdc);
3090
3091                 [DllImport ("gdi32.dll", EntryPoint="DeleteDC", CallingConvention=CallingConvention.StdCall, ExactSpelling = true, SetLastError = true)]
3092                 internal static extern bool Win32DeleteDC (IntPtr hdc);
3093
3094                 [DllImport ("gdi32.dll", EntryPoint="CreateCompatibleBitmap", CallingConvention=CallingConvention.StdCall)]
3095                 internal static extern IntPtr Win32CreateCompatibleBitmap (IntPtr hdc, int nWidth, int nHeight);
3096                 #endregion
3097         }
3098 }