can you change the background?

Started by
10 comments, last by KuroKitten 18 years, 4 months ago
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.
Advertisement
http://www.daniweb.com/techtalkforums/thread9150.html
-----"Master! Apprentice! Heartborne, 7th Seeker Warrior! Disciple! In me the Wishmaster..." Wishmaster - Nightwish
Quote:Original post by Red_falcon
http://www.daniweb.com/techtalkforums/thread9150.html


Clickified!
It is IActiveDesktop::SetWallpaper ()
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
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);
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.
It only takes one mistake to wake up dead the next morning.
According to MSDN, SPI_SETDESKWALLPAPER expects a null terminated string [char*], not an actual string. Try BackImage.c_str() instead of &BackImage.

CM
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.
Quote:Original post by KuroKitten
changing &BackImage to BackImage.c_str() pops the same error as leaving it alone...

What is that error?

CM
You might have to cast your char* to a void* because that is what it expects.
so...

string BackImage = "C:\\Main\\Desktop\\GiftsUngiven.jpg";
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.

This topic is closed to new replies.

Advertisement