2013-06-25 25 views
0

我可以使用Java代碼更改Windows 7的壁紙嗎?在Windows 7中更換壁紙的java代碼

這裏是我的代碼:

public class Changer { 
    /** 
    * @param args 
    */ 
    public static native int SystemParametersInfo(int uiAction,int uiParam,String pvParam,int fWinIni); 

    static 
    { 
     System.loadLibrary("user32"); 
    } 

    public int Change(String path) 
    { 
     return SystemParametersInfo(20, 0, path, 0); 
    } 

    public static void main(String args[]) 
    { 
     String wallpaper_file = "D:\\Photos\\walli\\dream girls\\jes54d.jpeg"; 
     Changer mychanger = new Changer(); 
     mychanger.Change(wallpaper_file); 
    } 
} 

此代碼Eclipse IDE中失敗。我得到這個錯誤:

Exception in thread "main" java.lang.UnsatisfiedLinkError: com.changer.Changer.SystemParametersInfo(IILjava/lang/String;I)I 
    at com.changer.Changer.SystemParametersInfo(Native Method) 
    at com.changer.Changer.Change(Changer.java:18) 
    at com.changer.Changer.main(Changer.java:25) 

我是新來的Java,並不能找出什麼是可能的解決方案。

在此先感謝。

回答

1

函數調用SystemParametersInfo(20, 0, path, 0)是錯誤的。它期望SystemParametersInfo(UINT_PTR uiAction, UINT_PTR uiParam, String pvParam, UINT_PTR fWinIni)

請參閱accepted這裏回答。

您可以從here獲得JNA。並參考javadocs here