dsh-zcode-cua 0.0.0-stage → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +133 -0
- package/LICENSE +21 -0
- package/README.md +208 -2
- package/README.zh.md +209 -0
- package/client.js +209 -0
- package/cordis.patch.yml +43 -0
- package/docs/DETAIL.md +1 -0
- package/docs/DETAIL.zh.md +1 -0
- package/docs/preview.svg +51 -0
- package/icon.svg +28 -0
- package/index.js +226 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +73 -6
- package/server/access.js +94 -0
- package/server/helper-launcher.js +64 -0
- package/server/index.js +498 -0
- package/server/overlay/Overlay.cs +777 -0
- package/server/overlay/host.ps1 +130 -0
- package/server/overlay.js +374 -0
- package/server/paths.js +231 -0
- package/skills/zcode-computer-use/SKILL.md +304 -0
|
@@ -0,0 +1,777 @@
|
|
|
1
|
+
// Win32 layered-window overlay that tells the user an AI is driving the desktop.
|
|
2
|
+
//
|
|
3
|
+
// Ported visually from windows-mcp's control_overlay (Python/PIL). The reason this
|
|
4
|
+
// exists at all is the third requirement in the design: the indicator must be
|
|
5
|
+
// VISIBLE TO THE USER BUT ABSENT FROM EVERY SCREENSHOT the model takes. Two
|
|
6
|
+
// mechanisms are combined, because neither is sufficient alone:
|
|
7
|
+
//
|
|
8
|
+
// * SetWindowDisplayAffinity(WDA_EXCLUDEFROMCAPTURE) makes Windows itself skip
|
|
9
|
+
// this window in any capture (PrintScreen, Graphics.CopyFromScreen, DWM-based
|
|
10
|
+
// grabbers). Unavailable on some compositors, so it is best-effort.
|
|
11
|
+
// * Hide-before-capture, driven by the host: the JS side calls Hide() before a
|
|
12
|
+
// capture_app request and Show() after. This is the one that actually holds
|
|
13
|
+
// for the CUA pipeline, which captures through GDI/DWM directly.
|
|
14
|
+
//
|
|
15
|
+
// Every window here is click-through (WS_EX_TRANSPARENT), non-focusable
|
|
16
|
+
// (WS_EX_NOACTIVATE) and a tool window (WS_EX_TOOLWINDOW, so it never shows in
|
|
17
|
+
// the taskbar or Alt-Tab). Nothing in this file ever takes input.
|
|
18
|
+
//
|
|
19
|
+
// Rendering is CPU-side GDI+ into a premultiplied 32-bit DIB, pushed with
|
|
20
|
+
// UpdateLayeredWindow. No WPF, no WinForms, no external packages: this compiles
|
|
21
|
+
// with the C# compiler that ships inside Windows.
|
|
22
|
+
|
|
23
|
+
using System;
|
|
24
|
+
using System.Collections.Generic;
|
|
25
|
+
using System.Drawing;
|
|
26
|
+
using System.Drawing.Drawing2D;
|
|
27
|
+
using System.Drawing.Imaging;
|
|
28
|
+
using System.Drawing.Text;
|
|
29
|
+
using System.Runtime.InteropServices;
|
|
30
|
+
|
|
31
|
+
namespace DshZcodeCua
|
|
32
|
+
{
|
|
33
|
+
/// <summary>One device-pixel rectangle of a layered overlay window.</summary>
|
|
34
|
+
internal sealed class OverlayForm
|
|
35
|
+
{
|
|
36
|
+
public IntPtr Handle;
|
|
37
|
+
public string ClassName;
|
|
38
|
+
public int X, Y, W, H;
|
|
39
|
+
public Bitmap Content;
|
|
40
|
+
public byte[] Pixels;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
internal static class Native
|
|
44
|
+
{
|
|
45
|
+
public const int WS_POPUP = unchecked((int)0x80000000);
|
|
46
|
+
public const int WS_EX_LAYERED = 0x00080000;
|
|
47
|
+
public const int WS_EX_TRANSPARENT = 0x00000020;
|
|
48
|
+
public const int WS_EX_TOPMOST = 0x00000008;
|
|
49
|
+
public const int WS_EX_TOOLWINDOW = 0x00000080;
|
|
50
|
+
public const int WS_EX_NOACTIVATE = 0x08000000;
|
|
51
|
+
|
|
52
|
+
public const int ULW_ALPHA = 0x00000002;
|
|
53
|
+
public const byte AC_SRC_OVER = 0x00;
|
|
54
|
+
public const byte AC_SRC_ALPHA = 0x01;
|
|
55
|
+
|
|
56
|
+
public const int SW_SHOWNA = 8;
|
|
57
|
+
|
|
58
|
+
public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
|
|
59
|
+
public const int SWP_NOSIZE = 0x0001;
|
|
60
|
+
public const int SWP_NOMOVE = 0x0002;
|
|
61
|
+
public const int SWP_NOACTIVATE = 0x0010;
|
|
62
|
+
public const int SWP_SHOWWINDOW = 0x0040;
|
|
63
|
+
|
|
64
|
+
public const int WM_NCHITTEST = 0x0084;
|
|
65
|
+
public const int HTTRANSPARENT = -1;
|
|
66
|
+
|
|
67
|
+
public const uint WDA_NONE = 0x00000000;
|
|
68
|
+
public const uint WDA_EXCLUDEFROMCAPTURE = 0x00000011;
|
|
69
|
+
|
|
70
|
+
public const int SM_XVIRTUALSCREEN = 76;
|
|
71
|
+
public const int SM_YVIRTUALSCREEN = 77;
|
|
72
|
+
public const int SM_CXVIRTUALSCREEN = 78;
|
|
73
|
+
public const int SM_CYVIRTUALSCREEN = 79;
|
|
74
|
+
|
|
75
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
76
|
+
public struct POINT
|
|
77
|
+
{
|
|
78
|
+
public int x;
|
|
79
|
+
public int y;
|
|
80
|
+
public POINT(int x, int y) { this.x = x; this.y = y; }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
84
|
+
public struct SIZE
|
|
85
|
+
{
|
|
86
|
+
public int cx;
|
|
87
|
+
public int cy;
|
|
88
|
+
public SIZE(int cx, int cy) { this.cx = cx; this.cy = cy; }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
92
|
+
public struct RECT
|
|
93
|
+
{
|
|
94
|
+
public int left;
|
|
95
|
+
public int top;
|
|
96
|
+
public int right;
|
|
97
|
+
public int bottom;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
[DllImport("user32.dll")]
|
|
101
|
+
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
|
|
102
|
+
|
|
103
|
+
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
|
104
|
+
public struct BLENDFUNCTION
|
|
105
|
+
{
|
|
106
|
+
public byte BlendOp;
|
|
107
|
+
public byte BlendFlags;
|
|
108
|
+
public byte SourceConstantAlpha;
|
|
109
|
+
public byte AlphaFormat;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
113
|
+
public struct BITMAPINFOHEADER
|
|
114
|
+
{
|
|
115
|
+
public int biSize;
|
|
116
|
+
public int biWidth;
|
|
117
|
+
public int biHeight;
|
|
118
|
+
public short biPlanes;
|
|
119
|
+
public short biBitCount;
|
|
120
|
+
public int biCompression;
|
|
121
|
+
public int biSizeImage;
|
|
122
|
+
public int biXPelsPerMeter;
|
|
123
|
+
public int biYPelsPerMeter;
|
|
124
|
+
public int biClrUsed;
|
|
125
|
+
public int biClrImportant;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
129
|
+
public struct BITMAPINFO
|
|
130
|
+
{
|
|
131
|
+
public BITMAPINFOHEADER bmiHeader;
|
|
132
|
+
public int bmiColors;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public delegate IntPtr WndProcDelegate(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
|
136
|
+
|
|
137
|
+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
138
|
+
public struct WNDCLASSEX
|
|
139
|
+
{
|
|
140
|
+
public int cbSize;
|
|
141
|
+
public uint style;
|
|
142
|
+
public WndProcDelegate lpfnWndProc;
|
|
143
|
+
public int cbClsExtra;
|
|
144
|
+
public int cbWndExtra;
|
|
145
|
+
public IntPtr hInstance;
|
|
146
|
+
public IntPtr hIcon;
|
|
147
|
+
public IntPtr hCursor;
|
|
148
|
+
public IntPtr hbrBackground;
|
|
149
|
+
[MarshalAs(UnmanagedType.LPWStr)] public string lpszMenuName;
|
|
150
|
+
[MarshalAs(UnmanagedType.LPWStr)] public string lpszClassName;
|
|
151
|
+
public IntPtr hIconSm;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// CharSet.Unicode on BOTH sides is not cosmetic. Without it the default
|
|
155
|
+
// Ansi marshaling registers the class under a mangled ANSI name while
|
|
156
|
+
// CreateWindowExW looks the name up as UTF-16, and every create fails
|
|
157
|
+
// with 1411 ERROR_CLASS_DOES_NOT_EXIST even though RegisterClassEx
|
|
158
|
+
// returned a valid atom.
|
|
159
|
+
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
|
160
|
+
public static extern ushort RegisterClassEx(ref WNDCLASSEX lpwcx);
|
|
161
|
+
|
|
162
|
+
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
|
163
|
+
public static extern bool UnregisterClass(string lpClassName, IntPtr hInstance);
|
|
164
|
+
|
|
165
|
+
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
|
166
|
+
public static extern IntPtr CreateWindowEx(
|
|
167
|
+
int dwExStyle, string lpClassName, string lpWindowName, int dwStyle,
|
|
168
|
+
int x, int y, int nWidth, int nHeight,
|
|
169
|
+
IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
|
|
170
|
+
|
|
171
|
+
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
|
172
|
+
public static extern IntPtr DefWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
|
173
|
+
|
|
174
|
+
[DllImport("user32.dll")]
|
|
175
|
+
public static extern bool DestroyWindow(IntPtr hWnd);
|
|
176
|
+
|
|
177
|
+
[DllImport("user32.dll")]
|
|
178
|
+
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
|
|
179
|
+
|
|
180
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
181
|
+
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags);
|
|
182
|
+
|
|
183
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
184
|
+
public static extern bool SetWindowDisplayAffinity(IntPtr hWnd, uint dwAffinity);
|
|
185
|
+
|
|
186
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
187
|
+
public static extern bool GetWindowDisplayAffinity(IntPtr hWnd, out uint dwAffinity);
|
|
188
|
+
|
|
189
|
+
[DllImport("user32.dll")]
|
|
190
|
+
public static extern int GetSystemMetrics(int nIndex);
|
|
191
|
+
|
|
192
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
193
|
+
public static extern bool GetCursorPos(out POINT lpPoint);
|
|
194
|
+
|
|
195
|
+
[DllImport("user32.dll")]
|
|
196
|
+
public static extern IntPtr GetDC(IntPtr hWnd);
|
|
197
|
+
|
|
198
|
+
[DllImport("user32.dll")]
|
|
199
|
+
public static extern int ReleaseDC(IntPtr hWnd, IntPtr hDC);
|
|
200
|
+
|
|
201
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
202
|
+
public static extern bool UpdateLayeredWindow(
|
|
203
|
+
IntPtr hwnd, IntPtr hdcDst, ref POINT pptDst, ref SIZE psize,
|
|
204
|
+
IntPtr hdcSrc, ref POINT pptSrc, int crKey, ref BLENDFUNCTION pblend, int dwFlags);
|
|
205
|
+
|
|
206
|
+
[DllImport("gdi32.dll")]
|
|
207
|
+
public static extern IntPtr CreateCompatibleDC(IntPtr hDC);
|
|
208
|
+
|
|
209
|
+
[DllImport("gdi32.dll")]
|
|
210
|
+
public static extern bool DeleteDC(IntPtr hDC);
|
|
211
|
+
|
|
212
|
+
[DllImport("gdi32.dll", SetLastError = true)]
|
|
213
|
+
public static extern IntPtr CreateDIBSection(
|
|
214
|
+
IntPtr hdc, ref BITMAPINFO pbmi, uint iUsage, out IntPtr ppvBits, IntPtr hSection, uint dwOffset);
|
|
215
|
+
|
|
216
|
+
[DllImport("gdi32.dll")]
|
|
217
|
+
public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);
|
|
218
|
+
|
|
219
|
+
[DllImport("gdi32.dll")]
|
|
220
|
+
public static extern bool DeleteObject(IntPtr hObject);
|
|
221
|
+
|
|
222
|
+
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
|
223
|
+
public static extern IntPtr GetModuleHandle(string lpModuleName);
|
|
224
|
+
|
|
225
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
226
|
+
public static extern bool SetProcessDpiAwarenessContext(IntPtr value);
|
|
227
|
+
|
|
228
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
229
|
+
public static extern IntPtr SetThreadDpiAwarenessContext(IntPtr value);
|
|
230
|
+
|
|
231
|
+
[DllImport("user32.dll")]
|
|
232
|
+
public static extern uint GetDpiForSystem();
|
|
233
|
+
|
|
234
|
+
[DllImport("user32.dll")]
|
|
235
|
+
public static extern int GetDpiForWindow(IntPtr hwnd);
|
|
236
|
+
|
|
237
|
+
// DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 as a raw handle value.
|
|
238
|
+
public static readonly IntPtr DPI_AWARENESS_PER_MONITOR_V2 = new IntPtr(-4);
|
|
239
|
+
public static readonly IntPtr DPI_AWARENESS_PER_MONITOR = new IntPtr(-3);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/// <summary>
|
|
243
|
+
/// Owns every overlay HWND and draws the four edge glows, the top banner and
|
|
244
|
+
/// the cursor ring. All public members are safe to call from any thread.
|
|
245
|
+
///
|
|
246
|
+
/// Must be `public`: PowerShell's Add-Type emits into a dynamic assembly and
|
|
247
|
+
/// can only reach exported types, so an internal class compiles fine and is
|
|
248
|
+
/// then invisible to the host ("cannot find type").
|
|
249
|
+
/// </summary>
|
|
250
|
+
public static class Overlay
|
|
251
|
+
{
|
|
252
|
+
static readonly object Gate = new object();
|
|
253
|
+
static readonly List<OverlayForm> Forms = new List<OverlayForm>();
|
|
254
|
+
static readonly List<string> ClassNames = new List<string>();
|
|
255
|
+
static Native.WndProcDelegate procKeepAlive;
|
|
256
|
+
static bool visible;
|
|
257
|
+
static string phase = "working";
|
|
258
|
+
static string detail = "";
|
|
259
|
+
|
|
260
|
+
// Visual constants, matching windows-mcp's control_overlay_art.
|
|
261
|
+
const int BORDER = 56;
|
|
262
|
+
const int CURSOR_SIZE = 88;
|
|
263
|
+
const int CURSOR_LABEL_SIZE = 20;
|
|
264
|
+
const string CURSOR_LABEL = "DSH";
|
|
265
|
+
|
|
266
|
+
static Color PhaseColor()
|
|
267
|
+
{
|
|
268
|
+
// Blue while working, amber while waiting on the user.
|
|
269
|
+
return phase == "waiting"
|
|
270
|
+
? Color.FromArgb(255, 170, 55)
|
|
271
|
+
: Color.FromArgb(45, 145, 255);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
static string PhaseTitle()
|
|
275
|
+
{
|
|
276
|
+
return phase == "waiting"
|
|
277
|
+
? "DSH 需要你来决定"
|
|
278
|
+
: "DSH 正在控制电脑";
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/// <summary>
|
|
282
|
+
/// The action to show under the title: whatever the current tool call said
|
|
283
|
+
/// it was doing. Empty means the caller gave no description, in which case
|
|
284
|
+
/// the banner keeps a generic line rather than showing a blank row.
|
|
285
|
+
/// </summary>
|
|
286
|
+
static string PhaseDetail()
|
|
287
|
+
{
|
|
288
|
+
string text = detail == null ? "" : detail.Trim();
|
|
289
|
+
return text.Length > 0 ? text : "正在执行操作…";
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
static IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
|
|
293
|
+
{
|
|
294
|
+
if (msg == Native.WM_NCHITTEST) return new IntPtr(Native.HTTRANSPARENT);
|
|
295
|
+
return Native.DefWindowProc(hWnd, msg, wParam, lParam);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
static OverlayForm CreateForm(string name, int x, int y, int w, int h, Bitmap content, bool excludeFromCapture)
|
|
299
|
+
{
|
|
300
|
+
string cls = "DshCuaOverlay_" + name + "_" + Guid.NewGuid().ToString("N").Substring(0, 8);
|
|
301
|
+
var wc = new Native.WNDCLASSEX();
|
|
302
|
+
wc.cbSize = Marshal.SizeOf(typeof(Native.WNDCLASSEX));
|
|
303
|
+
wc.style = 0;
|
|
304
|
+
wc.lpfnWndProc = procKeepAlive;
|
|
305
|
+
wc.hInstance = Native.GetModuleHandle(null);
|
|
306
|
+
wc.lpszClassName = cls;
|
|
307
|
+
if (Native.RegisterClassEx(ref wc) == 0)
|
|
308
|
+
throw new InvalidOperationException("RegisterClassEx failed: " + Marshal.GetLastWin32Error());
|
|
309
|
+
|
|
310
|
+
int ex = Native.WS_EX_LAYERED | Native.WS_EX_TRANSPARENT | Native.WS_EX_TOPMOST
|
|
311
|
+
| Native.WS_EX_TOOLWINDOW | Native.WS_EX_NOACTIVATE;
|
|
312
|
+
IntPtr hwnd = Native.CreateWindowEx(
|
|
313
|
+
ex, cls, "dsh-zcode-cua indicator", Native.WS_POPUP, x, y, w, h,
|
|
314
|
+
IntPtr.Zero, IntPtr.Zero, wc.hInstance, IntPtr.Zero);
|
|
315
|
+
if (hwnd == IntPtr.Zero)
|
|
316
|
+
{
|
|
317
|
+
Native.UnregisterClass(cls, wc.hInstance);
|
|
318
|
+
throw new InvalidOperationException("CreateWindowEx failed: " + Marshal.GetLastWin32Error());
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
var form = new OverlayForm
|
|
322
|
+
{
|
|
323
|
+
Handle = hwnd,
|
|
324
|
+
ClassName = cls,
|
|
325
|
+
X = x, Y = y, W = w, H = h,
|
|
326
|
+
Content = content,
|
|
327
|
+
Pixels = Premultiplied(content),
|
|
328
|
+
};
|
|
329
|
+
ClassNames.Add(cls);
|
|
330
|
+
|
|
331
|
+
// Best-effort: on compositors that reject the affinity we still get
|
|
332
|
+
// exclusion from the host's hide-before-capture.
|
|
333
|
+
Native.SetWindowDisplayAffinity(
|
|
334
|
+
hwnd, excludeFromCapture ? Native.WDA_EXCLUDEFROMCAPTURE : Native.WDA_NONE);
|
|
335
|
+
Push(form, 255);
|
|
336
|
+
return form;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
static byte[] Premultiplied(Bitmap bmp)
|
|
340
|
+
{
|
|
341
|
+
var rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
|
|
342
|
+
BitmapData data = bmp.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
|
343
|
+
try
|
|
344
|
+
{
|
|
345
|
+
byte[] raw = new byte[data.Stride * bmp.Height];
|
|
346
|
+
Marshal.Copy(data.Scan0, raw, 0, raw.Length);
|
|
347
|
+
// GDI+ gives BGRA with straight alpha; UpdateLayeredWindow wants
|
|
348
|
+
// premultiplied. Doing it here keeps the upload path allocation-free.
|
|
349
|
+
for (int i = 0; i < raw.Length; i += 4)
|
|
350
|
+
{
|
|
351
|
+
int a = raw[i + 3];
|
|
352
|
+
if (a == 255) continue;
|
|
353
|
+
if (a == 0)
|
|
354
|
+
{
|
|
355
|
+
raw[i] = 0; raw[i + 1] = 0; raw[i + 2] = 0;
|
|
356
|
+
continue;
|
|
357
|
+
}
|
|
358
|
+
raw[i] = (byte)(raw[i] * a / 255);
|
|
359
|
+
raw[i + 1] = (byte)(raw[i + 1] * a / 255);
|
|
360
|
+
raw[i + 2] = (byte)(raw[i + 2] * a / 255);
|
|
361
|
+
}
|
|
362
|
+
return raw;
|
|
363
|
+
}
|
|
364
|
+
finally
|
|
365
|
+
{
|
|
366
|
+
bmp.UnlockBits(data);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
static void Push(OverlayForm form, byte opacity)
|
|
371
|
+
{
|
|
372
|
+
IntPtr screenDc = Native.GetDC(IntPtr.Zero);
|
|
373
|
+
if (screenDc == IntPtr.Zero) return;
|
|
374
|
+
try
|
|
375
|
+
{
|
|
376
|
+
IntPtr memDc = Native.CreateCompatibleDC(screenDc);
|
|
377
|
+
if (memDc == IntPtr.Zero) return;
|
|
378
|
+
try
|
|
379
|
+
{
|
|
380
|
+
var bmi = new Native.BITMAPINFO();
|
|
381
|
+
bmi.bmiHeader.biSize = Marshal.SizeOf(typeof(Native.BITMAPINFOHEADER));
|
|
382
|
+
bmi.bmiHeader.biWidth = form.W;
|
|
383
|
+
bmi.bmiHeader.biHeight = -form.H; // top-down
|
|
384
|
+
bmi.bmiHeader.biPlanes = 1;
|
|
385
|
+
bmi.bmiHeader.biBitCount = 32;
|
|
386
|
+
bmi.bmiHeader.biCompression = 0; // BI_RGB
|
|
387
|
+
|
|
388
|
+
IntPtr bits;
|
|
389
|
+
IntPtr hbm = Native.CreateDIBSection(screenDc, ref bmi, 0, out bits, IntPtr.Zero, 0);
|
|
390
|
+
if (hbm == IntPtr.Zero) return;
|
|
391
|
+
try
|
|
392
|
+
{
|
|
393
|
+
if (opacity >= 255)
|
|
394
|
+
{
|
|
395
|
+
Marshal.Copy(form.Pixels, 0, bits, form.Pixels.Length);
|
|
396
|
+
}
|
|
397
|
+
else
|
|
398
|
+
{
|
|
399
|
+
// Fade by scaling the premultiplied channels, which is
|
|
400
|
+
// what a constant-alpha blend does anyway.
|
|
401
|
+
byte[] faded = (byte[])form.Pixels.Clone();
|
|
402
|
+
for (int i = 0; i < faded.Length; i += 4)
|
|
403
|
+
{
|
|
404
|
+
faded[i] = (byte)(faded[i] * opacity / 255);
|
|
405
|
+
faded[i + 1] = (byte)(faded[i + 1] * opacity / 255);
|
|
406
|
+
faded[i + 2] = (byte)(faded[i + 2] * opacity / 255);
|
|
407
|
+
faded[i + 3] = (byte)(faded[i + 3] * opacity / 255);
|
|
408
|
+
}
|
|
409
|
+
Marshal.Copy(faded, 0, bits, faded.Length);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
IntPtr old = Native.SelectObject(memDc, hbm);
|
|
413
|
+
try
|
|
414
|
+
{
|
|
415
|
+
var pos = new Native.POINT(form.X, form.Y);
|
|
416
|
+
var size = new Native.SIZE(form.W, form.H);
|
|
417
|
+
var src = new Native.POINT(0, 0);
|
|
418
|
+
var blend = new Native.BLENDFUNCTION
|
|
419
|
+
{
|
|
420
|
+
BlendOp = Native.AC_SRC_OVER,
|
|
421
|
+
BlendFlags = 0,
|
|
422
|
+
SourceConstantAlpha = 255,
|
|
423
|
+
AlphaFormat = Native.AC_SRC_ALPHA,
|
|
424
|
+
};
|
|
425
|
+
Native.UpdateLayeredWindow(
|
|
426
|
+
form.Handle, screenDc, ref pos, ref size, memDc, ref src, 0, ref blend, Native.ULW_ALPHA);
|
|
427
|
+
}
|
|
428
|
+
finally
|
|
429
|
+
{
|
|
430
|
+
Native.SelectObject(memDc, old);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
finally
|
|
434
|
+
{
|
|
435
|
+
Native.DeleteObject(hbm);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
finally
|
|
439
|
+
{
|
|
440
|
+
Native.DeleteDC(memDc);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
finally
|
|
444
|
+
{
|
|
445
|
+
Native.ReleaseDC(IntPtr.Zero, screenDc);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
static GraphicsPath RoundedRect(Rectangle rect, int radius)
|
|
450
|
+
{
|
|
451
|
+
var path = new GraphicsPath();
|
|
452
|
+
int d = Math.Max(1, radius * 2);
|
|
453
|
+
path.AddArc(rect.X, rect.Y, d, d, 180, 90);
|
|
454
|
+
path.AddArc(rect.Right - d, rect.Y, d, d, 270, 90);
|
|
455
|
+
path.AddArc(rect.Right - d, rect.Bottom - d, d, d, 0, 90);
|
|
456
|
+
path.AddArc(rect.X, rect.Bottom - d, d, d, 90, 90);
|
|
457
|
+
path.CloseFigure();
|
|
458
|
+
return path;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/// <summary>One screen edge: a feather that peaks at the very edge.</summary>
|
|
462
|
+
static Bitmap EdgeStrip(int w, int h, string side, Color color)
|
|
463
|
+
{
|
|
464
|
+
var bmp = new Bitmap(Math.Max(1, w), Math.Max(1, h), PixelFormat.Format32bppArgb);
|
|
465
|
+
using (var g = Graphics.FromImage(bmp))
|
|
466
|
+
{
|
|
467
|
+
g.SmoothingMode = SmoothingMode.None;
|
|
468
|
+
bool horizontal = side == "top" || side == "bottom";
|
|
469
|
+
int extent = Math.Min(BORDER, horizontal ? h : w);
|
|
470
|
+
for (int depth = 0; depth < extent; depth++)
|
|
471
|
+
{
|
|
472
|
+
// Peak 240 at the edge, easing to 0 inward.
|
|
473
|
+
double t = 1.0 - (double)depth / Math.Max(1, extent - 1);
|
|
474
|
+
int alpha = (int)Math.Round(240 * Math.Pow(t, 1.4));
|
|
475
|
+
if (alpha <= 0) continue;
|
|
476
|
+
using (var pen = new Pen(Color.FromArgb(alpha, color), 1f))
|
|
477
|
+
{
|
|
478
|
+
switch (side)
|
|
479
|
+
{
|
|
480
|
+
case "top": g.DrawLine(pen, 0, depth, w, depth); break;
|
|
481
|
+
case "bottom": g.DrawLine(pen, 0, h - 1 - depth, w, h - 1 - depth); break;
|
|
482
|
+
case "left": g.DrawLine(pen, depth, 0, depth, h); break;
|
|
483
|
+
default: g.DrawLine(pen, w - 1 - depth, 0, w - 1 - depth, h); break;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return bmp;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
/// <summary>Soft radial aura behind the pointer, plus a small "AI" chip.</summary>
|
|
492
|
+
static Bitmap CursorRing(Color color)
|
|
493
|
+
{
|
|
494
|
+
var bmp = new Bitmap(CURSOR_SIZE, CURSOR_SIZE, PixelFormat.Format32bppArgb);
|
|
495
|
+
double half = (CURSOR_SIZE - 1) / 2.0;
|
|
496
|
+
using (var g = Graphics.FromImage(bmp))
|
|
497
|
+
{
|
|
498
|
+
g.SmoothingMode = SmoothingMode.AntiAlias;
|
|
499
|
+
for (int y = 0; y < CURSOR_SIZE; y++)
|
|
500
|
+
{
|
|
501
|
+
for (int x = 0; x < CURSOR_SIZE; x++)
|
|
502
|
+
{
|
|
503
|
+
double r = Math.Sqrt((x - half) * (x - half) + (y - half) * (y - half));
|
|
504
|
+
// Hollow centre so the real pointer stays readable.
|
|
505
|
+
double clearCenter = 1.0 - Math.Exp(-0.5 * Math.Pow(Math.Max(0.0, r - 1) / 5.0, 2));
|
|
506
|
+
double outerGlow = Math.Exp(-0.5 * Math.Pow(r / 20.0, 2));
|
|
507
|
+
double edgeFade = Math.Min(1.0, Math.Max(0.0, (half - r) / 8.0));
|
|
508
|
+
int alpha = (int)Math.Round(230 * clearCenter * outerGlow * edgeFade);
|
|
509
|
+
if (alpha <= 0) continue;
|
|
510
|
+
bmp.SetPixel(x, y, Color.FromArgb(alpha, color));
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// "AI" chip above-right of the hotspot, clear of the arrow body.
|
|
515
|
+
using (var font = new Font("Segoe UI", CURSOR_LABEL_SIZE / 2f + 1f, FontStyle.Bold, GraphicsUnit.Pixel))
|
|
516
|
+
{
|
|
517
|
+
SizeF text = g.MeasureString(CURSOR_LABEL, font);
|
|
518
|
+
int chipW = (int)text.Width + 12;
|
|
519
|
+
int chipH = (int)text.Height + 4;
|
|
520
|
+
int left = CURSOR_SIZE / 2 + 8;
|
|
521
|
+
int bottom = CURSOR_SIZE / 2 - 8;
|
|
522
|
+
var chip = new Rectangle(left, bottom - chipH, chipW, chipH);
|
|
523
|
+
using (var path = RoundedRect(chip, chipH / 2))
|
|
524
|
+
using (var brush = new SolidBrush(color))
|
|
525
|
+
{
|
|
526
|
+
g.FillPath(brush, path);
|
|
527
|
+
}
|
|
528
|
+
using (var white = new SolidBrush(Color.White))
|
|
529
|
+
{
|
|
530
|
+
g.DrawString(CURSOR_LABEL, font, white, left + 6, bottom - chipH + 2);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
return bmp;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
/// <summary>The top-centre banner: what is happening and how to stop it.</summary>
|
|
538
|
+
static Bitmap Notice(int screenWidth, Color color)
|
|
539
|
+
{
|
|
540
|
+
const int pad = 32;
|
|
541
|
+
int available = screenWidth - 32;
|
|
542
|
+
if (available < 240) return null;
|
|
543
|
+
|
|
544
|
+
string title = PhaseTitle();
|
|
545
|
+
string hint = PhaseDetail();
|
|
546
|
+
|
|
547
|
+
Font titleFont = null, hintFont = null;
|
|
548
|
+
SizeF titleSize = SizeF.Empty, hintSize = SizeF.Empty;
|
|
549
|
+
using (var probe = Graphics.FromImage(new Bitmap(1, 1)))
|
|
550
|
+
{
|
|
551
|
+
for (int px = 21; px >= 11; px--)
|
|
552
|
+
{
|
|
553
|
+
var tf = new Font("Segoe UI", px + 6f, FontStyle.Bold, GraphicsUnit.Pixel);
|
|
554
|
+
var hf = new Font("Segoe UI", px, FontStyle.Regular, GraphicsUnit.Pixel);
|
|
555
|
+
SizeF ts = probe.MeasureString(title, tf);
|
|
556
|
+
SizeF hs = probe.MeasureString(hint, hf);
|
|
557
|
+
if (ts.Width + pad * 2 <= available && hs.Width + pad * 2 <= available)
|
|
558
|
+
{
|
|
559
|
+
titleFont = tf;
|
|
560
|
+
hintFont = hf;
|
|
561
|
+
titleSize = ts;
|
|
562
|
+
hintSize = hs;
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
tf.Dispose();
|
|
566
|
+
hf.Dispose();
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
if (titleFont == null) return null;
|
|
570
|
+
|
|
571
|
+
const int glowPad = 32;
|
|
572
|
+
int width = (int)Math.Ceiling(Math.Max(titleSize.Width, hintSize.Width)) + pad * 2;
|
|
573
|
+
int height = (int)Math.Ceiling(titleSize.Height + hintSize.Height) + 30;
|
|
574
|
+
|
|
575
|
+
var bmp = new Bitmap(width + glowPad * 2, height + glowPad * 2, PixelFormat.Format32bppArgb);
|
|
576
|
+
using (var g = Graphics.FromImage(bmp))
|
|
577
|
+
{
|
|
578
|
+
g.SmoothingMode = SmoothingMode.AntiAlias;
|
|
579
|
+
g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
|
|
580
|
+
var panel = new Rectangle(glowPad, glowPad, width, height);
|
|
581
|
+
|
|
582
|
+
// Aura: concentric rounded outlines, densest near the panel.
|
|
583
|
+
for (int i = glowPad; i >= 2; i -= 2)
|
|
584
|
+
{
|
|
585
|
+
double t = 1.0 - (double)i / glowPad;
|
|
586
|
+
int alpha = (int)Math.Round(120 * t * t);
|
|
587
|
+
if (alpha <= 0) continue;
|
|
588
|
+
var outer = new Rectangle(panel.X - i, panel.Y - i, panel.Width + i * 2, panel.Height + i * 2);
|
|
589
|
+
using (var path = RoundedRect(outer, 22 + i))
|
|
590
|
+
using (var brush = new SolidBrush(Color.FromArgb(alpha, color)))
|
|
591
|
+
{
|
|
592
|
+
g.FillPath(brush, path);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
// Panel body: deep navy, 80% opaque, rounded.
|
|
597
|
+
using (var path = RoundedRect(panel, 22))
|
|
598
|
+
using (var brush = new SolidBrush(Color.FromArgb(204, 8, 42, 88)))
|
|
599
|
+
{
|
|
600
|
+
g.FillPath(brush, path);
|
|
601
|
+
}
|
|
602
|
+
using (var path = RoundedRect(panel, 22))
|
|
603
|
+
using (var pen = new Pen(Color.FromArgb(90, color), 1f))
|
|
604
|
+
{
|
|
605
|
+
g.DrawPath(pen, path);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
using (var titleBrush = new SolidBrush(Color.FromArgb(255, 248, 251, 255)))
|
|
609
|
+
using (var hintBrush = new SolidBrush(Color.FromArgb(255, 225, 240, 255)))
|
|
610
|
+
{
|
|
611
|
+
float titleY = glowPad + 12;
|
|
612
|
+
g.DrawString(title, titleFont, titleBrush,
|
|
613
|
+
glowPad + (width - titleSize.Width) / 2f, titleY);
|
|
614
|
+
g.DrawString(hint, hintFont, hintBrush,
|
|
615
|
+
glowPad + (width - hintSize.Width) / 2f, titleY + titleSize.Height + 2);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
titleFont.Dispose();
|
|
619
|
+
hintFont.Dispose();
|
|
620
|
+
return bmp;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/// <summary>Destroy every window and forget the cached bitmaps.</summary>
|
|
624
|
+
public static void Hide()
|
|
625
|
+
{
|
|
626
|
+
lock (Gate)
|
|
627
|
+
{
|
|
628
|
+
HideInternal();
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
/// <summary>
|
|
633
|
+
/// Raise the overlay for the current phase. Idempotent: calling it while
|
|
634
|
+
/// already visible just repaints (so a phase change takes effect).
|
|
635
|
+
///
|
|
636
|
+
/// <paramref name="excludeFromCapture"/> exists for diagnostics only: with
|
|
637
|
+
/// it false the windows are capturable, which is how a test proves the
|
|
638
|
+
/// overlay really paints instead of being an invisible-but-present window.
|
|
639
|
+
/// </summary>
|
|
640
|
+
public static string Show(string newPhase, bool excludeFromCapture = true, string newDetail = null)
|
|
641
|
+
{
|
|
642
|
+
lock (Gate)
|
|
643
|
+
{
|
|
644
|
+
if (!string.IsNullOrEmpty(newPhase)) phase = newPhase;
|
|
645
|
+
if (newDetail != null) detail = newDetail;
|
|
646
|
+
HideInternal();
|
|
647
|
+
try
|
|
648
|
+
{
|
|
649
|
+
Color color = PhaseColor();
|
|
650
|
+
int sx = Native.GetSystemMetrics(Native.SM_XVIRTUALSCREEN);
|
|
651
|
+
int sy = Native.GetSystemMetrics(Native.SM_YVIRTUALSCREEN);
|
|
652
|
+
int sw = Native.GetSystemMetrics(Native.SM_CXVIRTUALSCREEN);
|
|
653
|
+
int sh = Native.GetSystemMetrics(Native.SM_CYVIRTUALSCREEN);
|
|
654
|
+
if (sw <= 0 || sh <= 0) return "no-display";
|
|
655
|
+
|
|
656
|
+
int border = Math.Min(BORDER, Math.Min(sw, sh) / 4);
|
|
657
|
+
if (border <= 0) return "display-too-small";
|
|
658
|
+
|
|
659
|
+
// Four edge strips. Vertical strips start below the horizontal
|
|
660
|
+
// ones so corners are not blended twice.
|
|
661
|
+
Forms.Add(CreateForm("top", sx, sy, sw, border,
|
|
662
|
+
EdgeStrip(sw, border, "top", color), excludeFromCapture));
|
|
663
|
+
Forms.Add(CreateForm("bottom", sx, sy + sh - border, sw, border,
|
|
664
|
+
EdgeStrip(sw, border, "bottom", color), excludeFromCapture));
|
|
665
|
+
int sideH = Math.Max(1, sh - border * 2);
|
|
666
|
+
Forms.Add(CreateForm("left", sx, sy + border, border, sideH,
|
|
667
|
+
EdgeStrip(border, sideH, "left", color), excludeFromCapture));
|
|
668
|
+
Forms.Add(CreateForm("right", sx + sw - border, sy + border, border, sideH,
|
|
669
|
+
EdgeStrip(border, sideH, "right", color), excludeFromCapture));
|
|
670
|
+
|
|
671
|
+
// Banner.
|
|
672
|
+
Bitmap notice = Notice(sw, color);
|
|
673
|
+
if (notice != null)
|
|
674
|
+
{
|
|
675
|
+
const int glowPad = 32;
|
|
676
|
+
int nx = sx + (sw - notice.Width) / 2;
|
|
677
|
+
int ny = sy + border + glowPad / 2;
|
|
678
|
+
Forms.Add(CreateForm("notice", nx, ny, notice.Width, notice.Height, notice, excludeFromCapture));
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// Cursor aura, only while the pointer is on the virtual screen.
|
|
682
|
+
// GetCursorPos rather than WinForms' Cursor.Position: the C#
|
|
683
|
+
// here must compile without a WinForms reference, because the
|
|
684
|
+
// host only guarantees System.Drawing.
|
|
685
|
+
Native.POINT cursor;
|
|
686
|
+
if (Native.GetCursorPos(out cursor)
|
|
687
|
+
&& cursor.x >= sx && cursor.x < sx + sw
|
|
688
|
+
&& cursor.y >= sy && cursor.y < sy + sh)
|
|
689
|
+
{
|
|
690
|
+
Forms.Add(CreateForm("cursor",
|
|
691
|
+
cursor.x - CURSOR_SIZE / 2, cursor.y - CURSOR_SIZE / 2,
|
|
692
|
+
CURSOR_SIZE, CURSOR_SIZE, CursorRing(color), excludeFromCapture));
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
foreach (OverlayForm form in Forms)
|
|
696
|
+
{
|
|
697
|
+
Native.ShowWindow(form.Handle, Native.SW_SHOWNA);
|
|
698
|
+
Native.SetWindowPos(form.Handle, Native.HWND_TOPMOST, 0, 0, 0, 0,
|
|
699
|
+
Native.SWP_NOSIZE | Native.SWP_NOMOVE | Native.SWP_NOACTIVATE | Native.SWP_SHOWWINDOW);
|
|
700
|
+
}
|
|
701
|
+
visible = true;
|
|
702
|
+
return "ok:" + Forms.Count;
|
|
703
|
+
}
|
|
704
|
+
catch (Exception error)
|
|
705
|
+
{
|
|
706
|
+
HideInternal();
|
|
707
|
+
return "error:" + error.Message;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
static void HideInternal()
|
|
713
|
+
{
|
|
714
|
+
foreach (OverlayForm form in Forms)
|
|
715
|
+
{
|
|
716
|
+
if (form.Handle != IntPtr.Zero) Native.DestroyWindow(form.Handle);
|
|
717
|
+
if (form.Content != null) form.Content.Dispose();
|
|
718
|
+
}
|
|
719
|
+
Forms.Clear();
|
|
720
|
+
foreach (string cls in ClassNames)
|
|
721
|
+
Native.UnregisterClass(cls, Native.GetModuleHandle(null));
|
|
722
|
+
ClassNames.Clear();
|
|
723
|
+
visible = false;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
/// <summary>Probe used by the host to prove capture exclusion is on.</summary>
|
|
727
|
+
public static string Diagnose()
|
|
728
|
+
{
|
|
729
|
+
lock (Gate)
|
|
730
|
+
{
|
|
731
|
+
int sx = Native.GetSystemMetrics(Native.SM_XVIRTUALSCREEN);
|
|
732
|
+
int sy = Native.GetSystemMetrics(Native.SM_YVIRTUALSCREEN);
|
|
733
|
+
int sw = Native.GetSystemMetrics(Native.SM_CXVIRTUALSCREEN);
|
|
734
|
+
int sh = Native.GetSystemMetrics(Native.SM_CYVIRTUALSCREEN);
|
|
735
|
+
string metrics = string.Format("virtual={0},{1} {2}x{3}", sx, sy, sw, sh);
|
|
736
|
+
if (Forms.Count == 0) return "hidden " + metrics;
|
|
737
|
+
|
|
738
|
+
uint affinity;
|
|
739
|
+
bool ok = Native.GetWindowDisplayAffinity(Forms[0].Handle, out affinity);
|
|
740
|
+
var parts = new List<string>();
|
|
741
|
+
parts.Add(string.Format("visible:{0} windows:{1} affinity_ok:{2} affinity:0x{3:x}",
|
|
742
|
+
visible, Forms.Count, ok, affinity));
|
|
743
|
+
parts.Add(metrics);
|
|
744
|
+
foreach (OverlayForm form in Forms)
|
|
745
|
+
{
|
|
746
|
+
Native.RECT rect;
|
|
747
|
+
string where = Native.GetWindowRect(form.Handle, out rect)
|
|
748
|
+
? string.Format("{0}@{1},{2} {3}x{4}", form.ClassName.Substring(15),
|
|
749
|
+
rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top)
|
|
750
|
+
: form.ClassName.Substring(15) + "@?";
|
|
751
|
+
parts.Add(where);
|
|
752
|
+
}
|
|
753
|
+
return string.Join(" ", parts.ToArray());
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
|
|
757
|
+
public static void Init()
|
|
758
|
+
{
|
|
759
|
+
// Per-monitor-v2 FIRST, before any window or metric call. Without it
|
|
760
|
+
// the process is DPI-unaware: GetSystemMetrics reports virtualized
|
|
761
|
+
// (smaller) sizes while the compositor scales our windows up again,
|
|
762
|
+
// and every overlay lands at the wrong place — a banner centred in a
|
|
763
|
+
// 1600-wide virtual screen renders in the right half of a 3200-wide
|
|
764
|
+
// physical one, half of it off-screen.
|
|
765
|
+
if (!Native.SetProcessDpiAwarenessContext(Native.DPI_AWARENESS_PER_MONITOR_V2))
|
|
766
|
+
{
|
|
767
|
+
// Older builds: fall back to the v1 context, then to the thread.
|
|
768
|
+
Native.SetProcessDpiAwarenessContext(Native.DPI_AWARENESS_PER_MONITOR);
|
|
769
|
+
Native.SetThreadDpiAwarenessContext(Native.DPI_AWARENESS_PER_MONITOR_V2);
|
|
770
|
+
}
|
|
771
|
+
procKeepAlive = new Native.WndProcDelegate(WndProc);
|
|
772
|
+
// Keep the delegate reachable: a collected WndProc crashes the window
|
|
773
|
+
// procedure the moment Windows calls into it.
|
|
774
|
+
GC.KeepAlive(procKeepAlive);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
}
|