2017-02-11 115 views
-1

就像一个有趣的项目,我想为我的笔记本电脑背景重新创建Matrix雨。我研究了如何进行Matrix下雨,并且有很多关于如何做到这一点的想法,但是我没有真正发现以编程方式更改或设置桌面背景的任何内容。所以,这是我的问题。 如何以编程方式更改桌面背景?我最好喜欢用C或C++来做到这一点,任何帮助都非常感谢!以编程方式更改桌面背景

+0

http://superuser.com/questions/153075/setting-an-animated-gif-as-the-desktop-background-on-windows-7 – user463035818

+0

使用[SystemParametersInfo一些诡计( https://msdn.microsoft.com/en-us/library/windows/desktop/ms724947(v=vs.85).aspx)是我过去看过的。打一些google-fu,看看你找到了什么。 – WhozCraig

回答

2

从我的节目之一的一些摘录:

在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); 
} 
相关问题