Jump to content

GUICtrlSetBkColor - 10 times slower after graphic creation


Go to solution Solved by IanN1990,

Recommended Posts

Hi All,

I have discovered something odd and am unsure how to counter it.

I am using labels (for BkColor) to act as coloured borders for richedit controls (for coloured text).

When loading a number of items  (50 for example) there is a noticeable delay, after troubleshooting this is down to GUICtrlSetBkColor.

Normally GUICtrlSetBkColor() is really fast <0.5-0.7 MS but when i load my grid (using graphics) this slows down to 5-5.5MS.

In the above case this is adds a 250ms delay vs 25ms without the grid.

Example Code.

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

local $iDiagramWidth = 664, $iDiagramHeight = 498
local $iDiagramPadding = 8, $GridSize = 16

GUICreate("Example", $iDiagramWidth, $iDiagramHeight+$GridSize, -1, -1, -1, $WS_EX_COMPOSITED)
    $hGraphic   = GUICtrlCreateGraphic(0, $GridSize, $iDiagramWidth, $iDiagramHeight, BitOR($GUI_SS_DEFAULT_PIC,$WS_BORDER))
    $hLabel     = GUICtrlCreateLabel("Example", 0, 0, $iDiagramWidth,$GridSize)

GUISetState()

MsgBox(0, "Msg", "Click Ok to start")

AvgBckColorChange()
CreateGrid()
AvgBckColorChange()

MsgBox(0, "Msg", "End of Demo")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch
WEnd

Func AvgBckColorChange()
    ;Timer to change BCKColor of Label 10 times
    $Test = TimerInit()
    For $i = 1 to 10
        GUICtrlSetBkColor($hLabel, 0x00000 & $i)
    Next
    MsgBox(0, "Msg", "Avg time to change color 10 times " & TimerDiff($Test)/10)
EndFunc

Func CreateGrid()
    ;Create Grid
    $iWidth = Floor(($iDiagramWidth - ($iDiagramPadding * 2)) / $GridSize)
    $iHeight = Floor(($iDiagramHeight - ($iDiagramPadding * 2)) / $GridSize)

    GUICtrlSetGraphic($hGraphic, $GUI_GR_COLOR, 0x000000)

    $icount = 0
    For $iH = 0 To $iHeight
        For $iW = 0 To $iWidth
            GUICtrlSetGraphic($hGraphic, $GUI_GR_PIXEL, $iDiagramPadding + ($iW * $GridSize) - 1, $iDiagramPadding + ($iH * $GridSize) - 1)
            $icount += 1
        Next
    Next

    ConsoleWrite($icount & @CRLF)

    GUICtrlSetGraphic($hGraphic, $GUI_GR_REFRESH)
EndFunc

 

I have a bloated workaround (see below) but wondered if the orginal issue can be fixed or if i am using graphics* incorrectly.

  • Load the grid in a separate $WS_POPUP GUI
  • Screencapture the GUI in memory (as the script will not have write permissions)
  • Apply the $hBitmap to a PIC control
  • Delete the $hBitmap, graphic & GUI

*I am aware the more added to a graphic can slow it down but this should be around the 50k mark, My grid is only 1,250.

Edited by IanN1990
Link to post
Share on other sites
  • IanN1990 changed the title to GUICtrlSetBkColor - 10 times slower after graphic creation

I tested your script and in my case it is about 3 time faster after graphic creation.

I must admit I tested it on Win7 without DWM (classic theme).  If you are running it on win10, then you cannot disable totally DWM, that might be the reason of the slowness.

 

Link to post
Share on other sites
  • Solution

Hi All,

After more research i came to understand each pixel was an object within the graphic. I thought if i reduced the number of total objects this would fix the issue.

Instead of a dotted grid, I would created a line-grid (see below) which ended up having 72 objects and a big improvement but a noticeable delay remained.

GUICtrlSetGraphic($hGraphicDiagram, $GUI_GR_COLOR, 0xCACACA)


    For $iW = 1 To $iWidth
        GUICtrlSetGraphic($hGraphicDiagram, $GUI_GR_MOVE, $GridSize * $iW, 0)
        GUICtrlSetGraphic($hGraphicDiagram, $GUI_GR_LINE, $GridSize * $iW, $iDiagramHeight)
    Next

    For $iH = 1 To $iHeight
        GUICtrlSetGraphic($hGraphicDiagram, $GUI_GR_MOVE, 0, $GridSize * $iH)
        GUICtrlSetGraphic($hGraphicDiagram, $GUI_GR_LINE, $iDiagramWidth, $GridSize * $iH)
    Next

Unlimitedly the solution came from using GUISetState(@SW_LOCK) and GUISetState(@SW_UNLOCK) while updating the controls.

Edited by IanN1990
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.

×
×
  • Create New...