My wish is to handle an unknown number of images.
Usually there are a few pictures one, two or three, but there can be more than that.
(I want to see all the pictures and choose one of them)
If there are a few images to show, there is no problem (fits in the GUI window)
But if there are too many...
Wrote a small test script that shows two images (easy to add more)
Code: Select all
; Version 20 jan 2020
#Singleinstance force
allImages := [{}] ; Create an object in an array
images =
( LTrim
C:\Windows\Web\4K\Wallpaper\Windows\img0_768x1024.jpg
C:\Windows\Web\4K\Wallpaper\Windows\img0_1366x768.jpg
)
imgNames := strSplit(images, "`n", "`n")
; The start values
imgGuiWidth = 200
imgGuiHeight = 200
guiRatio := imgGuiWidth / imgGuiHeight
imgGuiX := 75
imgGuiY := 50
; Create an Array with information about the images
for k, v in imgNames
{ imgInfo := []
; Handle the imagename
SplitPath v, imgName, imgPath
imgInfo.name := imgName
imgInfo.path := imgPath
; Check and handle width and height of the image to fit an Area
Gui 2: add, picture, hwndmypic, % v
ControlGetPos,,, imgWidth, imgHeight,, ahk_id %mypic%
imgInfo.orgWidth := imgWidth
imgInfo.orgHeight := imgHeight
imgInfo.ratioWidth := imgWidth / imgGuiWidth
imgInfo.ratioHeight := imgHeight / imgGuiHeight
If ( imgInfo.ratioWidth > imgInfo.ratioHeight ) ; Width is larger
{ imgInfo.newWidth := imgGuiWidth
imgInfo.newHeight := Round(imgInfo.orgHeight / imgInfo.ratioWidth, 0)
}
else
{ imgInfo.newWidth := Round(imgInfo.orgWidth / imgInfo.ratioHeight, 0) ; Height is larger
imgInfo.newHeight := imgGuiHeight
}
imgInfo.picX := imgGuiX
imgInfo.picY := imgGuiY
/*
MsgBox ,, %A_ScriptName% - Row %A_LineNumber%,
( LTrim
% "Gui wide .: " imgGuiWidth "`tGui Height .: " imgGuiHeight "
Path . .: `t" imgInfo.path "
Image .: `t" imgInfo.name "
Image Width . . .: `t" imgInfo.orgWidth "`tRatio Width .: " imgInfo.ratioWidth "
Image Height . . .: `t" imgInfo.orgHeight "`tRatio Height .: " imgInfo.ratioHeight "
New Width . . . . .: `t" imgInfo.newWidth "`tNew Height. .: " imgInfo.newHeight "
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
imgInfo.picX .: " imgInfo.picX "
imgInfo.picY .: " imgInfo.picY
)
*/
allImages[A_Index] := imgInfo
imgGuiY += imgGuiHeight + 50
}
; Max height on GUI
shGUI := imgGuiY + 50 ; winGuiSizeHeight
If ( shGUI > 600 )
shGUI = 600
swGUI = 350 ; winGuiSizeWidth
; Show the result in a GUI
; --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
Gui 1: Font, S14 cGreen Bold, Verdana
Gui 1: Add, Text, x0 y5 w%swGUI% h25 center , Images
Loop % allImages.count()
{ posX := allImages[A_Index].picX
posY := allImages[A_Index].picY
Gui 1: Font, s10 cGreen Normal, Arial
Gui 1: Add, Text, x%posX% y%posY%, % allImages[A_Index].name
height := allImages[A_Index].newHeight
width := allImages[A_Index].newWidth
imgName := allImages[A_Index].path "\" allImages[A_Index].name
Gui 1: Add, Picture, xp+10 yp+25 h%height% w%width% vImg%A_Index%, % imgName
}
Gui 1: Show, x100 y200 w%swGUI% h%shGUI% , %A_ScriptName%
Return
; --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
ExitApp
Right now, it feels like clicking on the image to show the next, would be the nicest solution
How is this solved (in a simple way)?
Ideas for other solutions?