2017-02-11 113 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); 
} 
相關問題