title: Changing the windows wallpaper in pure java,
body: <p>Can anyone help me change my (<em>windows xp</em>) desktop wallpaper with pure java code,<br>
   I have copied the two programs below from stackoverflow answers, but they are not working,<br>
  (i don’t understand them),or give me a link where I can learn about this code, </p>
  
  <p><strong>the first one:</strong></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:\\w.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>It removes the wallpaper, but it never changed it, I am getting a black desktop,  </p>
  
  <p><strong>the second:</strong> </p>
  
  <pre><code>import java.util.*;
  
  public class changer {
  
      public static void main(String args[]) {
          String wallpaper_file = "C:\\w.jpg";
          changer mychanger = new changer();
          mychanger.Change(wallpaper_file);
      }
  
  
      static {
          Runtime.getRuntime().loadLibrary("user32");
          //System.loadLibrary("user32");
      }
  
      public int Change(String path) {
          return SystemParametersInfo(20, 0, path, 0);   //my error //
      }
  
      public static native int SystemParametersInfo(int uiAction, int uiParam,
              String pvParam, int fWinIni);
  
  
  }
  </code></pre>
  
  <p>In this code, I am getting an error on that line: <strong><em>return SystemParametersInfo(20, 0, path, 0);</em></strong></p>