Skip to content

Commit

Permalink
Merge pull request #96 from r0x0r/winforms-icon-fix
Browse files Browse the repository at this point in the history
[WinForms] Add application icon when frozen with PyInstaller
  • Loading branch information
Roman authored Mar 26, 2017
2 parents cccc773 + e7b120c commit d725b0f
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions webview/winforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from webview.localization import localization
from webview.win32_shared import set_ie_mode


logger = logging.getLogger(__name__)


Expand All @@ -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

Expand Down

0 comments on commit d725b0f

Please sign in to comment.