Sign in to follow this  
Followers 0
Sori

Basic Slideshow Wallpaper (Multiple Monitor)

1 post in this topic

#1 ·  Posted (edited)

While looking for a way to change my desktop background of only my secondary monitor, I found a few simple solutions that are built into Windows. But when you look up how to do such with a slideshow... You only find programs that cost money. So, I set out to make it myself.
This is a pretty basic program. It simply displays an image in the center of the screen (scaled to fit screen) and uses a black background.
The program does allow mouse passthrough, though you can't drag and drop over it, so it wouldn't really work well if you have icons on your second monitor.
 
#include <File.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <Misc.au3>
#include <Array.au3>
#include <GDIPlus.au3>

;User Changeable Variables
;========================================================================
$pictureFolder = "D:\Wallpapers"
$changeTime = 5 ;Seconds
Global $smWidth = 1600
Global $smHeight = 900
Global $monitorPosition = "Right"
;Global $monitorPosition = "Left"
;========================================================================
Global $imageList = _FileListToArray($pictureFolder)
Global $imageCount = $imageList[0]
Global $imageHeight, $imageWidth, $pHeight, $pWidth, $pic, $gdiPic

_GDIPlus_Startup()
OnAutoItExitRegister("CloseProgram")

$GUIStyle = BitOR($WS_POPUP, $WS_VISIBLE, $HWND_BOTTOM) ;Popup, Visible, Window on Bottom
$GUIStyleEx = BitOR($WS_EX_TRANSPARENT, $WS_EX_TOOLWINDOW) ;Allow Passthrough, Hide from Alt+Tab
$Parent = WinGetHandle('Program Manager', '') ;Sets parent to the program manager, allowing you to right click the desktop
If $monitorPosition = "Right" Then
    $GUI = GUICreate("Secondary Wallpaper", $smWidth, $smHeight, @DesktopWidth, 0, $GUIStyle, $GUIStyleEx, $Parent)
Else
    $GUI = GUICreate("Secondary Wallpaper", $smWidth, $smHeight, (-1 * @DesktopWidth), 0, $GUIStyle, $GUIStyleEx, $Parent)
EndIf
GUISetBkColor(0, $GUI)
_WinAPI_SetWindowPos($GUI, $HWND_BOTTOM, 0, 0, 0, 0, BitOR($SWP_NOACTIVATE, $SWP_NOMOVE, $SWP_NOSIZE, $SWP_SHOWWINDOW)) ;Forces window to bottom of screen
WinSetTrans($GUI, '', 255) ;Sets Window Visible Transparency: Required for mouse passthrough
ChangeImage()
GUISetState(@SW_SHOW) ;Show GUI

While 1
    Sleep($changeTime * 1000)
    ChangeImage()
WEnd

