2 // System.Windows.Forms.Design.Native
5 // Ivan N. Zlatev (contact i-nZ.net)
7 // (C) 2006-2007 Ivan N. Zlatev
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System
.Windows
.Forms
;
32 using System
.Runtime
.InteropServices
;
33 using System
.Reflection
;
36 namespace System
.Windows
.Forms
.Design
42 private static Type _xplatuiType
;
46 Assembly assembly
= Assembly
.Load (Consts
.AssemblySystem_Windows_Forms
);
48 throw new InvalidOperationException ("Can't load System.Windows.Forms assembly.");
50 _xplatuiType
= assembly
.GetType ("System.Windows.Forms.XplatUI");
51 if (_xplatuiType
== null)
52 throw new InvalidOperationException ("Can't find the System.Windows.Forms.XplatUI type.");
55 private static object InvokeMethod (string methodName
, object[] args
)
57 return InvokeMethod (methodName
, args
, null);
60 // will also match types
61 private static object InvokeMethod (string methodName
, object[] args
, Type
[] types
)
63 MethodInfo method
= null;
66 method
= _xplatuiType
.GetMethod (methodName
, BindingFlags
.NonPublic
| BindingFlags
.Static
|
67 BindingFlags
.InvokeMethod
, null, types
, null);
69 method
= _xplatuiType
.GetMethod (methodName
, BindingFlags
.NonPublic
| BindingFlags
.Static
|
70 BindingFlags
.InvokeMethod
);
74 throw new InvalidOperationException (methodName
+ " not found!");
76 return method
.Invoke (null, args
);
79 public static void DefWndProc (ref Message m
)
81 object[] args
= new object[] { m }
;
82 m
.Result
= (IntPtr
) InvokeMethod ("DefWndProc", args
);
83 m
= (Message
) args
[0];
86 public static IntPtr
SendMessage (IntPtr hwnd
, Msg message
, IntPtr wParam
, IntPtr lParam
)
89 Assembly assembly
= Assembly
.Load (Consts
.AssemblySystem_Windows_Forms
);
90 Type refType
= assembly
.GetType ("System.Windows.Forms.Message&");
91 object[] args
= new object[] { Message.Create (hwnd, (int)message, wParam, lParam) }
;
92 InvokeMethod ("SendMessage", args
, new Type
[] { refType }
);
93 return ((Message
)args
[0]).Result
;
96 public static Point
PointToClient (Control control
, Point point
)
99 throw new ArgumentNullException ("control");
101 object[] args
= new object[] { control.Handle, point.X, point.Y }
;
102 InvokeMethod ("ScreenToClient", args
);
103 return new Point ((int) args
[1], (int) args
[2]);
106 public static IntPtr
SetParent (IntPtr childHandle
, IntPtr parentHandle
)
108 return (IntPtr
) InvokeMethod ("SetParent", new object[] { childHandle, parentHandle }
);
113 public static int HiWord (int dword
)
115 // 12345678 -> 12340000 -> 00001234
116 return ((dword
>> 16) & 0x0000ffff);
119 public static int LoWord (int dword
)
121 // 12345678 -> 00005678
122 return (dword
& 0x0000ffff);
125 public static IntPtr
LParam (int hiword
, int loword
)
127 // results [hiword|loword] dword
129 return (IntPtr
)((loword
<< 16) | (hiword
& 0x0000FFFF));
135 WM_SETFOCUS
= 0x0007,
137 WM_CANCELMODE
= 0x001F,
138 WM_SETCURSOR
= 0x0020,
139 WM_CONTEXTMENU
= 0x007B,
140 WM_NCHITTEST
= 0x0084,
142 // AccessabilityObject
144 WM_GETOBJECT
= 0x003D,
146 // Mouse input - Client area
148 WM_MOUSEFIRST
= 0x0200,
149 WM_MOUSEMOVE
= 0x0200,
150 WM_LBUTTONDOWN
= 0x0201,
151 WM_LBUTTONUP
= 0x0202,
152 WM_LBUTTONDBLCLK
= 0x0203,
153 WM_RBUTTONDOWN
= 0x0204,
154 WM_RBUTTONUP
= 0x0205,
155 WM_RBUTTONDBLCLK
= 0x0206,
156 WM_MBUTTONDOWN
= 0x0207,
157 WM_MBUTTONUP
= 0x0208,
158 WM_MBUTTONDBLCLK
= 0x0209,
159 WM_MOUSEWHEEL
= 0x020A,
160 WM_MOUSELAST
= 0x020A,
161 WM_NCMOUSEHOVER
= 0x02A0,
162 WM_MOUSEHOVER
= 0x02A1,
163 WM_NCMOUSELEAVE
= 0x02A2,
164 WM_MOUSELEAVE
= 0x02A3,
166 // Mouse input - Non-client area
168 WM_NCMOUSEMOVE
= 0x00A0,
169 WM_NCLBUTTONDOWN
= 0x00A1,
170 WM_NCLBUTTONUP
= 0x00A2,
171 WM_NCLBUTTONDBLCLK
= 0x00A3,
172 WM_NCRBUTTONDOWN
= 0x00A4,
173 WM_NCRBUTTONUP
= 0x00A5,
174 WM_NCRBUTTONDBLCLK
= 0x00A6,
175 WM_NCMBUTTONDOWN
= 0x00A7,
176 WM_NCMBUTTONUP
= 0x00A8,
177 WM_NCMBUTTONDBLCLK
= 0x00A9,
181 WM_KEYFIRST
= 0x0100,
185 WM_DEADCHAR
= 0x0103,
186 WM_SYSKEYDOWN
= 0x0104,
187 WM_SYSKEYUP
= 0x0105,
188 WM_SYS1CHAR
= 0x0106,
189 WM_SYSDEADCHAR
= 0x0107,
198 // IME - International Text
200 WM_IME_SETCONTEXT
= 0x0281,
201 WM_IME_NOTIFY
= 0x0282,
202 WM_IME_CONTROL
= 0x0283,
203 WM_IME_COMPOSITIONFULL
= 0x0284,
204 WM_IME_SELECT
= 0x0285,
205 WM_IME_CHAR
= 0x0286,
206 WM_IME_REQUEST
= 0x0288,
207 WM_IME_KEYDOWN
= 0x0290,
208 WM_IME_KEYUP
= 0x0291,
212 WM_MOUSE_ENTER
= 0x0401,