IActiveDesktop.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. from win32com.shell import shell, shellcon
  2. import pythoncom
  3. import time
  4. website='https://github.com/mhammond/pywin32/'
  5. iad=pythoncom.CoCreateInstance(shell.CLSID_ActiveDesktop, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IActiveDesktop)
  6. opts=iad.GetDesktopItemOptions()
  7. if not (opts['ActiveDesktop'] and opts['EnableComponents']):
  8. print('Warning: Enabling Active Desktop')
  9. opts['ActiveDesktop']=True
  10. opts['EnableComponents']=True
  11. iad.SetDesktopItemOptions(opts)
  12. iad.ApplyChanges(0xffff)
  13. iad=None
  14. ## apparently takes a short while for it to become active
  15. time.sleep(2)
  16. iad=pythoncom.CoCreateInstance(shell.CLSID_ActiveDesktop, None, pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IActiveDesktop)
  17. cnt=iad.GetDesktopItemCount()
  18. print('Count:', cnt)
  19. for i in range(cnt):
  20. print(iad.GetDesktopItem(i))
  21. component={
  22. 'ID': cnt+1,
  23. 'ComponentType': shellcon.COMP_TYPE_WEBSITE,
  24. 'CurItemState': shellcon.IS_NORMAL,
  25. 'SubscribedURL': website,
  26. 'Source' : website,
  27. 'FriendlyName' : 'Pywin32 on SF',
  28. 'Checked' : True, ## this controls whether item is currently displayed
  29. 'NoScroll' : False,
  30. 'Dirty': False,
  31. 'Pos': {'Top':69, 'Left':69, 'Height': 400, 'Width': 400, 'zIndex': 1002,
  32. 'CanResize': True, 'CanResizeX': True, 'CanResizeY': True,
  33. 'PreferredLeftPercent': 0, 'PreferredTopPercent': 0},
  34. 'Original': {'Top': 33, 'Left': 304, 'Height': 362, 'Width': 372, 'ItemState': shellcon.IS_NORMAL},
  35. 'Restored': {'Top': 33, 'Left': 304, 'Height': 362, 'Width': 372, 'ItemState': shellcon.IS_NORMAL}
  36. }
  37. try:
  38. existing_item=iad.GetDesktopItemBySource(website)
  39. except pythoncom.com_error:
  40. pass
  41. else:
  42. iad.RemoveDesktopItem(existing_item)
  43. iad.ApplyChanges(0xffff)
  44. iad.AddDesktopItem(component)
  45. iad.ApplyChanges(0xffff) ## need to check which AD_APPLY constants are actually needed