Jump to content

[Resolved] GUI with vertical scrollbar to display and select pictures from folder


Faalamva
 Share

Recommended Posts

Hello,

I'm new to GUI autoit programming, and so far I have checked several threads with solutions that would fit my need, but none using a scrollbar like I wish... :sweating:

Please let me explain what I'm trying to do :

I want a simple GUI, this GUI shall contain a zone with a vertical scrollbar.

In this zone, I want to display several pictures all in 1 column.

Since I won't have enough place to display them all, I'd like to have the scrollbar to help me... well... scroll the pictures as I want. :sorcerer:

  • I don't know yet how to create a specific zone, so I have created a scrollbar on the main GUI : GUICreate(..., $WS_VSCROLL)
  • I have also managed to display several pictures in my GUI using GUICtrlCreatePic, including pictures located outside the GUI lower boundary. I thought it would "activate" the scrollbar, but no, it doesn't work.
So I'm a bit stucked at this point. Is what I'm trying to do even possible ? :huh:

Thank you so much for your help !

Cheers !

Edited by Faalamva
Link to comment
Share on other sites

Did you search Scrollbars in the help file and in the Examples section of the Forum?

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • Moderators

Faalamva,

Welcome to the AutoIt forum. :)

Take a look at the Scrollbars UDF in my sig - it will help you. ;)

M23

Edit: Here is an example of it being used:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

#include <GUIScrollBars_Ex.au3>

Global $aButton[5]

; Create GUI
$hGUI_Main = GUICreate("Test", 500, 500)
GUISetBkColor(0xC4C4C4)

; Create child GUI
$hChild = GUICreate("", 200, 150, 100, 100, $WS_POPUP, $WS_EX_MDICHILD, $hGUI_Main)

; Add controls to child
For $i = 0 To 4
    $aButton[$i] = GUICtrlCreateButton("Button " & $i, 10, 10 + (50 * $i), 80, 30)
Next

; Create scrollbars in child
_GUIScrollBars_Generate($hChild, 0, 240)

; Show GUIs
GUISetState(@SW_SHOW, $hChild)
GUISetState(@SW_SHOW, $hGUI_Main)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case Else
            ; Look for a button
            For $i = 0 To 4
                If $nMsg = $aButton[$i] Then
                    MsgBox(0, "Pressed", "Button " & $i)
                    ExitLoop
                EndIf
            Next
    EndSwitch
WEnd
Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thank you both, :guitar:

OK, here is the code of my application so far.

I didn't have much time today to focus on the scrollbars, so what it does basically so far is : display all JPG images in a directory called "Images" placed in the current directory.

  • Some images are created outside the GUI lower boundary and I will now concentrate my efforts to implement the vertical scrollbar.
  • After that, I'll try to put the images in a separate zone with scrollbar, because I want to place more (fixed) buttons on the main GUI.
  • The images are clickable. Still working on that part too. I'd like to be able to select/unselect several images.
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.8.1
Author: myName
#ce ----------------------------------------------------------------------------

#include 
#include 
#include 
#include 

Local $ScreenWidth = 1920
Local $ScreenHeight = 1080
Local $GUIWidth = 1200
Local $GUIHeight = 800
Local $ImgRep = ".\Images\"
Local $Images[100]
Local $Pic[100]
Local $ZoomFactor = 0.1
Local $Spacer = 10

; Initialize GDI+ library and GUI
_GDIPlus_Startup()
$GUI = GUICreate("My application", $GUIWidth, $GUIHeight, ($ScreenWidth-$GUIWidth)/2, ($ScreenHeight-$GUIHeight)/2, $WS_SYSMENU + $WS_VSCROLL)

; Browse all filenames in Images directory
Local $search = FileFindFirstFile($ImgRep & "*.jpg")
If $search = -1 Then
MsgBox(0, "Error", "No files in directory")
Exit
EndIf

$Index = 0
Do
$Images[$Index] = FileFindNextFile($search)
$Index = $Index + 1
Until @error <> 0
$Index = $Index - 2

; Close the search handle
FileClose($search)

$yPos = $Spacer
For $i = 0 To $Index
; Get image size
$hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $Images[$i])
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)
_GDIPlus_ImageDispose($hImage)
; Create image in GUI
$Pic[$i] = GUICtrlCreatePic($ImgRep & $Images[$i], $Spacer, $yPos, $iX*$ZoomFactor, $iY*$ZoomFactor)
$yPos = $yPos + $iY*$ZoomFactor + $Spacer
Next

