Jump to content

Checkbox Disappears When Graphic Control Refreshes


Recommended Posts

I combined two support questions together and formed a third.

Here's the code:

#include <GUIConstants.au3>
HotKeySet ("{ESC}", "quitme")

$MyGui = GUICreate(" My GUI")

$g1 = GUICtrlCreateGraphic(20, 50, 200, 200)
GUICtrlSetColor($g1, 3763621)

GUICtrlCreateCheckbox ("checkerest", 200, 300)
GUICtrlSetColor (-1, 0xff0000)

GUISetState()

While 1
    _CopyArea()
    Sleep(10)
WEnd


Func _CopyArea()
    TrayTip ("copy", "starting", 1)
    $x1 = 10
    $y1 = 10
    For $i = $x1 to $x1+100
        for $j = $y1 To $y1+100
            $PixColour = PixelGetColor($i,$j)
            GUICtrlSetGraphic($g1, $GUI_GR_COLOR, $PixColour)
            GUICtrlSetGraphic($g1, $GUI_GR_PIXEL, $i,$j)
        Next
    Next
    GUICtrlSetGraphic($g1, $GUI_GR_REFRESH)
    TrayTip ("copy", "done", 1)
EndFunc ;==>_CopyArea

Func quitme()
    Exit
EndFunc

Here are the questions:

Why does the GUI lag so much after a few rounds of drawing? I could definitely notice a slowdown of the drawing, among other things.

Why does the checkbox disappear when the graphic control is drawing? I'm pretty sure that isn't supposed to happen, but should it be considered a bug?

Link to comment
Share on other sites

Creating the Graphic in a child window stops the flickering

#include <GUIConstants.au3>
HotKeySet ("{ESC}", "quitme")

$MyGui = GUICreate(" My GUI")

GUICtrlCreateCheckbox ("checkerest", 200, 300)
GUICtrlSetColor (-1, 0xff0000)
GUISetState()
$child = GuiCreate ("",200,200,20,50,$WS_CHILD,-1,$myGui)
$g1 = GUICtrlCreateGraphic(0, 0, 200, 200)
GUICtrlSetColor($g1, 3763621)
GUISetState()

While 1
    _CopyArea()
    Sleep(10)
WEnd


Func _CopyArea()
    
    TrayTip ("copy", "starting", 1)
    $x1 = 10
    $y1 = 10
    For $i = $x1 to $x1+100
        for $j = $y1 To $y1+100
            $PixColour = PixelGetColor($i,$j)
            GUICtrlSetGraphic($g1, $GUI_GR_COLOR, $PixColour)
            GUICtrlSetGraphic($g1, $GUI_GR_PIXEL, $i,$j)
        Next
    Next
    GUICtrlSetGraphic($g1, $GUI_GR_REFRESH)
    TrayTip ("copy", "done", 1)
    
EndFunc;==>_CopyArea

Func quitme()
    Exit
EndFunc
Link to comment
Share on other sites

I also noticed that it was taking and taking memory probably why it slowed down, also did you get the problem that if you had a window in the top left, then opened another window, it then drew both graphics one after the other.

If you delete the child GUI each time, the memory use was stable for me and it stopped that redrawing of previous pixels.

#include <GUIConstants.au3>
HotKeySet ("{ESC}", "quitme")

$MyGui = GUICreate(" My GUI")

GUICtrlCreateCheckbox ("checkerest", 200, 300)
GUICtrlSetColor (-1, 0xff0000)
GUISetState()
$child = GuiCreate ("",200,200,20,50,$WS_CHILD,-1,$myGui)
$g1 = GUICtrlCreateGraphic(0, 0, 200, 200)
GUICtrlSetColor($g1, 3763621)
GUISetState()

While 1
    CreateChild()
    _CopyArea()
    Sleep(10)
    
WEnd

Func CreateChild()
GuiDelete ($Child)
$child = GuiCreate ("",200,200,20,50,$WS_CHILD,-1,$myGui)
$g1 = GUICtrlCreateGraphic(0, 0, 200, 200)
GUICtrlSetColor($g1, 3763621)
GUISetState()

EndFunc

Func _CopyArea()
    
    TrayTip ("copy", "starting", 1)
    $x1 = 10
    $y1 = 10
    For $i = $x1 to $x1+100
        for $j = $y1 To $y1+100
            $PixColour = PixelGetColor($i,$j)
            GUICtrlSetGraphic($g1, $GUI_GR_COLOR, $PixColour)
            GUICtrlSetGraphic($g1, $GUI_GR_PIXEL, $i,$j)
        Next
    Next
    GUICtrlSetGraphic($g1, $GUI_GR_REFRESH)
    TrayTip ("copy", "done", 1)
    
EndFunc;==>_CopyArea

Func quitme()
    Exit
EndFunc
Link to comment
Share on other sites

Hmm I had forgotten to look at memory/CPU usage. That was bad....

It appears that GUICtrlSetGraphic adds each piece of the graphic to an array (or something similar) and then draws each piece of the array onto the graphic control. That would be why the memory keeps going up - more and more things are trying to be drawn each round. That would also explain the "memory effect" of overlapping windows. Deleting the graphic control each time solves this issue because it creates a new, fresh array for the graphics to be stored. It all makes sense now.

I wonder, what about closing the drawing each time instead of deleting and recreating it? But then, the helpfile says it can only be attached to a line or bezier curve drawing, so maybe not.

Link to comment
Share on other sites

I wonder, what about closing the drawing each time instead of deleting and recreating it? But then, the helpfile says it can only be attached to a line or bezier curve drawing, so maybe not.

I'm not sure about that either, I did look at it in the help file and saw the same as you so didn't bother. I just played around with it with what I did, but I don't really know what your doing.

So my question to you is what are you doing? It looks very interesting and I'd really like to see your finished project.

Chris

Link to comment
Share on other sites

I'm not sure about that either, I did look at it in the help file and saw the same as you so didn't bother. I just played around with it with what I did, but I don't really know what your doing.

So my question to you is what are you doing? It looks very interesting and I'd really like to see your finished project.

Chris

Well honestly I'm not doing anything with it - I just noticed two separate problems and happened to be testing them on the same GUI and created a new problem.

This was the first thread: http://www.autoitscript.com/forum/index.php?showtopic=25349

This was the second: http://www.autoitscript.com/forum/index.php?showtopic=25428

Link to comment
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...