Setting Wallpaper

Sign in to queue

The Discussion

  • User profile image
    Yingqiang

    this porgram does not work for my computer,

    my OS is WinXP.

    It is strange, for some picture it will be ok to work correcly, but for many others, it doesn't work.

  • User profile image
    Clint

    @Yingqiang:  What are the file types that work and what won't work?  Do you see a pattern?

  • User profile image
    Lee

    Bitmaps will only work, for me at least, and probably for Yingqiang also.

    You must convert other image filetypes to a bitmap...save the bitmap...then load into systemparamentersinfo.

  • User profile image
    Axel

    This is documented: https://msdn2.microsoft.com/en-us/library/ms724947(VS.85).aspx

    In short, BMP works on all versions and JPEG only on Vista or 2008.

  • User profile image
    Clint

    You set the program up to be a command line application and do everything through args.

  • User profile image
    A

    Is there a way to make this work from CMD using RunDll32?

    Ex:  RunDll32.exe user32.dll,SystemParametersInfo 20,0,C:\path\to\wallpaper.bmp,0x01

    or something similar?

  • User profile image
    Clint
  • User profile image
    A

    I'm actually asking more for the purpose of a batch file rather than an application.  I'm having trouble figuring out the exact syntax to use though.  Do you have any advice or resources I could check for how to properly use RunDll32 and user32.dll to change a Windows wallpaper?

  • User profile image
    A

    Woohoo!  That website had so much useful information on it!  Thanks!  Though, now my problem is that Windows XP only supports using BMP files as backgrounds when setting them to

    HKEY_CURRENT_USER\Control Panel\Desktop

    which is what the "RUNDLL32.EXE user32.dll, UpdatePerUserSystemParameters" command is used to refresh.  To use a JPG image, http://windowsitpro.com/article/articleid/74578/jsi-tip-3259-windows-2000-wallpaper-policy.html suggests that I use the Active Desktop feature to load a JPG as the background.  I'm currently trying this, but I haven't yet gotten it to change within Windows without requiring a reboot (admittedly, I'm a little fuzzy on Active Desktop, so I'm still working through some options I haven't tried yet).  Do you have any words of wisdom for me on this?

    Also, out of morbid curiosity, how does Windows go about converting non-BMP images to BMP when you normally set a wallpaper anyway?

  • User profile image
    DZ

    "Also, out of morbid curiosity, how does Windows go about converting non-BMP images to BMP when you normally set a wallpaper anyway?"

    Simple. Somewhere inside your profile folder (usually C:\Documents and Settings\<your username>), there's a bitmap with the generic name "wallpaper.bmp" -- that's the actual image that's being set as the wallpaper. When Windows finds that an image isn't a wallpaper, it simply converts to BMP, rewrites the generic wallpaper file, and sets it to that, while saving the location of the original image elsewhere.

  • User profile image
    Ross

    How do I do the same for Active Desktop .jpg files?

  • User profile image
    MS

    Python on Vista:

    import ctypes

    SPI_SETDESKWALLPAPER = 0x14

    SPIF_UPDATEINIFILE = 0X01

    SPIF_SENDWININICHANGE = 0X02

    def change_paper(picture):

       try:

           ctypes.windll.user32.SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, picture, SPIF_UPDATEINIFILE|SPIF_SENDWININICHANGE)

       except:

           print("Set Wallpaper failed!")

  • User profile image
    tired

    unfortunately this doesn't always work in vista...

  • User profile image
    Isaac

    I thought I'd get fancy and set my application to detect the OS version.  If it's XP, copy the jpg/gif/whatever (non-bmp) to a file with the same name .bmp in the temp folder.  Then, I'd set that to the background.  No good on XP, so there must be something more that's needed.  Has anyone been able to find a workaround for XP?  I know the OS can handle it, as you can open a JPG in a number of applications and select "Set as wallpaper" and it works.

  • User profile image
    Isaac

    Answered my own question.  I am converting to a BMP as so:

                   Image oldImage = Image.FromFile(sourceFile, false);

                   oldImage.Save(tempfilename, System.Drawing.Imaging.ImageFormat.Bmp);

    //sourceFile = the full path to and file name of the JPG, GIF, etc

    //tempfilename = the full path to and file name of the BMP getting created

  • User profile image
    Duke

    wouldnt it work on vista if you just lib 64?

  • User profile image
    Clint

    @Duke, it should.  You can even make VS have a "Any CPU" setting so you don't target x86 or x64 CPUs

  • User profile image
    Durgesh

    Hi!!!

    This is very good for set desktop wallpaper.

    But I want some disadvantage this project i.e.

    we can only *.bmp format file set not of

    all image formate like these *.JPG, *.GIF  etc;

    Please provide some hint(code) for others image format set wallpaper.

    Thanks & Regards

    Durgesh

    India

  • User profile image
    Clint

    @durgesh, this is a pretty old article.  The quick solution is to just save the image as a bmp?

  • User profile image
    Joel

    Hello I am trying to use this code but I don't really understand it much. I've read through the entire article and when I pasted the code it didn't work. I'm using vbexpress 2008 and i'm not sure if i'm pasting the code properly. I'll continue messing around with it till it works but even with the select case statement its being weird. So right now i'm going to go back through the code and place some of it in separate functions just to see if that will clear anything up.

  • User profile image
    Clint

    @Joel, use the download link at the top of the page.  The articles are there to talk you through the concepts and show the harder code and the "heart of it" code.  With that being said, most articles alone won't produce a 100% functional program.

  • User profile image
    Meenu

    This code and document works...it really help me out.

    thanks a ton.

  • User profile image
    Manish Kumar Baderiya

    public enum Style: int

    {

       Tiled, Centered, Stretched

    }

    Visual Basic

    Public Enum Style As Integer

       Tiled

       Centered

       Stretched

    End Enum

    switch( style )

    {

       case Style.Stretched :

           key.SetValue(@"WallpaperStyle", "2") ;

           key.SetValue(@"TileWallpaper", "0") ;

           break;

       case Style.Centered :

           key.SetValue(@"WallpaperStyle", "1") ;

           key.SetValue(@"TileWallpaper", "0") ;

           break;

       case Style.Tiled :

           key.SetValue(@"WallpaperStyle", "1") ;

           key.SetValue(@"TileWallpaper", "1") ;

           break;

    }

  • User profile image
    Igor Tykhyy

    There's actually a problem.. or rather: I've got a question... if I have an animated gif, I can set it as background and it's still animated - how does it work? Does it use ActiveDesktop? can't I use it just as well? I target my "Wallpaper Changer" to XP, Vista and 7, but I don't want to use any WPF.

    And on another note: is there any way to use the wallpaper-changing-animation that comes with Windows 7 when it adjusts the paper? It slowly fades one into the other .. it'd be great if my program could do this just as well...

    I'd be glad to receive a reply Smiley,

    Igor.

  • User profile image
    Clint

    @Igor Tykhyy First part, animated gifs won't animate.  I'm confused on exactly what you're asking here on the second part.  

    You also have to remember this source code example came out before Vista was even released.

  • User profile image
    Anthony

    Thanks for sharing! Do you know how this could be applied to change Lock Screen image to what I already have as my background?

Add Your 2 Cents