Public Group

# can you change the background?

This topic is 4540 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.

• 15
• 13
• 23
• 10
• 19