如何设置CEF窗口图标(在python中)

时间:2019-02-07 17:18:57

标签: python chromium-embedded cefpython

不是wx,gtk3,pyqt等... 我需要类似的东西:

cef.Initialize(设置=设置) window_info = cef.WindowInfo() browser = cef.CreateBrowserSync(url =“ localhost:8080 /”,window_title =“ Hello World!” icon =“ myicon.png”

1 个答案:

答案 0 :(得分:0)

在Linux上,使用xseticon函数或类似程序以编程方式执行os.system()程序,请参见:http://www.leonerd.org.uk/code/xseticon/

在Windows上,使用ctypes内置的Python模块执行本机win32函数。下面的示例代码。 _hWnd变量包含可以通过调用browser.GetWindowHandle()获得的窗口句柄。

from ctypes import *
from ctypes.wintypes import *
from os import path
import platform

LRESULT = c_int64 if platform.architecture()[0] == "64bit" else c_long

SendMessage = windll.user32.SendMessageW
SendMessage.restype = LRESULT
SendMessage.argtypes = [HWND, UINT, WPARAM, LPARAM]

GetModuleHandle = windll.kernel32.GetModuleHandleW
GetModuleHandle.restype = HMODULE
GetModuleHandle.argtypes = [LPCWSTR]

IMAGE_ICON = 1
LR_LOADFROMFILE = 0x00000010
LR_CREATEDIBSECTION = 0x00002000

LoadImage = windll.user32.LoadImageW
LoadImage.restype = HANDLE
LoadImage.argtypes = [HINSTANCE, LPCWSTR, UINT, c_int, c_int, UINT]

RelPath = lambda file : path.join(path.dirname(path.abspath(__file__)), file)


def AlterIcon(_hWnd, lpszIcon):

    WM_SETICON = 0x0080
    ICON_BIG = 1

    hModel = GetModuleHandle(None)
    hIcon = LoadImage(hModel,
                      RelPath(lpszIcon),
                      IMAGE_ICON,
                      0, 0,
                      LR_LOADFROMFILE | LR_CREATEDIBSECTION)


    SendMessage(_hWnd, WM_SETICON, ICON_BIG, hIcon)

参考:http://qaru.site/questions/7837596/how-to-include-image-in-message-box-using-ctypes-in-python