Jump to content

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


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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 post
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 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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ashraful089
      #include <ButtonConstants.au3>
      #include <ComboConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <WindowsConstants.au3>
      #Region ### START Koda GUI section ### Form=C:\Users\Engr. Ashraful\Videos\koda_1.7.3.0\Forms\ProgramPlayer\FormProgamToOpen.kxf
      $FormInput = GUICreate("Input", 302, 205, 454, 285)
      $Resolution = GUICtrlCreateCombo("Resolution", 80, 24, 145, 25)
      GUICtrlSetData(-1, "1920|VM1920|1366")
      $ComboProgramType = GUICtrlCreateCombo("Program Type Selection", 80, 64, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL))
      GUICtrlSetData(-1, "Multimedia|Official|Design|Web")
      $ButtonEnter = GUICtrlCreateButton("Enter", 104, 104, 75, 25)
      GUISetState(@SW_SHOW)
      #EndRegion ### END Koda GUI section ###
      While 1
          $nMsg = GUIGetMsg()
          Switch $nMsg
              Case $GUI_EVENT_CLOSE
                  Exit
          EndSwitch
      WEnd
       
      please help me to read combo box input and use the value for another function/ work
       
    • By Aapjuh
      Hi,
      I am having a problem properly saving the Width of a resizable Gui.
      When a user resizes the Gui it gets saved in an ini when the Gui closes to then restore the new Width upon reopening the app.
      with GUICreate("myGui",300,200,Default,Default,$WS_SIZEBOX)
      WinGetPos($hGUI) returns 314, and WinGetClientSize($hGUI) returns 298
      when its then saved in the ini the gui keeps expanding or shrinking every time its opened by +14 or -2
      I figure it has to do with borders etc, but i also guess borders depend on the window theme and whatnot or is user specific, so i can't just do $GuiWidth = $GetGuiWidth[arr] -14 or +2 right?

      is there a proper way of doing this?
      Thanks in advance,
      Aapjuh
    • By ahha
      Under program control is there an easy way to move a slider (thumb) to the top or bottom?
      I am aware of Melba23's GUIScrollbars_Ex UDF (https://www.autoitscript.com/forum/topic/113723-scrollbars-made-easy-bugfix-version-2-may-21/) but I believe it's overkill for my simple needs.
      In a listview with a vertical scrollbar when the window is active one can hit Ctrl+Home to move the scrollbar slider (thumb) to the top and Ctrl+End to the bottom.
      One can also right click the slider and choose Scroll Here, Top, Bottom, Page UP, Page Down, Scroll Up, and Scroll Down.
      I must be doing something basically wrong but am stuck.  Move the thumb to the middle before clicking the Top button to test the code below (Bottom is not coded).  I've commented out other trys.  try #3 is a strange fail.
      Any comments on what I'm missing greatly appreciated as I'm stuck
      #AutoIt3Wrapper_run_debug_mode=Y #include <Debug.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiScrollBars.au3> AutoItSetOption("MustDeclareVars", 1) ;v1b - cut out extraneous code Example() Exit Func Example() Local $i, $j, $x, $hGUI, $idListView, $bTop, $bBottom $hGUI = GUICreate("Scrollbar Question", 300, 400) ;get handle in case we need it later $idListView = GUICtrlCreateListView("Col 0", 10, 10, 280, 300) $bTop = GUICtrlCreateButton("Top", 10, 350, 60, 25) $bBottom = GUICtrlCreateButton("Bottom", 120, 350, 60, 25) ;Pause("$hGUI = '" & $hGUI &"'"& @CRLF & "$idListView = '" & $idListView &"'") For $i = 1 to 100 _GUICtrlListView_AddItem($idListView, $i) Next GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $bTop ;drag thumb to middle of scrollbar before clicking Top button ;try #1 - FAILS Opt("WinTitleMatchMode", 2) ;2 = Match any substring in the title $x = WinActivate("Scrollbar Question") ;not $idListview but main GUI $hGUI - neither working If $x <> $hGUI Then Pause("WinActivate FAILED") Send("^{HOME}") ;Ctrl+home ;try#2 - FAILS ;~ $x = WinActivate($hGUI) ;try Main GUI ;~ If $x <> $hGUI Then Pause("WinActivate FAILED") ;~ Send("^{HOME}") ;Ctrl+home ;try#3 - strange FAILS ;~ $x = WinActivate($idListview) ;try $idListview ;~ If $x <> $idListview Then Pause("WinActivate FAILED") ;strange it works BUT if I comment out this line it fails ;~ ;Sleep(1000) ;it's not a time delay issue ;~ Send("^{HOME}") ;Ctrl+home ;try#4 - same strange fail as #3 ;~ $x = WinActivate($idListview) ;try $idListview ;~ If $x <> $idListview Then Pause("WinActivate FAILED") ;~ Send("{UP 100}") ;try#5 - what the heck is going on? same strange fail as #3 ;$x = WinActivate($idListview) ;try $idListview ;~ $x = WinActivate($hGUI) ;try Main GUI ;~ If $x <> $idListview Then Pause("WinActivate FAILED") ;~ MouseWheel($MOUSE_WHEEL_UP, 100) ;_GUIScrollBars_ScrollWindow($hGUI, 0, 100) ;NO - moves the ListView window in the $hGUI ;_GUIScrollBars_ScrollWindow($idListview, 0, 100) ;does not seem to work ;_GUIScrollBars_SetScrollInfoPos($hGUI, $SB_VERT, 30) ;does not work ;_GUIScrollBars_SetScrollInfoPos($idListview, $SB_VERT, 30) ;does not work ;I'm doing something very basic wrong. I need help. Pause("Scrollbar thumb should be at Top") Case $bBottom Pause("In: Case $bBottom") Pause("Scroll bar should be at BOttom") EndSwitch WEnd GUIDelete($idListView) EndFunc ;Func Example() Func Pause($text="") MsgBox(262144, "DEBUG", "Paused: " & $text) EndFunc  
    • By It_is_me_Me
      I have provided a portion of my script (seen below) and I wanted to use what the USER will input into my IP address box and input box for TCP port. I set the IP address to use 0.0.0.0 as default and the Port to 502. But I want to let the user change it and when they click the buttons (IP Address and Port), the tooltip will show what the USER entered. How can I use the details that the User will input into my input box and IP address box and let them see what they entered when they click the buttons?
       
      Here are the scripts:
      ;-------------------------------------------------------------
      #include <ButtonConstants.au3>
      #include <ComboConstants.au3>
      #include <EditConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <GuiIPAddress.au3>
      #include <StaticConstants.au3>
      #include <WindowsConstants.au3>
      #include <GuiEdit.au3>
      #include <MsgBoxConstants.au3>
      #include <Date.au3>
      #include <TabConstants.au3>
      #include <GuiTab.au3>

      Global $Form1 = GUICreate("Security Automation", 490, 339, -1, -1)
      ;MAIN Tab
      Global $TAB = GUICtrlCreateTab(0, 0, 489, 337)
      Global $tab_main = GUICtrlCreateTabItem("Main")
      $label_Title = GUICtrlCreateLabel("ETP-073 Security", 12, 33, 103, 17)
      GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
      ;-----------------TCP User input information-------------------------------------------------------------------------------
      $groupBox_TCP = GUICtrlCreateGroup("TCP", 12, 49, 289, 57, BitOR($GUI_SS_DEFAULT_GROUP,$BS_FLAT))
      ;TCP IP address
      Global $IPAddress1 = _GUICtrlIpAddress_Create($Form1, 20, 81, 170, 21)
      $Label_ipAddress = GUICtrlCreateLabel("Host IP Address", 20, 65, 80, 17)
      $userInputIP = _GUICtrlIpAddress_Set($IPAddress1, "0.0.0.0")
      ;TCP Port
      $label_tcpPort = GUICtrlCreateLabel("Port", 196, 65, 23, 17)
      Global $input_tcpPort = GUICtrlCreateInput("502", 196, 81, 57, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
      $userPort = GUICtrlRead($input_tcpPort)
      ;TCP Address
      $label_tcpAddress = GUICtrlCreateLabel("Addr.", 260, 65, 29, 17)
      Global $input_tcpDevAddress = GUICtrlCreateInput("1", 260, 81, 33, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
      ;Buttons
      Global $btn_userIP = GUICtrlCreateButton("User IP", 308, 297, 81, 25)
      Global $btn_Port = GUICtrlCreateButton("Port", 404, 297, 75, 25)
      ;Showing the GUI
      GUISetState(@SW_SHOW)
      While 1
         $nMsg = GUIGetMsg()
         Switch $nMsg
            Case $GUI_EVENT_CLOSE
               Exit
            Case $btn_userIP
               ToolTip($userInputIP)
            Case $btn_Port
               ToolTip($userPort)
         EndSwitch
      WEnd
      ;--------------end of script ------------------
       
      Note: There will be a "!->Includefile <WMDebug.au3> not found." Pay no attention to it.
    • By CYBRIX
      So I am a person who has learned programming off the internet, without structured courses, and I'm trying to create a UI element that can be used like "GUICtrlCreate...".

      I'd like to get some kind of insight on how to improve the code of a Graph element that I have created.
      I am unfamiliar on the standards for creating such UI elements, and assume I'll get some valuable insight here.
       
      Here's some sample code: (I tried to make it look a bit less upsetting to those who know better, but be warned: not pretty.)
      #include <WinAPISys.au3> #include <WinAPI.au3> #include <WinAPIGdi.au3> #include <Array.au3> #include <WindowsConstants.au3> #include <GUIConstants.au3> Local $hWnd = GUICreate("Test", 200, 200) GUISetState(@SW_SHOW, $hWnd) Local $hGraph = _GraphStartUp($hWnd, 10, 30, 180, 180) Local $nData, $nDataMax = 1000, $hDataTimer = TimerInit() While GUIGetMsg() <> $GUI_EVENT_ClOSE If TimerDiff($hDataTimer) >= 150 Then $nData = Random(0, $nDataMax) _UpdateGraph($nData) $hDataTimer = TimerInit() EndIf Sleep(20) WEnd _GraphShutDown($hWnd, $hGraph) Exit Func _GraphStartUp($hWnd, $x, $y, $w, $h, $nUpdateTimes = 1000, $nResolution = 60) Global $hBluePen = _WinAPI_CreatePen($PS_SOLID, 2, _WinAPI_RGB(220, 0, 0)) Global $hGreyPen = _WinAPI_CreatePen($PS_DASH, 1, _WinAPI_RGB(100, 100, 100)) Global $hBlackPen = _WinAPI_CreatePen($PS_SOLID, 1, _WinAPI_RGB(0, 0, 0)) Global $hWhitePen = _WinAPI_CreatePen($PS_SOLID, 1, _WinAPI_RGB(255, 255, 255)) Global $nGraphRes = $nResolution Global $aGraphData[$nGraphRes + 1] For $i = 2 To $nGraphRes $aGraphData[$i] = 0 Next Global $hWinDC = _WinAPI_GetWindowDC($hWnd) Global $nGraphX = $x Global $nGraphY = $y Global $nGraphWidth = $w Global $nGraphHeight = $h Global $nGraphXUnit = $nGraphWidth / ($nGraphRes - 1) Global $nGraphBottomY = $nGraphY + $nGraphHeight Global $nGraphMaxX = $nGraphX + $nGraphWidth Global $aUpdateArea[4][2] = [[$nGraphX - 1, $nGraphY - 1], [$nGraphX - 1, $nGraphBottomY + 1], [$nGraphMaxX + 1, $nGraphBottomY + 1], [$nGraphMaxX + 1, $nGraphY - 1]] Global $pUpdateAreaRgn = _WinAPI_CreatePolygonRgn($aUpdateArea) Global $pTextRect = _WinAPI_CreateRectEx($nGraphX + 1, $nGraphY + 1, $nGraphWidth / 2, $nGraphHeight / 4) Global $nGreatestValue = 1 GLobal $pGraphArea = _WinAPI_CreateRectEx($nGraphX - 7, $nGraphY - 26, $nGraphWidth + 14, $nGraphHeight + 2) Global $pDrawCall = DllCallbackRegister('_DrawGraph', 'none', '') Global $pGraphTimer = _WinAPI_SetTimer($hWnd, 567891234, $nUpdateTimes, DllCallbackGetPtr($pDrawCall)) _DrawGraph() Return $pGraphTimer EndFunc Func _DrawGraph() Global $hPen $nGreatestValue = _ArrayMax($aGraphData, 1, 1) $hPen = _WinAPI_SelectObject($hWinDC, $hWhitePen) _WinAPI_PaintRgn($hWinDC, $pUpdateAreaRgn) $hPen = _WinAPI_SelectObject($hWinDC, $hGreyPen) _WinAPI_DrawLine($hWinDC, $nGraphX, $nGraphY, $nGraphMaxX, $nGraphY) _WinAPI_DrawLine($hWinDC, $nGraphX, $nGraphY + ($nGraphHeight / 2), $nGraphMaxX, $nGraphY + ($nGraphHeight / 2)) _WinAPI_DrawLine($hWinDC, $nGraphMaxX, $nGraphY, $nGraphMaxX, $nGraphBottomY) $hPen = _WinAPI_SelectObject($hWinDC, $hBluePen) For $i = 1 To $nGraphRes - 1 _WinAPI_DrawLine($hWinDC, $nGraphX + (($i - 1) * $nGraphXUnit), $nGraphBottomY - ($aGraphData[$i] / $nGreatestValue * $nGraphHeight), $nGraphX + ($i * $nGraphXUnit), $nGraphBottomY - ($aGraphData[$i + 1] / $nGreatestValue * $nGraphHeight)) Next $hPen = _WinAPI_SelectObject($hWinDC, $hBlackPen) _WinAPI_DrawLine($hWinDC, $nGraphX, $nGraphBottomY, $nGraphMaxX, $nGraphBottomY) _WinAPI_DrawLine($hWinDC, $nGraphX, $nGraphY, $nGraphX, $nGraphBottomY) _WinAPI_DrawText($hWinDC, Round($aGraphData[$nGraphRes], 2), $pTextRect, $DT_LEFT) EndFunc Func _UpdateGraph($nData) _ArrayAdd($aGraphData, $nData) _ArrayDelete($aGraphData, 1) EndFunc Func _GraphShutDown($hWnd, $pGraphTimer) _WinAPI_SelectObject($hWinDC, $hPen) _WinAPI_DeleteObject($hBlackPen) _WinAPI_DeleteObject($hGreyPen) _WinAPI_DeleteObject($hBluePen) _WinAPI_DeleteObject($hWhitePen) _WinAPI_ReleaseDC($hWnd, $hWinDC) _WinAPI_KillTimer($hWnd, $pGraphTimer) DllCallbackFree($pDrawCall) _WinAPI_RedrawWindow($hWnd, $pGraphArea) EndFunc  
×
×
  • Create New...