471 references to NativeMethods
aspire-tray (471)
FolderApplication.cs (2)
122
Marshal.ThrowExceptionForHR(
NativeMethods
.ParseDisplayName(path, 0, out var item, 0, out _));
125
Marshal.ThrowExceptionForHR(
NativeMethods
.OpenFolderAndSelectItems(item, 0, 0, 0));
NativeSmokeHarness.cs (1)
103
Require(flags ==
NativeMethods
.SafeConfirmation && (flags & 0x100) != 0, "Confirmation must default to Cancel.");
Program.cs (2)
156
NativeMethods
.OutputDebugString($"Tray diagnostic write failed ({ex.GetType().Name}).{Environment.NewLine}");
158
NativeMethods
.OutputDebugString(message + Environment.NewLine);
TrayApplication.Actions.cs (6)
107
ShowMessage("Aspire", ex.Message,
NativeMethods
.MbIconError);
158
var accept = ConfirmForSmoke?.Invoke(title, detail,
NativeMethods
.SafeConfirmation)
162
var result =
NativeMethods
.MessageBox(_modalOwner, detail, title,
NativeMethods
.SafeConfirmation);
189
NativeCallException.Require(
NativeMethods
.MessageBox(_modalOwner, detail, title, flags) != 0, "MessageBoxW");
208
var result =
NativeMethods
.ShellExecute(_window, "open", uri.AbsoluteUri, null, null, 1);
TrayApplication.Clipboard.cs (8)
20
var memory =
NativeMethods
.GlobalAlloc(0x2, checked((nuint)(path.Length + 1) * sizeof(char)));
24
var buffer =
NativeMethods
.GlobalLock(memory);
30
var unlocked =
NativeMethods
.GlobalUnlock(memory);
32
NativeCallException.Require(
NativeMethods
.OpenClipboard(_window) != 0, "OpenClipboard");
35
NativeCallException.Require(
NativeMethods
.EmptyClipboard() != 0, "EmptyClipboard");
36
NativeCallException.Require(
NativeMethods
.SetClipboardData(13, memory) != 0, "SetClipboardData");
41
NativeCallException.Require(
NativeMethods
.CloseClipboard() != 0, "CloseClipboard");
48
Cleanup(
NativeMethods
.GlobalFree(memory) == 0, "GlobalFree(clipboard)");
TrayApplication.cs (79)
37
private
NativeMethods
.NotifyIconData _iconData;
66
if (_window != 0 &&
NativeMethods
.PostMessage(_window,
NativeMethods
.RestoreMessage, 0, 0) == 0)
80
if (_window != 0 && !_loopEnded &&
NativeMethods
.PostMessage(_window,
NativeMethods
.QuitMessage, 0, 0) == 0)
93
|| sizeof(
NativeMethods
.WindowClass) != 72 || sizeof(
NativeMethods
.Message) != 48
94
|| sizeof(
NativeMethods
.NotifyIconData) != 976 || sizeof(
NativeMethods
.MenuItemInfo) != 80
95
|| sizeof(
NativeMethods
.IconInfo) != 32 || sizeof(
NativeMethods
.BitmapInfo) != 44
96
|| sizeof(
NativeMethods
.ToolInfo) != 72)
111
var result =
NativeMethods
.GetMessage(out var message, 0, 0, 0);
118
|| (_settingsWindow != 0 &&
NativeMethods
.IsDialogMessage(_settingsWindow, ref message) != 0))
122
NativeMethods
.TranslateMessage(in message);
123
NativeMethods
.DispatchMessage(in message);
146
var controls = new
NativeMethods
.CommonControls
148
Size = (uint)sizeof(
NativeMethods
.CommonControls),
151
NativeCallException.Require(
NativeMethods
.InitCommonControlsEx(in controls) != 0, "InitCommonControlsEx");
152
_previousDpiContext =
NativeMethods
.SetThreadDpiAwarenessContext(-4);
154
_module =
NativeMethods
.GetModuleHandle(null);
156
_taskbarCreated =
NativeMethods
.RegisterWindowMessage("TaskbarCreated");
160
var windowClass = new
NativeMethods
.WindowClass
164
NativeCallException.Require(
NativeMethods
.RegisterClass(ref windowClass) != 0, "RegisterClassW");
168
var window =
NativeMethods
.CreateWindowEx(0, ClassName, "Aspire Tray", 0, 0, 0, 0, 0, 0, 0, _module, 0);
174
_iconData = new
NativeMethods
.NotifyIconData
176
Size = (uint)sizeof(
NativeMethods
.NotifyIconData), Window = window, Id = 1,
177
Flags =
NativeMethods
.NifMessage |
NativeMethods
.NifIcon |
NativeMethods
.NifTip |
NativeMethods
.NifShowTip,
178
CallbackMessage =
NativeMethods
.TrayCallback
196
_timerAdded =
NativeMethods
.SetTimer(window, TimerId, 200, 0) != 0;
202
NativeCallException.Require(
NativeMethods
.PostMessage(window,
NativeMethods
.ReadyMessage, 0, 0) != 0, "PostMessageW(ready)");
213
if (
NativeMethods
.PostMessage(_window,
NativeMethods
.RefreshMessage, 0, 0) == 0)
231
if (
NativeMethods
.ShellNotifyIcon(
NativeMethods
.NimAdd, ref _iconData) == 0)
240
_iconData.Version =
NativeMethods
.NotifyIconVersion4;
241
if (
NativeMethods
.ShellNotifyIcon(
NativeMethods
.NimSetVersion, ref _iconData) == 0)
264
if (
NativeMethods
.ShellNotifyIcon(
NativeMethods
.NimModify, ref _iconData) == 0)
308
NativeMethods
.PostQuitMessage(1);
312
return
NativeMethods
.DefWindowProc(window, message, wParam, lParam);
326
case
NativeMethods
.ReadyMessage:
337
case
NativeMethods
.RefreshMessage:
344
case
NativeMethods
.RestoreMessage:
347
case
NativeMethods
.QuitMessage:
350
case
NativeMethods
.SettingsMessage when !_quitRequested:
354
case
NativeMethods
.SmokeMessage when smokeSeconds is not null:
357
case
NativeMethods
.WmTimer when wParam == TimerId:
360
case
NativeMethods
.WmDpiChanged:
361
case
NativeMethods
.WmSettingChange:
362
case
NativeMethods
.WmSysColorChange:
363
case
NativeMethods
.WmThemeChanged:
367
case
NativeMethods
.WmMenuRightButtonUp when _menuOpen && _modalDepth == 0:
370
case
NativeMethods
.WmMenuSelect:
373
case
NativeMethods
.TrayCallback when !_menuOpen && !_quitRequested && _modalDepth == 0:
376
if (notification is
NativeMethods
.WmContextMenu or
NativeMethods
.NinSelect or
NativeMethods
.NinKeySelect)
381
case
NativeMethods
.WmClose:
382
case
NativeMethods
.WmDestroy:
383
case
NativeMethods
.WmEndSession when wParam != 0:
387
return
NativeMethods
.DefWindowProc(window, message, wParam, lParam);
440
Cleanup(
NativeMethods
.EndMenu() != 0, "EndMenu");
450
Cleanup(
NativeMethods
.PostMessage(popup,
NativeMethods
.WmClose, 0, 0) != 0, "PostMessageW(close dialog)");
453
NativeMethods
.PostQuitMessage(ExitCode);
461
return
NativeMethods
.GetWindow(owner,
NativeMethods
.GwEnabledPopup);
497
Cleanup(
NativeMethods
.KillTimer(_window, TimerId) != 0, "KillTimer");
501
Cleanup(
NativeMethods
.ShellNotifyIcon(
NativeMethods
.NimDelete, ref _iconData) != 0, "Shell_NotifyIconW(NIM_DELETE)");
515
if (
NativeMethods
.DestroyWindow(_window) == 0)
522
if (_classRegistered &&
NativeMethods
.UnregisterClass(ClassName, _module) == 0)
530
Cleanup(
NativeMethods
.SetThreadDpiAwarenessContext(_previousDpiContext) != 0, "SetThreadDpiAwarenessContext(restore)");
TrayApplication.Icons.cs (35)
29
if (_iconAdded &&
NativeMethods
.ShellNotifyIcon(
NativeMethods
.NimModify, ref _iconData) == 0)
79
Size =
NativeMethods
.GetSystemMetricsForDpi(
NativeMethods
.SmCxSmallIcon, dpi);
83
var original =
NativeMethods
.LoadImage(0, Path.Combine(AppContext.BaseDirectory, "Aspire.ico"),
84
NativeMethods
.ImageIcon, Size, Size,
NativeMethods
.LrLoadFromFile);
170
var mask =
NativeMethods
.CreateBitmap(Size, Size, 1, 1, (nint)maskBits);
174
var info = new
NativeMethods
.IconInfo { IsIcon = 1, Color = canvas.Handle, Mask = mask };
175
var icon =
NativeMethods
.CreateIconIndirect(ref info);
182
_owner.Cleanup(
NativeMethods
.DeleteObject(mask) != 0, "DeleteObject(icon mask)");
196
_owner.Cleanup(
NativeMethods
.DestroyIcon(icon) != 0, "DestroyIcon");
221
var info = new
NativeMethods
.BitmapInfo
225
Handle =
NativeMethods
.CreateDIBSection(0, ref info, 0, out var bits, 0, 0);
253
var dc =
NativeMethods
.CreateCompatibleDC(0);
260
previousBitmap =
NativeMethods
.SelectObject(dc, Handle);
264
font =
NativeMethods
.CreateFont(-height, 0, 0, 0, 400, 0, 0, 0, 1, 0, 0, 4, 0, "Segoe MDL2 Assets");
266
previousFont =
NativeMethods
.SelectObject(dc, font);
268
NativeCallException.Require(
NativeMethods
.SetTextColor(dc, 0xFFFFFF) != uint.MaxValue, "SetTextColor(menu glyph)");
269
NativeCallException.Require(
NativeMethods
.SetBkMode(dc, 1) != 0, "SetBkMode(menu glyph)"); // TRANSPARENT.
270
var bounds = new
NativeMethods
.Rect { Right = _size, Bottom = _size };
271
NativeCallException.Require(
NativeMethods
.DrawText(dc, glyph, glyph.Length, ref bounds,
273
NativeCallException.Require(
NativeMethods
.GdiFlush() != 0, "GdiFlush(menu glyph)");
277
var color =
NativeMethods
.GetSysColor(7); // COLOR_MENUTEXT.
295
_owner.Cleanup(
NativeMethods
.SelectObject(dc, previousFont) != 0, "SelectObject(restore menu font)");
299
_owner.Cleanup(
NativeMethods
.SelectObject(dc, previousBitmap) != 0, "SelectObject(restore menu bitmap)");
301
_owner.Cleanup(
NativeMethods
.DeleteDC(dc) != 0, "DeleteDC(menu glyph)");
304
_owner.Cleanup(
NativeMethods
.DeleteObject(font) != 0, "DeleteObject(menu font)");
334
var dc =
NativeMethods
.CreateCompatibleDC(0);
339
previous =
NativeMethods
.SelectObject(dc, Handle);
341
NativeCallException.Require(
NativeMethods
.DrawIconEx(dc, 0, 0, icon, _size, _size, 0, 0, 3) != 0, "DrawIconEx");
343
NativeCallException.Require(
NativeMethods
.GdiFlush() != 0, "GdiFlush");
349
_owner.Cleanup(
NativeMethods
.SelectObject(dc, previous) != 0, "SelectObject(restore)");
351
_owner.Cleanup(
NativeMethods
.DeleteDC(dc) != 0, "DeleteDC");
359
_owner.Cleanup(
NativeMethods
.DeleteObject(Handle) != 0, "DeleteObject(canvas)");
TrayApplication.Menus.cs (60)
21
var replacement = new Artwork(this,
NativeMethods
.GetDpiForWindow(_window));
59
root.StatusPosition = (uint)
NativeMethods
.GetMenuItemCount(root.Handle);
60
Append(root.Handle,
NativeMethods
.MfGrayed, 0, state.Status);
66
Append(root.Handle,
NativeMethods
.MfSeparator, 0, null);
75
Append(recent,
NativeMethods
.MfGrayed, 0, "No recently opened AppHosts");
77
Append(recent,
NativeMethods
.MfSeparator, 0, null);
79
Append(root.Handle,
NativeMethods
.MfSeparator, 0, null);
85
Append(root.Handle,
NativeMethods
.MfSeparator, 0, null);
98
var position = (uint)
NativeMethods
.GetMenuItemCount(parent);
121
Append(submenu,
NativeMethods
.MfSeparator, 0, null);
132
Append(row.OpenIn,
NativeMethods
.MfGrayed, 0, "No supported applications installed");
134
Append(submenu,
NativeMethods
.MfSeparator, 0, null);
135
row.StatusPosition = (uint)
NativeMethods
.GetMenuItemCount(submenu);
136
Append(submenu,
NativeMethods
.MfGrayed, 0, AppHostPresentation.GetMenuDetailsLabel(GetMenuStatusText(host, discoveryAvailable)));
137
row.DetailsPosition = (uint)
NativeMethods
.GetMenuItemCount(submenu);
138
Append(submenu,
NativeMethods
.MfGrayed, 0, AppHostPresentation.GetPathLabel(host.Id.AppHostPath));
178
NativeCallException.Require(
NativeMethods
.EnumThreadWindows(
NativeMethods
.GetCurrentThreadId(), &RedrawPopup, 0) != 0,
189
var count =
NativeMethods
.GetClassName(window, name, 32);
193
NativeCallException.Require(
NativeMethods
.RedrawWindow(window, 0, 0, 0x101) != 0, "RedrawWindow(menu)");
226
var submenu =
NativeMethods
.CreatePopupMenu();
230
Append(parent,
NativeMethods
.MfPopup, (nuint)submenu, title);
235
if (
NativeMethods
.DestroyMenu(submenu) == 0)
247
Append(parent, enabled ? 0u :
NativeMethods
.MfGrayed, id, title);
258
=> NativeCallException.Require(
NativeMethods
.AppendMenu(menu, flags, id, Literal(text)) != 0, "AppendMenuW");
270
var info = new
NativeMethods
.MenuItemInfo
272
Size = (uint)sizeof(
NativeMethods
.MenuItemInfo), Mask =
NativeMethods
.MiimBitmap, Bitmap = bitmap
274
NativeCallException.Require(
NativeMethods
.SetMenuItemInfo(menu, item, byPosition ? 1 : 0, ref info) != 0, "SetMenuItemInfoW(menu bitmap)");
279
NativeCallException.Require(
NativeMethods
.SetMenuDefaultItem(menu, command, 0) != 0, "SetMenuDefaultItem");
284
var previous = new
NativeMethods
.MenuItemInfo
286
Size = (uint)sizeof(
NativeMethods
.MenuItemInfo), Mask =
NativeMethods
.MiimState
288
NativeCallException.Require(
NativeMethods
.GetMenuItemInfo(menu, id, byPosition ? 1 : 0, ref previous) != 0, "GetMenuItemInfoW(update)");
295
NativeCallException.Require(
NativeMethods
.SetMenuDefaultItem(menu, uint.MaxValue, 0) != 0, "SetMenuDefaultItem(clear)");
299
var info = new
NativeMethods
.MenuItemInfo
301
Size = (uint)sizeof(
NativeMethods
.MenuItemInfo),
302
Mask =
NativeMethods
.MiimString |
NativeMethods
.MiimState,
303
Text = text, State = (previous.State & ~(3u | 0x1000u)) | (enabled ? 0u :
NativeMethods
.MfGrayed)
305
NativeCallException.Require(
NativeMethods
.SetMenuItemInfo(menu, id, byPosition ? 1 : 0, ref info) != 0, "SetMenuItemInfoW");
308
NativeCallException.Require(
NativeMethods
.SetMenuDefaultItem(menu, id, byPosition ? 1u : 0u) != 0,
316
var point = new
NativeMethods
.Point
323
NativeCallException.Require(
NativeMethods
.GetCursorPos(out point) != 0, "GetCursorPos");
329
private void PrepareMenu(
NativeMethods
.Point point)
333
NativeCallException.Require(
NativeMethods
.SetWindowPos(_window, 0, point.X, point.Y, 0, 0, 0x1 | 0x4 | 0x10) != 0, "SetWindowPos(tray monitor)");
337
private void TrackMenu(nint popup,
NativeMethods
.Point point)
342
if (
NativeMethods
.SetForegroundWindow(_window) == 0)
350
var selected =
NativeMethods
.TrackPopupMenuEx(popup,
351
NativeMethods
.TpmReturnCmd |
NativeMethods
.TpmRightButton,
376
NativeCallException.Require(
NativeMethods
.PostMessage(_window,
NativeMethods
.WmNull, 0, 0) != 0, "PostMessageW");
390
NativeCallException.Require(
NativeMethods
.GetCursorPos(out var point) != 0, "GetCursorPos");
392
var selected =
NativeMethods
.TrackPopupMenuEx(context.Handle,
393
NativeMethods
.TpmReturnCmd |
NativeMethods
.TpmNonotify |
NativeMethods
.TpmRightButton | 0x1,
443
var handle =
NativeMethods
.CreatePopupMenu();
453
owner.Cleanup(
NativeMethods
.DestroyMenu(Handle) != 0, "DestroyMenu");
TrayApplication.NativeSmoke.cs (110)
16
internal bool IsTooltipVisibleForSmoke => _menuTooltipWindow != 0 &&
NativeMethods
.IsWindowVisible(_menuTooltipWindow) != 0;
26
var data = new
NativeMethods
.NotifyIconData
28
Size = (uint)sizeof(
NativeMethods
.NotifyIconData),
34
Icon =
NativeMethods
.LoadIcon(0, 32512)
37
Program.Log($"C# NOTIFYICONDATAW architecture={RuntimeInformation.ProcessArchitecture} size={sizeof(
NativeMethods
.NotifyIconData)} "
42
var added =
NativeMethods
.ShellNotifyIcon(
NativeMethods
.NimAdd, ref data);
46
NativeCallException.Require(
NativeMethods
.ShellNotifyIcon(
NativeMethods
.NimDelete, ref data) != 0, "Shell_NotifyIconW(smoke control delete)");
49
static nint Offset(string field) => Marshal.OffsetOf<
NativeMethods
.NotifyIconData>(field);
84
var defaultId = (nuint)
NativeMethods
.SendMessage(dialog, 0x400, 0, 0);
89
var checkbox =
NativeMethods
.GetDlgItem(dialog, StopSuppressionId);
91
&&
NativeMethods
.SendMessage(checkbox,
NativeMethods
.BmGetCheck, 0, 0) == 0,
93
NativeSmokeHarness.Require(ReadControlText(
NativeMethods
.GetDlgItem(dialog, StopDetailId)) == _stopDetail,
97
NativeMethods
.SendMessage(checkbox,
NativeMethods
.BmClick, 0, 0);
98
NativeSmokeHarness.Require(
NativeMethods
.SendMessage(checkbox,
NativeMethods
.BmGetCheck, 0, 0) == 1,
102
var button =
NativeMethods
.GetDlgItem(dialog, pending.Response);
106
NativeCallException.Require(
NativeMethods
.PostMessage(dialog,
NativeMethods
.WmCommand, (nuint)pending.Response, button) != 0, "PostMessageW(smoke dialog response)");
122
NativeMethods
.SendMessage(_window,
NativeMethods
.SmokeMessage, (nuint)token, 0);
128
NativeCallException.Require(
NativeMethods
.GetCursorPos(out var point) != 0, "GetCursorPos(smoke)");
136
NativeCallException.Require(_menuOpen &&
NativeMethods
.EndMenu() != 0, "EndMenu(smoke)");
143
var last = (uint)(
NativeMethods
.GetMenuItemCount(row.Submenu) - 1);
154
_tooltipFocusForSmoke =
NativeMethods
.GetFocus();
158
NativeCallException.Require(
NativeMethods
.HiliteMenuItem(_window, row.Submenu,
159
details ? row.DetailsPosition : row.Pin, (details ?
NativeMethods
.MfByPosition : 0) | 0x80) != 0,
168
NativeSmokeHarness.Require(
NativeMethods
.GetFocus() == _tooltipFocusForSmoke, "The tooltip stole keyboard focus.");
174
NativeMethods
.SendMessage(_menuTooltipWindow,
NativeMethods
.TtmGetText, (nuint)text.Length, (nint)(&tool));
177
NativeCallException.Require(
NativeMethods
.GetWindowRect(_menuTooltipWindow, out var bounds) != 0,
179
var monitor = new
NativeMethods
.MonitorInfo { Size = (uint)sizeof(
NativeMethods
.MonitorInfo) };
180
NativeCallException.Require(
NativeMethods
.GetMonitorInfo(
NativeMethods
.MonitorFromWindow(_window, 2), ref monitor) != 0,
198
NativeCallException.Require(
NativeMethods
.ShellNotifyIcon(
NativeMethods
.NimDelete, ref _iconData) != 0, "Shell_NotifyIconW(smoke delete)");
200
NativeMethods
.SendMessage(_window, _taskbarCreated, 0, 0);
208
NativeMethods
.SendMessage(_window,
NativeMethods
.WmDpiChanged, 0, 0);
232
NativeSmokeHarness.Require(
NativeMethods
.GetMenuItemCount(menu.Handle) == state.AppHosts.Count + 7 + (state.ShowStatus ? 1 : 0),
237
&& (ReadItem(menu.Handle, (uint)(rootTitles.Length - 2), true).Type &
NativeMethods
.MfSeparator) != 0,
270
NativeSmokeHarness.Require((ReadItem(row.Submenu, (uint)(firstActions.Length + 1), true).Type &
NativeMethods
.MfSeparator) != 0,
274
&& (ReadItem(row.Submenu, row.StatusPosition - 1, true).Type &
NativeMethods
.MfSeparator) != 0,
337
var count =
NativeMethods
.GetMenuItemCount(menu);
372
private static
NativeMethods
.MenuItemInfo ReadItem(nint menu, uint id, bool position)
374
var info = new
NativeMethods
.MenuItemInfo
376
Size = (uint)sizeof(
NativeMethods
.MenuItemInfo),
377
Mask =
NativeMethods
.MiimState |
NativeMethods
.MiimBitmap |
NativeMethods
.MiimSubmenu |
NativeMethods
.MiimId |
NativeMethods
.MiimFType
379
NativeCallException.Require(
NativeMethods
.GetMenuItemInfo(menu, id, position ? 1 : 0, ref info) != 0, "GetMenuItemInfoW(smoke)");
385
var info = new
NativeMethods
.MenuItemInfo { Size = (uint)sizeof(
NativeMethods
.MenuItemInfo), Mask =
NativeMethods
.MiimString };
386
NativeCallException.Require(
NativeMethods
.GetMenuItemInfo(menu, id, position ? 1 : 0, ref info) != 0, "GetMenuItemInfoW(smoke text length)");
392
NativeCallException.Require(
NativeMethods
.GetMenuItemInfo(menu, id, position ? 1 : 0, ref info) != 0, "GetMenuItemInfoW(smoke text)");
399
var count =
NativeMethods
.GetMenuItemCount(menu);
424
NativeSmokeHarness.Require(target != 0 &&
NativeMethods
.IsWindowVisible(target) != 0, "The Settings control is not visible.");
425
NativeMethods
.SendMessage(target,
NativeMethods
.BmClick, 0, 0);
431
if (
NativeMethods
.IsWindowVisible(_settingsRefresh) != 0)
445
NativeMethods
.SendMessage(_settingsWindow,
NativeMethods
.WmClose, 0, 0);
456
NativeSmokeHarness.Require(
NativeMethods
.IsThemeActive() == 0 ||
NativeMethods
.IsAppThemed() != 0,
459
&& ReadControlText(
NativeMethods
.GetDlgItem(_settingsWindow, SettingsGeneralId)) == "General"
460
&& ReadControlText(
NativeMethods
.GetDlgItem(_settingsWindow, SettingsAboutId)) == "About",
462
NativeSmokeHarness.Require(
NativeMethods
.SendMessage(_settingsCheckbox,
NativeMethods
.BmGetCheck, 0, 0) == (nint)checkState
463
&& (
NativeMethods
.IsWindowEnabled(_settingsCheckbox) != 0) == enabled, "The native startup checkbox misrepresents backend state.");
466
NativeSmokeHarness.Require((
NativeMethods
.IsWindowVisible(_settingsStatus) != 0) == showDetails
467
&& (
NativeMethods
.IsWindowVisible(_settingsRefresh) != 0) == showDetails,
476
for (var control =
NativeMethods
.GetWindow(_settingsWindow, 5); control != 0; control =
NativeMethods
.GetWindow(control, 2))
479
if (
NativeMethods
.IsWindowVisible(control) != 0)
489
var length =
NativeMethods
.GetClassName(label, className, 32);
494
NativeCallException.Require(
NativeMethods
.GetWindowRect(_settingsStatus, out var statusBounds) != 0, "GetWindowRect(Settings status smoke)");
495
NativeCallException.Require(
NativeMethods
.GetWindowRect(_settingsRefresh, out var refreshBounds) != 0, "GetWindowRect(Settings refresh smoke)");
496
NativeCallException.Require(
NativeMethods
.GetWindowRect(_settingsClose, out var closeBounds) != 0, "GetWindowRect(Settings close smoke)");
497
NativeCallException.Require(
NativeMethods
.GetWindowRect(_settingsWindow, out var windowBounds) != 0, "GetWindowRect(Settings window smoke)");
506
NativeSmokeHarness.Require(
NativeMethods
.SendMessage(_settingsLogo, 0x171, 0, 0) == _settingsIcon
513
NativeSmokeHarness.Require(
NativeMethods
.IsChild(_settingsWindow,
NativeMethods
.GetFocus()) != 0,
520
var monitor = new
NativeMethods
.MonitorInfo { Size = (uint)sizeof(
NativeMethods
.MonitorInfo) };
521
NativeCallException.Require(
NativeMethods
.GetMonitorInfo(
NativeMethods
.MonitorFromWindow(_settingsWindow, 2), ref monitor) != 0,
531
NativeCallException.Require(
NativeMethods
.GetWindowRect(_settingsWindow, out var window) != 0, "GetWindowRect(Settings scroll smoke)");
534
NativeMethods
.SetFocus(_settingsClose);
536
NativeMethods
.SendMessage(_settingsWindow,
NativeMethods
.WmVerticalScroll, 6, 0); // SB_TOP.
538
NativeMethods
.SendMessage(_settingsWindow,
NativeMethods
.WmVerticalScroll, 7, 0); // SB_BOTTOM.
539
var scroll = new
NativeMethods
.ScrollInfo { Size = (uint)sizeof(
NativeMethods
.ScrollInfo), Mask = 4 };
540
NativeCallException.Require(
NativeMethods
.GetScrollInfo(_settingsWindow, 1, ref scroll) != 0, "GetScrollInfo(Settings scroll smoke)");
543
NativeMethods
.SetFocus(_settingsCheckbox);
554
NativeCallException.Require(
NativeMethods
.GetClientRect(_settingsWindow, out var client) != 0, "GetClientRect(Settings focus smoke)");
555
NativeCallException.Require(
NativeMethods
.GetWindowRect(control, out var bounds) != 0, "GetWindowRect(Settings focus smoke)");
556
var origin = new
NativeMethods
.Point();
557
NativeCallException.Require(
NativeMethods
.ClientToScreen(_settingsWindow, ref origin) != 0, "ClientToScreen(Settings focus smoke)");
558
NativeSmokeHarness.Require(
NativeMethods
.GetFocus() == control
565
var length =
NativeMethods
.GetWindowTextLength(control);
569
var count =
NativeMethods
.GetWindowText(control, buffer, text.Length);
TrayApplication.Settings.cs (72)
60
var window =
NativeMethods
.CreateDialogIndirectParam(_module, pointer, _window, &SettingsDialogProcedure, 0);
86
NativeMethods
.SendMessage(_settingsWindow, 0x401, SettingsCloseId, 0); // DM_SETDEFID.
134
var rect = new
NativeMethods
.Rect { Left = x, Top = y, Right = x + width, Bottom = y + height };
135
NativeCallException.Require(
NativeMethods
.MapDialogRect(dialog, ref rect) != 0, "MapDialogRect");
136
var control =
NativeMethods
.CreateWindowEx(0, className, text, 0x40000000 | 0x10000000 | style,
139
var font =
NativeMethods
.SendMessage(dialog, 0x31, 0, 0); // WM_GETFONT; owned by the dialog manager.
141
NativeMethods
.SendMessage(control, 0x30, (nuint)font, 1); // WM_SETFONT.
147
NativeMethods
.ShowWindow(_settingsWindow, 9); // SW_RESTORE, including minimized windows.
151
if (
NativeMethods
.SetForegroundWindow(_settingsWindow) == 0)
155
var focus =
NativeMethods
.GetFocus();
156
if (
NativeMethods
.IsChild(_settingsWindow, focus) == 0 ||
NativeMethods
.IsWindowEnabled(focus) == 0
157
||
NativeMethods
.IsWindowVisible(focus) == 0)
159
var target =
NativeMethods
.IsWindowEnabled(_settingsCheckbox) != 0 ? _settingsCheckbox : _settingsRefresh;
160
NativeMethods
.SetFocus(target);
161
NativeCallException.Require(
NativeMethods
.GetFocus() == target, "SetFocus(Settings)");
175
NativeMethods
.SendMessage(_settingsCheckbox,
NativeMethods
.BmSetCheck, 2, 0);
187
NativeMethods
.SendMessage(_settingsCheckbox,
NativeMethods
.BmSetCheck, state.Enabled ? 1u : 0u, 0);
194
NativeCallException.Require(
NativeMethods
.SetWindowText(_settingsStatus, message) != 0, "SetWindowTextW(Settings status)");
197
if (!showDetails &&
NativeMethods
.GetFocus() == _settingsRefresh)
199
NativeMethods
.SetFocus(
NativeMethods
.IsWindowEnabled(_settingsCheckbox) != 0 ? _settingsCheckbox : _settingsClose);
201
NativeMethods
.ShowWindow(_settingsStatus, showDetails ? 5 : 0); // SW_SHOW / SW_HIDE.
202
NativeMethods
.ShowWindow(_settingsRefresh, showDetails ? 5 : 0);
208
var moveFocus = !enabled &&
NativeMethods
.GetFocus() == _settingsCheckbox;
209
NativeMethods
.EnableWindow(_settingsCheckbox, enabled ? 1 : 0);
212
NativeMethods
.SetFocus(_settingsStatusText.Length != 0 ? _settingsRefresh : _settingsClose);
249
NativeCallException.Require(
NativeMethods
.DestroyWindow(_settingsWindow) != 0, "DestroyWindow(Settings)");
258
if (
NativeMethods
.UnhookWindowsHookEx(_settingsMenuFilter) == 0)
295
case
NativeMethods
.WmInitDialog:
298
case
NativeMethods
.WmCtlColorDialog:
299
return
NativeMethods
.GetSysColorBrush(15); // COLOR_BTNFACE.
300
case
NativeMethods
.WmCtlColorStatic:
301
case
NativeMethods
.WmCtlColorButton:
302
NativeMethods
.SetTextColor((nint)wParam,
NativeMethods
.IsWindowEnabled(lParam) == 0
304
?
NativeMethods
.GetSysColor(17) :
NativeMethods
.GetSysColor(18)); // COLOR_GRAYTEXT / COLOR_BTNTEXT.
305
NativeMethods
.SetBkMode((nint)wParam, 1); // TRANSPARENT.
306
return
NativeMethods
.GetSysColorBrush(15);
307
case
NativeMethods
.WmVerticalScroll:
308
case
NativeMethods
.WmMouseWheel:
311
case
NativeMethods
.WmDpiChanged:
312
case
NativeMethods
.WmSettingChange:
313
case
NativeMethods
.WmSysColorChange:
314
case
NativeMethods
.WmThemeChanged:
317
NativeCallException.Require(
NativeMethods
.PostMessage(window,
NativeMethods
.SettingsLayoutMessage, 0, 0) != 0,
320
case
NativeMethods
.SettingsLayoutMessage when !_settingsInitializing && _settingsHeadingFont != 0:
324
case
NativeMethods
.WmCommand when !_settingsInitializing && !_quitRequested:
353
NativeCallException.Require(
NativeMethods
.GetCursorPos(out var point) != 0, "GetCursorPos(preview)");
358
case
NativeMethods
.WmClose:
361
case
NativeMethods
.WmNcDestroy:
383
Cleanup(
NativeMethods
.DestroyIcon(_settingsIcon) != 0, "DestroyIcon(Settings)");
397
var info = new
NativeMethods
.MenuItemInfo
399
Size = (uint)sizeof(
NativeMethods
.MenuItemInfo), Mask =
NativeMethods
.MiimString, Text = text
401
NativeCallException.Require(
NativeMethods
.SetMenuItemInfo(menu, command, 0, ref info) != 0, "SetMenuItemInfoW(Settings shortcut)");
409
_settingsMenuFilter =
NativeMethods
.SetWindowsHookEx(-1, &SettingsMenuFilter, 0,
NativeMethods
.GetCurrentThreadId());
413
private bool HandleSettingsShortcut(in
NativeMethods
.Message message)
416
&& (message.Window == _settingsWindow ||
NativeMethods
.IsChild(_settingsWindow, message.Window) != 0));
417
if (_quitRequested || _modalDepth != 0 || !localFocus || message.Id !=
NativeMethods
.WmKeyDown || message.WParam != 0xBC
418
||
NativeMethods
.GetKeyState(0x11) >= 0 ||
NativeMethods
.GetKeyState(0x12) < 0)
429
NativeCallException.Require(
NativeMethods
.EndMenu() != 0, "EndMenu(Settings shortcut)");
431
NativeCallException.Require(
NativeMethods
.PostMessage(_window,
NativeMethods
.SettingsMessage, 0, 0) != 0, "PostMessageW(Settings shortcut)");
441
&& application.HandleSettingsShortcut(in *(
NativeMethods
.Message*)lParam))
457
return
NativeMethods
.CallNextHookEx(0, code, wParam, lParam);
TrayApplication.SettingsAppearance.cs (46)
8
private readonly Dictionary<nint,
NativeMethods
.Rect> _settingsControlBounds = [];
10
private
NativeMethods
.Rect _settingsGeneralBounds;
11
private
NativeMethods
.Rect _settingsAboutBounds;
18
var dpi =
NativeMethods
.GetDpiForWindow(_settingsWindow);
19
var font =
NativeMethods
.CreateFont(-checked((int)((9 * dpi + 36) / 72)), 0, 0, 0, 700, 0, 0, 0, 1, 0, 0, 5, 0, "Segoe UI");
23
NativeMethods
.SendMessage(control, 0x30, (nuint)font, 1); // WM_SETFONT.
28
Cleanup(
NativeMethods
.DeleteObject(_settingsHeadingFont) != 0, "DeleteObject(Settings font)");
33
var icon =
NativeMethods
.LoadImage(0, Path.Combine(AppContext.BaseDirectory, "Aspire.ico"),
34
NativeMethods
.ImageIcon, size, size,
NativeMethods
.LrLoadFromFile);
36
NativeMethods
.SendMessage(_settingsLogo, 0x170, (nuint)icon, 0); // STM_SETICON; the static control borrows the icon.
39
Cleanup(
NativeMethods
.DestroyIcon(_settingsIcon) != 0, "DestroyIcon(Settings logo)");
86
NativeCallException.Require(
NativeMethods
.GetWindowRect(_settingsWindow, out var window) != 0, "GetWindowRect(Settings)");
87
NativeCallException.Require(
NativeMethods
.GetClientRect(_settingsWindow, out var client) != 0, "GetClientRect(Settings)");
88
var monitor = new
NativeMethods
.MonitorInfo { Size = (uint)sizeof(
NativeMethods
.MonitorInfo) };
89
NativeCallException.Require(
NativeMethods
.GetMonitorInfo(
NativeMethods
.MonitorFromWindow(_settingsWindow, 2), ref monitor) != 0,
95
var scroll = new
NativeMethods
.ScrollInfo
97
Size = (uint)sizeof(
NativeMethods
.ScrollInfo), Mask = 1 | 2 | 4, // SIF_RANGE | SIF_PAGE | SIF_POS.
100
NativeMethods
.SetScrollInfo(_settingsWindow, 1, in scroll, 1); // SB_VERT; hidden when all content fits.
102
NativeCallException.Require(
NativeMethods
.GetClientRect(_settingsWindow, out client) != 0, "GetClientRect(Settings scroll)");
107
NativeCallException.Require(
NativeMethods
.SetWindowPos(_settingsWindow, 0, x, y, width, height, 0x4 | 0x10) != 0,
110
EnsureSettingsControlVisible(
NativeMethods
.GetFocus());
113
private
NativeMethods
.Rect SettingsRect(int x, int y, int width, int height)
115
var dpi =
NativeMethods
.GetDpiForWindow(_settingsWindow);
124
NativeCallException.Require(
NativeMethods
.SetWindowPos(control, 0, bounds.Left, bounds.Top - _settingsScrollPosition,
127
NativeCallException.Require(
NativeMethods
.RedrawWindow(_settingsWindow, 0, 0, 1 | 4 | 0x80) != 0,
137
NativeCallException.Require(
NativeMethods
.GetClientRect(_settingsWindow, out var client) != 0, "GetClientRect(Settings focus)");
156
var scroll = new
NativeMethods
.ScrollInfo { Size = (uint)sizeof(
NativeMethods
.ScrollInfo), Mask = 4, Position = position };
157
NativeMethods
.SetScrollInfo(_settingsWindow, 1, in scroll, 1);
163
NativeCallException.Require(
NativeMethods
.GetClientRect(_settingsWindow, out var client) != 0, "GetClientRect(Settings scroll)");
165
if (message ==
NativeMethods
.WmMouseWheel)
168
NativeCallException.Require(
NativeMethods
.GetWheelScrollLines(0x68, 0, ref lines, 0) != 0,
177
var scroll = new
NativeMethods
.ScrollInfo { Size = (uint)sizeof(
NativeMethods
.ScrollInfo), Mask = 0x10 }; // SIF_TRACKPOS.
181
NativeCallException.Require(
NativeMethods
.GetScrollInfo(_settingsWindow, 1, ref scroll) != 0, "GetScrollInfo(Settings)");
199
var dc =
NativeMethods
.GetDC(_settingsWindow);
201
var previous =
NativeMethods
.SelectObject(dc,
NativeMethods
.SendMessage(_settingsWindow, 0x31, 0, 0));
205
var rect = new
NativeMethods
.Rect { Right = units.Right };
206
NativeCallException.Require(
NativeMethods
.DrawText(dc, text, text.Length, ref rect,
214
Cleanup(
NativeMethods
.SelectObject(dc, previous) != 0, "SelectObject(Settings measure restore)");
216
Cleanup(
NativeMethods
.ReleaseDC(_settingsWindow, dc) != 0, "ReleaseDC(Settings measure)");
224
Cleanup(
NativeMethods
.DeleteObject(_settingsHeadingFont) != 0, "DeleteObject(Settings font)");
TrayApplication.StopConfirmation.cs (13)
32
var accept = ConfirmForSmoke?.Invoke("Stop AppHost", _stopDetail,
NativeMethods
.SafeConfirmation)
40
result =
NativeMethods
.DialogBoxIndirectParam(_module, pointer, _modalOwner, &StopDialogProcedure, 0);
68
case
NativeMethods
.WmInitDialog:
74
NativeMethods
.SendMessage(dialog, 0x401, 2, 0); // DM_SETDEFID.
75
NativeMethods
.SetFocus(cancel);
77
case
NativeMethods
.WmCommand when (wParam & 0xFFFF) is 1 or 2:
80
&&
NativeMethods
.SendMessage(
NativeMethods
.GetDlgItem(dialog, StopSuppressionId),
81
NativeMethods
.BmGetCheck, 0, 0) == 1;
82
NativeCallException.Require(
NativeMethods
.EndDialog(dialog, result) != 0, "EndDialog(Stop)");
84
case
NativeMethods
.WmClose:
85
NativeCallException.Require(
NativeMethods
.EndDialog(dialog, 2) != 0, "EndDialog(Cancel)");
107
NativeMethods
.EndDialog(dialog, 2);
TrayApplication.Tooltips.cs (37)
26
&& menu != 0 && command == 0 && (flags & (
NativeMethods
.MfPopup |
NativeMethods
.MfSeparator)) == 0
40
var delay =
NativeMethods
.SendMessage(_menuTooltipWindow,
NativeMethods
.TtmGetDelayTime, 3, 0);
53
_menuTooltipWindow =
NativeMethods
.CreateWindowEx(
58
NativeCallException.Require(
NativeMethods
.SendMessage(_menuTooltipWindow,
NativeMethods
.TtmAddTool, 0, (nint)(&tool)) != 0,
62
private
NativeMethods
.ToolInfo MenuTooltipInfo() => new()
64
Size = (uint)sizeof(
NativeMethods
.ToolInfo),
87
NativeMethods
.SendMessage(_menuTooltipWindow,
NativeMethods
.TtmUpdateTipText, 0, (nint)(&tool));
94
NativeMethods
.SendMessage(_menuTooltipWindow,
NativeMethods
.TtmTrackActivate, 1, (nint)(&tool));
105
NativeCallException.Require(
NativeMethods
.GetWindowRect(_menuTooltipWindow, out var bounds) != 0,
107
var monitor = new
NativeMethods
.MonitorInfo { Size = (uint)sizeof(
NativeMethods
.MonitorInfo) };
108
NativeCallException.Require(
NativeMethods
.GetMonitorInfo(
NativeMethods
.MonitorFromWindow(_window, 2), ref monitor) != 0,
112
NativeCallException.Require(
NativeMethods
.SetWindowPos(_menuTooltipWindow, 0, x, y, 0, 0,
116
private void PositionMenuTooltip(HostRow row, ref
NativeMethods
.ToolInfo tool)
118
NativeCallException.Require(
NativeMethods
.GetMenuItemRect(0, row.Submenu, 0, out var first) != 0,
120
NativeCallException.Require(
NativeMethods
.GetMenuItemRect(0, row.Submenu, row.DetailsPosition, out var last) != 0,
122
var monitor = new
NativeMethods
.MonitorInfo { Size = (uint)sizeof(
NativeMethods
.MonitorInfo) };
123
NativeCallException.Require(
NativeMethods
.GetMonitorInfo(
NativeMethods
.MonitorFromWindow(_window, 2), ref monitor) != 0,
125
var dpi =
NativeMethods
.GetDpiForWindow(_window);
129
NativeMethods
.SendMessage(_menuTooltipWindow,
NativeMethods
.TtmSetMaxTipWidth, 0, maximumWidth);
131
fixed (
NativeMethods
.ToolInfo* info = &tool)
133
size = (nuint)
NativeMethods
.SendMessage(_menuTooltipWindow,
NativeMethods
.TtmGetBubbleSize, 0, (nint)info);
146
NativeMethods
.SendMessage(_menuTooltipWindow,
NativeMethods
.TtmTrackPosition, 0,
157
NativeMethods
.SendMessage(_menuTooltipWindow,
NativeMethods
.TtmTrackActivate, 0, (nint)(&tool));
166
if (
NativeMethods
.DestroyWindow(_menuTooltipWindow) == 0)