; Display GUI
GUISetState(@SW_SHOW)

; Main events listener
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Pic[0] To $Pic[$Index]
For $n = 0 To $Index
If $nMsg = $Pic[$n] Then MsgBox(64 + 8192, "Message", "This is image " & $Images[$n])
Next
EndSwitch
WEnd

; Shut down GDI+ library
_GDIPlus_Shutdown()

The vertical scrollbar is displayed but doesn't work. I will now read thoroughly the previous posts to know why.

Any comments and improvements are welcome ! :sorcerer:

Cheers !

Link to comment
Share on other sites

  • Moderators

Faalamva,

Quick tip: Use FileListToArray to get all the files in the folder rather than using FileFindFirst/NextFile - why do all the work yourself when the function does it for you? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Works like a charm, thank you !

The code is now :

#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.8.1
Author:      myName
#ce ----------------------------------------------------------------------------

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <File.au3>

Local $ScreenWidth = 1920
Local $ScreenHeight = 1080
Local $GUIWidth = 1200
Local $GUIHeight = 800
Local $ImgRep = ".\Images\"
Local $Images[100]
Local $Pic[100]
Local $ZoomFactor = 0.1
Local $Spacer = 10

; Initialize GDI+ library and GUI
_GDIPlus_Startup()
$GUI = GUICreate("My application", $GUIWidth, $GUIHeight, ($ScreenWidth-$GUIWidth)/2, ($ScreenHeight-$GUIHeight)/2, $WS_SYSMENU + $WS_VSCROLL)

; Browse all filenames in Images directory
Local $Images = _FileListToArray($ImgRep, "*.jpg", 1)
If @error = 4 Then
MsgBox(0, "Error", "No files found in " & $ImgRep)
Exit
EndIf

; Create images in GUI
$yPos = $Spacer
For $i = 1 To $Images[0]
; Get image size
$hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $Images[$i])
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)
_GDIPlus_ImageDispose($hImage)
; Resizes and places image in GUI
$Pic[$i] = GUICtrlCreatePic($ImgRep & $Images[$i], $Spacer, $yPos, $iX*$ZoomFactor, $iY*$ZoomFactor)
$yPos = $yPos + $iY*$ZoomFactor + $Spacer
Next

; Display GUI
GUISetState(@SW_SHOW)

; Main events listener
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
     Case $GUI_EVENT_CLOSE
         Exit
     Case $Pic[1] To $Pic[$Images[0]]
For $n = 1 To $Images[0]
If $nMsg = $Pic[$n] Then MsgBox(64 + 8192, "Message", "This is image " & $Images[$n])
Next
EndSwitch
WEnd

; Shut down GDI+ library
_GDIPlus_Shutdown()
Edited by Faalamva
Link to comment
Share on other sites

  • Moderators

Faalamva,

Next tip: Use the @DesktopWidth/Height macros rather than hard coding the screen size - then you can adjust the size of your GUI to fit. :)

Have you looked at my Scrollbars UDF to see how easy it is to add scrollbars to your GUI yet? If not, please do so - because you only need 1 line of code as shown in the example I posted. ;)

M23

P.S. And I have lifted your "New Member" 5 post limitation so do not worry about that any more. :)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thank you for this new tip. I'll sure use it on the next code iteration.

Yes yes, I have read carefully your post about scrollbars. UDF's have been installed, example is working, everything looks perfectly clear AND also perfectly fitting my needs ! :thumbsup:

I'll post the new code when it's ready, and of course, tested !

Oh, and thank you also for the extra posts ! :zorro:

Edited by Faalamva
Link to comment
Share on other sites

  • Moderators

Faalamva,

everything looks perfectly clear AND also perfectly fitting my needs !

Excellent! I look forward to seeing the finished script. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Here it is, along with some questions : :graduated:

1) At first, I have put the "$ChildGUI = GUICreate(..." line just after the "$ParentGUI = GUICreate(..." line, resulting in the images being systematically displayed in the parent GUI...

This is confusing because from what I know, the last handle created (i.e. the child one) should be the one used by default by the next commands ?

So as a workaround, I have moved the ChildGUI creation just before the "$Pic[$i] = GUICtrlCreatePic(..." loop, for it to work properly.

