Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sorry I'm a bit behind @ataylor's answer because I was preparing a snippet to do it. Yes, JNA is a correct approach. Here you go:</p> <pre><code>import java.util.HashMap; import com.sun.jna.Native; import com.sun.jna.platform.win32.WinDef.UINT_PTR; import com.sun.jna.win32.*; public class WallpaperChanger { public static void main(String[] args) { //supply your own path instead of using this one String path = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Chrysanthemum.jpg"; SPI.INSTANCE.SystemParametersInfo( new UINT_PTR(SPI.SPI_SETDESKWALLPAPER), new UINT_PTR(0), path, new UINT_PTR(SPI.SPIF_UPDATEINIFILE | SPI.SPIF_SENDWININICHANGE)); } public interface SPI extends StdCallLibrary { //from MSDN article long SPI_SETDESKWALLPAPER = 20; long SPIF_UPDATEINIFILE = 0x01; long SPIF_SENDWININICHANGE = 0x02; SPI INSTANCE = (SPI) Native.loadLibrary("user32", SPI.class, new HashMap&lt;Object, Object&gt;() { { put(OPTION_TYPE_MAPPER, W32APITypeMapper.UNICODE); put(OPTION_FUNCTION_MAPPER, W32APIFunctionMapper.UNICODE); } }); boolean SystemParametersInfo( UINT_PTR uiAction, UINT_PTR uiParam, String pvParam, UINT_PTR fWinIni ); } } </code></pre> <p>You need to have the JNA libraries on the classpath for this to work. This was tested in Windows 7, there might be some nuances in XP but I think it should work. That API is presumably stable.</p> <h2>References</h2> <ul> <li><a href="http://blogs.msdn.com/b/coding4fun/archive/2006/10/31/912569.aspx" rel="nofollow noreferrer">Setting Wallpaper - Coding4Fun</a></li> <li><a href="https://stackoverflow.com/questions/2057492/how-to-determine-if-a-screensaver-is-running-in-java">How to determine if a screensaver is running in Java?</a></li> <li><a href="http://www.koders.com/java/fidFD72484D3A2451C9E8B017577D085D8C95154A35.aspx" rel="nofollow noreferrer">W32API.java</a></li> </ul> <h2>Edit (2010/01/20):</h2> <p>I had previously omitted the options <code>SPIF_UPDATEINIFILE</code> and <code>SPIF_SENDWININICHANGE</code>. These are now being used as they were suggested in the Coding4Fun MSDN article.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload