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.
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.
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;
Dialog.Message("Error","The image you have selected is not supported.");
setreg = false;
--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);