Computing.Net > Forums > Programming > Changing Background

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Changing Background

Reply to Message Icon

Name: dducharme
Date: May 22, 2009 at 19:40:58 Pacific
OS: Microsoft Windows Vista Home Premium
CPU/Ram: 2.401 GHz / 3573 MB
Product: Dell / INSPIRON 1525
Subcategory: C/C++
Comment:

Hello everyone I am trying to write a program that will change my background randomly every 15 minutes using visual C++. I know how to do most of the code but the code that is supposed to be changing the background is only resetting the background to black. If you could please let me know of any errors in the code or any suggestions it would be very helpful, thanks.

HKEY wall;
//Known Path to Background
string file = "C:\\Users\\dducharme\\Documents\\Screen Saver\\Backgrounds\\Warhammer 40k Ship.jpeg";
//Changes path to a pointer
string* filename = &file;
//Should set the background to the file DOES NOT WORK
SystemParametersInfoA(SPI_SETDESKWALLPAPER, 0, (LPVOID)filename, SPIF_SENDCHANGE);
//Used to output the error being thrown by the SPI(), is 0
cout << GetLastError();
//Opens the Registry Keys for the desktop
RegOpenKeyEx(HKEY_CURRENT_USER, (LPCWSTR)L"Control Panel\\Desktop", 0, KEY_ALL_ACCESS, &wall);
//Noticed that after calling SPI this was blank yet after clicking set as desktop it was this
RegSetValueEx(wall, (LPCWSTR)L"Wallpaper", 0, REG_SZ, (LPBYTE)L"C:\\Users\\dducharme\\AppData\\Roaming\\Microsoft\\Windows Photo Gallery\\Windows Photo Gallery Wallpaper.jpg\0", 206);
//I want the wallpaper streched
RegSetValueEx(wall, (LPCWSTR)L"WallpaperStyle", 0, REG_SZ, (LPBYTE)"2\0", 2);
//I do not want the wallpaper tiled
RegSetValueEx(wall, (LPCWSTR)L"WallpaperTile", 0, REG_SZ, (LPBYTE)"0\0", 2);
//Should force a refresh on the desktop
::PostMessage(::GetDesktopWindow(), WM_SETTINGCHANGE, NULL, NULL);
//We close the handle to the registry
RegCloseKey(wall);



Sponsored Link
Ads by Google

Response Number 1
Name: tonysathre
Date: May 22, 2009 at 22:02:34 Pacific
Reply:

You could use this program instead:

Google Wallpaper


0

Response Number 2
Name: dducharme
Date: May 23, 2009 at 07:39:04 Pacific
Reply:

I know there are other programs out there, I am even using one right now until I get mine working, the point is I am trying to use this exercise to help learn windows API programming as well GUI programming. So does anyone see any problems with the code because from what I have read in the MSDN pages, that should be working although it is not.


0

Response Number 3
Name: dducharme
Date: May 27, 2009 at 15:22:10 Pacific
Reply:

Does no one know what is wrong with my code because I can get SystemParametersInfoA to work on Windows XP without all of the registry changes but nothing I do will get me anything besides a black background on Windows Vista.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Changing Background

Image background www.computing.net/answers/programming/image-background/7502.html

How do i change the backgroun www.computing.net/answers/programming/how-do-i-change-the-backgroun/18052.html

adding a movie/flash background to webpage www.computing.net/answers/programming/adding-a-movieflash-background-to-webpage/19341.html