Winand

Untitled

Sep 22nd, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.46 KB | None | 0 0
  1. from com import create_instance, gen_method, Structure, POINTER, byref
  2. from com import HWND, ULARGE_INTEGER, INT, UINT, DWORD, HICON, WCHAR
  3. CLSID_TaskbarList = "{56FDF344-FD6D-11d0-958A-006097C9A090}"
  4. IID_ITaskbarList3 = "{EA1AFB91-9E28-4B86-90E9-9E9F8A5EEFAF}"
  5.  
  6. from ctypes import windll
  7. LoadImage = windll.user32.LoadImageW
  8. IMAGE_ICON = 1
  9. LR_LOADFROMFILE = 0x00000010
  10. LR_DEFAULTSIZE = 0x00000040
  11. LR_SHARED = 0x00008000
  12. ic = HICON(LoadImage(0, u'res\win_taskbar_pause.ico', IMAGE_ICON, 0, 0, LR_LOADFROMFILE|LR_DEFAULTSIZE|LR_SHARED))
  13. print ic
  14.  
  15. class THUMBBUTTON(Structure):
  16.     _fields_ = [("dwMask", INT),
  17.                 ("iId", UINT),
  18.                 ("iBitmap", UINT),
  19.                 ("hIcon", HICON),
  20.                 ("szTip", WCHAR*260),
  21.                 ("dwFlags", INT)]
  22.  
  23. class ITaskBarList3:
  24.     methods = ("SetProgressValue", 9, (HWND,ULARGE_INTEGER,ULARGE_INTEGER)), \
  25.             ("SetProgressState", 10, (HWND,INT)), \
  26.             ("RegisterTab", 11, (HWND,HWND)), \
  27.             ("UnregisterTab", 12, (HWND,)), \
  28.             ("SetTabOrder", 13, (HWND,HWND)), \
  29.             ("SetTabActive", 14, (HWND,HWND,DWORD)), \
  30.             ("ThumbBarAddButtons", 15, (HWND,UINT, POINTER(THUMBBUTTON)))
  31.                
  32.     def __init__(self):
  33.         self.ptr = create_instance(CLSID_TaskbarList, IID_ITaskbarList3)
  34.         if self.ptr:
  35.             for i in self.methods:
  36.                 setattr(self, i[0], gen_method(self.ptr, i[1], *i[2]))
  37.             self.Release = gen_method(self.ptr, 2)
  38.         else: print "CoCreateInstance failed"
  39.                                
  40.     def __del__(self):
  41.         if self.ptr:
  42.             self.Release()
  43.    
  44. import PyQt4.QtGui, sys
  45. app = PyQt4.QtGui.QApplication(sys.argv)
  46. mainwnd = PyQt4.QtGui.QMainWindow()
  47. mainwnd.show()
  48.  
  49. taskbar = ITaskBarList3()
  50. taskbar.SetProgressValue(int(mainwnd.winId()), 5, 10)
  51. taskbar.SetProgressState(int(mainwnd.winId()), 4)
  52. buttons = (THUMBBUTTON * 1)()
  53. buttons[0].dwMask = INT()
  54. buttons[0].iId = UINT()
  55. buttons[0].iBitmap = UINT()
  56. buttons[0].hIcon = ic
  57. buttons[0].szTip = u"hello\0"
  58. buttons[0].dwFlags = INT()
  59. print len(buttons[0].szTip)
  60. print taskbar.ThumbBarAddButtons(int(mainwnd.winId()),1,buttons[0])
  61. del taskbar
  62.  
  63. ret = app.exec_()
  64. del app
  65.  
  66.  
  67.  
  68.  
  69. #######################com.py#####################################################################
  70.  
  71. import ctypes
  72. from ctypes import c_int,c_uint,c_short,c_ubyte,byref,Structure,oledll,c_long, POINTER
  73. from ctypes.wintypes import HRESULT, HWND, ULARGE_INTEGER, INT, DWORD, UINT, HICON, WCHAR
  74. #from _ctypes import call_commethod
  75. ole32 = oledll.ole32
  76.  
  77. class Guid(Structure):
  78.     _fields_ = [("Data1", c_uint),
  79.                 ("Data2", c_short),
  80.                 ("Data3", c_short),
  81.                 ("Data4", c_ubyte*8)]
  82.                
  83.     def __init__(self, name):
  84.         ole32.CLSIDFromString(unicode(name), byref(self))
  85.  
  86. def gen_method(ptr, method_index, *arg_types):
  87.     c_long_p = POINTER(ctypes.c_int)
  88.     vtable = ctypes.cast(ptr, c_long_p).contents.value
  89.     def func(*args):
  90.         return ctypes.WINFUNCTYPE(HRESULT, c_long, *arg_types)(
  91.             ctypes.cast(vtable + method_index*4, c_long_p).contents.value)(
  92.             ptr, *args)
  93.     return func
  94.    
  95. def create_instance(clsid, iid):
  96.     ptr = c_int()
  97.     try:
  98.         res = ole32.CoCreateInstance(byref(Guid(clsid)), 0, 1, byref(Guid(iid)), byref(ptr))
  99.         if not res:
  100.             return ptr.value
  101.         else: return 0
  102.     except: return 0
Advertisement
Add Comment
Please, Sign In to add comment