RichardL Posted April 11, 2014 Posted April 11, 2014 I realised that I'd never used AutoIt to draw anything, and assumed that it didn't have pixel, line, circle etc. I looked in the help and found GUICtrlCreateGraphic and GUICtrlSetGraphic - wow, fantastic. Then I tried something dynamic and saw the flicker problem, which makes it useless for most things I'd want to do. There are several forum topics about the flicker, usually recommending using other graphic methods. There's one >topic with a post by Detefon that has the answer, but without sufficient recognition. With the $WS_EX_COMPOSITED option the flicker is gone, and the 'wow fantastic' status is restored. (I've only tested on XP, and there are threads that indicate that it may flicker on W7.) The code below is the help example from GUICtrlCreateGraphic, + the bezier graphic from the GUICtrlSetGraphic help + a label by each graphic to make it easier to see which code makes each graphic. + a dynamic bar derived from Detefon's bar. expandcollapse popup#include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> Global $MAXGr = 6, $del Global $a[$MAXGr + 1] ; 0 and $MAXGr entries not used to allow GUICtrlDelete result Example() Func Example() Local $msg, $inc, $i Local $sec, $prev_sec = -1 $gr = CreateChild() $i = 1 $inc = 1 ; Loop until the user exits. Do $msg = GUIGetMsg() If $msg = $del Then GUICtrlDelete($a[$i]) $i = $i + $inc If $i < 0 Or $i > $MAXGr Then Exit EndIf If $msg > 0 Then MsgBox($MB_SYSTEMMODAL, "clicked", $msg & @CRLF & $a[5], 2) $height = 5 $sec = @SEC $bar_a = $sec If $sec <> $prev_sec Then If $sec = 0 Then GUICtrlSetGraphic($gr, $GUI_GR_COLOR, 0xD0E3D3, 0xD0E3D3) GUICtrlSetGraphic($gr, $GUI_GR_RECT, 1, 1, 59, $height * 3 -1 ) Else GUICtrlSetGraphic($gr, $GUI_GR_COLOR, 0xDE8D69, 0xDE8D69) GUICtrlSetGraphic($gr, $GUI_GR_RECT, 1, 1, $bar_a, $height) GUICtrlSetGraphic($gr, $GUI_GR_COLOR, 0xBE371C, 0xBE371C) GUICtrlSetGraphic($gr, $GUI_GR_RECT, 1, $height , $bar_a, $height) GUICtrlSetGraphic($gr, $GUI_GR_COLOR, 0x540404, 0x540404) GUICtrlSetGraphic($gr, $GUI_GR_RECT, 1, $height * 2, $bar_a, $height) EndIf GUICtrlSetGraphic($gr, $GUI_GR_REFRESH) $prev_sec = $sec EndIf Until $msg = $GUI_EVENT_CLOSE EndFunc ;==>Example Func CreateChild() GUICreate("My Draw", Default, Default, Default, -1, -1, $WS_EX_COMPOSITED) $del = GUICtrlCreateButton("Delete", 50, 165, 50) GUICtrlCreateLabel("G1", 20, 35, 30, 15) $a[1] = GUICtrlCreateGraphic(20, 50, 100, 100) GUICtrlSetBkColor(-1, 0xffffff) GUICtrlSetColor(-1, 0) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000, 0xff0000) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 40, 30, 270) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0xffffff) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 58, 50, 40, -60, 90) GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 100, 100, 50, 80) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0xc0c0ff) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 350, 200, 50, 80) GUICtrlCreateLabel("label", 65, 100, 30) GUICtrlSetColor(-1, 0xff) GUICtrlCreateLabel("G2", 220, 45, 30, 15) $a[2] = GUICtrlCreateGraphic(220, 50, 100, 100) GUICtrlSetStyle(-1, $SS_NOTIFY) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xff) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 50, 50, 40, 30, 270) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x00ff00, 0xffffff) GUICtrlSetGraphic(-1, $GUI_GR_PIE, 58, 50, 40, -60, 90) GUICtrlCreateLabel("G3", 220, 135, 30, 15) $a[3] = GUICtrlCreateGraphic(220, 150, 100, 100, 0) GUICtrlSetBkColor(-1, 0xf08080) GUICtrlSetColor(-1, 0xff) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff00) GUICtrlSetGraphic(-1, $GUI_GR_RECT, 50, 50, 80, 80) GUICtrlCreateLabel("G4", 20, 185, 30, 15) $a[4] = GUICtrlCreateGraphic(20, 200, 80, 80) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetBkColor(-1, 0xffffff) GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 10, 10) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 30, 40) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff00) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 70, 70) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 10, 50) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xffff00) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 10, 10) GUICtrlCreateLabel("G5", 150, 0, 30, 15) $a[5] = GUICtrlCreateGraphic(150, 15, 50, 50, 0) GUICtrlSetBkColor(-1, 0xa0ffa0) GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 20, 20) ; start point ; it is better to draw line and after point ; to avoid to switch color at each drawing GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x0000ff) GUICtrlSetGraphic(-1, $GUI_GR_DOT, 30, 30) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 20, 40) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0xff0000) GUICtrlSetGraphic(-1, $GUI_GR_DOT, 25, 25) GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 40, 40) GUICtrlSetGraphic(-1, $GUI_GR_DOT, 40, 40) GUICtrlCreateLabel("G6", 110, 245, 30, 15) $a[6] = GUICtrlCreateGraphic(110, 260, 230, 130) GUICtrlSetColor(-1, 0) ; to display a black border line GUICtrlSetBkColor(-1, 0xc0c0ff) GUICtrlSetGraphic(-1, $GUI_GR_HINT, 3) ; to display control lines and end points GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0, 0xff); fill in blue GUICtrlSetGraphic(-1, $GUI_GR_MOVE, 120, 20) ; start point GUICtrlSetGraphic(-1, $GUI_GR_BEZIER, 120, 100, 200, 20, 200, 100) GUICtrlSetGraphic(-1, $GUI_GR_BEZIER + $GUI_GR_CLOSE, 100, 40, 40, 100, 40, 20) GUICtrlSetGraphic(-1, $GUI_GR_LINE, 60, 30) ; start point GUICtrlCreateLabel("G7", 280, 0, 30, 15) $gr = GUICtrlCreateGraphic(280, 15, 61, 16) GUICtrlSetColor(-1, 0) ; to display a black border line GUISetState(@SW_SHOW) Return $gr EndFunc ;==>CreateChild
Vincor Posted April 11, 2014 Posted April 11, 2014 Tried briefly on W7 x64 - no flickering with $WS_EX_COMPOSITED, some flickering when removing it. Wow
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