Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IActiveDesktop.py 2.1KB

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