0

I am using the Active Desktop interface in C# to change desktop wallpaper in Windows. I am only using the IActiveDesktop.SetWallpaper method and never use IActiveDesktop.SetWallpaperOptions, so I would expect only the wallpaper image to change and not its fit (tile, stretch, fill, etc.).

When I my compile my code as a .NET desktop app, this behaves as expected. However, when I use Desktop Bridge to compile my app as a UWP app for the Windows Store, the wallpaper fit changes and not just the image. I don't understand why running my code as a UWP app should make the Active Desktop interface behave any differently.

For example, if I select "Span" in the Windows 10 Settings app to make the wallpaper stretch across my two monitors, my UWP app does not respect this setting. When it changes the wallpaper image, the fit also changes to show the image separately on each monitor. But the .NET desktop version of my app respects the wallpaper fit setting and does not change it.

I have included the relevant part of my code below. The entire file can be found here.

[ComImport]
[Guid("F490EB00-1240-11D1-9888-006097DEACF9")]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IActiveDesktop
{
    [PreserveSig]
    int ApplyChanges(AD_Apply dwFlags);
    [PreserveSig]
    int SetWallpaper([MarshalAs(UnmanagedType.LPWStr)] string pwszWallpaper, int dwReserved);
}

public class WallpaperChanger
{
    public static readonly Guid CLSID_ActiveDesktop =
        new Guid("{75048700-EF1F-11D0-9888-006097DEACF9}");

    public static IActiveDesktop GetActiveDesktop()
    {
        Type typeActiveDesktop = Type.GetTypeFromCLSID(WallpaperChanger.CLSID_ActiveDesktop);
        return (IActiveDesktop)Activator.CreateInstance(typeActiveDesktop);
    }

    public static void SetWallpaper(string imagePath)
    {
        IActiveDesktop iad = GetActiveDesktop();
        iad.SetWallpaper(imagePath, 0);
        iad.ApplyChanges(AD_Apply.ALL | AD_Apply.FORCE | AD_Apply.BUFFERED_REFRESH);
    }
}

Note: I've tried using the SetWallpaperAsync function available in the Windows UWP library, and it has the same problem. Also this problem is not specific to multiple monitors, the same thing happens with just a single one.

tjohnson
  • 1,047
  • 1
  • 11
  • 18
  • I used your dessktop app and UWP app to test on my side, I got the same result 'it changes the wallpaper image, the fit also changes to show the image separately on each monitor.' – Xie Steven Nov 05 '18 at 05:19
  • @XavierXie-MSFT I removed usage of `SetWallpaperAsync` from my app to ensure the desktop and UWP apps are using the same code to change the wallpaper, and recorded a video demonstrating the issue I am experiencing: https://youtu.be/iz15h3-cpKo – tjohnson Nov 07 '18 at 14:33
  • I followed your steps in your video to test, but it worked well. The UWP app did work like the desktop app. What's your OS build version? – Xie Steven Nov 08 '18 at 02:19

0 Answers0