But it's not very satisfying. It seems the GUICtrlCreatePic doesn't accept any handle parameter, too bad...

2) Do you know what is the default scrollbar width ? I have checked the GUIScrollBars_Ex.au3 inner code but couldn't find this information. I assume it's something like 15 pixels. Can it be changed for a wider one (it's only a minor detail anyway) ?

3) The main objective of this thread has been reached. Thank you for your very quick feedback and accuracy. Although I'm not new in programming, this is very encouraging for an AutoIt newcomer like me. Shall I continue the next program evolutions in this very thread, or create a new thread (if needed of course) ? As said before, I may now focus on multiple images selection, and some more functionalities in the parent interface.

Cheers, :ILA3:

#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.8.1
Purpose: Displays all images in the $ImgRep directory (by default, the .\Images directory)
         The images are displayed in a child GUI with vertical scrollbar.
Images are resized according to the $ZoomFactor parameter.
#ce ----------------------------------------------------------------------------

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <File.au3>
#include <GUIScrollBars_Ex.au3>

Local $ImgRep = ".\Images\"
Local $Images[100]
Local $Pic[100]
Local $MaxImgWidth = 1200
Local $ZoomFactor = 0.2
Local $Spacer = 20
Local $ParentGUIWidth = 1200
Local $ParentGUIHeight = 800
Local $ChildGUIWidth = $MaxImgWidth*$ZoomFactor + 2*$Spacer + 15
Local $ChildGUIHeight = $ParentGUIHeight - 2*$Spacer

; Initialize GDI+ library and parent GUI
_GDIPlus_Startup()
$ParentGUI = GUICreate("My application", $ParentGUIWidth, $ParentGUIHeight, (@DesktopWidth-$ParentGUIWidth)/2, (@DesktopHeight-$ParentGUIHeight)/2)
GUISetBkColor(0xC4C4C4, $ParentGUI)

; Browse all filenames in Images directory
Local $Images = _FileListToArray($ImgRep, "*.jpg", 1)
If @error = 4 Then
MsgBox(0, "Error", "No files found in " & $ImgRep)
Exit
EndIf

; Initialize child GUI
$ChildGUI = GUICreate("", $ChildGUIWidth, $ChildGUIHeight, $Spacer, $Spacer, $WS_POPUP, $WS_EX_MDICHILD, $ParentGUI)

; Create images in GUI
$yPos = $Spacer
For $i = 1 To $Images[0]
; Get image size
$hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $Images[$i])
$iX = _GDIPlus_ImageGetWidth($hImage)
$iY = _GDIPlus_ImageGetHeight($hImage)
_GDIPlus_ImageDispose($hImage)
; Resizes and places image in GUI
$Pic[$i] = GUICtrlCreatePic($ImgRep & $Images[$i], $Spacer, $yPos, $iX*$ZoomFactor, $iY*$ZoomFactor)
$yPos = $yPos + $iY*$ZoomFactor + $Spacer
Next

; Create scrollbars in child
_GUIScrollBars_Generate($ChildGUI, 0, $yPos - $Spacer)

; Display GUIs
GUISetState(@SW_SHOW, $ParentGUI)
GUISetState(@SW_SHOW, $ChildGUI)

; Main events listener
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
     Case $GUI_EVENT_CLOSE
         Exit
     Case $Pic[1] To $Pic[$Images[0]]
         For $n = 1 To $Images[0]
             If $nMsg = $Pic[$n] Then MsgBox(64 + 8192, "Message", "This is image " & $Images[$n])
         Next
EndSwitch
WEnd

; Shut down GDI+ library
_GDIPlus_Shutdown()
Edited by Faalamva
Link to comment
Share on other sites

  • Moderators

Faalamva,

1. AutoIt creates controls in the last created GUI. I think your problem is the order of the GUISetState commands - try showing the child before the parent as in my example. ;)

2. Scrollbar width is set by the system - they are 17 pixels wide (on my machine) and I have never found a way to change it. :(

3. If the question deals with this particular script then ask away here. But I encourage you to open a new thread if the question is significantly different. ;)

Glad you got the script working - and that I could help. Welcome to the forum again! :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

OK, now that I have my image display working, I'd like to be able to click on one or several images, and set/unset some kind of visual effect (a border maybe ?) on selected/unselected images.

I'd also want to dynamically set an array containing the filenames of the selected images.