Func ChangeImage()
    $picName = Random(1, $imageCount, 1)
    ;Get Dimensions of image
    GetDimensions($imageList[$picName])
    $imageHeight = $pHeight
    $imageWidth = $pWidth

    ;Turn them all into integers. (Fixes glitch that caused some images to skip resizing)
    $imageHeight = Int($imageHeight)
    $imageWidth = Int($imageWidth)
    $smHeight = Int($smHeight)
    $smWidth = Int($smWidth)


        ;Adjust the image size
    ;-----------------------------------------------
    ;If the image is bigger than the screen, adjust it
    If $imageWidth > $smWidth = 1 Or $imageHeight > $smHeight = 1 Then
        ;Calculate Aspect Ratio of image
        $aspectRatioX = $smWidth / $imageWidth
        $aspectRatioY = $smHeight / $imageHeight
        If $aspectRatioX < $aspectRatioY Then
            $scaleFactor = $aspectRatioX
        Else
            $scaleFactor = $aspectRatioY
        EndIf
        $imageHeight = $imageHeight * $scaleFactor
        $imageWidth = $imageWidth * $scaleFactor
    ;Else
        ;Image is smaller/same size as monitor
    EndIf

    ;Calculate Center of monitor
    ;(Monitor size - image size) / 2
    $smCenterX = ($smWidth - $imageWidth) / 2
    $smCenterY = ($smHeight - $imageHeight) / 2

    ;Resize the image
    $hHBmp = $pictureFolder & "\" & $imageList[$picName]
    $gdiPic = _GDIPlus_BitmapCreateFromFile($hHBmp) ;convert GDI bitmap to GDI+ bitmap
        _GDIPlus_BitmapDispose($pic)
    $pic = _GDIPlus_ImageResize($gdiPic, $imageWidth, $imageHeight) ;resize image
    _GDIPlus_BitmapDispose($gdiPic)

    GUISetBkColor(0, $GUI)
    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($GUI) ;create a graphics object from a window handle
    $gdiPic = _GDIPlus_BitmapCreateFromFile($pictureFolder & "\" & $imageList[$picName])

    _GDIPlus_GraphicsDrawImage($hGraphics, $pic, $smCenterX, $smCenterY) ;display scaled image
    _GDIPlus_GraphicsDispose($hGraphics) ;Garbage Cleanup
EndFunc   ;==>ChangeImage


Func GetDimensions($picName)
    Local $prop, $dArray, $fileSize, $imageDimensionsGDI

    $path = $pictureFolder & "\" & $picName
    $fileSize = FileGetSize($path)
    ;Save information to registry for faster access. Compare size of picture to verify changes to picture
    If $fileSize <> RegRead("HKEY_CURRENT_USER\Software\Secondary Wallpaper\Pictures", $picName & " Size") Then
        ;File sizes do not match
        RegWrite("HKEY_CURRENT_USER\Software\Secondary Wallpaper\Pictures", $picName & " Size", "REG_SZ", $fileSize)
        $imageDimensionsGDI = _GDIPlus_ImageLoadFromFile($path)
        $pWidth = _GDIPlus_ImageGetWidth($imageDimensionsGDI)
        $pHeight = _GDIPlus_ImageGetHeight($imageDimensionsGDI)
        _GDIPlus_ImageDispose($imageDimensionsGDI)
        RegWrite("HKEY_CURRENT_USER\Software\Secondary Wallpaper\Pictures", $picName & " Width", "REG_SZ", $pWidth)
        RegWrite("HKEY_CURRENT_USER\Software\Secondary Wallpaper\Pictures", $picName & " Height", "REG_SZ", $pHeight)
    Else
        ;File sizes match
        $pWidth = RegRead("HKEY_CURRENT_USER\Software\Secondary Wallpaper\Pictures", $picName & " Width")
        $pHeight = RegRead("HKEY_CURRENT_USER\Software\Secondary Wallpaper\Pictures", $picName & " Height")
        If $pWidth = "-1" Or $pHeight = "-1" Then
            RegWrite("HKEY_CURRENT_USER\Software\Secondary Wallpaper\Pictures", $picName & " Size", "REG_SZ", $fileSize)
            $imageDimensionsGDI = _GDIPlus_ImageLoadFromFile($path)
            $pWidth = _GDIPlus_ImageGetWidth($imageDimensionsGDI)
            $pHeight = _GDIPlus_ImageGetHeight($imageDimensionsGDI)
            _GDIPlus_ImageDispose($imageDimensionsGDI)
            RegWrite("HKEY_CURRENT_USER\Software\Secondary Wallpaper\Pictures", $picName & " Width", "REG_SZ", $pWidth)
            RegWrite("HKEY_CURRENT_USER\Software\Secondary Wallpaper\Pictures", $picName & " Height", "REG_SZ", $pHeight)
        EndIf
    EndIf

EndFunc   ;==>GetDimensions



Func CloseProgram()
    ;Garbage Cleanup
    _GDIPlus_GraphicsDispose($gdiPic)
    _GDIPlus_Shutdown()
EndFunc   ;==>CloseProgram

 

 

 

Secondary Wallpaper.au3

Edited by Sori
Now includes scaled images and centering.
1 person likes this

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites



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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • SimTheNo1
      By SimTheNo1
      I am busy with building a solution for change monitoring of VOIP call program and to be properly automated means among others need for some limited OCR functionality. Current works of others are way too much overkill for this case what makes the need to build it myself. But to do it properly I significantly have to increase my knowledge about digital graphics management.
      For now I already have discovered here and there some mind blowing  Autoit miracles what can be achieved with Windows own possibilities to manipulate that what is output to the monitor. And as far I can judge there are 2 options to process graphics without use of any external libraries like ImageMagick, FreeImage and so on. These are:
       WinAPI  GDIPlus It is for me quite obvious to have various holes in general understanding of graphics and it is once more very clear what advantages gives consistent general study in 1 or another official institutions like University.  Cause there you are introduced into certain domain of knowledge in a way which usually has been perfected over long period of time. So you are not overloaded by stuff which requires a certain amount of information to be initially clear for you. For example, before starting to solve physics you first learn to read, count and so on and then move to subjects like physics.
      Though in my case opportunity to study in such educational system I had only for 8 years, from my 7th to 15th year of age in the country that was falling apart now Ukraine but used to be USSR, was all what it was. After have immigrated to Netherlands possibilities to study further haven't occur. And this therefor causes often various implications when going deep in that or another field of practical knowledge acquiring for any needed physical result, like programming to perform enormous amount of tasks. In this particular case automating VOIP call program.
      Anyway, right now I think the best direction to move is to concentrate on as basic as possible image management and if someone would maybe explain in general what is a pixel will definitely help. Particularly I am very curious about how to do picture manipulations in Autoit. Especially would help a lot to produce eventually following functions:
      createImage($imageFileName, $width, $height, $color) readImagePixel($imageFileName, $x, $y)  writeImagePixel($imageFileName, $x, $y) I do not know exactly how image is handled in computer but preferably above mentioned functions should deal with so far possible origin of graphics creation on computer. But nevertheless I definitely would love to hear any proposition for solution.
      The problem with explaining screenshots:
       VOIPConnect full Window  Part of Window with control to monitor for changes  Exact location of area where actual changes occur and have to be processed  It comes down to a rectangle of approximately 51 pixel wide and 7 pixel high. In fact if I get to learn as far as to be able exactly read, write and compare 2 images consistently across different computers I could narrow down then even further the area to watch as little as a square of 2-5 pixels wide. 
      To finish here is last detail about particularly no need for ultra fast solution at all. This because it is needed only once when it is first run on a new computer and to have to wait few minutes while it is being set instead of just a few seconds make no sence.
      This is it and what I too think to do beside this very particular case is to purify out beautiful generic Autoit functions for core image manipulation by using WinAPI or/and GDIPlus. 
    • corgano
      By corgano
      What I am trying to accomplish is to simplify a .PNG image and convert it to use only a specified pallet of colors. Eg if I have a pallet of 0xFF0000, 0x00FF00, 0x0000FF, it would change every pixel in the image to one of those three colors by whichever color is closest.
       
      The simplest method I have tried is simply converting the image to a 16 bit bitmap, and that does simplify the pallet of the image, but I want to be able to specify what colors it specifies to. The other problem is the resulting saved .BMP file is much larger (file size) than the original, and I don't know if it's possible to make a 16 bit jpg.
       
      It looks like _GDIPlus_BitmapConvertFormat is the solution but the help file doesn't go into how to use the pallet and I couldn't find an example that did what I needed. Can anyone help me?
    • timmalos
      By timmalos
      Hello all . i'm trying to build a tool to generate some pictures/graphs automatically based on some variables. I have completed the first part and I'm struggling now on what I thought would be the easiest part :
      In my tool there is a "preview" button, which helps to display on a new children GUI the generated picture. What I do in simplified :
      Global $g_hGraphics = _GDIPlus_GraphicsCreateFromHWND($g_hGUI) ;Then, I'll add multiple objects to this graphic, for example $Temp = _GDIPlus_ImageLoadFromFile($temp[1]) _GDIPlus_GraphicsDrawImage($g_hGraphics,$temp)  
      I'm then able to have a preview GUI showing all my elements perfectly. This works but now I want to be able to really generate it and have a ".png" file written to disk.
      What I tried without success:
      $g_hBitmap = _GDIPlus_BitmapCreateFromGraphics($previewWidth, $previewHeight, $g_hGraphics) _GDIPlus_ImageSaveToFile($g_hBitmap,$OUTPUTDIR & "\generated\test-"&@HOUR&@MIN&@SEC&".png") But what I write to file is a transparent PNG without anything.
      I'm pretty sure I'm missing something obvious there, I need your help
       
       
      NB : If this change your answer, my goal will be to generate transparent png, meaning I'll add multiple objects/pictures/texts on a transparent png background and if there are some "transparent holes" I need them to be transparent in the generated png.
       
      Thanks a lot for any help !
      Tim
    • timmalos
      By timmalos
      Hello all.
      I'm trying to do something simple, but I can't manage to find where to start since I can have multiple possibilities and not sure what is the best one :
      Taking screen capture (I can do that) On this capture, I'll look for 10 particular regions that will give me 10 images of 40px * 40px (I can do that) Then what I want is for each of these regions, find on my library of ~140 images which one is the closest one to my region (= the match)  
      What do you think is the best approach ? Ican easily do step 1 and 2, however for the third step :
      I can't use memcmp because they won't be exactly the same (original library can differ a very little bit from what I'll get from my screen capture) There is no text, only drawing Should I do a pixelSum of what I get on screen and do the same via GDIPlus for each of my images in the library?  
      Thanks a lot,
      Tim
       
    • GtaSpider
      By GtaSpider
      Hey everyone,
      When I try to add blur to an Image with _GDIPlus_EffectCreateBlur and _GDIPlus_BitmapApplyEffect the blur is only horizontal, not horizontal and vertical, if the blur radius is <= 20. 
      Easy to test with the Image I attached and the default example from the helpfile of 
      _GDIPlus_BitmapApplyEffect The second Image I attached is the result and as you can see the cross is only blurred in one direction.  Does anyone have a clue why this happens and furthermore a solution for this problem? (I could just rotate the picture but then it would be twice as time consuming...)
      Thanks in advance,
      Spider
      p.s.: Running Win 10 Pro with all updates