int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iShowCmd){ SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "/*Full Path: C:\\A.bmp*/", SPIF_UPDATEINIFILE); return 0 ;}
I bypassed error checking and <Windows.h> header, but this little program functions perfectly on VC 2003 with warning level 4. Note that all images that are not bitmap will be converted to a temporary bitmap when you select a wallpaper in Display Properties. So when calling this function, a bitmap should be passed (this stuff is not documented in MSDN - from my experiences, oh well).
With IActiveDesktop::SetWallpaper method:
#include <Windows.h>#include <WinInet.h> //This header must be included for IActiveDesktop to be declared in <ShlObj.h>#include <ShlObj.h> //IActiveDesktop is declared when _WININET_ is definedint WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iShowCmd){CoInitialize (NULL) ;HRESULT hr;IActiveDesktop *pActiveDesktop;//Create an instance of the Active Desktophr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (void**)&pActiveDesktop);//Insert code to call the IActiveDesktop methods pActiveDesktop -> SetWallpaper ("/*Full Path: C:\\A.JPG*/", 0) ;// Call the Release methodpActiveDesktop->Release();CoUninitialize () ;return 0 ;}
I bypassed error checking, this function will work with other file types other than bitmap, but Active Desktop must be actived (one often used feature in Win9x when user select JPEG images, sort of).