I really have no idea what function I could use for that. And what kind of sexy select/unselect effect I could use. Any idea is welcome ! :gathering:

Edit : Concerning Pt. 1 above, I have found what's wrong : the GUISetBkColor(0xC4C4C4, $ParentGUI) sets the current GUI back to ParentGUI, making the GUICtrlCreatePic(...) defaulting to Parent GUI. So if I want the pictures in the Child GUI, I have to create the Child GUI after the GUISetBkColor(0xC4C4C4, $ParentGUI) line.

Edit 2 : I think I have found what I need in the GUICtrlSetStyle function. Gotta check later those Common styles and Extended styles to see what is possible to do.

Edited by Faalamva
Link to comment
Share on other sites

  • Moderators

Faalamva,

GUISwitch allows you to determine in which GUI the script will create controls - using it will allow you to be very specific about where you want teh next commands to act. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Faalamva,

And this thread might give you some hints as to how you might highlight your images. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Wow thank you, this is exactly what I needed. It works perfectly but I still have two issues :

- The first is the major one : if you check my script, you will see that I have deactivated the scrollbar. The yellow borders are working and their size is correct. Now, if I uncomment the scrollbars, you may notice that the yellow borders are somehow truncated. How can it be explained, and fixed ?

Without scrollbars :

Posted Image

With scrollbars :

Posted Image

- Second, a minor issue : the select/unselect speed is quite slow. Sometimes if I click too fast on the same image, it doesn't select or unselect. Is there a way to improve the speed of my program ?

Code :

#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.8.1
Purpose: Displays all images in the $ImgRep directory (by default, the .\Images directory)
The images are displayed in a child GUI with vertical scrollbar.
Images are resized according to the $ZoomFactor parameter.
#ce ----------------------------------------------------------------------------

#include 
#include 
#include 
#include 
#include 

Local $ImgRep = ".\Images\"
Local $NbMaxImages = 100
Local $ImageFilenames[$NbMaxImages]
Local $hLabel[$NbMaxImages]
Local $hPic[$NbMaxImages]
Local $PicXPos[$NbMaxImages]
Local $PicYPos[$NbMaxImages]
Local $PicWidth[$NbMaxImages]
Local $PicHeight[$NbMaxImages]
Local $SelectedState[$NbMaxImages]
Local $MaxImgWidth = 1200
Local $ZoomFactor = 0.2
Local $Spacer = 20
Local $BorderWidth = 5
Local $ParentGUIWidth = 1200
Local $ParentGUIHeight = 800
Local $ChildGUIWidth = $MaxImgWidth*$ZoomFactor + 2*$Spacer + 13
Local $ChildGUIHeight = $ParentGUIHeight - 2*$Spacer
Local $ParentBkColor = 0xBBBBBB
Local $ChildBkColor = 0xDDDDDD
Local $BorderColor = 0xFFFF00

; Initialize GDI+ library and parent GUI
_GDIPlus_Startup()
$ParentGUI = GUICreate("My application", $ParentGUIWidth, $ParentGUIHeight, (@DesktopWidth-$ParentGUIWidth)/2, (@DesktopHeight-$ParentGUIHeight)/2)
GUISetBkColor($ParentBkColor, $ParentGUI)
$ChildGUI = GUICreate("", $ChildGUIWidth, $ChildGUIHeight, $Spacer, $Spacer, $WS_POPUP, $WS_EX_MDICHILD, $ParentGUI)
GUISetBkColor($ChildBkColor, $ChildGUI)

; Browse all filenames in Images directory
Local $ImageFilenames = _FileListToArray($ImgRep, "*.jpg", 1)
If @error = 4 Then
MsgBox(0, "Error", "No files found in " & $ImgRep)
Exit
EndIf

; Create images in child GUI
$PicHeight[0] = 0
$PicYPos[0] = 0
For $i = 1 To $ImageFilenames[0]
; Get image size
$hImage = _GDIPlus_ImageLoadFromFile($ImgRep & $ImageFilenames[$i])
$PicWidth[$i] = _GDIPlus_ImageGetWidth($hImage)*$ZoomFactor
$PicHeight[$i] = _GDIPlus_ImageGetHeight($hImage)*$ZoomFactor
_GDIPlus_ImageDispose($hImage)
; Resizes and places image in child GUI
$PicXPos[$i] = $Spacer
$PicYPos[$i] = $PicYPos[$i-1] + $PicHeight[$i-1] + $Spacer
$hLabel[$i] = GUICtrlCreateLabel("", $PicXPos[$i]-$BorderWidth, $PicYPos[$i]-$BorderWidth, $PicWidth[$i]+2*$BorderWidth, $PicHeight[$i]+2*$BorderWidth)
GUICtrlSetBkColor($hLabel[$i], $ChildBkColor)
GUICtrlSetState($hLabel[$i], $GUI_DISABLE)
$SelectedState[$i] = 0
$hPic[$i] = GUICtrlCreatePic($ImgRep & $ImageFilenames[$i], $PicXPos[$i], $PicYPos[$i], $PicWidth[$i], $PicHeight[$i])
Next

