创建可定期更改桌面墙纸的程序的最佳方法是什么?我还想在程序周围创建一个GUI.我是一名计算机科学专业的学生,因此我了解Java和C++等基础编程.这将在Windows 7操作系统上完成.
对于像这样的项目,最好的语言是什么?
理想情况下,我想使用系统时钟来触发更改.这可能吗?
我在我头上吗?
任何答案将非常感谢.谢谢.
Sof*_*ner 17
在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);
}
}
Run Code Online (Sandbox Code Playgroud)
在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;
}
Run Code Online (Sandbox Code Playgroud)
这是一个相当简单的项目,可以使用任何可以调用Win32 API函数的语言(例如C++)轻松完成.更改壁纸的非显而易见的功能是SystemParametersInfo带有SPI_SETDESKWALLPAPER标志.你给它一个新图像的文件名,壁纸改变.
| 归档时间: |
|
| 查看次数: |
15092 次 |
| 最近记录: |