fix(gui): set titlebar icon directly on root HWND and remove iconphoto conflict on Windows
This commit is contained in:
parent
872ead4406
commit
a8f11dcd53
1 changed files with 33 additions and 9 deletions
|
|
@ -103,9 +103,33 @@ class BetterCFApp:
|
||||||
ico_path = find_asset("icon.ico")
|
ico_path = find_asset("icon.ico")
|
||||||
if ico_path and os.name == "nt":
|
if ico_path and os.name == "nt":
|
||||||
try:
|
try:
|
||||||
|
self.root.iconbitmap(str(ico_path.resolve()))
|
||||||
self.root.iconbitmap(default=str(ico_path.resolve()))
|
self.root.iconbitmap(default=str(ico_path.resolve()))
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
import ctypes
|
||||||
|
user32 = ctypes.windll.user32
|
||||||
|
GA_ROOT = 2
|
||||||
|
WM_SETICON = 0x0080
|
||||||
|
IMAGE_ICON = 1
|
||||||
|
LR_LOADFROMFILE = 0x0010
|
||||||
|
|
||||||
|
self.root.update_idletasks()
|
||||||
|
inner_hwnd = self.root.winfo_id()
|
||||||
|
root_hwnd = user32.GetAncestor(inner_hwnd, GA_ROOT) or inner_hwnd
|
||||||
|
|
||||||
|
self._win32_icon_sm = user32.LoadImageW(None, str(ico_path.resolve()), IMAGE_ICON, 16, 16, LR_LOADFROMFILE)
|
||||||
|
self._win32_icon_bg = user32.LoadImageW(None, str(ico_path.resolve()), IMAGE_ICON, 32, 32, LR_LOADFROMFILE)
|
||||||
|
|
||||||
|
for h in (inner_hwnd, root_hwnd):
|
||||||
|
if self._win32_icon_sm:
|
||||||
|
user32.SendMessageW(h, WM_SETICON, 0, self._win32_icon_sm)
|
||||||
|
if self._win32_icon_bg:
|
||||||
|
user32.SendMessageW(h, WM_SETICON, 1, self._win32_icon_bg)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
elif os.name != "nt":
|
||||||
png_path = find_asset("icon_512.png") or find_asset("icon.png")
|
png_path = find_asset("icon_512.png") or find_asset("icon.png")
|
||||||
if png_path:
|
if png_path:
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue