move icon

This commit is contained in:
kornerr committed 2026-11-05 17:21:41 +03:00
1 parent b5772432b8
commit 005616054a
3 files changed
+38 -20

No files matched your search

@@ -0,0 +1,36 @@
import WinSDK
func otherSetupWindowIcons(_ iconId: Int) {
// Only visit windows owned by this UI thread, never another application's window.
EnumThreadWindows(GetCurrentThreadId(), { wnd, iconId in
let resource = UnsafePointer<WCHAR>(bitPattern: iconId)
let module = GetModuleHandleW(nil)
// Small icon
if let small = LoadImageW(
module,
resource,
UINT(IMAGE_ICON),
GetSystemMetrics(SM_CXSMICON),
GetSystemMetrics(SM_CYSMICON),
UINT(LR_SHARED)
) {
SendMessageW(wnd, UINT(WM_SETICON), WPARAM(ICON_SMALL), LPARAM(Int(bitPattern: small)))
}
// Large icon
if let large = LoadImageW(
module,
resource,
UINT(IMAGE_ICON),
GetSystemMetrics(SM_CXICON),
GetSystemMetrics(SM_CYICON),
UINT(LR_SHARED)
) {
SendMessageW(wnd, UINT(WM_SETICON), WPARAM(ICON_BIG), LPARAM(Int(bitPattern: large)))
}
// Shared resource icons remain valid for the lifetime of the process.
return true
}, LPARAM(iconId))
}
@@ -8,26 +8,7 @@ final class HPAppDelegate {
func setup() {
otherSetupConsoleLogging(hp.ctrl, "HP")
hp.setup()
setWindowIcons()
otherSetupWindowIcons(101)
}
func setWindowIcons() {
// Only visit windows owned by this UI thread, never another application's window.
EnumThreadWindows(GetCurrentThreadId(), { window, _ in
let resource = UnsafePointer<WCHAR>(bitPattern: 101)
let module = GetModuleHandleW(nil)
if let small = LoadImageW(module, resource, UINT(IMAGE_ICON),
GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
UINT(LR_SHARED)) {
SendMessageW(window, UINT(WM_SETICON), WPARAM(ICON_SMALL), LPARAM(Int(bitPattern: small)))
}
if let large = LoadImageW(module, resource, UINT(IMAGE_ICON),
GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON),
UINT(LR_SHARED)) {
SendMessageW(window, UINT(WM_SETICON), WPARAM(ICON_BIG), LPARAM(Int(bitPattern: large)))
}
// Shared resource icons remain valid for the lifetime of the process.
return true
}, 0)
}
}
@@ -0,0 +1 @@
../../../../../components/other/windows/otherWindows.swift