2012-08-31 112 views
7

要創建定期更改桌面壁紙的程序,最佳方法是什麼?我還想在程序周圍創建一個GUI。我是一名計算機科學專業的學生,​​因此我掌握Java和C++等基礎編程。這將在Windows 7操作系統上完成。以編程方式定期更改桌面壁紙

什麼是最好的語言用於這樣的項目?

理想情況下,我想用系統時鐘觸發更改。這可能嗎?

我在我的頭上嗎?

任何答案將非常感激。謝謝。

+0

您對這個項目的盡職調查結果是什麼?你目前正在進行的哪些調查顯示給你? –

+1

你肯定不會在沒有JNI調用的情況下用java做到這一點,但C++可能 – axl

+0

我已經看到很多使用各種語言的類似項目的解決方案。我已經看過SystemParametersInfo,它似乎必須被合併。我沒有看到任何有關使用系統時鐘或使用GUI的信息。 –

回答

9

這是一個相當簡單的項目,可以使用任何可以調用Win32 API函數(例如C++)的語言輕鬆完成。用於更改壁紙的非顯而易見的功能是SystemParametersInfoSPI_SETDESKWALLPAPER標誌。您給它一個新圖像的文件名稱,並更改壁紙。

+1

好的,這是一個相當簡單的項目,所有的信心真的很有幫助,並給了我開始這個項目的信心。似乎我所有的問題都得到了回答,現在我開始了。謝謝大家。 –

+0

不客氣。如果您還有其他問題,請隨時提問(請記住,Stack Overflow最適合特定問題)。 –

15

在Java:

import java.util.*; 

public class changer 
{ 
    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 = "c:\\wallpaper.jpg"; 
     changer mychanger = new changer(); 
     mychanger.Change(wallpaper_file); 
    } 

} 

在Win32 C++中,你可以使用SetTimer觸發的變化。

#define STRICT 1 
#include <windows.h> 
#include <iostream.h> 

VOID CALLBACK TimerProc(HWND hWnd, UINT nMsg, UINT nIDEvent, DWORD dwTime) 
{ 

    LPWSTR wallpaper_file = L"C:\\Wallpapers\\wallpaper.png"; 
    int return_value = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, wallpaper_file, SPIF_UPDATEINIFILE); 


    cout << "Programmatically change the desktop wallpaper periodically: " << dwTime << '\n'; 
    cout.flush(); 
} 

int main(int argc, char *argv[], char *envp[]) 
{ 
    int Counter=0; 
    MSG Msg; 

    UINT TimerId = SetTimer(NULL, 0, 2000, &TimerProc); //2000 milliseconds 

    cout << "TimerId: " << TimerId << '\n'; 
    if (!TimerId) 
    return 16; 

    while (GetMessage(&Msg, NULL, 0, 0)) 
    { 
     ++Counter; 
     if (Msg.message == WM_TIMER) 
     cout << "Counter: " << Counter << "; timer message\n"; 
     else 
     cout << "Counter: " << Counter << "; message: " << Msg.message << '\n'; 
     DispatchMessage(&Msg); 
    } 

    KillTimer(NULL, TimerId); 
return 0; 
} 
+0

什麼應該在mac os中寫入id x。它無法加載user32庫。 – saman