6

Is there a way to trigger a shuffle in windows wallpaper slideshow? Preferably something I can use from .net

EDIT: so I'm trying to use the IActiveDesktop interface, I got it from here, I tried to use it like this:

public static IActiveDesktop GetActiveDesktop()
{
    Type typeActiveDesktop = Type.GetTypeFromCLSID(new Guid("{75048700-EF1F-11D0-9888-006097DEACF9}"));
    return (IActiveDesktop) Activator.CreateInstance(typeActiveDesktop);
}

and then calling it like this:

IActiveDesktop dt = GetActiveDesktop();
dt.ApplyChanges(AD_APPLY.ALL | AD_APPLY.FORCE | AD_APPLY.BUFFERED_REFRESH);

nothing happens when I run the code, no errors too.

1
  • I doubt if there is an API for that. Mar 24, 2012 at 16:38

5 Answers 5

3

Try the following:

Your theme located in C:\Users\USERNAME\AppData\Local\Microsoft\Windows\Themes\.theme

Open the .theme file and update a Shuffle flag in the [Slideshow] section:

[Slideshow]     
Shuffle=1

Then use IActiveDesktop interface to reload theme, call ApplyChange with the following parameters:

AD_APPLY_ALL | AD_APPLY_FORCE | AD_APPLY_BUFFERED_REFRESH

3
  • You should be using the Personalization control panel instead of editing the theme file to toggle shuffling.
    – BoltClock
    Mar 24, 2012 at 19:36
  • It's not guaranteed that the user's profile will be in a directory corresponding exactly to their username. If I were writing code to solve this problem then I wouldn't rely on the path being consistent. First I'd grab the profile directory of the current user to construct the string. Mar 24, 2012 at 19:37
  • I got the interface from here, but it doesn't seem to work, I create a new instance of this Type typeActiveDesktop = Type.GetTypeFromCLSID(new Guid("{75048700-EF1F-11D0-9888-006097DEACF9}"))
    – Madd0g
    Mar 25, 2012 at 20:38
1

OH WAIT, just discovered you just want to shuffle. Flot2011's answer is the way to go.

You can find the full path to the current user's theme via:

HKCU\Software\Microsoft\Windows\CurrentVersion\Themes\CurrentTheme

If there's any api for this, it probably won't be exposed yet. Best thing I will do if I were you is to simulate a click of the 'Next desktop background' option in the Desktop Context Menu. There are several ways to do this, but I will suggest you use GetDesktopWindow api, simulate a right mouse click and send the 'n' key. I am not completely sure about what effect this will achieve but it should work.

Also take a look at this: http://www.technixupdate.com/keyboard-shortcut-or-hotkey-to-switch-to-next-windows-7-desktop-wallpaper/

0

The registry key

HKEY_CURRENT_USER\Control Panel\Personalization\Desktop Slideshow

contains values which should give you control over several aspects of the feature.

1
  • I've never tried to trigger changes in the current environment by changing those values so I can't guarantee that you'll see an immediate difference after editing them. Mar 24, 2012 at 19:49
0

If all someone needs is a quick, hacky script, this seems to work for me in powershell, if you don't mind a couple seconds delay and the windows going down and then back up:

Function Next-Slide() {

   $shellApp = New-Object -ComObject  Shell.Application
   $wScript = New-Object -ComObject WScript.Shell

   # stack.push(...)
   # I guess this is assuming we aren't on the desktop already...
   $shellApp.ToggleDesktop();

   # This doesn't seem to be needed...
   #$desktopLoc = $wScript.SpecialFolders('Desktop');
   #$wScript.AppActivate($desktopLoc);

   #Give time to get to the desktop
   sleep 1;

   # Hack to make sure something is selected on the desktop
   # if there is something to select.
   $wScript.SendKeys('{RIGHT}');
   $wScript.SendKeys('{UP}');
   $wScript.SendKeys('{LEFT}');
   $wScript.SendKeys('{DOWN}');

   # Now undo the selection so that we get the desktop context
   # menu, not the icon one. This toggles selection on desktop.
   $wScript.SendKeys("^ ");


   # Open a context menu and select the option to see the next slide
   $wScript.SendKeys("+{F10}");
   $wScript.SendKeys("n");
   $wScript.SendKeys("~"); #This is ENTER

   # Give the key commands time to be read
   sleep 1;

   # stack.pop()
   $shellApp.ToggleDesktop();
}

Caveat: I am seeing the numlock on/off indicator pop up on the bottom right of my screen when I run this. I'm not sure why. It may be changing.

0

I utilize AutoHotkey to call IDesktopWallpaper::AdvanceSlideshow via COM. This could also be done programmatically a variety of ways.

I cannot take credit for this AHK implementation, I believe original credit goes to qwerty12 on the AHK forums:

#^w::  ; Ctrl-Win-W to advance to next wallpaper
   try if ((pDesktopWallpaper := ComObjCreate("{C2CF3110-460E-4fc1-B9D0-8A1C0C9CC4BD}", "{B92B56A9-8B55-4E14-9A89-0199BBB6F93B}"))) {
      DllCall(NumGet(NumGet(pDesktopWallpaper+0)+16*A_PtrSize), "Ptr", pDesktopWallpaper, "Ptr", 0, "UInt", 0) ; IDesktopWallpaper::AdvanceSlideshow - https://msdn.microsoft.com/en-us/library/windows/desktop/hh706947(v=vs.85).aspx
      ObjRelease(pDesktopWallpaper)
   }
return

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.