; Create scrollbars in child GUI
;_GUIScrollBars_Generate($ChildGUI, 0, $PicYPos[$ImageFilenames[0]] + $PicHeight[$ImageFilenames[0]])

; Display GUIs
GUISetState(@SW_SHOW, $ParentGUI)
GUISetState(@SW_SHOW, $ChildGUI)

; Main events listener
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $hPic[1] To $hPic[$ImageFilenames[0]]
$n = 0
Do
$n = $n + 1
Until $hPic[$n] = $nMsg
$SelectedState[$n] = 1 - $SelectedState[$n]
GUICtrlSetBkColor($hLabel[$n], $SelectedState[$n]*$BorderColor + (1-$SelectedState[$n])*$ChildBkColor)
EndSwitch
WEnd

; Shut down GDI+ library
_GDIPlus_Shutdown()
Link to comment
Share on other sites

  • Moderators

Faalamva,

Adding this to the top of your script should fix the first problem:

Opt("GUIResizeMode", $GUI_DOCKSIZE)

That prevents the controls from being resized when the scrollbars affect the size of the client area. ;)

I cannot see any delay in selecting/unselecting - how many images are you displaying? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Works perfectly, as always, thank you ! :sorcerer:

Posted Image

I have only 10 images displayed for now. It's not really a matter of delay when I click, for the border to appear, but rather a delay in case of several fast consecutive clicks. For example, if I click 5 times rapidly on the same image, the image may be only unselected and selected once instead of twice.

It's a very minor issue, I can live with that. I'm not supposed to click fast several times on the same image anyway, it's more a crashtest or somethin' for me to test the interface stability. :zorro:

Next step : add a button that removes the selected images from the list when clicked. For now, I don't know how I'm supposed to manage that from a GUI point of view (disable the image-controls and refresh the child GUI ?). Gotta test some ideas but any hint is obviously welcome !

Cheers !

Edited by Faalamva
Link to comment
Share on other sites

  • Moderators

Faalamva,

Each click on the control will be honoured, but you have to wait until the border is set/cleared before the subsequent click is honoured. Perhaps you might want to disable the pic control to prevent clicks from being registered until the border has been changed. ;)

In any event, I would write the Case like this:

Case $hPic[1] To $hPic[$ImageFilenames[0]]
    For $n = 1 To $ImageFilenames[0]
        If $nMsg = $hPic[$n] Then
            GUICtrlSetState($hPic[$n], $GUI_DISABLE)
            $SelectedState[$n] = Not $SelectedState[$n]
            GUICtrlSetBkColor($hLabel[$n], $SelectedState[$n] * $BorderColor + (1 - $SelectedState[$n]) * $ChildBkColor)
            GUICtrlSetState($hPic[$n], $GUI_ENABLE)
            ExitLoop
        EndIf
    Next

Please ask if you do understand what I have changed, or why I have done it. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I understand what you mean. However, the testing shows that it pretty much doesn't change anything, so I'll just leave it as is and focus on the next developments, thank you ! :idiot:

Do you think it is better to have a "for/if" instead of a "do...until" to retrieve the correct control handler ? I had changed that by thinking the loop would be faster, since it stops as soon as the handler is found. Technically, the only risk I see is an infinite loop but the Case range should prevent that from happening.

Edited by Faalamva
Link to comment
Share on other sites

  • Moderators

Faalamva,

Do you think it is better to have a "for/if" instead of a "do...until" to retrieve the correct control handler ?

Your choice - I do not think it makes a lot of differnce! :)

But note that I too exit the loop when I find a match - so I do not waste extra passes either. ;)

M23

P.S. And please stop quoting the entire post - I know what I wrote! :D

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

×
×
  • Create New...