can you change the background?

Started by
10 comments, last by KuroKitten 18 years, 4 months ago
With SystemParametersInfo () function:
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).
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
Advertisement
Whoa, thanks^^ I got the SystemParametersInfo() to work, however SetWallpaper() still throughs out a bunch of errors. It may be my compiler as far as that one is concerned.

Perhaps when i'm finished i can include the whole source code^^

This topic is closed to new replies.

Advertisement