Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from com import create_instance, gen_method, Structure, POINTER, byref
- from com import HWND, ULARGE_INTEGER, INT, UINT, DWORD, HICON, WCHAR
- CLSID_TaskbarList = "{56FDF344-FD6D-11d0-958A-006097C9A090}"
- IID_ITaskbarList3 = "{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}"
- from ctypes import windll
- LoadImage = windll.user32.LoadImageW
- IMAGE_ICON = 1
- LR_LOADFROMFILE = 0x00000010
- LR_DEFAULTSIZE = 0x00000040
- LR_SHARED = 0x00008000
- ic = HICON(LoadImage(0, u'res\win_taskbar_pause.ico', IMAGE_ICON, 0, 0, LR_LOADFROMFILE|LR_DEFAULTSIZE|LR_SHARED))
- print ic
- class THUMBBUTTON(Structure):
- _fields_ = [("dwMask", INT),
- ("iId", UINT),
- ("iBitmap", UINT),
- ("hIcon", HICON),
- ("szTip", WCHAR*260),
- ("dwFlags", INT)]
- class ITaskBarList3:
- methods = ("SetProgressValue", 9, (HWND,ULARGE_INTEGER,ULARGE_INTEGER)), \
- ("SetProgressState", 10, (HWND,INT)), \
- ("RegisterTab", 11, (HWND,HWND)), \
- ("UnregisterTab", 12, (HWND,)), \
- ("SetTabOrder", 13, (HWND,HWND)), \
- ("SetTabActive", 14, (HWND,HWND,DWORD)), \
- ("ThumbBarAddButtons", 15, (HWND,UINT, POINTER(THUMBBUTTON)))
- def __init__(self):
- self.ptr = create_instance(CLSID_TaskbarList, IID_ITaskbarList3)
- if self.ptr:
- for i in self.methods:
- setattr(self, i[0], gen_method(self.ptr, i[1], *i[2]))
- self.Release = gen_method(self.ptr, 2)
- else: print "CoCreateInstance failed"
- def __del__(self):
- if self.ptr:
- self.Release()
- import PyQt4.QtGui, sys
- app = PyQt4.QtGui.QApplication(sys.argv)
- mainwnd = PyQt4.QtGui.QMainWindow()
- mainwnd.show()
- taskbar = ITaskBarList3()
- taskbar.SetProgressValue(int(mainwnd.winId()), 5, 10)
- taskbar.SetProgressState(int(mainwnd.winId()), 4)
- buttons = (THUMBBUTTON * 1)()
- buttons[0].dwMask = INT()
- buttons[0].iId = UINT()
- buttons[0].iBitmap = UINT()
- buttons[0].hIcon = ic
- buttons[0].szTip = u"hello\0"
- buttons[0].dwFlags = INT()
- print len(buttons[0].szTip)
- print taskbar.ThumbBarAddButtons(int(mainwnd.winId()),1,buttons[0])
- del taskbar
- ret = app.exec_()
- del app
- #######################com.py#####################################################################
- import ctypes
- from ctypes import c_int,c_uint,c_short,c_ubyte,byref,Structure,oledll,c_long, POINTER
- from ctypes.wintypes import HRESULT, HWND, ULARGE_INTEGER, INT, DWORD, UINT, HICON, WCHAR
- #from _ctypes import call_commethod
- ole32 = oledll.ole32
- class Guid(Structure):
- _fields_ = [("Data1", c_uint),
- ("Data2", c_short),
- ("Data3", c_short),
- ("Data4", c_ubyte*8)]
- def __init__(self, name):
- ole32.CLSIDFromString(unicode(name), byref(self))
- def gen_method(ptr, method_index, *arg_types):
- c_long_p = POINTER(ctypes.c_int)
- vtable = ctypes.cast(ptr, c_long_p).contents.value
- def func(*args):
- return ctypes.WINFUNCTYPE(HRESULT, c_long, *arg_types)(
- ctypes.cast(vtable + method_index*4, c_long_p).contents.value)(
- ptr, *args)
- return func
- def create_instance(clsid, iid):
- ptr = c_int()
- try:
- res = ole32.CoCreateInstance(byref(Guid(clsid)), 0, 1, byref(Guid(iid)), byref(ptr))
- if not res:
- return ptr.value
- else: return 0
- except: return 0
Advertisement
Add Comment
Please, Sign In to add comment