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

How to set a CEF window icon (in python)

不是 wx、gtk3、pyqt 等... 我需要这样的东西:

cef.Initialize(设置=设置) window_info = cef.WindowInfo() 浏览器 = cef.CreateBrowserSync(url="localhost:8080/", window_title="Hello World!" icon="myicon.png")

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

在 Windows 上使用 ctypes 内置 Python 模块来执行本机 win32 函数。下面的示例代码。 _hWnd 变量持有 window 句柄,可以通过调用 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