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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
|
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
// THE ENTIRE RISK OF USE OR RESULTS IN CONNECTION WITH THE USE OF THIS CODE
// AND INFORMATION REMAINS WITH THE USER.
//
/*********************************************************************
* NOTE: A copy of this file exists at: WF\Common\Shared
* The two files must be kept in sync. Any change made here must also
* be made to WF\Common\Shared\NativeMethods.cs
*********************************************************************/
namespace System.Workflow.Activities.Common
{
using System;
using System.Runtime.InteropServices;
using System.Diagnostics.CodeAnalysis;
static class NativeMethods
{
internal const int HDI_WIDTH = 0x0001;
internal const int HDI_HEIGHT = HDI_WIDTH;
internal const int HDI_TEXT = 0x0002;
internal const int HDI_FORMAT = 0x0004;
internal const int HDI_LPARAM = 0x0008;
internal const int HDI_BITMAP = 0x0010;
internal const int HDI_IMAGE = 0x0020;
internal const int HDI_DI_SETITEM = 0x0040;
internal const int HDI_ORDER = 0x0080;
internal const int HDI_FILTER = 0x0100;
internal const int HDF_LEFT = 0x0000;
internal const int HDF_RIGHT = 0x0001;
internal const int HDF_CENTER = 0x0002;
internal const int HDF_JUSTIFYMASK = 0x0003;
internal const int HDF_RTLREADING = 0x0004;
internal const int HDF_OWNERDRAW = 0x8000;
internal const int HDF_STRING = 0x4000;
internal const int HDF_BITMAP = 0x2000;
internal const int HDF_BITMAP_ON_RIGHT = 0x1000;
internal const int HDF_IMAGE = 0x0800;
internal const int HDF_SORTUP = 0x0400;
internal const int HDF_SORTDOWN = 0x0200;
internal const int LVM_GETHEADER = (0x1000 + 31);
internal const int HDM_GETITEM = (0x1200 + 11);
internal const int HDM_SETITEM = (0x1200 + 12);
internal const int HORZRES = 8;
internal const int VERTRES = 10;
internal const int LOGPIXELSX = 88;
internal const int LOGPIXELSY = 90;
internal const int PHYSICALWIDTH = 110;
internal const int PHYSICALHEIGHT = 111;
internal const int PHYSICALOFFSETX = 112;
internal const int PHYSICALOFFSETY = 113;
internal const int WM_SETREDRAW = 0x000B;
internal const int HOLLOW_BRUSH = 5;
internal const int OBJ_PEN = 1;
internal const int OBJ_BRUSH = 2;
internal const int OBJ_EXTPEN = 11;
internal const int GM_ADVANCED = 2;
internal const int PS_COSMETIC = 0x00000000;
internal const int PS_USERSTYLE = 7;
internal const int BS_SOLID = 0;
internal const int WS_POPUP = unchecked((int)0x80000000);
internal const int WS_EX_DLGMODALFRAME = 0x00000001;
internal const int WM_SETICON = 0x0080;
internal const int SMALL_ICON = 0;
internal const int LARGE_ICON = 1;
internal const int PS_SOLID = 0;
internal const int SWP_NOSIZE = unchecked((int)0x0001);
internal const int SWP_NOZORDER = unchecked((int)0x0004);
internal const int SWP_NOACTIVATE = unchecked((int)0x0010);
internal const int WM_NOTIFY = unchecked((int)0x004E);
internal const int WM_SETFONT = unchecked((int)0x0030);
internal const int WS_EX_TOPMOST = unchecked((int)0x00000008L);
internal const int WM_KEYDOWN = 0x100;
internal const int WM_KEYUP = 0x101;
internal const int WM_SYSKEYDOWN = 0x104;
internal const int WM_SYSKEYUP = 0x105;
internal const int TTF_IDISHWND = (0x0001);
internal const int TTF_CENTERTIP = (0x0002);
internal const int TTF_RTLREADING = (0x0004);
internal const int TTF_SUBCLASS = (0x0010);
internal const int TTF_TRACK = (0x0020);
internal const int TTF_ABSOLUTE = (0x0080);
internal const int TTF_TRANSPARENT = (0x0100);
internal const int TTF_PARSELINKS = (0x1000);
internal const int TTF_DI_SETITEM = (0x8000);
internal const int TTS_ALWAYSTIP = (0x01);
internal const int TTS_NOPREFIX = (0x02);
internal const int TTS_NOANIMATE = (0x10);
internal const int TTS_NOFADE = (0x20);
internal const int TTS_BALLOON = (0x40);
internal const int TTS_CLOSE = (0x80);
internal const int TTDT_AUTOMATIC = 0;
internal const int TTDT_RESHOW = 1;
internal const int TTDT_AUTOPOP = 2;
internal const int TTDT_INITIAL = 3;
internal const int TTI_NONE = 0;
internal const int TTI_INFO = 1;
internal const int TTI_WARNING = 2;
internal const int TTI_ERROR = 3;
internal static readonly int TTN_GETDISPINFO;
internal static readonly int TTN_NEEDTEXT;
internal static readonly int TTN_SHOW = ((0 - 520) - 1);
internal static readonly int TTN_POP = ((0 - 520) - 2);
internal static readonly int TTM_POP = (0x0400 + 28);
internal static readonly int TTM_ADDTOOL;
internal static readonly int TTM_SETTITLE;
internal static readonly int TTM_DELTOOL;
internal static readonly int TTM_NEWTOOLRECT;
internal static readonly int TTM_GETTOOLINFO;
internal static readonly int TTM_SETTOOLINFO;
internal static readonly int TTM_HITTEST;
internal static readonly int TTM_GETTEXT;
internal static readonly int TTM_UPDATETIPTEXT;
internal static readonly int TTM_ENUMTOOLS;
internal static readonly int TTM_GETCURRENTTOOL;
internal static readonly int TTM_TRACKACTIVATE = (0x0400 + 17);
internal static readonly int TTM_TRACKPOSITION = (0x0400 + 18);
internal static readonly int TTM_ACTIVATE = (0x0400 + 1);
internal static readonly int TTM_ADJUSTRECT = (0x400 + 31);
internal static readonly int TTM_SETDELAYTIME = (0x0400 + 3);
internal static readonly int TTM_RELAYEVENT = (0x0400 + 7);
internal static readonly int TTM_UPDATE = (0x0400 + 29);
internal static readonly int TTM_WINDOWFROMPOINT = (0x0400 + 16);
internal static readonly int TTM_GETDELAYTIME = (0x0400 + 21);
internal static readonly int TTM_SETMAXTIPWIDTH = (0x0400 + 24);
private const int TTN_GETDISPINFOA = ((0 - 520) - 0);
private const int TTN_GETDISPINFOW = ((0 - 520) - 10);
private const int TTN_NEEDTEXTA = ((0 - 520) - 0);
private const int TTN_NEEDTEXTW = ((0 - 520) - 10);
private const int TTM_SETTITLEA = (0x0400 + 32);
private const int TTM_SETTITLEW = (0x0400 + 33);
private const int TTM_ADDTOOLA = (0x0400 + 4);
private const int TTM_ADDTOOLW = (0x0400 + 50);
private const int TTM_DELTOOLA = (0x0400 + 5);
private const int TTM_DELTOOLW = (0x0400 + 51);
private const int TTM_NEWTOOLRECTA = (0x0400 + 6);
private const int TTM_NEWTOOLRECTW = (0x0400 + 52);
private const int TTM_GETTOOLINFOA = (0x0400 + 8);
private const int TTM_GETTOOLINFOW = (0x0400 + 53);
private const int TTM_SETTOOLINFOA = (0x0400 + 9);
private const int TTM_SETTOOLINFOW = (0x0400 + 54);
private const int TTM_HITTESTA = (0x0400 + 10);
private const int TTM_HITTESTW = (0x0400 + 55);
private const int TTM_GETTEXTA = (0x0400 + 11);
private const int TTM_GETTEXTW = (0x0400 + 56);
private const int TTM_UPDATETIPTEXTA = (0x0400 + 12);
private const int TTM_UPDATETIPTEXTW = (0x0400 + 57);
private const int TTM_ENUMTOOLSA = (0x0400 + 14);
private const int TTM_ENUMTOOLSW = (0x0400 + 58);
private const int TTM_GETCURRENTTOOLA = (0x0400 + 15);
private const int TTM_GETCURRENTTOOLW = (0x0400 + 59);
static NativeMethods()
{
if (Marshal.SystemDefaultCharSize == 1)
{
TTN_GETDISPINFO = TTN_GETDISPINFOA;
TTN_NEEDTEXT = TTN_NEEDTEXTA;
TTM_ADDTOOL = TTM_ADDTOOLA;
TTM_SETTITLE = TTM_SETTITLEA;
TTM_DELTOOL = TTM_DELTOOLA;
TTM_NEWTOOLRECT = TTM_NEWTOOLRECTA;
TTM_GETTOOLINFO = TTM_GETTOOLINFOA;
TTM_SETTOOLINFO = TTM_SETTOOLINFOA;
TTM_HITTEST = TTM_HITTESTA;
TTM_GETTEXT = TTM_GETTEXTA;
TTM_UPDATETIPTEXT = TTM_UPDATETIPTEXTA;
TTM_ENUMTOOLS = TTM_ENUMTOOLSA;
TTM_GETCURRENTTOOL = TTM_GETCURRENTTOOLA;
}
else
{
TTN_GETDISPINFO = TTN_GETDISPINFOW;
TTN_NEEDTEXT = TTN_NEEDTEXTW;
TTM_ADDTOOL = TTM_ADDTOOLW;
TTM_SETTITLE = TTM_SETTITLEW;
TTM_DELTOOL = TTM_DELTOOLW;
TTM_NEWTOOLRECT = TTM_NEWTOOLRECTW;
TTM_GETTOOLINFO = TTM_GETTOOLINFOW;
TTM_SETTOOLINFO = TTM_SETTOOLINFOW;
TTM_HITTEST = TTM_HITTESTW;
TTM_GETTEXT = TTM_GETTEXTW;
TTM_UPDATETIPTEXT = TTM_UPDATETIPTEXTW;
TTM_ENUMTOOLS = TTM_ENUMTOOLSW;
TTM_GETCURRENTTOOL = TTM_GETCURRENTTOOLW;
}
}
internal static bool Failed(int hr)
{
return (hr < 0);
}
internal static int ThrowOnFailure(int hr)
{
return ThrowOnFailure(hr, null);
}
internal static int ThrowOnFailure(int hr, params int[] expectedHRFailure)
{
if (Failed(hr))
{
if ((null == expectedHRFailure) || (Array.IndexOf(expectedHRFailure, hr) < 0))
{
Marshal.ThrowExceptionForHR(hr);
}
}
return hr;
}
internal static IntPtr ListView_GetHeader(IntPtr hWndLV)
{
return SendMessage(hWndLV, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);
}
internal static bool Header_GetItem(IntPtr hWndHeader, int index, [In, Out] NativeMethods.HDITEM hdi)
{
IntPtr success = SendMessage(hWndHeader, HDM_GETITEM, new IntPtr(index), hdi);
return (success != IntPtr.Zero) ? true : false;
}
internal static bool Header_SetItem(IntPtr hWndHeader, int index, [In, Out] NativeMethods.HDITEM hdi)
{
IntPtr success = SendMessage(hWndHeader, HDM_SETITEM, new IntPtr(index), hdi);
return (success != IntPtr.Zero) ? true : false;
}
//[DllImport("gdi32.dll", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
//public static extern IntPtr CreateSolidBrush(int crColor);
//[DllImport("gdi32.dll", ExactSpelling = true, CharSet = CharSet.Auto)]
//internal static extern bool RoundRect(HandleRef hDC, int left, int top, int right, int bottom, int width, int height);
//[DllImport("gdi32.dll", ExactSpelling = true, EntryPoint = "CreatePen", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
//internal static extern IntPtr CreatePen(int nStyle, int nWidth, int crColor);
[DllImport("gdi32", EntryPoint = "DeleteObject", CharSet = CharSet.Auto)]
internal static extern bool DeleteObject(IntPtr hObject);
[System.Runtime.InteropServices.DllImport("gdi32.dll", ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern int GetDeviceCaps(IntPtr hDC, int nIndex);
[DllImport("user32", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, [In, Out] NativeMethods.HDITEM lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public extern static bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public extern static IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);
[DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern bool LineTo(HandleRef hdc, int x, int y);
[DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern bool MoveToEx(HandleRef hdc, int x, int y, POINT pt);
[DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true, CharSet = CharSet.Auto)]
public static extern IntPtr SelectObject(HandleRef hdc, HandleRef obj);
[DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern IntPtr GetCurrentObject(HandleRef hDC, uint uObjectType);
[DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern int DeleteObject(HandleRef hObject);
[DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern IntPtr ExtCreatePen(int style, int nWidth, LOGBRUSH logbrush, int styleArrayLength, int[] styleArray);
[DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern int SetWorldTransform(HandleRef hdc, XFORM xform);
[DllImport("gdi32.dll", SetLastError = true, ExactSpelling = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern int SetGraphicsMode(HandleRef hdc, int iMode);
[DllImport("user32.dll")]
internal static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref TOOLINFO ti);
[DllImport("user32.dll")]
internal static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, ref RECT rc);
[DllImport("user32.dll")]
internal static extern int SetWindowPos(IntPtr hWnd, IntPtr hwndInsertAfter, int x, int y, int width, int height, int flags);
[System.Runtime.InteropServices.ComVisible(false), StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
internal class HDITEM
{
public int mask = 0;
public int cxy = 0;
public IntPtr pszText = IntPtr.Zero;
public IntPtr hbm = IntPtr.Zero;
public int cchTextMax = 0;
public int fmt = 0;
public int lParam = 0;
public int image = 0;
public int order = 0;
public int type = 0;
public IntPtr filter = IntPtr.Zero;
}
[StructLayout(LayoutKind.Sequential)]
internal class XFORM
{
//Default is identity matrix
public float eM11 = 1.0f;
public float eM12 = 0.0f;
public float eM21 = 0.0f;
public float eM22 = 1.0f;
public float eDx = 0.0f;
public float eDy = 0.0f;
public XFORM()
{
}
public XFORM(System.Drawing.Drawing2D.Matrix transform)
{
this.eM11 = transform.Elements[0];
this.eM12 = transform.Elements[1];
this.eM21 = transform.Elements[2];
this.eM22 = transform.Elements[3];
this.eDx = transform.Elements[4];
this.eDy = transform.Elements[5];
}
}
[StructLayout(LayoutKind.Sequential)]
internal class LOGBRUSH
{
public int lbStyle;
public int lbColor;
public long lbHatch;
public LOGBRUSH(int style, int color, int hatch)
{
this.lbStyle = style;
this.lbColor = color;
this.lbHatch = hatch;
}
}
[StructLayout(LayoutKind.Sequential)]
internal class POINT
{
public int x;
public int y;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Auto)]
internal class NMHDR
{
public IntPtr hwndFrom;
public int idFrom;
public int code;
public NMHDR()
{
this.hwndFrom = IntPtr.Zero;
this.idFrom = 0;
this.code = 0;
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Auto)]
internal struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Auto)]
internal struct TOOLINFO
{
public int size;
public int flags;
public IntPtr hwnd;
public IntPtr id;
public RECT rect;
public IntPtr hinst;
[SuppressMessage("Microsoft.Reliability", "CA2006:UseSafeHandleToEncapsulateNativeResources", Justification = "Not a security threat since its used by designer scenarios only")]
public IntPtr text;
public IntPtr lParam;
}
}
}
|