CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Changing wallpaper via command line

  1. #1
    Join Date
    Nov 2009
    Posts
    4

    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?

  2. #2
    Join Date
    Dec 2007
    Posts
    69

    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.

  3. #3
    Join Date
    Nov 2009
    Posts
    4

    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

  4. #4
    Join Date
    Nov 2009
    Posts
    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?

  5. #5
    Join Date
    Apr 2004
    Posts
    102

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

  6. #6
    Join Date
    Nov 2009
    Posts
    4

    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
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)