Windows API to trigger wallpaper shuffle

天涯浪子 提交于 2020-01-03 09:39:08

问题


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:


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




回答2:


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/




回答3:


The registry key

HKEY_CURRENT_USER\Control Panel\Personalization\Desktop Slideshow

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




回答4:


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.



来源:https://stackoverflow.com/questions/9853393/windows-api-to-trigger-wallpaper-shuffle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!