Changing Background

Dell INSPIRON 1525
May 22, 2009 at 19:40:58
Specs: Microsoft Windows Vista Home Premium, 2.401 GHz / 3573 MB
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
//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

See More: Changing Background

Report •

May 22, 2009 at 22:02:34
You could use this program instead:

Google Wallpaper

Report •

May 23, 2009 at 07:39:04
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.

Report •

May 27, 2009 at 15:22:10
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.

Report •

Related Solutions

Ask Question