通过程序定期更改桌面壁纸
Programmatically change the desktop wallpaper periodically
创建一个定期更改桌面壁纸的程序的最佳方法是什么?我也想围绕这个程序创建一个GUI。我是一名计算机科学专业的学生,因此我知道Java和C++等语言的基本编程。这将在Windows 7操作系统上完成。
对于这样的项目,最好使用什么语言?
理想情况下,我想使用系统时钟来触发更改。这可能吗?
我疯了吗?
任何答案都将不胜感激。非常感谢。
在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 messagen";
else
cout << "Counter: " << Counter << "; message: " << Msg.message << 'n';
DispatchMessage(&Msg);
}
KillTimer(NULL, TimerId);
return 0;
}
这是一个相当简单的项目,可以使用任何可以调用Win32 API函数的语言(例如C++)轻松完成。更改壁纸的非明显功能是带有SPI_SETDESKWALLPAPER
标志的SystemParametersInfo
。你给它一个新图像的文件名,壁纸就会改变。
相关文章:
- 递归函数计算序列中的平方和(并输出过程)
- 试图在visual studio上用C++创建一个桌面应用程序
- 是否删除在对象构造过程中创建的对象
- 如何在鼠标挂钩过程中检测拖动
- 此测试()中发生了什么意外过程?为什么总是覆盖 ch[0 1 2..]?
- clang 插件:在编译过程中修改 AST
- 如何在桌面C++上使用 WinApi 画线
- 如何使变量从 x 到 y,然后从 y 返回到 x 并始终重复该过程
- 在C++中调用 MS SQL 存储过程
- 桌面中的Qt QMessageBox中心'critical'
- Qt QML桌面应用程序自动化测试
- 阻塞信号会导致升压过程不起作用
- Adafruit 羽毛RFM69HCW在使用过程中会冻结,需要硬重置
- 使用提升过程获取 shell 命令的标准输出
- 下一个云桌面客户端构建过程
- 'SystemParametersInfo'函数在获取桌面壁纸时返回不正确的值
- 创建在新Windows桌面上运行IE的过程
- 通过程序定期更改桌面壁纸
- 获取当前桌面壁纸的路径
- 如何在c++中更改活动桌面壁纸