Sign in to follow this  
Followers 0
Phaser

GUICtrlCreatePic is it compounding the images?

7 posts in this topic

Hi guys

I am trying to add some images to my database processing script so when a figure is reached a tick image shows, if the figure is not reached a red cross shows until that figure is reached.

With each data input this bit gets called, it checks the count

If $count > 25 Then

GUICtrlCreatePic("tick.jpg", 130, 170, 13, 13)

Else

GUICtrlCreatePic("cross.jpg", 130, 170, 13, 13)

EndIf

It works perfectly fine but starts to slow down after about 300 entries? is it putting an image on an image each time? should I be doing something else?

Share this post


Link to post
Share on other sites



Phaser,

is it putting an image on an image each time?

Exactly what is happening - you fire the loop and create a new control each time you pass through it. ;)

I suggest using a flag to indicate which image is being displayed and then only change it when required - deleting the old version:

; Declare a flag and a place holder for the image control
Global $fImage_Tick = False, $cImage = 9999

; Then your If structure looks like this
If $count > 25 And $fImage_Tick = False Then
    ; Delete the current control
    GUICtrlDelete($cImage)
    ; Create the new image
    $cImage = GUICtrlCreatePic("tick.jpg", 130, 170, 13, 13)
    ; Set the flag to prevent this firing again
    $fImage_Tick = True
ElseIf $count <= 25 And $fImage_Tick = True Then
    ; Delete the current control
    GUICtrlDelete($cImage)
    ; Create the new image
    $cImage = GUICtrlCreatePic("cross.jpg", 130, 170, 13, 13)
    ; Clear the flag to prevent this firing again
    $fImage_Tick = False
EndIf

Now you only create a new image as the count passes the magic 25 (in either direction) and not every time you pass through the loop. ;)

Another little wrinkle would be to create the image control just the once and then use GUICtrlSetImage to change the content - you would still need an If structure like that above to prevent the image flickering. ;)

All clear? :)

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

#3 ·  Posted (edited)

Create the Pic control in your gui. then use GUICtrlSetImage to set the image there

Edit:Erm,Melba was faster xD

Edited by mihaibr

Share this post


Link to post
Share on other sites

Thanks guys, Melba, the images did appear to flicker thats what made me think it was layering the new image on top each time, then I noticed the grinding get worse, closed the software and reopened it then it worked fine again.

Thanks both of you for your help.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@ Melba

Another little wrinkle would be to create the image control just the once and then use GUICtrlSetImage to change the content

Struggling with this, can you give an example using the above vars please

$cImage = GUICtrlCreatePic("tick.jpg", 130, 170, 13, 13)

Where do I put $cImage ?

Edited by Phaser

Share this post


Link to post
Share on other sites

Phaser,

Does this help: :)

#include <GUIConstantsEx.au3>

; Declare a flag
Global $fImage_Tick = False

$hGUI = GUICreate("Test", 500, 500)

; Create the image control in the GUI
$cImage = GUICtrlCreatePic("cross.jpg", 130, 170, 13, 13)

GUISetState()

; Set the counter
$iCount = 20
; And get a timestamp
$iBegin = TimerInit()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    ; Increase the count every second to simulate your counter increasing through the 25 limit
    If TimerDiff($iBegin) > 1000 Then
        $iCount += 1

        ; Just for interest we display the counter
        ConsoleWrite("Count = " & $iCount & @CRLF) ; <<<<<<<<<<<<<<<<<<<

        ; Now we use the If strcuture I posted earlier
        If $iCount > 25 And $fImage_Tick = False Then
            ; Show the tick image
            GUICtrlSetImage($cImage, "tick.jpg")
            ; Set the flag to prevent this firing again
            $fImage_Tick = True
        ElseIf $iCount <= 25 And $fImage_Tick = True Then
            ; Show the cross image
            GUICtrlSetImage($cImage, "cross.jpg")
            ; Clear the flag to prevent this firing again
            $fImage_Tick = False
        EndIf

        ; And finally we reset the timestamp to wait for the next increase
        $iBegin = TimerInit()
    EndIf

WEnd

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

Melba, yes it does, just couldn't work out what needed changing on the front end, thanks again, always very helpful, much appreciated

; Create the image control in the GUI

$cImage = GUICtrlCreatePic("cross.jpg", 130, 170, 13, 13)

That's what I needed, thanks again

PS, did try to use the Autoit code but I get a javascript error in my browser status bar, sorry

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0