Skip to content

Commit c0bb82a

Browse files
committed
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 <simon@rozman.si>
1 parent 45de27c commit c0bb82a

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

icon.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -246,20 +246,15 @@ func (i *Icon) handleForDPIWithError(dpi int) (win.HICON, error) {
246246

247247
var hInst win.HINSTANCE
248248
var name *uint16
249-
var flags uint32
250249
if i.filePath != "" {
251250
absFilePath, err := filepath.Abs(i.filePath)
252251
if err != nil {
253252
return 0, err
254253
}
255254

256255
name = syscall.StringToUTF16Ptr(absFilePath)
257-
258-
flags |= win.LR_LOADFROMFILE
259256
} else {
260-
if i.isStock {
261-
flags |= win.LR_SHARED
262-
} else {
257+
if !i.isStock {
263258
if hInst = win.GetModuleHandle(nil); hInst == 0 {
264259
return 0, lastError("GetModuleHandle")
265260
}
@@ -270,7 +265,6 @@ func (i *Icon) handleForDPIWithError(dpi int) (win.HICON, error) {
270265

271266
var size Size
272267
if i.size96dpi.Width == 0 || i.size96dpi.Height == 0 {
273-
flags |= win.LR_DEFAULTSIZE
274268
size = SizeFrom96DPI(defaultIconSize(), dpi)
275269
} else {
276270
size = SizeFrom96DPI(i.size96dpi, dpi)
@@ -290,15 +284,14 @@ func (i *Icon) handleForDPIWithError(dpi int) (win.HICON, error) {
290284
return 0, newError("SHDefExtractIcon")
291285
}
292286
} else {
293-
hIcon = win.HICON(win.LoadImage(
287+
hr := win.HICON(win.LoadIconWithScaleDown(
294288
hInst,
295289
name,
296-
win.IMAGE_ICON,
297290
int32(size.Width),
298291
int32(size.Height),
299-
flags))
300-
if hIcon == 0 {
301-
return 0, lastError("LoadImage")
292+
&hIcon))
293+
if hr < 0 || hIcon == 0 {
294+
return 0, lastError("LoadIconWithScaleDown")
302295
}
303296
}
304297

0 commit comments

Comments
 (0)