UritOR Posted August 9, 2017 Share Posted August 9, 2017 Hi all, I'm trying to find how to draw an image (create a label in mspaint) and save it as .bmp. And set it to be a wallpaper I also need to know what wallpaper is use now, for restore it when the script is closed. What is the best way to do it? Do I need Gdi+ for it? I use this code (which I found here in forum) to set a .bmp file as wallpaper: expandcollapse popupFunc _ChangeWallpaper($sFile,$iType) ; Changes the wallpaper to $sFilename using $iType as: ; 1 Tiled ; 2 Centered ; 3 Stretched ; any other value (usually 0) unchanged ; ; Returns ; 0 if everything is allright. ; -1 if $sFile does not exist. @error is set to 1 ; -2 if £sFile is not a .bmp file. @error is set to 2 If Not FileExists($sFile) Then SetError(1) Return -1 EndIf If StringTrimLeft($sFile,StringInStr($sFile,'.',0,-1)) <> 'bmp' Then SetError(2) Return -2 EndIf Select Case $iType = 1 RegWrite('HKCU\Control Panel\Desktop','TileWallpaper','reg_sz','1') RegWrite('HKCU\Control Panel\Desktop','WallpaperStyle','reg_sz','0') Case $iType = 2 RegWrite('HKCU\Control Panel\Desktop','TileWallpaper','reg_sz','0') RegWrite('HKCU\Control Panel\Desktop','WallpaperStyle','reg_sz','0') Case $iType = 3 RegWrite('HKCU\Control Panel\Desktop','TileWallpaper','reg_sz','0') RegWrite('HKCU\Control Panel\Desktop','WallpaperStyle','reg_sz','2') Case Else EndSelect RegWrite('HKCU\Control Panel\Desktop','Wallpaper','reg_sz',$sFile) DllCall("User32.dll","int","SystemParametersInfo","int",20,"int",0,"str",$sFile,"int",0) Return 0 EndFunc The flow that I understand should be: 1) Check what wallpaper is in use now. I can find the path to it by going to registry key named "wallpaper" here :[HKEY_CURRENT_USER\Control Panel\Desktop] 2) Create a file mspaint 3) Create a label with its properties (size,color) in this file 3) Save this file in some temporary directory 4) Set a created file as a wallpaper using the above code 5) When the script is closed restore the old wallpaper. So again, my question is how to create a .bmp file with label in it? Link to comment Share on other sites More sharing options...
nend Posted August 9, 2017 Share Posted August 9, 2017 Maybe this is something for you. I made this a while ago but never finnished it. expandcollapse popup#Include <GDIPlus.au3> _GDIPlus_Startup () ConsoleWrite(@AppDataDir & "\Microsoft\Windows\Themes\TranscodedWallpaper" & @CRLF) FileCopy(@AppDataDir & "\Microsoft\Windows\Themes\TranscodedWallpaper", @AppDataDir & "\Nend Software\Weerstation Online\Current Wallpaper.bmp", 8) _setwallpaper(@AppDataDir & "\Nend Software\Weerstation Online\Current Wallpaper.bmp", 10, 1) _GDIPlus_ShutDown() Func _setwallpaper($pic, $style = 0, $warn = 1) If $warn = 1 then $m1 = @DesktopHeight/2 $m2 = @DeskTopWidth/2 EndIf If Not FileExists($pic) Then Return -1 $sString = "Hello world" $hImage = _GDIPlus_ImageLoadFromFile($pic) $sCLSID = _GDIPlus_EncodersGetCLSID ("BMP") $GC = _GDIPlus_ImageGetGraphicsContext($hImage) $hFormat = _GDIPlus_StringFormatCreate() $hFamily = _GDIPlus_FontFamilyCreate("Arial") $hBrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) $hFont = _GDIPlus_FontCreate($hFamily, 62, 2) $tLayout = _GDIPlus_RectFCreate(600, 110, 0, 0) $aInfo = _GDIPlus_GraphicsMeasureString($GC, $sString, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsDrawStringEx($GC, $sString, $hFont, $aInfo[0], $hFormat, $hBrush) $newBmp = _GDIPlus_BitmapCreateFromGraphics(@DeskTopWidth, @DesktopHeight, $GC) $newGC = _GDIPlus_ImageGetGraphicsContext($newBmp) _GDIPlus_GraphicsDrawImageRect($newGC, $hImage, 0, 0, @DeskTopWidth, @DesktopHeight) _GDIPlus_ImageSaveToFileEx($newBmp, @AppDataDir & "\Nend Software\Weerstation Online\Current Wallpaper set.bmp", $sCLSID) _GDIPlus_ImageDispose($hImage) _GDIPlus_ImageDispose($newBmp) _GDIPlus_GraphicsDispose($GC) _GDIPlus_GraphicsDispose($newGC) Local $SPI_SETDESKWALLPAPER = 20 Local $SPIF_UPDATEINIFILE = 1 Local $SPIF_SENDCHANGE = 2 RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop\", "TileWallPaper", "REG_SZ", 0) RegWrite("HKEY_CURRENT_USER\Control Panel\Desktop\", "WallpaperStyle", "REG_SZ", $style) DllCall("user32.dll", "int", "SystemParametersInfo", _ "int", $SPI_SETDESKWALLPAPER, _ "int", 0, _ "str", @AppDataDir & "\Nend Software\Weerstation Online\Current Wallpaper set.bmp", _ "int", BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE)) Return 0 If $warn = 1 then Sleep(2000) EndIf EndFunc ;==>_setwallpaper NassauSky 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now