Files
__mahjong/components/other/windows/otherWindows.swift
T
2026-11-05 17:21:41 +03:00

37 lines
1.1 KiB
Swift

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))
}