# can you change the background?

This topic is 4379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is it possible, using win32, to change the desktop background to a different image? I'm trying to make a simple desktop changing program, and havn't been able to find a command that can do this. I'm wondering if there even is one (it seems like something rather complicated, so i wouldn't be surprised) Thanks^^ Meow.

Quote:

Clickified!

##### Share on other sites
i've tried both functions, and with both i get errors that I'm unsure how to fix...

With SystemParametersInfo() The only error i get is with the value that i designate the image to be set as the wallpaper. this is how I have the function called:
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "C:\\mountain.bmp", SPIF_UPDATEINIFILE);

Now, with the IActiveDesktop::SetWallpaper() I get a whole slew of errors. My guess is there's a header I need to include?

Again, thanks for any help^^

Mreow.

Edit: I figured out the compiling error, i had to point to the adress of a string, not include a direct string. Now, however, my issue is that the background jsut gets set to black... I'm 100% possitive the file exists...

here is what i have now:
string BackImage = "C:\\Main\\Desktop\\GiftsUngiven.jpg";SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, &BackImage, SPIF_UPDATEINIFILE);

##### Share on other sites
This is totally from the hip, but if this is the win32 api, you'll probably want a pointer to a C-String rather than an std::string.

##### Share on other sites
According to MSDN, SPI_SETDESKWALLPAPER expects a null terminated string [char*], not an actual string. Try BackImage.c_str() instead of &BackImage.

CM

##### Share on other sites
changing &BackImage to BackImage.c_str() pops the same error as leaving it alone...

string BackImage = "C:\\Main\\Desktop\\GiftsUngiven.jpg";SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, BackImage.c_str(), SPIF_UPDATEINIFILE);

I'm looking into CStings aswell.

Mreow.

##### Share on other sites
Quote:
 Original post by KuroKittenchanging &BackImage to BackImage.c_str() pops the same error as leaving it alone...

What is that error?

CM

##### Share on other sites
You might have to cast your char* to a void* because that is what it expects.
so...

SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)BackImage.c_str(), SPIF_UPDATEINIFILE);

also, I think your image has to be a BMP, unless you have Active Desktop enabled. A jpg might result in a blank background being used.

##### Share on other sites
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).

##### Share on other sites
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^^

##### Share on other sites

This topic is 4379 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628686
• Total Posts
2984236

• 16
• 13
• 13
• 10
• 10