Changing wallpaper via command line
Ive got this code
#include <windows.h>
#include <string>
using namespace std;
int main(string PATH)
{
SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, PATH, SPIF_UPDATEINIFILE );
return 0;
}
But when i try to compile it i get,
cannot convert `std::string' to `void*'
If i add (PVOID) infront of path then i get
cannot convert `PATH' from type `std::string' to type `void*'
any tips/advice?
Re: Changing wallpaper via command line
Use "PATH.c_str()" to get a C-style string that you can pass to that function.
By the way, make sure that you're not using the Unicode functions, because that would also make it fail.
Re: Changing wallpaper via command line
yeah unicode isnt a problem
but in line 7:
SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, PATH.c_str(), SPIF_UPDATEINIFILE );
now gives "invalid conversion from const void* to void*" if i use (PVOID) infront of it, it compiles but it crashes when i run it, so ill guess im referencing something thats null
Re: Changing wallpaper via command line
I did a bit more reading on command lines and altered it to this
#include <windows.h>
int main(int argc, char *argv[])
{
if (argc==2){
SystemParametersInfo( SPI_SETDESKWALLPAPER, 0, argv[1], SPIF_UPDATEINIFILE );
}
return 0;
}
with the argument being passed as the path to the new wallpaper, it runs but it doesn't change the wallpaper?
Re: Changing wallpaper via command line
give this a try....
Code:
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, argv[1], SPIF_SENDCHANGE);
PostMessage(GetDesktopWindow(), WM_SETTINGCHANGE, NULL, NULL);
Re: Changing wallpaper via command line
Doesnt change.... Is it just a windows 7 thing? if someone else could run this does it work?
EDIT: It works if i specify the file in the code so i think its a problem with how the argument is sent to SystemParametersInfo