From e7b120cfc22444f49d0b09c69d14b301f4704469 Mon Sep 17 00:00:00 2001 From: Roman Date: Mon, 27 Mar 2017 00:11:09 +0300 Subject: [PATCH] [WinForms] Add application icon when frozen with PyInstaller --- webview/winforms.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/webview/winforms.py b/webview/winforms.py index 72a0a8d0..cc530126 100644 --- a/webview/winforms.py +++ b/webview/winforms.py @@ -24,6 +24,7 @@ from webview.localization import localization from webview.win32_shared import set_ie_mode + logger = logging.getLogger(__name__) @@ -39,12 +40,13 @@ def __init__(self, title, url, width, height, resizable, fullscreen, min_size, c self.MaximizeBox = False # Application icon - try: # Try loading an icon embedded in the exe file. This will crash when frozen with PyInstaller - handler = windll.kernel32.GetModuleHandleW(None) - icon_handler = windll.user32.LoadIconW(handler, 1) - self.Icon = Icon.FromHandle(IntPtr.op_Explicit(Int32(icon_handler))) - except: - pass + handle = windll.kernel32.GetModuleHandleW(None) + icon_handle = windll.shell32.ExtractIconW(handle, sys.executable, 0) + + if icon_handle != 0: + self.Icon = Icon.FromHandle(IntPtr.op_Explicit(Int32(icon_handle))).Clone() + + windll.user32.DestroyIcon(icon_handle) self.webview_ready = webview_ready