|
-
November 7th, 2009, 06:07 PM
#1
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?
-
November 7th, 2009, 07:39 PM
#2
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.
-
November 7th, 2009, 07:59 PM
#3
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
-
November 7th, 2009, 10:03 PM
#4
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?
-
November 7th, 2009, 10:38 PM
#5
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);
-
November 7th, 2009, 11:08 PM
#6
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
Last edited by snippet20; November 7th, 2009 at 11:17 PM.
Reason: adding more details
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|