Skip to content

Commit 16b7e24

Browse files
committed
Icon: Assume default icon size is always 16x16
win.GetSystemMetricsForDpi() ignores dpi parameter prior Windows 10. It returns 16x16, or 24x24, or 32x32 depending on "zoom" set by user. Assume the default small icon size is always 16x16 at 96dpi. Reverts: 8f6d762 See-also: #636 Signed-off-by: Simon Rozman <simon@rozman.si>
1 parent 45de27c commit 16b7e24

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

icon.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"github.com/lxn/win"
1818
)
1919

20+
var defaultIconSize96dpi = Size{16, 16}
21+
2022
// Icon is a bitmap that supports transparency and combining multiple
2123
// variants of an image in different resolutions.
2224
type Icon struct {
@@ -77,7 +79,7 @@ func IconShield() *Icon {
7779
}
7880

7981
func stockIcon(id uintptr) *Icon {
80-
return &Icon{res: win.MAKEINTRESOURCE(id), size96dpi: defaultIconSize(), isStock: true}
82+
return &Icon{res: win.MAKEINTRESOURCE(id), size96dpi: defaultIconSize96dpi, isStock: true}
8183
}
8284

8385
// NewIconFromFile returns a new Icon, using the specified icon image file and default size.
@@ -88,7 +90,7 @@ func NewIconFromFile(filePath string) (*Icon, error) {
8890
// NewIconFromFileWithSize returns a new Icon, using the specified icon image file and size.
8991
func NewIconFromFileWithSize(filePath string, size Size) (*Icon, error) {
9092
if size.Width == 0 || size.Height == 0 {
91-
size = defaultIconSize()
93+
size = defaultIconSize96dpi
9294
}
9395

9496
return checkNewIcon(&Icon{filePath: filePath, size96dpi: size})
@@ -116,7 +118,7 @@ func NewIconFromResourceIdWithSize(id int, size Size) (*Icon, error) {
116118

117119
func newIconFromResource(res *uint16, size Size) (*Icon, error) {
118120
if size.Width == 0 || size.Height == 0 {
119-
size = defaultIconSize()
121+
size = defaultIconSize96dpi
120122
}
121123

122124
return checkNewIcon(&Icon{res: res, size96dpi: size})
@@ -271,7 +273,7 @@ func (i *Icon) handleForDPIWithError(dpi int) (win.HICON, error) {
271273
var size Size
272274
if i.size96dpi.Width == 0 || i.size96dpi.Height == 0 {
273275
flags |= win.LR_DEFAULTSIZE
274-
size = SizeFrom96DPI(defaultIconSize(), dpi)
276+
size = SizeFrom96DPI(defaultIconSize96dpi, dpi)
275277
} else {
276278
size = SizeFrom96DPI(i.size96dpi, dpi)
277279
}
@@ -416,8 +418,3 @@ func sizeFromHICON(hIcon win.HICON) (Size, error) {
416418

417419
return Size{int(bi.BmiHeader.BiWidth), int(bi.BmiHeader.BiHeight)}, nil
418420
}
419-
420-
// defaultIconSize returns default small icon size in 1/92" units.
421-
func defaultIconSize() Size {
422-
return Size{int(win.GetSystemMetricsForDpi(win.SM_CXSMICON, 96)), int(win.GetSystemMetricsForDpi(win.SM_CYSMICON, 96))}
423-
}

0 commit comments

Comments
 (0)