different wallpaper for each screen for multi-monitor setups in Windows

后端 未结 1 1263
一向
一向 2021-01-03 10:49

I\'m using:

ctypes.windll.user32.SystemParametersInfoA(SPI_SETDESKWALLPAPER,
                                           0, \"picturefile\", 0)
相关标签:
1条回答
  • 2021-01-03 11:11
    1. After joining the images together into a big image, you have to set the wallpaper mode to tiled to make it so the image spans the desktop (otherwise it will restart on each monitor).

      Couple of ways to do this:

      a) Using IActiveDesktop (which does not require Active Desktop to be used, don't worry). This is nicest as on Win7 the new wallpaper will fade in.

      You create an IActiveDesktop / CLSID_ActiveDesktop COM object and then call SetWallpaper, SetWallpaperOptions and finally ApplyChanges. (As I'm not a Python dev, I'm not sure exactly how you access the COM object, sorry.)

      OR:

      b) Via the registry. This isn't as nice, but works well enough.

      Under HKEY_CURRENT_USER\Control Panel\Desktop set:

      • TileWallpaper to (REG_SZ) 1 (i.e. the string "1" not the number 1)
      • WallpaperStyle to (REG_SZ) 0 (i.e. the string "0" not the number 0)
      • Then call SystemParameterInfo(SPI_SETDESKTOPWALLPAPER...) as you do already.

      .

      By the way, the code I'm looking at, which uses IActiveDesktop and falls back on the registry if that fails, passes SPIF_UPDATEINIFILE | SPIF_SENDCHANGE as the last argument to SystemParameterInfo; you're currently passing 0 which could be wrong.

    2. EnumDisplayMonitors is the Win32 API for getting details on the monitors, including their screen sizes and positions relative to each other.

      That API returns its results via a callback function that you have to provide. (It calls it once for each monitor.) I am not a Python developer so I'm not sure how you can call such a function from Python.

      A quick Google for "Python EnumWindows" (EnumWindows being a commonly-used API which returns results in the same way) finds people talking about that, and using a Lambda function for the callback, so it looks like it's possible but I'll leave it to someone who knows more about Python.

      Note: Remember to cope with monitors that aren't right next to each other or aren't aligned with each other. Your compiled image may need to have blank areas to make things line up right on all the monitors. If you move one of the monitors around and do a PrtScn screenshot of the whole desktop you'll see what I mean in the result.

    0 讨论(0)
提交回复
热议问题