Skip to content

set the current display wallpaper (and update it when the display is resized)

Notifications You must be signed in to change notification settings

rgl/SetWindowsDesktopWallpaper

Repository files navigation

About

Build status

This set the current display wallpaper (and update it when the display is resized).

Usage

Install the .NET 6.0 SDK.

Execute the Debug version:

cd SetWindowsDesktopWallpaper
dotnet run

Execute the Release version:

dotnet publish --runtime win-x64 --self-contained --configuration Release
.\bin\Release\net6.0-windows10.0.17763\win-x64\publish\SetWindowsDesktopWallpaper.exe

You can also use vagrant to try this in a multiple display environment.

COM Interop

This uses IDesktopWallpaper.SetWallpaper COM method to set a display wallpaper.

This uses the Microsoft.Windows.CsWin32 source code generator to automatically generate the required COM Interop code to call IDesktopWallpaper.SetWallpaper.

Manual COM Interop

Instead of using the code generator, we could manually create the interop code with this powershell script:

$vsInstallPath = 'C:\VisualStudio2019Community'
Import - Module $vsInstallPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll
  Enter-VsDevShell -VsInstallPath $vsInstallPath

# convert the COM interfaces to a dotnet assembly.
# e.g. C:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um\ShObjIdl_core.idl
$idlPath = $env:INCLUDE - split ';' | ForEach - Object { "$_\ShObjIdl_core.idl" } | Where - Object { Test - Path $_ }
midl.exe / target NT62 /out $PWD / tlb ShObjCore.tlb / x64 $idlPath
tlbimp.exe ShObjCore.tlb /out:ShObjCore.dll /namespace:ShObjCore /machine:X64

Then use ILSpy to manually extract the relevant code (ShObjCore.IDesktopWallpaper interface et all).

Then convert all out parameters to return values.

Or better, use the Vanara.Windows.Shell.WallpaperManager wrapper.

Reference

About

set the current display wallpaper (and update it when the display is resized)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published