Create hello-platform for Windows #10
No files matched your search
@@ -8,7 +8,9 @@ struct HPApp: App {
|
||||
var body: some Scene {
|
||||
WindowGroup("Hello platform") {
|
||||
HPView(delegate.hpVM)
|
||||
.onAppear {
|
||||
delegate.setWindowIcons()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import SwiftCrossUI
|
||||
import WinSDK
|
||||
|
||||
final class HPAppDelegate {
|
||||
let hp = HPComponent()
|
||||
@@ -8,4 +9,24 @@ final class HPAppDelegate {
|
||||
otherSetupConsoleLogging(hp.ctrl, "HP")
|
||||
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