From c0bb82ae46cb0e5cafd3fbf13476978e232326af Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Thu, 31 Oct 2019 09:14:29 +0100 Subject: [PATCH] Icon: Switch to LoadIconWithScaleDown() Legacy LoadImage() picks a smaller icon variant and scales it up when the desired size is not available. LoadIconWithScaleDown() introduced in Windows Vista picks a larger icon variant and scales it down producing slightly better results. Signed-off-by: Simon Rozman --- icon.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/icon.go b/icon.go index 3074c621..e4870bfb 100644 --- a/icon.go +++ b/icon.go @@ -246,7 +246,6 @@ func (i *Icon) handleForDPIWithError(dpi int) (win.HICON, error) { var hInst win.HINSTANCE var name *uint16 - var flags uint32 if i.filePath != "" { absFilePath, err := filepath.Abs(i.filePath) if err != nil { @@ -254,12 +253,8 @@ func (i *Icon) handleForDPIWithError(dpi int) (win.HICON, error) { } name = syscall.StringToUTF16Ptr(absFilePath) - - flags |= win.LR_LOADFROMFILE } else { - if i.isStock { - flags |= win.LR_SHARED - } else { + if !i.isStock { if hInst = win.GetModuleHandle(nil); hInst == 0 { return 0, lastError("GetModuleHandle") } @@ -270,7 +265,6 @@ func (i *Icon) handleForDPIWithError(dpi int) (win.HICON, error) { var size Size if i.size96dpi.Width == 0 || i.size96dpi.Height == 0 { - flags |= win.LR_DEFAULTSIZE size = SizeFrom96DPI(defaultIconSize(), dpi) } else { size = SizeFrom96DPI(i.size96dpi, dpi) @@ -290,15 +284,14 @@ func (i *Icon) handleForDPIWithError(dpi int) (win.HICON, error) { return 0, newError("SHDefExtractIcon") } } else { - hIcon = win.HICON(win.LoadImage( + hr := win.HICON(win.LoadIconWithScaleDown( hInst, name, - win.IMAGE_ICON, int32(size.Width), int32(size.Height), - flags)) - if hIcon == 0 { - return 0, lastError("LoadImage") + &hIcon)) + if hr < 0 || hIcon == 0 { + return 0, lastError("LoadIconWithScaleDown") } }