Andromo - Start Making Apps - Free Signup

Announcement

Collapse

New Forum Software

If you're here, you've found the new home for our forums. There will be some bugs to iron out, so thanks for your patience...
See more
See less

Function: Setting Windows Wallpaper

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Function: Setting Windows Wallpaper

    This is a function that allows you to take either a jpg or bmp image and set it as the windows wallpaper.

    This code should be placed on the button or image [On Click] event that you want to use to set the users wallpaper.

    Code:
    SetWallpaper(0,2,image_name_or_variable)
    The function takes three parameters. The first two are for the orientation (tile and style respectively) of the image and the third is the image itself. Only pass .jpgs or .bmps to this function.

    Centered = 0 , 0
    Stretched = 0 , 2
    Tiled = 1 , 0

    NOTE: For the jpg conversion to work you need to use a program by Worm called JPG2BMP.EXE, which can be found in the IndigoRose Forums.

    The following code should be placed on the Global Functions area of your project. This function will always create an entry in the wallpaper dialog on the users computer called "ams5.bmp". This was done to keep the number of items displayed in the Windows wallpaper dialog box to a minimum. This item can be changed to reflect the name of your application or any other name as is appropriate.

    Code:
    function SetWallpaper(tile,style,img)
    	local imagesplit = String.SplitPath(img)
    	if imagesplit.Extension == ".jpg" then
    		--runs a program created by Worm from the AMS Forum to convert .jpgs to .bmps
    		File.Run(_SourceFolder .."\\JPG2BMP.EXE", img .. ";;" .. _WindowsFolder .. "\\ams5.bmp", "", SW_MINIMIZE, true);
    		setreg = true;
    	elseif imagesplit.Extension == ".bmp" then
    		--copy the image to the windows folder
    		File.Copy(img, _WindowsFolder .. "\\ams5.bmp", false, true, true, true, nil)
    		setreg = true;
    	else
    		Dialog.Message("Error","The image you have selected is not supported.");
    		setreg = false;
    	end
    	--sets the registry value for tile and stretch
    	if setreg == true then
    		Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "TileWallpaper", tile, REG_SZ);
    		Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "WallpaperStyle", style, REG_SZ);
    		DLL.CallFunction(_SystemFolder .. "\\User32.dll", "SystemParametersInfoA", "20,0,\"" .. _WindowsFolder .. "\\ams5.bmp\",1", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);
    	end
    end
    TJ-Tigger
    "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
    "Draco dormiens nunquam titillandus."
    Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

  • #2
    That's an excellent function, rock on!

    Here's the thread with the app, should anyone need it:
    http://www.indigorose.com/forums/sho...hlight=jpg2bmp

    Comment


    • #3
      Originally posted by Desmond
      That's an excellent function, rock on!

      Here's the thread with the app, should anyone need it:
      http://www.indigorose.com/forums/sho...hlight=jpg2bmp
      Thanks Desmond. I was going to attach the file but the forum told me it was too large. I have it hosted on my site as well. Here it is.

      JPG2bmp.zip
      TJ-Tigger
      "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
      "Draco dormiens nunquam titillandus."
      Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

      Comment


      • #4
        ya, my original plan was to attach it to the thread, but i got the same error. ahh well. Thanks for hosting it!
        Last edited by Desmond; 07-20-2004, 03:05 PM.

        Comment


        • #5
          I'm happy to upload stuff for anyone anytime. Would you like me to transfer the file to our site and edit the link Tigger?

          Corey Milner
          Creative Director, Indigo Rose Software

          Comment


          • #6
            Corey,

            That would be great. That way if I accidently delete if from my site I don't break the link.

            Tigg
            TJ-Tigger
            "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
            "Draco dormiens nunquam titillandus."
            Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

            Comment


            • #7
              K. I'll do it after dinner and let you know in this thread. Rock on. :yes

              Corey Milner
              Creative Director, Indigo Rose Software

              Comment


              • #8
                Great Function, makes my live much easier. Now I am waiting just to get the same for a Screensaver which is defined as a file within the project

                Comment


                • #9
                  Wallpaper with unique filename

                  Here is the function that uses the image name to create a new wallpaper.

                  Code:
                  --[[
                  **************************************************************************************
                  ** Use this function if you want each wallpaper you assign to have it's own name.	**
                  ** WARNING I suggest you use the above for testing so you don't end up with a lot 	**
                  ** of different names in your Wallpaper dialog.  The following function is the same **
                  ** as the above but uses the name of the selected image as the name of the 			**
                  ** wallpaper image instead of ams5.bmp.												**
                  **************************************************************************************
                  ]]--
                  
                  function SetWallpaper(tile,style,img)
                  	local imagesplit = String.SplitPath(img)
                  	if imagesplit.Extension == ".jpg" then
                  		--runs a program created by Worm from the AMS Forum to convert .jpgs to .bmps
                  		File.Run(_SourceFolder .."\\JPG2BMP.EXE", img .. ";;" .. _WindowsFolder .. imagesplit.Filename .. ".bmp", "", SW_MINIMIZE, true);
                  		setreg = true;
                  	elseif imagesplit.Extension == ".bmp" then
                  		--copy the image to the windows folder
                  		File.Copy(img, _WindowsFolder .. imagesplit.Filename .. ".bmp", false, true, true, true, nil)
                  		setreg = true;
                  	else
                  		Dialog.Message("Error","The image you have selected is not supported.");
                  		setreg = false;
                  	end
                  	--sets the registry value for tile and stretch
                  	if setreg == true then
                  		Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "TileWallpaper", tile, REG_SZ);
                  		Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "WallpaperStyle", style, REG_SZ);
                  		DLL.CallFunction(_SystemFolder .. "\\User32.dll", "SystemParametersInfoA", "20,0,\"" .. _WindowsFolder .. imagesplit.Filename .. ".bmp\",1", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);
                  	end
                  end
                  TJ-Tigger
                  "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
                  "Draco dormiens nunquam titillandus."
                  Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

                  Comment


                  • #10
                    what about themes?

                    I've used this code on my project, and it works great. I have been looking for the code to change the theme on XP (using valid theme file such as Luna) nad ahve not found it. I have found third party apps that can do this (settheme.exe), but am wanting to have this be a pure registry and or dll function. Im thinking it has something to do with uxtheme.dll or user32.dll but my knowledge of dll's stop there. Any help or links to where i can help myself would be much appreciated.

                    Comment


                    • #11
                      Wallpaper

                      I saw this string on setting wallpaper on the users computer with a click, but I can get it to work. I cut and pasted the info below onto the global function, and also put the other info on my picture. But I don't know where ot change the file name.

                      thanks

                      Comment


                      • #12
                        Are you wanting to change the input file name or the output file name.

                        The input is changed when you call the function.

                        function SetWallpaper(tile,style,img)

                        The output is changed here
                        function SetWallpaper(tile,style,img)
                        local imagesplit = String.SplitPath(img)
                        if imagesplit.Extension == ".jpg" then
                        --runs a program created by Worm from the AMS Forum to convert .jpgs to .bmps
                        File.Run(_SourceFolder .."\\JPG2BMP.EXE", img .. ";;" .. _WindowsFolder .. imagesplit.Filename .. ".bmp", "", SW_MINIMIZE, true);
                        setreg = true;
                        elseif imagesplit.Extension == ".bmp" then
                        --copy the image to the windows folder
                        File.Copy(img, _WindowsFolder .. imagesplit.Filename .. ".bmp", false, true, true, true, nil)
                        setreg = true;
                        else
                        Dialog.Message("Error","The image you have selected is not supported.");
                        setreg = false;
                        end
                        --sets the registry value for tile and stretch
                        if setreg == true then
                        Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "TileWallpaper", tile, REG_SZ);
                        Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "WallpaperStyle", style, REG_SZ);
                        DLL.CallFunction(_SystemFolder .. "\\User32.dll", "SystemParametersInfoA", "20,0,\"" .. _WindowsFolder .. imagesplit.Filename .. ".bmp\",1", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);
                        end
                        end
                        TJ-Tigger
                        "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
                        "Draco dormiens nunquam titillandus."
                        Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

                        Comment


                        • #13
                          wall paper

                          thanks for your reply, I am fairly new with codes. What I am trying to do is give the user 3 choices of wall paper. I have a little thumbnail that when the user rollsover a larger image fades in so they can get a better look at it.

                          Underneath the thumbnail I give the user the option of 800 by 600 or
                          1024 x 768

                          so when he clicks on the numbers I would like a jpg to load to his desktop.

                          So with the code above. Do I put it into the global? and then I link the text 800 X 600 to the .jpg file that will go to their desktop? What action do I put on the link?

                          Willie

                          Comment


                          • #14
                            If I understand correctly you want to do this.

                            Your two images are based on two resolutions, lets call them Tigg1024x768.jpg and Tigg800x600.jpg. You have the above function loaded in your global functions area and then when they click the button or label you would do the following.

                            Code:
                            SetWallpaper(0, 2, "AutoPlay\\Images\\Tigg1024x768.jpg")
                            --Tile of 0 equals no tile and style of 2 equals stretched.
                            The function will then do the rest, in the case of using the jpg it will convert to bmp (Tigg1024x768.bmp) and copy the file to the _WindowsFolder, set the registry accordingly and apply the new wallpaper.

                            for the other image you would do this
                            Code:
                            SetWallpaper(0, 2, "AutoPlay\\Images\\Tigg800x600.jpg")
                            You could even go so far as the label your two options 1024x786 and 800x600 then when they click the button you could use that res as part of the name.

                            Code:
                            sRes = Button.GetText(this)
                            SetWallpaper(0, 2, "AutoPlay\\Images\\Tigg".. sRes ..".jpg")
                            
                            --Or if your buttons were named Tigg1024x768 and Tigg800x600 the same as your images without the extension you could do this
                            --sNameandRes = Button.GetText(this)
                            --SetWallpaper(0, 2, "AutoPlay\\Images\\".. sNameandRes ..".jpg")

                            I hope that helps. I kept thinking of ideas as you can probably note, so I hope that those ideas help rather than add confusion.

                            Tigg
                            TJ-Tigger
                            "A common mistake that people make when trying to design something completely foolproof was to underestimate the ingenuity of complete fools."
                            "Draco dormiens nunquam titillandus."
                            Map of IR Forum Users - IR Project CodeViewer - Online Help - TiggTV - QuizEngine

                            Comment


                            • #15
                              wall paper

                              I think that i am getting close, thanks for your patients

                              So I copy the code for the button, and in the actions for the label that i have, I paste it on the click, and change the name in the code to match my file?

                              Comment

                              Working...
                              X