以编程方式更改桌面背景
Changing a desktop background programmatically
作为一个有趣的项目,我想为我的笔记本电脑的背景重新创建矩阵雨。我研究了如何做矩阵雨,并且有很多关于如何做到这一点的想法,但我还没有真正找到任何关于以编程方式更改或设置桌面背景的内容。所以,这是我的问题。如何以编程方式更改桌面背景?我最好使用 C 或 C++ 来做到这一点,非常感谢任何帮助!
我的一个程序的一些摘录:
在Windows 7中,系统中只有一个壁纸文件。因此,我们将当前壁纸保存在临时文件中,并将壁纸替换为我们的图像。稍后我们恢复原始文件:
// Get the system's wallpaper filename from the registry
GetRegKeyStrHK(HKEY_CURRENT_USER, "Control Panel\Desktop","WallPaper", szFilename, sizeof(szFilename));
// Now copy that file to a temporary file
CopyFile(szFilename, "C:\myTmpWallpaper.bmp",FALSE);
// Then tell the system to use a new file (it will copy it to the old filename)
SystemParametersInfo (SPI_SETDESKWALLPAPER, 0, (LPSTR) szMyDesktopImage, 0);
函数GetRegKeyStrHK()
来自我的库,它从注册表中获取值(壁纸文件名(。
int GetRegKeyStrHK (HKEY hK, const char *szRoot, const char *szName, char *szValue, int iValueSize)
{
HKEY hkResult;
int iKeyType, bufsize, result;
if (RegOpenKeyEx(hK, szRoot, 0, KEY_READ, &hkResult)
!= ERROR_SUCCESS) return(FALSE); // no such key
bufsize=iValueSize;
result= RegQueryValueEx(hkResult,szName,0, &iKeyType, (BYTE *)szValue, &bufsize);
RegCloseKey (hkResult);
if (result != ERROR_SUCCESS) return(FALSE); // no such name/value pair or buffer too small
return (TRUE);
}
相关文章:
- 试图在visual studio上用C++创建一个桌面应用程序
- 如何在全屏模式下(在OpenGL中)使背景透明
- 使用窗口中的QSlider更改背景音量
- 如何在桌面C++上使用 WinApi 画线
- SDL2 透明背景
- 桌面中的Qt QMessageBox中心'critical'
- Qt QML桌面应用程序自动化测试
- Windows 10 上的 Linphone 桌面
- 如何使用opencv和Qt拍摄部分桌面的照片
- 在 Visual C++ 中以编程方式更改按钮的背景图像
- 多重采样背景不显示
- Windows桌面程序保存您的计算机会话 - 基于程序崩溃时的恢复会话
- 直接2D用WM_ERASEBKGND擦除背景?
- 在特定时间内更改 QLabel 的背景颜色
- 具有SPI_SETDESKWALLPAPER功能的程序仅在尝试使用C++将其更改为图像时将桌面背景更改为黑色
- 以编程方式更改桌面背景
- 什么是真正的桌面背景HWND
- 根据代码设置桌面背景颜色
- 重置现有的HBITMAP作为桌面背景(Win32)
- 如何用vc++改变桌面背景