Jump to content
Sign in to follow this  
Faalamva

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

Recommended Posts

Faalamva

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

Share this post


Link to post
Share on other sites
guinness

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

Share this post


Link to post
Share on other sites
Melba23

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

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Faalamva

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 !

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Faalamva

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

Share this post


Link to post
Share on other sites
Melba23

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. :)


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Faalamva

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

Share this post


Link to post
Share on other sites
Melba23

Faalamva,

everything looks perfectly clear AND also perfectly fitting my needs !

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Faalamva

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

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Faalamva

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

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Melba23

Faalamva,

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

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Faalamva

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()

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Faalamva

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

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Faalamva

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

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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  

  • Similar Content

    • Emmhor1
      By Emmhor1
      Hi All,

      MAIN QUESTION:
      Is it possible to Call specific function within a GUI

      So I have a script with multiple functions although I don't want to use every function every time.
      My Idea is to create a simple GUI which allows me to select what functions I want to use then run the funtions by clicking a button.
      I have already made a GUI which allows me to select specific .exe's I would like to run after selection it runs the .exe one by one.
      This script is on my work laptops and cannot access it right now.
       
      Who can help me with this?
      GUIcreate
      Func1 
      Func2
      Func3
      Then have a boxes which allows me to select the specif Func.(I used GUIChecked and Unchecked in my other script)
      Then a button which executes/calls the selected functions
    • Blois
      By Blois
      Hi Guis,
       
      I need to create keyboard shortcut to navigate the tabs and activate them, but I could not use the code below:
      #include <TabConstants.au3> #include <WindowsConstants.au3> #include <GuiTab.au3> #include <GUIConstantsEx.au3> HotKeySet("^{TAB}", "_TabRight") HotKeySet("^+{TAB}", "_TabLeft") $gui = GUICreate("test",450, 300) $Tab1 = GUICtrlCreateTab(20, 24, 425, 201) $TabSheet1 = GUICtrlCreateTabItem("Tabsheet 1") $lbContagemGrupos2 = GUICtrlCreateLabel("aaaa", 50, 50) GUICtrlSetColor(-1, 0x0000FF) GUICtrlCreateTabItem("") $TabSheet2 = GUICtrlCreateTabItem(" ") $TabSheet3 = GUICtrlCreateTabItem(" ") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd Func _TabRight() $CurPos = _GUICtrlTab_GetCurSel($Tab1) _GUICtrlTab_SetCurSel($Tab1, $CurPos + 1) $tab = "$TabSheet" & $CurPos GUICtrlSetState($TabSheet1 + $CurPos, $GUI_SHOW) Return EndFunc Func _TabLeft() $CurPos = _GUICtrlTab_GetCurSel($Tab1) _GUICtrlTab_SetCurSel($Tab1, $CurPos - 1) $tab = "$TabSheet" & $CurPos GUICtrlSetState($TabSheet1 + $CurPos, $GUI_SHOW) Return EndFunc Exit  
      can you help me?
    • Pricehacker
      By Pricehacker
      Hello again!
      I have tried searching for quite some time now but couldn´t find a single working way to change the class of your GUI that doesn´t include changing it manually after its compilation.
      First or "AutoIt v3 GUI" is a pretty boring name tbh and i would like to spice it up a bit, also, and more importantly, I would like to identify my windows by something other than its title as it will change depending on some factors and im using two different programs independently as multi threading isn't supported.
      Any help is appreciated! Thank you!
    • xtcislove
      By xtcislove
      Hello, 
      i have a Problem with  _WinAPI_SetLayeredWindowAttributes, everything is working as excepted if u are on Windows 7.

      But if u are on Windows 10 the transparent background of a control is not clickable anymore. 

      Could someone help?

      Please see example below, put cmd.jpg into the same folder as Example.au3

      Please see trigger.jpg to see which sections are not clickable in Windows 10 (the red dots, the green dots are clickable) on Windows 7 the red ones and green ones are clickable.
       
      The same problem occurs if i use 
       
       
      Example.au3


    • WilliamasKumeliukas
      By WilliamasKumeliukas
      Hello everyones reading this post,
      I'm struggling at resizing properly my radio buttons to fit long text inside without affecting others radio buttons and also adjust position of them relative to the string.
      I tried with _StringSize UDF but I guess im too tired to figure out how to use it correctly..
      I also tried: _Control_SetWidth2Text I found on this forum, it work aslong im not maximizing GUI (radio text is gone when I maximize and maximize is a must)
       
      here is the code example, I hope someone can figure out (sorry if guictrlsetpos is not included in the example, I know thats probably the way to go but I wanted to make sure there is nothing better before use it)
      Thank you
       
      Br,
      ~WilliamasKumeliukas
       
      #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <Array.au3> #include <StringConstants.au3> #include <FileConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <EditConstants.au3> #include <GUIListBox.au3> #include <ButtonConstants.au3> #include <ProgressConstants.au3> #include <ColorConstants.au3> #include <AutoitConstants.au3> #include <Misc.au3> #include <WinAPIReg.au3> #include <WinAPI.au3> #Region Opt's Opt("GUIResizeMode", 802) #EndRegion Opt's Global $q = "INTRO LINE" & @CRLF & @CRLF & "description of everything until user press start." Global $file = @TempDir & "\test.p" destroy() Global $msg, $score = 0, $rate, $com, $total = 0, $cfile, $cq, $i = 0, $time = 0, $min = 0, $sec = 0, $hour = 0, $qf, $ii = 0 Main() Func Main() Global $iGUIInitSize = 550 #Region GUI Opt("GUICloseOnEsc", 1) Global $gui = GUICreate("example", 1124, 550,-1 ,-1, BitOR($WS_MAXIMIZEBOX , $WS_MINIMIZEBOX)) Global $gui_size = WinGetClientSize($gui) Global $iFontSize = Int(2 * (.25 + (8 * $gui_size[0] / $iGUIInitSize))) / 2 Global $options = GUICtrlCreateMenu("&Options") Global $guide = GUICtrlCreateMenuItem("Guide", $options) Global $restart = GUICtrlCreateMenuItem("Restart", $options) Global $about = GUICtrlCreateMenuItem("About", $options) Global $exit = GUICtrlCreateMenuItem("Exit", $options) Global $extra = GUICtrlCreateMenu("Extras") Global $creator = GUICtrlCreateMenu("CQB", $extra ) Global $new = GUICtrlCreateMenuItem("custom QP", $creator) Global $load = GUICtrlCreateMenuItem("CQ", $creator ) Global $timer = GUICtrlCreateLabel("", 752, 472, 294, 30, $WS_BORDER) GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER) ) GUICtrlSetFont(-1, $iFontSize) GUICtrlSetState($timer, $GUI_HIDE) Global $info = GUICtrlCreateLabel( $q, 200, 20, 700, 200, $SS_CENTER ) GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER) ) $fi = GUICtrlSetFont($info, $iFontSize) Global $a = GUICtrlCreateRadio("A)", 100, 210, $WS_EX_CLIENTEDGE) $fa = GUICtrlSetFont($a, 15) GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER) ) GUICtrlSetState($a, 16) Global $b = GUICtrlCreateRadio("B)", 100, 310 , $WS_EX_CLIENTEDGE) $fb = GUICtrlSetFont($b, 15) GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER) ) GUICtrlSetState($b, 16) Global $c = GUICtrlCreateRadio("C)", 750, 210 , $WS_EX_CLIENTEDGE) $fc = GUICtrlSetFont($c, 15) GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER) ) GUICtrlSetState($c, 16) Global $d = GUICtrlCreateRadio( "D) ", 750, 310, $WS_EX_CLIENTEDGE) $fd = GUICtrlSetFont($d, 15) GUICtrlSetResizing (-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER) ) GUICtrlSetState($d, 16) Global $sign = GUICtrlCreateLabel( $file, 420, 480, -1, -1, BitOR ( $SS_CENTER, $WS_BORDER ) ) GUICtrlSetResizing ( -1, BitOR ( $GUI_DOCKHCENTER, $GUI_DOCKVCENTER ) ) GUICtrlSetFont($sign, 12) Global $yb = GUICtrlCreateRadio("True", 200, 420, 200, 50, $BS_PUSHLIKE) GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER,$GUI_DOCKSIZE)) GUICtrlSetFont($yb, 15) GUICtrlSetState($yb, 32) Global $nb = GUICtrlCreateRadio("False", 700, 420, 200, 50, $BS_PUSHLIKE) GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER, $GUI_DOCKSIZE)) GUICtrlSetFont($nb, 15) GUICtrlSetState($nb, 32) Global $start = GUICtrlCreateButton("Start", 20, 20, 100, 50, $SS_CENTER, $WS_EX_CLIENTEDGE) GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER)) GUICtrlSetFont($start, 12) Global $valid = GUICtrlCreateButton("Confirm", 20, 20, 100, 50, $SS_CENTER, $WS_EX_CLIENTEDGE) GUICtrlSetResizing(-1, BitOR($GUI_DOCKHCENTER, $GUI_DOCKVCENTER)) GUICtrlSetFont($valid, 12) GUICtrlSetState($valid, 32) GUISetState(@SW_SHOW) #EndRegion GUI While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Switch MsgBox(4096 + 4, "Warning", "Are you sure to exit?") Case 6 AdlibUnRegister("timer") If Not $qf = "" Then FileClose($file) EndIf Exit Case 7 ContinueLoop EndSwitch Case $start ;AdlibRegister("timer") ;Global $qf = StringSplit(StringStripWS(FileRead($file), 6), @CRLF, 0) ;qloop($file) GUICtrlSetData($a, "A) This long string is an example as string that I want to fit in 4 radio buttons because sometimes it can be that long.") GUICtrlSetData($b, "B) This long string is an example as string that I want to fit in 4 radio buttons because sometimes it can be that long.") GUICtrlSetData($c, "C) This long string is an example as string that I want to fit in 4 radio buttons because sometimes it can be that long.") GUICtrlSetData($d, "D) This long string is an example as string that I want to fit in 4 radio buttons because sometimes it can be that long.") Case $restart MsgBox(4096, "Warning", 'Normally, your suposed to start something before restarting it.') ContinueLoop Case $new ;GUISetState(@SW_HIDE, $gui) ;_CustomNew() ContinueLoop Case $load ;_CustomLoad() Case $about ;_About() EndSwitch WEnd EndFunc ;Main() Func timer() If $time = 0 Then Global $time = TimerInit() Global $diff = TimerDiff($time) Global $sec = Int(Mod($diff / 1000, 60)) Global $min = Int(Mod($diff / 60000, 60)) Global $hour = Int($diff / 3600000) If $sec < 10 Then $sec = "0" & $sec If $min < 10 Then $min = "0" & $min If $hour < 10 Then $hour = "0" & $hour GUICtrlSetData($timer, "Temps: " & $hour & ":" & $min & ":" & $sec) EndFunc ;==>timer Func destroy() If FileExists($file) Then FileDelete($file) EndIf DirCreate(@TempDir & "\About") FileInstall("C:\test.txt", $file) EndFunc ;==>destroy  
×