How to set application's taskbar icon in Windows 7

后端 未结 3 1321
花落未央
花落未央 2020-11-28 22:58

How do I set an application\'s taskbar icon in PyQt4?

I have tried setWindowIcon, and it successfully sets the icon in the top-left of the main window, but it does n

3条回答
  •  北海茫月
    2020-11-28 23:13

    @DamonJW's answer will work, but there is a minor catch: myappid should be unicode (argument type is PCWSTR).

    import ctypes
    myappid = u'mycompany.myproduct.subproduct.version' # arbitrary string
    ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid)
    

    Otherwise getting the AppUserModelID will get wrong unicode characters (祭潣灭湡⹹祭牰摯捵⹴畳灢潲畤瑣瘮牥楳湯):

    import ctypes
    from ctypes import wintypes
    lpBuffer = wintypes.LPWSTR()
    AppUserModelID = ctypes.windll.shell32.GetCurrentProcessExplicitAppUserModelID
    AppUserModelID(ctypes.cast(ctypes.byref(lpBuffer), wintypes.LPWSTR))
    appid = lpBuffer.value
    ctypes.windll.kernel32.LocalFree(lpBuffer)
    if appid is not None:
        print(appid)
    

    That said, it is a minor thing, since Windows will still recognize the unicode string as "another process" and switch the icon accordingly.

提交回复
热议问题