From 005616054ae1d4ab19121bfca0aa3a7d80101702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Thu, 5 Nov 2026 17:21:41 +0300 Subject: [PATCH] move icon --- components/other/windows/otherWindows.swift | 36 +++++++++++++++++++ .../ver-windows/src/HPAppDelegate.swift | 21 +---------- .../ver-windows/src/other/otherWindows.swift | 1 + 3 files changed, 38 insertions(+), 20 deletions(-) create mode 100644 components/other/windows/otherWindows.swift create mode 120000 hello/hello-platform/ver-windows/src/other/otherWindows.swift diff --git a/components/other/windows/otherWindows.swift b/components/other/windows/otherWindows.swift new file mode 100644 index 0000000..191d3d6 --- /dev/null +++ b/components/other/windows/otherWindows.swift @@ -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(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)) +} diff --git a/hello/hello-platform/ver-windows/src/HPAppDelegate.swift b/hello/hello-platform/ver-windows/src/HPAppDelegate.swift index 495f8c4..dde6e9b 100644 --- a/hello/hello-platform/ver-windows/src/HPAppDelegate.swift +++ b/hello/hello-platform/ver-windows/src/HPAppDelegate.swift @@ -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(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) - } } diff --git a/hello/hello-platform/ver-windows/src/other/otherWindows.swift b/hello/hello-platform/ver-windows/src/other/otherWindows.swift new file mode 120000 index 0000000..72dde1b --- /dev/null +++ b/hello/hello-platform/ver-windows/src/other/otherWindows.swift @@ -0,0 +1 @@ +../../../../../components/other/windows/otherWindows.swift \ No newline at end of file