IanN1990 Posted October 20, 2022 Share Posted October 20, 2022 (edited) 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. expandcollapse popup#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 October 21, 2022 by IanN1990 Link to comment Share on other sites More sharing options...
Nine Posted October 21, 2022 Share Posted October 21, 2022 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. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Solution IanN1990 Posted October 21, 2022 Author Solution Share Posted October 21, 2022 (edited) 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 October 21, 2022 by IanN1990 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now