Click to See Complete Forum and Search --> : Changing wallpaper via command line
snippet20
November 7th, 2009, 06:07 PM
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?
GameZelda
November 7th, 2009, 07:39 PM
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.
snippet20
November 7th, 2009, 07:59 PM
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
snippet20
November 7th, 2009, 10:03 PM
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?
BobS0327
November 7th, 2009, 10:38 PM
give this a try....
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, argv[1], SPIF_SENDCHANGE);
PostMessage(GetDesktopWindow(), WM_SETTINGCHANGE, NULL, NULL);
snippet20
November 7th, 2009, 11:08 PM
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
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.