1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
28 // $Log: XplatUIWin32.cs,v $
29 // Revision 1.43 2004/11/08 20:55:33 pbartok
30 // - Added argument to SetTopmost method
31 // - Fixed broken ClientToScreen function
33 // Revision 1.42 2004/10/20 03:58:05 pbartok
34 // - Small sanity check
36 // Revision 1.41 2004/10/18 05:17:32 pbartok
37 // - Removed VirtualKeys to XplatUIStructs
38 // - Implemented SetTopMost method
39 // - Implemented EnableWindow method
40 // - Bugfix in ScreenToClient()
41 // - Bugfixes in ClientToScreen()
43 // Revision 1.40 2004/10/13 20:18:21 pbartok
44 // - Added code to destroy a window
46 // Revision 1.39 2004/10/06 09:59:05 jordi
47 // removes warnings from compilation
49 // Revision 1.38 2004/10/02 19:08:38 pbartok
50 // - Added Win32EnableWindow method (test for implementing modal dialogs)
51 // - Added ClientToScreen method and imports
53 // Revision 1.37 2004/09/21 04:14:29 pbartok
54 // - Fixed accessibility level for Idle handler
56 // Revision 1.36 2004/09/21 00:54:15 jackson
57 // New message loop that uses poll so we don't get a busy loop
59 // Revision 1.35 2004/09/16 23:45:09 pbartok
60 // - Fixed sending a window to the front
61 // - Added overload for SetWindowPos to avoid casting
63 // Revision 1.34 2004/09/13 21:18:32 pbartok
64 // - Added Z-Ordering methods
66 // Revision 1.33 2004/09/11 00:57:35 pbartok
67 // - Added method to retrieve text from window
69 // Revision 1.32 2004/08/25 18:33:08 pbartok
70 // - Fixed timer handling, now seems to work
71 // - Improved error message for window creation
73 // Revision 1.31 2004/08/24 17:17:27 pbartok
74 // - Implemented SetTimer() and KillTimer()
76 // Revision 1.30 2004/08/24 11:29:44 jackson
77 // Move timers to the driver level. On X they are queued by the driver and checked on idle.
79 // Revision 1.29 2004/08/24 00:19:36 ravindra
80 // Removed the unwanted destructor.
82 // Revision 1.28 2004/08/23 19:39:30 pbartok
83 // - Added method to move mouse cursor
85 // Revision 1.27 2004/08/21 20:51:27 pbartok
86 // - Added method to get default display size
88 // Revision 1.26 2004/08/21 20:23:56 pbartok
89 // - Added method to query current grab state
90 // - Added argument to allow confining a grab to a window
92 // Revision 1.25 2004/08/21 18:35:38 pbartok
93 // - Fixed bug with Async message handling
94 // - Implemented getting the ModifierKeys
96 // Revision 1.24 2004/08/21 17:31:21 pbartok
97 // - Drivers now return proper mouse state
99 // Revision 1.23 2004/08/20 20:39:07 pbartok
100 // - Added jackson's Async code from X11 to Win32
102 // Revision 1.22 2004/08/20 20:02:45 pbartok
103 // - Added method for setting the background color
104 // - Added handling for erasing the window background
106 // Revision 1.21 2004/08/20 19:14:35 jackson
107 // Expose functionality to send async messages through the driver
109 // Revision 1.20 2004/08/20 01:37:47 pbartok
110 // - Added generation of MouseEnter, MouseLeave and MouseHover events
111 // - Added cleanup on EndPaint
113 // Revision 1.19 2004/08/18 19:16:53 jordi
114 // Move colors to a table
116 // Revision 1.18 2004/08/17 21:24:03 pbartok
117 // - Finished IsVisible
118 // - Added Win32GetWindowPlacement
120 // Revision 1.17 2004/08/13 21:42:15 pbartok
121 // - Changed signature for GetCursorPos
123 // Revision 1.16 2004/08/13 19:00:15 jordi
124 // implements PointToClient (ScreenToClient)
126 // Revision 1.15 2004/08/13 18:53:57 pbartok
127 // - Changed GetWindowPos to also provide client area size
128 // - Fixed broken prototypes for several win32 functions
130 // Revision 1.14 2004/08/12 22:59:03 pbartok
131 // - Implemented method to get current mouse position
133 // Revision 1.13 2004/08/11 22:20:59 pbartok
136 // Revision 1.12 2004/08/11 19:41:38 jordi
139 // Revision 1.11 2004/08/11 19:19:44 pbartok
140 // - We had SetWindowPos and MoveWindow to set window positions and size,
141 // removed MoveWindow. We have GetWindowPos, so it made sense to keep
142 // SetWindowPos as matching counterpart
143 // - Added some X11 sanity checking
145 // Revision 1.10 2004/08/11 18:55:46 pbartok
146 // - Added method to calculate difference between decorated window and raw
149 // Revision 1.9 2004/08/10 18:47:16 jordi
150 // Calls InvalidateRect before UpdateWindow
152 // Revision 1.8 2004/08/10 17:36:17 pbartok
153 // - Implemented several methods
155 // Revision 1.7 2004/08/09 20:55:59 pbartok
156 // - Removed Run method, was only required for initial development
158 // Revision 1.6 2004/08/09 20:51:25 pbartok
159 // - Implemented GrabWindow/ReleaseWindow methods to allow pointer capture
161 // Revision 1.5 2004/08/09 16:05:16 jackson
162 // These properties are handled by the theme now.
164 // Revision 1.4 2004/08/06 15:53:39 jordi
165 // X11 keyboard navigation
167 // Revision 1.3 2004/08/04 20:11:24 pbartok
168 // - Added Invalidate handling
170 // Revision 1.2 2004/07/21 16:19:17 jordi
171 // LinkLabel control implementation
173 // Revision 1.1 2004/07/09 05:21:25 pbartok
174 // - Initial check-in
181 using System.Drawing;
182 using System.ComponentModel;
183 using System.Collections;
184 using System.Diagnostics;
185 using System.Runtime.InteropServices;
189 namespace System.Windows.Forms {
190 internal class XplatUIWin32 : XplatUIDriver {
191 #region Local Variables
192 private static XplatUIWin32 instance;
193 private static int ref_count;
194 private static IntPtr FosterParent;
196 internal static MouseButtons mouse_state;
197 internal static Point mouse_position;
198 internal static bool grab_confined;
199 internal static IntPtr grab_hwnd;
200 internal static Rectangle grab_area;
201 internal static WndProc wnd_proc;
202 internal static IntPtr prev_mouse_hwnd;
204 internal static bool themes_enabled;
205 private static Hashtable handle_data;
206 private Hashtable timer_list;
207 #endregion // Local Variables
209 #region Private Structs
210 [StructLayout(LayoutKind.Sequential)]
\r
211 private struct WNDCLASS {
\r
212 internal int style;
\r
213 internal WndProc lpfnWndProc;
\r
214 internal int cbClsExtra;
\r
215 internal int cbWndExtra;
\r
216 internal IntPtr hInstance;
\r
217 internal IntPtr hIcon;
\r
218 internal IntPtr hCursor;
\r
219 internal IntPtr hbrBackground;
\r
220 internal string lpszMenuName;
\r
221 internal string lpszClassName;
\r
224 [StructLayout(LayoutKind.Sequential)]
\r
225 private struct RECT {
\r
228 internal int right;
\r
229 internal int bottom;
\r
232 [StructLayout(LayoutKind.Sequential)]
\r
233 private struct POINT {
\r
238 internal enum WindowPlacementFlags {
242 SW_SHOWMINIMIZED = 2,
\r
243 SW_SHOWMAXIMIZED = 3,
\r
245 SW_SHOWNOACTIVATE = 4,
\r
248 SW_SHOWMINNOACTIVE = 7,
\r
251 SW_SHOWDEFAULT = 10,
\r
252 SW_FORCEMINIMIZE = 11,
\r
256 [StructLayout(LayoutKind.Sequential)]
\r
257 private struct WINDOWPLACEMENT {
\r
258 internal uint length;
\r
259 internal uint flags;
\r
260 internal WindowPlacementFlags showCmd;
\r
261 internal POINT ptMinPosition;
\r
262 internal POINT ptMaxPosition;
\r
263 internal RECT rcNormalPosition;
\r
267 private enum TMEFlags {
\r
268 TME_HOVER = 0x00000001,
\r
269 TME_LEAVE = 0x00000002,
\r
270 TME_QUERY = unchecked((int)0x40000000),
\r
271 TME_CANCEL = unchecked((int)0x80000000)
\r
274 [StructLayout(LayoutKind.Sequential)]
\r
275 private struct TRACKMOUSEEVENT {
\r
277 internal TMEFlags dwFlags;
\r
278 internal IntPtr hWnd;
\r
279 internal int dwHoverTime;
\r
282 [StructLayout(LayoutKind.Sequential)]
\r
283 private struct PAINTSTRUCT {
\r
284 internal IntPtr hdc;
\r
285 internal int fErase;
\r
286 internal RECT rcPaint;
\r
287 internal int fRestore;
\r
288 internal int fIncUpdate;
\r
289 internal int Reserved1;
\r
290 internal int Reserved2;
\r
291 internal int Reserved3;
\r
292 internal int Reserved4;
\r
293 internal int Reserved5;
\r
294 internal int Reserved6;
\r
295 internal int Reserved7;
\r
296 internal int Reserved8;
\r
299 internal enum ClassStyle {
\r
300 CS_VREDRAW = 0x00000001,
\r
301 CS_HREDRAW = 0x00000002,
\r
302 CS_KEYCVTWINDOW = 0x00000004,
\r
303 CS_DBLCLKS = 0x00000008,
\r
304 CS_OWNDC = 0x00000020,
\r
305 CS_CLASSDC = 0x00000040,
\r
306 CS_PARENTDC = 0x00000080,
\r
307 CS_NOKEYCVT = 0x00000100,
\r
308 CS_NOCLOSE = 0x00000200,
\r
309 CS_SAVEBITS = 0x00000800,
\r
310 CS_BYTEALIGNCLIENT = 0x00001000,
\r
311 CS_BYTEALIGNWINDOW = 0x00002000,
\r
312 CS_GLOBALCLASS = 0x00004000,
\r
313 CS_IME = 0x00010000
\r
316 internal enum PeekMessageFlags {
\r
317 PM_NOREMOVE = 0x00000000,
\r
318 PM_REMOVE = 0x00000001,
\r
319 PM_NOYIELD = 0x00000002
\r
322 internal enum SetWindowPosZOrder {
330 internal enum SetWindowPosFlags {
331 SWP_ASYNCWINDOWPOS = 0x4000,
332 SWP_DEFERERASE = 0x2000,
333 SWP_DRAWFRAME = 0x0020,
334 SWP_FRAMECHANGED = 0x0020,
335 SWP_HIDEWINDOW = 0x0080,
336 SWP_NOACTIVATE = 0x0010,
337 SWP_NOCOPYBITS = 0x0100,
339 SWP_NOOWNERZORDER = 0x0200,
340 SWP_NOREDRAW = 0x0008,
341 SWP_NOREPOSITION = 0x0200,
342 SWP_NOENDSCHANGING = 0x0400,
344 SWP_NOZORDER = 0x0004,
345 SWP_SHOWWINDOW = 0x0040
348 internal enum GetSysColorIndex {
\r
349 COLOR_SCROLLBAR =0,
\r
350 COLOR_BACKGROUND =1,
\r
351 COLOR_ACTIVECAPTION =2,
\r
352 COLOR_INACTIVECAPTION =3,
\r
355 COLOR_WINDOWFRAME =6,
\r
357 COLOR_WINDOWTEXT =8,
\r
358 COLOR_CAPTIONTEXT =9,
\r
359 COLOR_ACTIVEBORDER =10,
\r
360 COLOR_INACTIVEBORDER =11,
\r
361 COLOR_APPWORKSPACE =12,
\r
362 COLOR_HIGHLIGHT =13,
\r
363 COLOR_HIGHLIGHTTEXT =14,
\r
365 COLOR_BTNSHADOW =16,
\r
366 COLOR_GRAYTEXT =17,
\r
368 COLOR_INACTIVECAPTIONTEXT =19,
\r
369 COLOR_BTNHIGHLIGHT =20,
\r
370 COLOR_3DDKSHADOW =21,
\r
372 COLOR_INFOTEXT =23,
\r
376 COLOR_3DSHADOW =16,
\r
377 COLOR_3DHIGHLIGHT =20,
\r
378 COLOR_3DHILIGHT =20,
\r
379 COLOR_BTNHILIGHT =20,
380 COLOR_MAXVALUE =24,/* Maximum value */
\r
383 private enum LoadCursorType {
\r
388 IDC_UPARROW =32516,
\r
391 IDC_SIZENWSE =32642,
\r
392 IDC_SIZENESW =32643,
\r
395 IDC_SIZEALL =32646,
\r
398 IDC_APPSTARTING =32650,
\r
403 private enum WindowLong {
\r
405 GWL_HINSTANCE = -6,
\r
406 GWL_HWNDPARENT = -8,
\r
409 GWL_USERDATA = -21,
\r
414 private enum LogBrushStyle {
\r
421 BS_DIBPATTERNPT = 6,
\r
423 BS_DIBPATTERN8X8 = 8,
\r
428 private enum LogBrushHatch {
\r
429 HS_HORIZONTAL = 0, /* ----- */
\r
430 HS_VERTICAL = 1, /* ||||| */
\r
431 HS_FDIAGONAL = 2, /* \\\\\ */
\r
432 HS_BDIAGONAL = 3, /* ///// */
\r
433 HS_CROSS = 4, /* +++++ */
\r
434 HS_DIAGCROSS = 5, /* xxxxx */
\r
437 private struct COLORREF {
\r
444 [StructLayout(LayoutKind.Sequential)]
\r
445 private struct LOGBRUSH {
\r
446 internal LogBrushStyle lbStyle;
\r
447 internal COLORREF lbColor;
\r
448 internal LogBrushHatch lbHatch;
\r
451 [StructLayout(LayoutKind.Sequential)]
\r
452 internal struct TEXTMETRIC {
\r
453 internal int tmHeight;
\r
454 internal int tmAscent;
\r
455 internal int tmDescent;
\r
456 internal int tmInternalLeading;
\r
457 internal int tmExternalLeading;
\r
458 internal int tmAveCharWidth;
\r
459 internal int tmMaxCharWidth;
\r
460 internal int tmWeight;
\r
461 internal int tmOverhang;
\r
462 internal int tmDigitizedAspectX;
\r
463 internal int tmDigitizedAspectY;
\r
464 internal byte tmFirstChar;
\r
465 internal byte tmLastChar;
\r
466 internal byte tmDefaultChar;
\r
467 internal byte tmBreakChar;
\r
468 internal byte tmItalic;
\r
469 internal byte tmUnderlined;
\r
470 internal byte tmStruckOut;
\r
471 internal byte tmPitchAndFamily;
\r
472 internal byte tmCharSet;
\r
477 #region Constructor & Destructor
478 private XplatUIWin32() {
482 // Handle singleton stuff first
485 // Now regular initialization
486 mouse_state = MouseButtons.None;
487 mouse_position = Point.Empty;
489 themes_enabled = false;
491 // Prepare 'our' window class
492 wnd_proc = new WndProc(NativeWindow.WndProc);
493 wndClass.style = (int)(ClassStyle.CS_OWNDC | ClassStyle.CS_DBLCLKS);
494 wndClass.lpfnWndProc = wnd_proc;
495 wndClass.cbClsExtra = 0;
496 wndClass.cbWndExtra = 0;
497 wndClass.hbrBackground = IntPtr.Zero;
498 wndClass.hCursor = Win32LoadCursor(IntPtr.Zero, LoadCursorType.IDC_ARROW);
499 wndClass.hIcon = IntPtr.Zero;
500 wndClass.hInstance = IntPtr.Zero;
501 wndClass.lpszClassName = XplatUI.DefaultClassName;
502 wndClass.lpszMenuName = "";
504 result=Win32RegisterClass(ref wndClass);
506 Win32MessageBox(IntPtr.Zero, "Could not register the "+XplatUI.DefaultClassName+" window class, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
509 FosterParent=Win32CreateWindow(0, "static", "Foster Parent Window", (int)WindowStyles.WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero);
511 if (FosterParent==IntPtr.Zero) {
512 Win32MessageBox(IntPtr.Zero, "Could not create foster window, win32 error " + Win32GetLastError().ToString(), "Oops", 0);
515 handle_data = new Hashtable ();
516 timer_list = new Hashtable ();
518 #endregion // Constructor & Destructor
520 #region Private Support Methods
521 private static IntPtr DefWndProc(IntPtr hWnd, Msg msg, IntPtr wParam, IntPtr lParam) {
522 return Win32DefWindowProc(hWnd, msg, wParam, lParam);
525 private void EraseWindowBackground(IntPtr hWnd, IntPtr hDc) {
532 argb = (uint)Win32GetWindowLong(hWnd, WindowLong.GWL_USERDATA);
535 lb.lbColor.B = (byte)((argb & 0xff0000)>>16);
536 lb.lbColor.G = (byte)((argb & 0xff00)>>8);
537 lb.lbColor.R = (byte)(argb & 0xff);
539 lb.lbStyle = LogBrushStyle.BS_SOLID;
540 hbr = Win32CreateBrushIndirect(ref lb);
541 Win32GetClientRect(hWnd, out rect);
542 Win32FillRect(hDc, ref rect, hbr);
543 Win32DeleteObject(hbr);
546 #endregion // Private Support Methods
548 #region Static Properties
549 internal override Keys ModifierKeys {
554 key_state = Keys.None;
556 state = Win32GetKeyState(VirtualKeys.VK_SHIFT);
557 if ((state & 0x8000) != 0) {
558 key_state |= Keys.Shift;
560 state = Win32GetKeyState(VirtualKeys.VK_CONTROL);
561 if ((state & 0x8000) != 0) {
562 key_state |= Keys.Control;
568 internal override MouseButtons MouseButtons {
574 internal override Point MousePosition {
576 return mouse_position;
580 internal override bool DropTarget {
587 throw new NotImplementedException("Need to figure out D'n'D for Win32");
591 #endregion // Static Properties
593 #region Singleton Specific Code
594 public static XplatUIWin32 GetInstance() {
595 if (instance==null) {
596 instance=new XplatUIWin32();
602 public int Reference {
609 #region Public Static Methods
610 internal override IntPtr InitializeDriver() {
\r
611 mouse_state=MouseButtons.None;
612 mouse_position=Point.Empty;
614 Console.WriteLine("#region #line XplatUI Win32 Constructor called");
616 return IntPtr.Zero;
\r
619 internal override void ShutdownDriver(IntPtr token) {
\r
620 Console.WriteLine("XplatUIWin32 ShutdownDriver called");
624 internal void Version() {
625 Console.WriteLine("Xplat version $revision: $");
628 internal override void Exit() {
629 Win32PostQuitMessage(0);
632 internal override void GetDisplaySize(out Size size) {
635 Win32GetWindowRect(Win32GetDesktopWindow(), out rect);
637 size = new Size(rect.right - rect.left, rect.bottom - rect.top);
640 internal override void EnableThemes() {
644 internal override IntPtr CreateWindow(CreateParams cp) {
648 ParentHandle=cp.Parent;
650 if ((ParentHandle==IntPtr.Zero) && (cp.Style & (int)(WindowStyles.WS_CHILD))!=0) {
651 // We need to use our foster parent window until this poor child gets it's parent assigned
652 ParentHandle=FosterParent;
654 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);
656 if (WindowHandle==IntPtr.Zero) {
657 uint error = Win32GetLastError();
659 Win32MessageBox(IntPtr.Zero, "Error : " + error.ToString(), "Failed to create window, class '"+cp.ClassName+"'", 0);
662 Win32SetWindowLong(WindowHandle, WindowLong.GWL_USERDATA, (IntPtr)ThemeEngine.Current.DefaultControlBackColor.ToArgb());
667 internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
668 CreateParams create_params = new CreateParams();
670 create_params.Caption = "";
673 create_params.Width = Width;
674 create_params.Height = Height;
676 create_params.ClassName=XplatUI.DefaultClassName;
677 create_params.ClassStyle = 0;
678 create_params.ExStyle=0;
679 create_params.Parent=IntPtr.Zero;
680 create_params.Param=0;
682 return CreateWindow(create_params);
685 internal override void DestroyWindow(IntPtr handle) {
686 Win32DestroyWindow(handle);
690 internal override void RefreshWindow(IntPtr handle) {
691 Win32InvalidateRect(handle, IntPtr.Zero, true);
692 Win32UpdateWindow(handle);
695 internal override void SetWindowBackground(IntPtr handle, Color color) {
696 Win32SetWindowLong(handle, WindowLong.GWL_USERDATA, (IntPtr)color.ToArgb());
699 [MonoTODO("Add support for internal table of windows/DCs for cleanup")]
700 internal override PaintEventArgs PaintEventStart(IntPtr handle) {
703 PaintEventArgs paint_event;
707 clip_rect = new Rectangle();
709 ps = new PAINTSTRUCT();
711 if (Win32GetUpdateRect(handle, ref rect, false)) {
714 hdc = Win32BeginPaint(handle, ref ps);
716 data = (HandleData) handle_data [0];
718 data = new HandleData();
719 handle_data[0] = data;
722 data.DeviceContext=(Object)ps;
724 // FIXME: Figure out why the rectangle is always 0 size
725 clip_rect = new Rectangle(ps.rcPaint.left, ps.rcPaint.top, ps.rcPaint.right-ps.rcPaint.left, ps.rcPaint.bottom-ps.rcPaint.top);
726 // clip_rect = new Rectangle(rect.top, rect.left, rect.right-rect.left, rect.bottom-rect.top);
729 EraseWindowBackground(handle, hdc);
732 hdc = Win32GetDC(handle);
733 // FIXME: Add the DC to internal list
734 clip_rect = new Rectangle(rect.top, rect.left, rect.right-rect.left, rect.bottom-rect.top);
737 paint_event = new PaintEventArgs(Graphics.FromHdc(hdc), clip_rect);
742 internal override void PaintEventEnd(IntPtr handle) {
\r
746 data = (HandleData) handle_data [0];
748 data = new HandleData();
749 handle_data[0] = data;
752 //paint_event.Graphics.Dispose();
753 if (data.DeviceContext != null) {
754 ps = (PAINTSTRUCT)data.DeviceContext;
755 Win32EndPaint(handle, ref ps);
760 internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
761 Win32MoveWindow(handle, x, y, width, height, true);
765 internal override void GetWindowPos(IntPtr handle, out int x, out int y, out int width, out int height, out int client_width, out int client_height) {
769 Win32GetWindowRect(handle, out rect);
770 width = rect.right - rect.left;
771 height = rect.bottom - rect.top;
775 Win32ScreenToClient(Win32GetParent(handle), ref pt);
779 Win32GetClientRect(handle, out rect);
780 client_width = rect.right - rect.left;
781 client_height = rect.bottom - rect.top;
785 internal override void Activate(IntPtr handle) {
786 Win32SetActiveWindow(handle);
789 internal override void Invalidate(IntPtr handle, Rectangle rc, bool clear) {
795 rect.bottom=rc.Bottom;
796 Win32InvalidateRect(handle, ref rect, clear);
799 internal override IntPtr DefWndProc(ref Message msg) {
800 msg.Result=Win32DefWindowProc(msg.HWnd, (Msg)msg.Msg, msg.WParam, msg.LParam);
804 internal override void HandleException(Exception e) {
805 StackTrace st = new StackTrace(e);
806 Win32MessageBox(IntPtr.Zero, e.Message+st.ToString(), "Exception", 0);
807 Console.WriteLine("{0}{1}", e.Message, st.ToString());
810 internal override void DoEvents() {
813 while (Win32PeekMessage(ref msg, IntPtr.Zero, 0, 0, (uint)PeekMessageFlags.PM_REMOVE)!=true) {
814 if (msg.message==Msg.WM_PAINT) {
815 XplatUI.TranslateMessage(ref msg);
816 XplatUI.DispatchMessage(ref msg);
821 internal override bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
822 return Win32PeekMessage(ref msg, hWnd, wFilterMin, wFilterMax, flags);
825 internal override bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
828 data = (HandleData) handle_data [0];
829 if ((data!=null) && data.GetMessage(ref msg)) {
833 result = Win32GetMessage(ref msg, hWnd, wFilterMin, wFilterMax);
835 // We need to fake WM_MOUSE_ENTER/WM_MOUSE_LEAVE
836 switch (msg.message) {
837 case Msg.WM_LBUTTONDOWN: {
838 mouse_state |= MouseButtons.Left;
842 case Msg.WM_MBUTTONDOWN: {
843 mouse_state |= MouseButtons.Middle;
847 case Msg.WM_RBUTTONDOWN: {
848 mouse_state |= MouseButtons.Right;
852 case Msg.WM_LBUTTONUP: {
853 mouse_state &= ~MouseButtons.Left;
857 case Msg.WM_MBUTTONUP: {
858 mouse_state &= ~MouseButtons.Middle;
862 case Msg.WM_RBUTTONUP: {
863 mouse_state &= ~MouseButtons.Right;
867 case Msg.WM_ERASEBKGND: {
868 EraseWindowBackground(msg.hwnd, msg.wParam);
872 case Msg.WM_ASYNC_MESSAGE: {
873 GCHandle handle = (GCHandle)msg.lParam;
874 AsyncMethodData asyncdata = (AsyncMethodData) handle.Target;
875 AsyncMethodResult asyncresult = asyncdata.Result.Target as AsyncMethodResult;
876 object ret = asyncdata.Method.DynamicInvoke (asyncdata.Args);
877 if (asyncresult != null) {
878 asyncresult.Complete (ret);
884 case Msg.WM_MOUSEMOVE: {
885 if (msg.hwnd != prev_mouse_hwnd) {
889 data = new HandleData();
890 handle_data[0] = data;
893 // The current message will be sent out next time around
894 data.StoreMessage(ref msg);
896 // This is the message we want to send at this point
897 msg.message = Msg.WM_MOUSE_ENTER;
899 prev_mouse_hwnd = msg.hwnd;
901 tme = new TRACKMOUSEEVENT();
902 tme.size = Marshal.SizeOf(tme);
904 tme.dwFlags = TMEFlags.TME_LEAVE | TMEFlags.TME_HOVER;
905 Win32TrackMouseEvent(ref tme);
911 case Msg.WM_MOUSELEAVE: {
912 prev_mouse_hwnd = IntPtr.Zero;
913 msg.message=Msg.WM_MOUSE_LEAVE;
918 Timer timer=(Timer)timer_list[(int)msg.wParam];
930 internal override bool TranslateMessage(ref MSG msg) {
931 return Win32TranslateMessage(ref msg);
934 internal override IntPtr DispatchMessage(ref MSG msg) {
935 return Win32DispatchMessage(ref msg);
938 internal override bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
940 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOP, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
942 } else if (!Bottom) {
943 Win32SetWindowPos(hWnd, AfterhWnd, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
945 Win32SetWindowPos(hWnd, (IntPtr)SetWindowPosZOrder.HWND_BOTTOM, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
951 internal override bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
953 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
956 Win32SetWindowPos(hWnd, SetWindowPosZOrder.HWND_NOTOPMOST, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE);
961 internal override bool Text(IntPtr handle, string text) {
962 Win32SetWindowText(handle, text);
966 internal override bool GetText(IntPtr handle, out string text) {
969 sb = new StringBuilder(256);
970 Win32GetWindowText(handle, sb, sb.Capacity);
971 text = sb.ToString();
975 internal override bool SetVisible(IntPtr handle, bool visible) {
977 Win32ShowWindow(handle, WindowPlacementFlags.SW_SHOWNORMAL);
979 Win32ShowWindow(handle, WindowPlacementFlags.SW_HIDE);
984 internal override bool IsVisible(IntPtr handle) {
985 WINDOWPLACEMENT wndpl;
987 wndpl = new WINDOWPLACEMENT();
988 wndpl.length=(uint)Marshal.SizeOf(wndpl);
989 Win32GetWindowPlacement(handle, ref wndpl);
990 if ((wndpl.showCmd == WindowPlacementFlags.SW_SHOWMINIMIZED)) {
996 internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
997 return Win32SetParent(handle, parent);
1000 internal override IntPtr GetParent(IntPtr handle) {
1001 return Win32GetParent(handle);
1004 internal override void GrabWindow(IntPtr hWnd, IntPtr ConfineToHwnd) {
1006 Win32SetCapture(hWnd);
1009 internal override void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
1011 GrabConfined = grab_confined;
1012 GrabArea = grab_area;
1015 internal override void ReleaseWindow(IntPtr hWnd) {
1016 Win32ReleaseCapture();
1017 grab_hwnd = IntPtr.Zero;
1020 internal override bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, bool HasMenu, out Rectangle WindowRect) {
1023 rect.left=ClientRect.Left;
1024 rect.top=ClientRect.Top;
1025 rect.right=ClientRect.Right;
1026 rect.bottom=ClientRect.Bottom;
1028 if (!Win32AdjustWindowRectEx(ref rect, Style, HasMenu, 0)) {
1029 WindowRect = new Rectangle(ClientRect.Left, ClientRect.Top, ClientRect.Width, ClientRect.Height);
1033 WindowRect = new Rectangle(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top);
1037 internal override void SetCursorPos(IntPtr handle, int x, int y) {
1038 Win32SetCursorPos(x, y);
1041 internal override void EnableWindow(IntPtr handle, bool Enable) {
1042 Win32EnableWindow(handle, Enable);
1045 internal override void SetModal(IntPtr handle, bool Modal) {
1046 // we do nothing on Win32; Application.cs simulates modal dialogs by disabling all toplevel windows
1049 internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
1052 Win32GetCursorPos(out pt);
1054 if (handle!=IntPtr.Zero) {
1055 Win32ScreenToClient(handle, ref pt);
1062 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y)
1064 POINT pnt = new POINT();
1068 Win32ScreenToClient (handle, ref pnt);
1074 internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) {
1075 POINT pnt = new POINT();
1080 Win32ClientToScreen(handle, ref pnt);
1086 internal override void SendAsyncMethod (AsyncMethodData method)
1088 Win32PostMessage(FosterParent, Msg.WM_ASYNC_MESSAGE, IntPtr.Zero, (IntPtr)GCHandle.Alloc (method));
1091 internal override void SetTimer (Timer timer)
1095 index = timer.GetHashCode();
1098 timer_list[index]=timer;
1101 Win32SetTimer(FosterParent, index, (uint)timer.Interval, IntPtr.Zero);
1104 internal override void KillTimer (Timer timer)
1108 index = timer.GetHashCode();
1110 Win32KillTimer(FosterParent, index);
1113 timer_list.Remove(index);
1118 private void CaretCallback(object sender, EventArgs e) {
\r
1119 Console.WriteLine("CaretCallback hit");
\r
1122 internal override void CreateCaret(IntPtr hwnd, int width, int height) {
1123 Win32CreateCaret(hwnd, IntPtr.Zero, width, height);
1126 internal override void DestroyCaret(IntPtr hwnd) {
1127 Win32DestroyCaret();
1130 internal override void SetCaretPos(IntPtr hwnd, int x, int y) {
1131 Win32SetCaretPos(x, y);
1134 internal override void CaretVisible(IntPtr hwnd, bool visible) {
1136 Win32ShowCaret(hwnd);
1138 Win32HideCaret(hwnd);
1142 internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
1146 tm = new TEXTMETRIC();
1148 dc = Win32GetDC(IntPtr.Zero);
1149 Win32SelectObject(dc, font.ToHfont());
1150 if (Win32GetTextMetrics(dc, ref tm) == false) {
1151 Win32ReleaseDC(IntPtr.Zero, dc);
1156 Win32ReleaseDC(IntPtr.Zero, dc);
1158 ascent = tm.tmAscent;
1159 descent = tm.tmDescent;
1164 internal override int KeyboardSpeed {
1166 Console.WriteLine ("KeyboardSpeed: need to query Windows");
1169 // Return values range from 0 to 31 which map to 2.5 to 30 repetitions per second.
1175 internal override int KeyboardDelay {
1177 Console.WriteLine ("KeyboardDelay: need to query Windows");
1180 // Return values must range from 0 to 4, 0 meaning 250ms,
1181 // and 4 meaning 1000 ms.
1187 internal override event EventHandler Idle;
1189 // Santa's little helper
1190 static void Where() {
1191 Console.WriteLine("Here: {0}", new StackTrace().ToString());
1193 #endregion // Public Static Methods
1195 #region Win32 Imports
1196 [DllImport ("kernel32.dll", EntryPoint="GetLastError", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1197 private extern static uint Win32GetLastError();
1199 [DllImport ("user32.dll", EntryPoint="CreateWindowExA", CallingConvention=CallingConvention.StdCall)]
1200 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);
1202 [DllImport ("user32.dll", EntryPoint="DestroyWindow", CallingConvention=CallingConvention.StdCall)]
1203 internal extern static bool Win32DestroyWindow(IntPtr hWnd);
1205 [DllImport ("user32.dll", EntryPoint="PeekMessageA", CallingConvention=CallingConvention.StdCall)]
1206 internal extern static bool Win32PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags);
1208 [DllImport ("user32.dll", EntryPoint="GetMessageA", CallingConvention=CallingConvention.StdCall)]
1209 internal extern static bool Win32GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax);
1211 [DllImport ("user32.dll", EntryPoint="TranslateMessage", CallingConvention=CallingConvention.StdCall)]
1212 internal extern static bool Win32TranslateMessage(ref MSG msg);
1214 [DllImport ("user32.dll", EntryPoint="DispatchMessageA", CallingConvention=CallingConvention.StdCall)]
1215 internal extern static IntPtr Win32DispatchMessage(ref MSG msg);
1217 [DllImport ("user32.dll", EntryPoint="MoveWindow", CallingConvention=CallingConvention.StdCall)]
1218 internal extern static bool Win32MoveWindow(IntPtr hWnd, int x, int y, int width, int height, bool repaint);
1220 [DllImport ("user32.dll", EntryPoint="SetWindowPos", CallingConvention=CallingConvention.StdCall)]
1221 internal extern static bool Win32SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, SetWindowPosFlags Flags);
1223 [DllImport ("user32.dll", EntryPoint="SetWindowPos", CallingConvention=CallingConvention.StdCall)]
1224 internal extern static bool Win32SetWindowPos(IntPtr hWnd, SetWindowPosZOrder pos, int x, int y, int cx, int cy, SetWindowPosFlags Flags);
1226 [DllImport ("user32.dll", EntryPoint="SetWindowTextA", CallingConvention=CallingConvention.StdCall)]
1227 internal extern static bool Win32SetWindowText(IntPtr hWnd, string lpString);
1229 [DllImport ("user32.dll", EntryPoint="GetWindowTextA", CallingConvention=CallingConvention.StdCall)]
1230 internal extern static bool Win32GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
1232 [DllImport ("user32.dll", EntryPoint="SetParent", CallingConvention=CallingConvention.StdCall)]
1233 internal extern static IntPtr Win32SetParent(IntPtr hWnd, IntPtr hParent);
1235 [DllImport ("user32.dll", EntryPoint="RegisterClassA", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1236 private extern static bool Win32RegisterClass(ref WNDCLASS wndClass);
1238 [DllImport ("user32.dll", EntryPoint="LoadCursorA", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1239 private extern static IntPtr Win32LoadCursor(IntPtr hInstance, LoadCursorType type);
1241 [DllImport ("user32.dll", EntryPoint="DefWindowProcA", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1242 private extern static IntPtr Win32DefWindowProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
1244 [DllImport ("user32.dll", EntryPoint="DefDlgProcA", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1245 private extern static IntPtr Win32DefDlgProc(IntPtr hWnd, Msg Msg, IntPtr wParam, IntPtr lParam);
1247 [DllImport ("user32.dll", EntryPoint="PostQuitMessage", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1248 private extern static IntPtr Win32PostQuitMessage(int nExitCode);
1250 [DllImport ("user32.dll", EntryPoint="UpdateWindow", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1251 private extern static IntPtr Win32UpdateWindow(IntPtr hWnd);
1253 [DllImport ("user32.dll", EntryPoint="GetUpdateRect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1254 private extern static bool Win32GetUpdateRect(IntPtr hWnd, ref RECT rect, bool erase);
1256 [DllImport ("user32.dll", EntryPoint="BeginPaint", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1257 private extern static IntPtr Win32BeginPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
1259 [DllImport ("user32.dll", EntryPoint="EndPaint", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1260 private extern static bool Win32EndPaint(IntPtr hWnd, ref PAINTSTRUCT ps);
1262 [DllImport ("user32.dll", EntryPoint="GetDC", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1263 private extern static IntPtr Win32GetDC(IntPtr hWnd);
1265 [DllImport ("user32.dll", EntryPoint="ReleaseDC", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1266 private extern static IntPtr Win32ReleaseDC(IntPtr hWnd, IntPtr hDC);
1268 [DllImport ("user32.dll", EntryPoint="MessageBoxA", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1269 private extern static IntPtr Win32MessageBox(IntPtr hParent, string pText, string pCaption, uint uType);
1271 [DllImport ("user32.dll", EntryPoint="InvalidateRect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1272 private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, ref RECT lpRect, bool bErase);
1274 [DllImport ("user32.dll", EntryPoint="InvalidateRect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1275 private extern static IntPtr Win32InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
1277 [DllImport ("user32.dll", EntryPoint="SetCapture", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1278 private extern static IntPtr Win32SetCapture(IntPtr hWnd);
1280 [DllImport ("user32.dll", EntryPoint="ReleaseCapture", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1281 private extern static IntPtr Win32ReleaseCapture();
1283 [DllImport ("user32.dll", EntryPoint="GetWindowRect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1284 private extern static IntPtr Win32GetWindowRect(IntPtr hWnd, out RECT rect);
1286 [DllImport ("user32.dll", EntryPoint="GetClientRect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1287 private extern static IntPtr Win32GetClientRect(IntPtr hWnd, out RECT rect);
1289 [DllImport ("user32.dll", EntryPoint="ScreenToClient", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1290 private extern static bool Win32ScreenToClient(IntPtr hWnd, ref POINT pt);
1292 [DllImport ("user32.dll", EntryPoint="ClientToScreen", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1293 private extern static bool Win32ClientToScreen(IntPtr hWnd, ref POINT pt);
1295 [DllImport ("user32.dll", EntryPoint="GetParent", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1296 private extern static IntPtr Win32GetParent(IntPtr hWnd);
1298 [DllImport ("user32.dll", EntryPoint="SetActiveWindow", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1299 private extern static IntPtr Win32SetActiveWindow(IntPtr hWnd);
1301 [DllImport ("user32.dll", EntryPoint="PostQuitMessage", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1302 private extern static IntPtr Win32PostQuitMessage(IntPtr hWnd);
1304 [DllImport ("user32.dll", EntryPoint="AdjustWindowRectEx", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1305 private extern static bool Win32AdjustWindowRectEx(ref RECT lpRect, int dwStyle, bool bMenu, int dwExStyle);
1307 [DllImport ("user32.dll", EntryPoint="GetCursorPos", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1308 private extern static bool Win32GetCursorPos(out POINT lpPoint);
1310 [DllImport ("user32.dll", EntryPoint="SetCursorPos", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1311 private extern static bool Win32SetCursorPos(int x, int y);
1313 [DllImport ("user32.dll", EntryPoint="GetWindowPlacement", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1314 private extern static bool Win32GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
1316 [DllImport ("user32.dll", EntryPoint="TrackMouseEvent", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1317 private extern static bool Win32TrackMouseEvent(ref TRACKMOUSEEVENT tme);
1319 [DllImport ("gdi32.dll", EntryPoint="CreateBrushIndirect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1320 private extern static IntPtr Win32CreateBrushIndirect(ref LOGBRUSH lb);
1322 [DllImport ("user32.dll", EntryPoint="FillRect", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1323 private extern static int Win32FillRect(IntPtr hdc, ref RECT rect, IntPtr hbr);
1325 [DllImport ("user32.dll", EntryPoint="SetWindowLong", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1326 private extern static IntPtr Win32SetWindowLong(IntPtr hwnd, WindowLong index, IntPtr value);
1328 [DllImport ("user32.dll", EntryPoint="GetWindowLong", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1329 private extern static IntPtr Win32GetWindowLong(IntPtr hwnd, WindowLong index);
1331 [DllImport ("gdi32.dll", EntryPoint="DeleteObject", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1332 private extern static bool Win32DeleteObject(IntPtr o);
1334 [DllImport ("user32.dll", EntryPoint="PostMessage", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1335 private extern static bool Win32PostMessage(IntPtr hwnd, Msg msg, IntPtr wParam, IntPtr lParam);
1337 [DllImport ("user32.dll", EntryPoint="GetKeyState", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1338 private extern static short Win32GetKeyState(VirtualKeys nVirtKey);
1340 [DllImport ("user32.dll", EntryPoint="GetDesktopWindow", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1341 private extern static IntPtr Win32GetDesktopWindow();
1343 [DllImport ("user32.dll", EntryPoint="SetTimer", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1344 private extern static IntPtr Win32SetTimer(IntPtr hwnd, int nIDEvent, uint uElapse, IntPtr timerProc);
1346 [DllImport ("user32.dll", EntryPoint="KillTimer", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1347 private extern static IntPtr Win32KillTimer(IntPtr hwnd, int nIDEvent);
1349 [DllImport ("user32.dll", EntryPoint="ShowWindow", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1350 private extern static IntPtr Win32ShowWindow(IntPtr hwnd, WindowPlacementFlags nCmdShow);
1352 [DllImport ("user32.dll", EntryPoint="EnableWindow", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1353 private extern static IntPtr Win32EnableWindow(IntPtr hwnd, bool Enabled);
1355 [DllImport ("user32.dll", EntryPoint="SetFocus", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1356 internal extern static IntPtr Win32SetFocus(IntPtr hwnd);
1358 [DllImport ("user32.dll", EntryPoint="CreateCaret", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1359 internal extern static bool Win32CreateCaret(IntPtr hwnd, IntPtr hBitmap, int nWidth, int nHeight);
1361 [DllImport ("user32.dll", EntryPoint="DestroyCaret", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1362 internal extern static bool Win32DestroyCaret();
1364 [DllImport ("user32.dll", EntryPoint="ShowCaret", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1365 internal extern static bool Win32ShowCaret(IntPtr hwnd);
1367 [DllImport ("user32.dll", EntryPoint="HideCaret", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1368 internal extern static bool Win32HideCaret(IntPtr hwnd);
1370 [DllImport ("user32.dll", EntryPoint="SetCaretPos", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1371 internal extern static bool Win32SetCaretPos(int X, int Y);
1373 [DllImport ("user32.dll", EntryPoint="GetCaretBlinkTime", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1374 internal extern static uint Win32GetCaretBlinkTime();
1376 [DllImport ("gdi32.dll", EntryPoint="GetTextMetricsA", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1377 internal extern static bool Win32GetTextMetrics(IntPtr hdc, ref TEXTMETRIC tm);
1379 [DllImport ("gdi32.dll", EntryPoint="SelectObject", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.StdCall)]
1380 internal extern static bool Win32SelectObject(IntPtr hdc, IntPtr hgdiobject);