-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathseticon.py
More file actions
26 lines (24 loc) · 952 Bytes
/
Copy pathseticon.py
File metadata and controls
26 lines (24 loc) · 952 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# -*- coding:utf-8 -*-
from ctypes import windll
from .winConst import WinConst
from os import path
user32 = windll.user32
kernel32= windll.kernel32
RelPath = lambda file : path.join(path.dirname(path.abspath(__file__)), file)
def set_icon(hwnd, filename):
if not filename.endswith('.ico'):
return False
hModel = kernel32.GetModuleHandleW(None)
hIcon = user32.LoadImageW(hModel,RelPath(filename),WinConst.IMAGE_ICON,48, 48,WinConst.LR_LOADFROMFILE | WinConst.LR_CREATEDIBSECTION)
user32.SendMessageW(hwnd, WinConst.WM_SETICON, WinConst.ICON_BIG, hIcon)
return True
def set_icon_2(hwnd,filename):
if not filename.endswith('.ico'):
return False
import win32api
import win32gui
icon_big = win32gui.LoadImage(
None, RelPath(filename), WinConst.IMAGE_ICON,
48, 48, WinConst.LR_LOADFROMFILE)
win32api.SendMessage(hwnd, WinConst.WM_SETICON,WinConst.ICON_BIG, icon_big)
return True