forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeMethods.cs
More file actions
205 lines (163 loc) · 7.45 KB
/
NativeMethods.cs
File metadata and controls
205 lines (163 loc) · 7.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
* This code is provided under the Code Project Open Licence (CPOL)
* See http://www.codeproject.com/info/cpol10.aspx for details
*/
using System.Drawing;
using System.Reflection;
using System.Runtime.InteropServices;
namespace System.Windows.Forms
{
/// <summary>
/// Description of NativeMethods.
/// </summary>
//[SecurityPermission(SecurityAction.Assert, Flags=SecurityPermissionFlag.UnmanagedCode)]
internal sealed class NativeMethods
{
private NativeMethods(){}
#region Windows Constants
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const int WM_GETTABRECT = 0x130a;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const int WS_EX_TRANSPARENT = 0x20;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const int WM_SETFONT = 0x30;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const int WM_FONTCHANGE = 0x1d;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const int WM_HSCROLL = 0x114;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const int TCM_HITTEST = 0x130D;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const int WM_PAINT = 0xf;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const int WS_EX_LAYOUTRTL = 0x400000;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public const int WS_EX_NOINHERITLAYOUT = 0x100000;
#endregion
#region Content Alignment
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public static readonly ContentAlignment AnyRightAlign = ContentAlignment.BottomRight | ContentAlignment.MiddleRight | ContentAlignment.TopRight;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public static readonly ContentAlignment AnyLeftAlign = ContentAlignment.BottomLeft | ContentAlignment.MiddleLeft | ContentAlignment.TopLeft;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public static readonly ContentAlignment AnyTopAlign = ContentAlignment.TopRight | ContentAlignment.TopCenter | ContentAlignment.TopLeft;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public static readonly ContentAlignment AnyBottomAlign = ContentAlignment.BottomRight | ContentAlignment.BottomCenter | ContentAlignment.BottomLeft;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public static readonly ContentAlignment AnyMiddleAlign = ContentAlignment.MiddleRight | ContentAlignment.MiddleCenter | ContentAlignment.MiddleLeft;
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
public static readonly ContentAlignment AnyCenterAlign = ContentAlignment.BottomCenter | ContentAlignment.MiddleCenter | ContentAlignment.TopCenter;
#endregion
#region User32.dll
// [DllImport("user32.dll"), SecurityPermission(SecurityAction.Demand)]
// public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
public static IntPtr SendMessage (IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam){
// This Method replaces the User32 method SendMessage, but will only work for sending
// messages to Managed controls.
Control control = Control.FromHandle(hWnd);
if (control == null){
return IntPtr.Zero;
}
Message message = new Message();
message.HWnd = hWnd;
message.LParam = lParam;
message.WParam = wParam;
message.Msg = msg;
MethodInfo wproc = control.GetType().GetMethod("WndProc"
, BindingFlags.NonPublic
| BindingFlags.InvokeMethod
| BindingFlags.FlattenHierarchy
| BindingFlags.IgnoreCase
| BindingFlags.Instance);
object[] args = new object[] {message};
wproc.Invoke(control, args);
return ((Message)args[0]).Result;
}
// [DllImport("user32.dll")]
// public static extern IntPtr BeginPaint(IntPtr hWnd, ref PAINTSTRUCT paintStruct);
//
// [DllImport("user32.dll")]
// [return: MarshalAs(UnmanagedType.Bool)]
// public static extern bool EndPaint(IntPtr hWnd, ref PAINTSTRUCT paintStruct);
//
#endregion
#region Misc Functions
public static int LoWord(IntPtr dWord){
return dWord.ToInt32() & 0xffff;
}
public static int HiWord(IntPtr dWord){
if ((dWord.ToInt32() & 0x80000000) == 0x80000000)
return (dWord.ToInt32() >> 16);
else
return (dWord.ToInt32() >> 16) & 0xffff;
}
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2106:SecureAsserts")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
public static IntPtr ToIntPtr(object structure){
IntPtr lparam = IntPtr.Zero;
lparam = Marshal.AllocCoTaskMem(Marshal.SizeOf(structure));
Marshal.StructureToPtr(structure, lparam, false);
return lparam;
}
#endregion
#region Windows Structures and Enums
[Flags()]
public enum TCHITTESTFLAGS{
TCHT_NOWHERE = 1,
TCHT_ONITEMICON = 2,
TCHT_ONITEMLABEL = 4,
TCHT_ONITEM = TCHT_ONITEMICON | TCHT_ONITEMLABEL
}
[StructLayout(LayoutKind.Sequential)]
public struct TCHITTESTINFO{
public TCHITTESTINFO(Point location){
pt = location;
flags = TCHITTESTFLAGS.TCHT_ONITEM;
}
public Point pt;
public TCHITTESTFLAGS flags;
}
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public struct PAINTSTRUCT{
public IntPtr hdc;
public int fErase;
public RECT rcPaint;
public int fRestore;
public int fIncUpdate;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=32)]
public byte[] rgbReserved;
}
[StructLayout(LayoutKind.Sequential)]
public struct RECT{
public int left;
public int top;
public int right;
public int bottom;
public RECT(int left, int top, int right, int bottom){
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public RECT(Rectangle r){
this.left = r.Left;
this.top = r.Top;
this.right = r.Right;
this.bottom = r.Bottom;
}
public static RECT FromXYWH(int x, int y, int width, int height){
return new RECT(x, y, x + width, y + height);
}
public static RECT FromIntPtr(IntPtr ptr){
RECT rect = (RECT)Marshal.PtrToStructure(ptr, typeof(RECT));
return rect;
}
public Size Size{
get{
return new Size(this.right - this.left, this.bottom - this.top);
}
}
}
#endregion
}
}