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);
|