Wallpaper function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • TJ_Tigger
    Indigo Rose Customer
    • Sep 2002
    • 3159

    Wallpaper function

    I have had a few questions on taking an image and making it the wallpaper for the desktop. This is a function that I have tried to tidy up so it can be put into anyones project. Here are the details:

    You will need to set the tile and style when using the function. So [On Click] place this code

    Code:
    SetWallpaper(0,2,image_name_or_variable)
    The function takes three parameters. The first two are for the orientation (ile 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 (attached below)

    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
  • Ted Sullivan
    Indigo Rose Staff Member
    • Oct 2003
    • 963

    #2
    That's a really great use of functions! Thanks for sharing that with everyone.
    New Release: Setup Factory 9.6 adds Windows 11 compatibility and support for hardware token OV/EV Code Signing certificates.

    Comment

    • SonG0han
      Forum Member
      • Dec 2003
      • 163

      #3
      Hi! Very nice function but I have a problem. The last wallpaper is always shown not the current one. but the image has been replaced and if i right click my desktop and select properties -> Desktop i can see the new pic. but on the desktop is the previous pic :(
      the images are all .jpg

      note: i tried it with double click and the e_Image (or something like that) event too but its the same. sometimes i get a random image as wallpaper

      here is the code. maybe you can find how to fix it?

      Code:
      SelectedThumb = ThumbList.GetSelectedItems("ThumbList");
      if SelectedThumb ~= nil then
      ThumbInfo = ThumbList.GetItemInfo("ThumbList", SelectedThumb[1]);
      Thumb = ThumbInfo.filepath;
      
      -- JPG2BMP
      File.Run(_SourceFolder.."\\DATA\\Wallpaper\\JPG2BMP.EXE", Thumb..";;".._WindowsFolder.."\\BIWall.bmp", "", SW_SHOWNORMAL, false);
      
      Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "WallpaperStyle", "0", REG_SZ);
      Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "TileWallpaper", "0", REG_SZ);
      
      DLL.CallFunction(_SystemFolder .. "\\User32.dll", "SystemParametersInfoA", "20,0,\"" .. _WindowsFolder .. "\\BIWall.bmp\",1", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);
      EDIT: one last thing, do you know how to make the wallpaper "fully stretched"?
      Last edited by SonG0han; 06-14-2004, 08:01 AM.

      Comment

      • TJ_Tigger
        Indigo Rose Customer
        • Sep 2002
        • 3159

        #4
        Originally posted by SonG0han
        Hi! Very nice function but I have a problem. The last wallpaper is always shown not the current one. but the image has been replaced and if i right click my desktop and select properties -> Desktop i can see the new pic. but on the desktop is the previous pic :(
        the images are all .jpg

        note: i tried it with double click and the e_Image (or something like that) event too but its the same. sometimes i get a random image as wallpaper

        here is the code. maybe you can find how to fix it?

        Code:
        SelectedThumb = ThumbList.GetSelectedItems("ThumbList");
        if SelectedThumb ~= nil then
        ThumbInfo = ThumbList.GetItemInfo("ThumbList", SelectedThumb[1]);
        Thumb = ThumbInfo.filepath;
        
        -- JPG2BMP
        File.Run(_SourceFolder.."\\DATA\\Wallpaper\\JPG2BMP.EXE", Thumb..";;".._WindowsFolder.."\\BIWall.bmp", "", SW_SHOWNORMAL, false);
        
        Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "WallpaperStyle", "0", REG_SZ);
        Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "TileWallpaper", "0", REG_SZ);
        
        DLL.CallFunction(_SystemFolder .. "\\User32.dll", "SystemParametersInfoA", "20,0,\"" .. _WindowsFolder .. "\\BIWall.bmp\",1", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);
        EDIT: one last thing, do you know how to make the wallpaper "fully stretched"?
        I will take a look at the problem when I get a chance, I am due for another plane ride here in a while. As for the Fully Stretched question, I use the following.


        Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "WallpaperStyle", "2", REG_SZ);
        Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "TileWallpaper", "0", REG_SZ);
        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

        • SonG0han
          Forum Member
          • Dec 2003
          • 163

          #5
          thx. stretching works now
          but if i apply a wallpaper i have to push the button (code above) 2 times until its shown on the desktop

          Comment

          • SonG0han
            Forum Member
            • Dec 2003
            • 163

            #6
            can anyone test it if it is the same?

            Comment

            • TJ_Tigger
              Indigo Rose Customer
              • Sep 2002
              • 3159

              #7
              Originally posted by SonG0han
              can anyone test it if it is the same?
              I have tried it here and even with over writting the picture it still replaces the image on a single click. What you may want to do is put an Application.Sleep(500); after the writing of the image and before the DLL call to make sure that the image is written before it is called by the DLL. What may be happening is that the BMP2JPG has no written the file when you first try to set it.


              Something like this.

              Code:
              SelectedThumb = ThumbList.GetSelectedItems("ThumbList");
              if SelectedThumb ~= nil then
              ThumbInfo = ThumbList.GetItemInfo("ThumbList", SelectedThumb[1]);
              Thumb = ThumbInfo.filepath;
              
              -- JPG2BMP
              File.Run(_SourceFolder.."\\DATA\\Wallpaper\\JPG2BMP.EXE", Thumb..";;".._WindowsFolder.."\\BIWall.bmp", "", SW_SHOWNORMAL, false);
              
              Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "WallpaperStyle", "0", REG_SZ);
              Registry.SetValue(HKEY_CURRENT_USER, "Control Panel\\Desktop", "TileWallpaper", "0", REG_SZ);
              Application.Sleep(500);
              DLL.CallFunction(_SystemFolder .. "\\User32.dll", "SystemParametersInfoA", "20,0,\"" .. _WindowsFolder .. "\\BIWall.bmp\",1", DLL_RETURN_TYPE_INTEGER, DLL_CALL_STDCALL);
              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

              • SonG0han
                Forum Member
                • Dec 2003
                • 163

                #8
                thanks! i'll try that tomorrow

                Comment

                • TJ_Tigger
                  Indigo Rose Customer
                  • Sep 2002
                  • 3159

                  #9
                  As I looked at this function again, you may want to just change this line
                  Code:
                  File.Run(_SourceFolder.."\\DATA\\Wallpaper\\JPG2BMP.EXE", Thumb..";;".._WindowsFolder.."\\BIWall.bmp", "", SW_SHOWNORMAL, false);
                  to this

                  Code:
                  File.Run(_SourceFolder.."\\DATA\\Wallpaper\\JPG2BMP.EXE", Thumb..";;".._WindowsFolder.."\\BIWall.bmp", "", SW_SHOWNORMAL, true);
                  and see if that works. I changed the WaitForReturn attribute to true so that the jpg2bmp would finish converting the jpg to bmp before continuing to set it as a wallpaper. By doing this you should be able to remove the Application.Sleep action.
                  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

                  • TJ_Tigger
                    Indigo Rose Customer
                    • Sep 2002
                    • 3159

                    #11
                    I was looking at your posts the otherday, unfortunately I do not have the Progress bar or the DB plugins.

                    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

                    • SonG0han
                      Forum Member
                      • Dec 2003
                      • 163

                      #12
                      oh :(

                      @IndigoRose Team: How about some free/cheap plugins for one of the best AMS-Helpers?

                      Comment

                      • TJ_Tigger
                        Indigo Rose Customer
                        • Sep 2002
                        • 3159

                        #13
                        Originally posted by SonG0han
                        oh :(

                        @IndigoRose Team: How about some free/cheap plugins for one of the best AMS-Helpers?
                        Nah, not a problem, I will get them through work when I need to use them in a project. That will get them approved for purchase.

                        thanks though
                        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

                        • SonG0han
                          Forum Member
                          • Dec 2003
                          • 163

                          #14
                          k.
                          there's still no reply. hope anyone can help soon. i dont know what to do now :|

                          Comment

                          • TJ_Tigger
                            Indigo Rose Customer
                            • Sep 2002
                            • 3159

                            #15
                            Originally posted by SonG0han
                            k.
                            there's still no reply. hope anyone can help soon. i dont know what to do now :|
                            Did the suggestions work for the Wallpaper app or is your above comment for the callback/database issue?
                            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

                            Working...
                            X