set icon raw
This commit is contained in:
1 parent
89ef340432
commit
d407e7f0ff
2 files changed
+24
-1
No files matched your search
@@ -8,7 +8,9 @@ struct HPApp: App {
|
|||||||
var body: some Scene {
|
var body: some Scene {
|
||||||
WindowGroup("Hello platform") {
|
WindowGroup("Hello platform") {
|
||||||
HPView(delegate.hpVM)
|
HPView(delegate.hpVM)
|
||||||
|
.onAppear {
|
||||||
|
delegate.setWindowIcons()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import SwiftCrossUI
|
import SwiftCrossUI
|
||||||
|
import WinSDK
|
||||||
|
|
||||||
final class HPAppDelegate {
|
final class HPAppDelegate {
|
||||||
let hp = HPComponent()
|
let hp = HPComponent()
|
||||||
@@ -8,4 +9,24 @@ final class HPAppDelegate {
|
|||||||
otherSetupConsoleLogging(hp.ctrl, "HP")
|
otherSetupConsoleLogging(hp.ctrl, "HP")
|
||||||
hp.setup()
|
hp.setup()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 1
|
||||||
|
}, 0)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user