Sign in to follow this  
Followers 0
greenmachine

Label And Graphic Flickering

21 posts in this topic

#1 ·  Posted (edited)

I found Larry's use of Polygon and round regions, and I got the idea to make a clock. It's pretty basic right now, because I figured that if I couldn't get rid of the flickering then there's no point adding more stuff to just make it flicker worse.

#include <guiconstants.au3>
Global $Labels[13]
Global Const $PI = 3.1415926535897932384626433832795
$GUI = GUICreate("Clock",500,500,-1,-1,$WS_POPUP)
GUISetFont (18)
$Graphic = GUICtrlCreateGraphic (0, 0, 5, 5)
GUICtrlSetGraphic ($Graphic, $GUI_GR_PIXEL, 250, 250)
GUICtrlSetGraphic ($Graphic, $GUI_GR_MOVE, 250, 250)
GUICtrlSetGraphic ($Graphic, $GUI_GR_LINE, 250 + Cos (TimeToRad("sec", @SEC))*210, 250 - Sin (TimeToRad("sec", @SEC))*210)
GUICtrlSetGraphic ($Graphic, $GUI_GR_MOVE, 250, 250)
GUICtrlSetGraphic ($Graphic, $GUI_GR_LINE, 250 + Cos (TimeToRad("min", @MIN))*190, 250 - Sin (TimeToRad("min", @MIN))*190)
GUICtrlSetGraphic ($Graphic, $GUI_GR_MOVE, 250, 250)
GUICtrlSetGraphic ($Graphic, $GUI_GR_LINE, 250 + Cos (TimeToRad("hour", @HOUR))*170, 250 - Sin (TimeToRad("hour", @HOUR))*170)

GUICtrlSetGraphic ($Graphic, $GUI_GR_REFRESH)

$Labels[12] = GUICtrlCreateLabel (12, 235, 0, 30, 30, $SS_CENTER)
$Labels[1] = GUICtrlCreateLabel (1, 229 + Cos ($PI/3)*250, 250 - Sin ($PI/3)*250, 30, 30, $SS_CENTER)
$Labels[2] = GUICtrlCreateLabel (2, 222 + Cos ($PI/6)*250, 248 - Sin ($PI/6)*250, 30, 30, $SS_CENTER)
$Labels[3] = GUICtrlCreateLabel (3, 470, 237, 30, 30, $SS_CENTER)
$Labels[4] = GUICtrlCreateLabel (4, 228 + Cos (-$PI/6)*250, 227 - Sin (-$PI/6)*250, 30, 30, $SS_CENTER)
$Labels[5] = GUICtrlCreateLabel (5, 230 + Cos (-$PI/3)*250, 222 - Sin (-$PI/3)*250, 30, 30, $SS_CENTER)
$Labels[6] = GUICtrlCreateLabel (6, 235, 470, 30, 30, $SS_CENTER)
$Labels[7] = GUICtrlCreateLabel (7, 242 + Cos (-2*$PI/3)*250, 223 - Sin (-2*$PI/3)*250, 30, 30, $SS_CENTER)
$Labels[8] = GUICtrlCreateLabel (8, 248 + Cos (-5*$PI/6)*250, 228 - Sin (-5*$PI/6)*250, 30, 30, $SS_CENTER)
$Labels[9] = GUICtrlCreateLabel (9, 0, 237, 30, 30, $SS_CENTER)
$Labels[10] = GUICtrlCreateLabel (10, 248 + Cos (5*$PI/6)*250, 247 - Sin (5*$PI/6)*250, 30, 30, $SS_CENTER)
$Labels[11] = GUICtrlCreateLabel (11, 240 + Cos (2*$PI/3)*250, 250 - Sin (2*$PI/3)*250, 30, 30, $SS_CENTER)
For $i = 1 To 12
    GUICtrlSetState ($Labels[$i], $GUI_DISABLE)
Next

$a = CreateRoundRectRgn(0,0,500,500,500,500)

SetWindowRgn($GUI,$a)

GUISetState()
$Sec = @SEC
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    If $Sec <> @SEC Then
        GUICtrlDelete ($Graphic)
        $Graphic = GUICtrlCreateGraphic (0, 0, 5, 5)
        GUICtrlSetGraphic ($Graphic, $GUI_GR_PIXEL, 250, 250)
        GUICtrlSetGraphic ($Graphic, $GUI_GR_MOVE, 250, 250)
        GUICtrlSetGraphic ($Graphic, $GUI_GR_LINE, 250 + Cos (TimeToRad("sec", @SEC))*210, 250 - Sin (TimeToRad("sec", @SEC))*210)
        GUICtrlSetGraphic ($Graphic, $GUI_GR_MOVE, 250, 250)
        GUICtrlSetGraphic ($Graphic, $GUI_GR_LINE, 250 + Cos (TimeToRad("min", @MIN))*190, 250 - Sin (TimeToRad("min", @MIN))*190)
        GUICtrlSetGraphic ($Graphic, $GUI_GR_MOVE, 250, 250)
        GUICtrlSetGraphic ($Graphic, $GUI_GR_LINE, 250 + Cos (TimeToRad("hour", @HOUR))*170, 250 - Sin (TimeToRad("hour", @HOUR))*170)
        GUICtrlSetGraphic ($Graphic, $GUI_GR_REFRESH)
        $Sec = @SEC
    EndIf
WEnd

Func TimeToRad($TimeType, $TimeVal = @SEC)
    Local $Rads
    Switch $TimeType
        Case "sec"
          ; 0 secs = pi/2, 7-8 secs = pi/4, 15 secs = 0, 22-23 secs = -pi/4 = 7pi/4, 30 secs = 3pi/2, 37-38 secs = 5pi/4, 45 secs = pi
          ; 5 secs = pi/3, 10 secs = pi/6, 20 secs = -pi/6, 25 secs = -pi/3
            $Rads = $PI/2 - ($TimeVal * $PI/30)
        Case "min"
            $Rads = $PI/2 - ($TimeVal * $PI/30) - Int (@SEC / 10)*$PI/180
        Case "hour"
            $Rads = $PI/2 - ($TimeVal * $PI/6) - (@MIN / 12)*$PI/30
    EndSwitch
    Return $Rads
EndFunc

Func SetWindowRgn($h_win, $rgn)
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)
EndFunc

Func CreateRoundRectRgn($l, $t, $w, $h, $e1, $e2)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $l, "long", $t, "long", $l + $w, "long", $t + $h, "long", $e1, "long", $e2)
    Return $ret[0]
EndFunc

Does anyone know how to make the labels and graphic control not flicker? I tried disabling the labels already, which is why they're gray (it looks cool too). I also couldn't think of any way to erase lines without just deleting and recreating the graphic control, so that's what I had to do.

Edit - added #include <guiconstants.au3>

Edited by greenmachine

Share this post


Link to post
Share on other sites



Greenmachine,

Just an idea: What would it look like if rather than delete your graphic control, you instead redrew the 3 hands of the clock again right before they change position... but with the color 0xE0DFE3 (the color of your clock, effectively erasing them). Then you could recalculate the new position of the hands and draw the new ones in black. Rinse and repeat. Just a thought.

Also, you should mention to #include <GuiConstants.au3>

-Simucal


AutoIt Scripts:Aimbot: Proof of Concept - PixelSearching Aimbot with several search/autoshoot/lock-on techniques.Sliding Toolbar - Add a nice Sliding Toolbar to your next script. Click the link to see an animation of it in action!FontInfo UDF - Get list of system fonts, or search to see if a particular font is installed.Get Extended Property UDF - Retrieve a files extended properties (e.g., video/image dimensions, file version, bitrate of song/video, etc)

Share this post


Link to post
Share on other sites

Hmm, yes I forgot guiconstants.au3 because I wrote this up in a test file which is 3000+ lines long and has all the includes at the top....

I'll try overwriting the hands, but I think I avoided that in the first place because my center was going to have more stuff in it (or something).

Share this post


Link to post
Share on other sites

Forgot to mention that I tried rewriting it to overwrite the old hands with the background color and then draw the new hands, but that isn't the issue. I'm pretty sure it has to do with the graphic control refreshing, which is a problem since I need it to refresh in order to see the changes.

Any other ideas?

Share this post


Link to post
Share on other sites

Well, it's definitely when it refreshes. If you comment out line 52, there's no flicker; no update, but no flicker. Another option, though, is to try a DllCall to set the pixels. I'll try to come up with an example, but in case you want to try it, do this:

SetPixel(hWnd, x, y, hexColor)

Func SetPixel ($handle, $x, $y, $color)
    $dc= DllCall ("user32.dll", "int", "GetDC", "hwnd", $handle)
    $setpixel= DllCall ("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $x, "long", $y, "long", $color)
    $realesedc= DllCall ("user32.dll", "int", "ReleaseDC", "hwnd", 0,  "int", $dc[0])
EndFunc

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Well, it's definitely when it refreshes. If you comment out line 52, there's no flicker; no update, but no flicker. Another option, though, is to try a DllCall to set the pixels. I'll try to come up with an example, but in case you want to try it, do this:

SetPixel(hWnd, x, y, hexColor)

Func SetPixel ($handle, $x, $y, $color)
    $dc= DllCall ("user32.dll", "int", "GetDC", "hwnd", $handle)
    $setpixel= DllCall ("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $x, "long", $y, "long", $color)
    $realesedc= DllCall ("user32.dll", "int", "ReleaseDC", "hwnd", 0,  "int", $dc[0])
EndFunc
Right about refreshing (I have done graphic control work before which is how I know), and right about trying DllCall (that was going to be my next attempt but I would like if this worked....). I'm still not sure why the graphic control makes everything flicker though. It's the refreshing, that's understood, but what does the refresh do? Redraw the whole GUI? It seems like it shouldn't....

Ah well, I guess it's off to work with Dlls some more. I could still use some more answers though.

PS - thanks for the confirmation and suggestion.

Edited by greenmachine

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

PS - thanks for the confirmation and suggestion.

No problem. I agree it shouldn't refresh the whole GUI, but then again, I know next to nothing about the behind the scenes stuff of AutoIt, and the probably ginormous difference between what we'd like to happen and what is feasible to happen.

In any case, I'm currently developing an algorithm that draws... a line. It's harder than you might think! Determining which pixels actually make up a simple line is quite a process. I'm nearing completion, though. I might have a working example in about 15 mins.

Edit: Spelling

Edited by neogia

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Before you get too far, I found some DllCalls that draw lines. My only issue now is to erase previous lines so there aren't tons of lines on the clock, or overwrite the previous lines with the background color if I can't figure out how to erase them. The thing is, I don't know how to work with COLORREFs....

$GUIHDC = DllCall ($user32_dll,"int","GetDC","hwnd", $GUI)
DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", 250 + Cos (TimeToRad("sec", @SEC))*210, "int", 250 - Sin (TimeToRad("sec", @SEC))*210)
    DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", 250 + Cos (TimeToRad("min", @MIN))*190, "int", 250 - Sin (TimeToRad("min", @MIN))*190)
    DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", 250 + Cos (TimeToRad("hour", @HOUR))*170, "int", 250 - Sin (TimeToRad("hour", @HOUR))*170)
DllCall ($user32_dll,"int","ReleaseDC","int",$GUIHDC[0],"hwnd",$GUI)

That does the drawing correctly, but it just keeps drawing and drawing....

Edited by greenmachine

Share this post


Link to post
Share on other sites

I got it, what you do is create a pen for each color, Background and Black, and then just switch between the two to change colors. Congratulations on the no flicker!

$curSecX = 250 + Cos (TimeToRad("sec", @SEC))*210
$curSecY = 250 - Sin (TimeToRad("sec", @SEC))*210
$curMinX = 250 + Cos (TimeToRad("min", @MIN))*190
$curMinY = 250 - Sin (TimeToRad("min", @MIN))*190
$curHourX = 250 + Cos (TimeToRad("hour", @HOUR))*170
$curHourY = 250 - Sin (TimeToRad("hour", @HOUR))*170

GUISetState()
$Sec = @SEC
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    If $Sec <> @SEC Then
        $GUIHDC = DllCall ("user32.dll","int","GetDC","hwnd", $GUI)
        $BkgrndPen = DllCall("gdi32.dll", "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", "0x00D8E9EC")
        $BkgrndPen = $BkgrndPen[0]
        $BlackPen = DllCall("gdi32.dll", "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", "0x00000000")
        $BlackPen = $BlackPen[0]
        DllCall("gdi32.dll", "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BkgrndPen)
        DllCall ("gdi32.dll", "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
        DllCall ("gdi32.dll", "int", "LineTo", "hwnd", $GUIHDC[0], "int", $curSecX, "int", $curSecY)
        If $curMinX <> 250 + Cos (TimeToRad("min", @MIN))*190 Or $curMinY <> 250 - Sin (TimeToRad("min", @MIN))*190 Then
            DllCall ("gdi32.dll", "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
            DllCall ("gdi32.dll", "int", "LineTo", "hwnd", $GUIHDC[0], "int", $curMinX, "int", $curMinY)
            $curMinX = 250 + Cos (TimeToRad("min", @MIN))*190
            $curMinY = 250 - Sin (TimeToRad("min", @MIN))*190
        EndIf
        If $curHourX <> 250 + Cos (TimeToRad("hour", @HOUR))*170 Or $curHourY <> 250 - Sin (TimeToRad("hour", @HOUR))*170 Then
            DllCall ("gdi32.dll", "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
            DllCall ("gdi32.dll", "int", "LineTo", "hwnd", $GUIHDC[0], "int", $curHourX, "int", $curHourY)
            $curHourX = 250 + Cos (TimeToRad("hour", @HOUR))*170
            $curHourY = 250 - Sin (TimeToRad("hour", @HOUR))*170
        EndIf
        DllCall("gdi32.dll", "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BlackPen)
        DllCall ("gdi32.dll", "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
        DllCall ("gdi32.dll", "int", "LineTo", "hwnd", $GUIHDC[0], "int", 250 + Cos (TimeToRad("sec", @SEC))*210, "int", 250 - Sin (TimeToRad("sec", @SEC))*210)
        DllCall ("gdi32.dll", "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
        DllCall ("gdi32.dll", "int", "LineTo", "hwnd", $GUIHDC[0], "int", 250 + Cos (TimeToRad("min", @MIN))*190, "int", 250 - Sin (TimeToRad("min", @MIN))*190)
        DllCall ("gdi32.dll", "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
        DllCall ("gdi32.dll", "int", "LineTo", "hwnd", $GUIHDC[0], "int", 250 + Cos (TimeToRad("hour", @HOUR))*170, "int", 250 - Sin (TimeToRad("hour", @HOUR))*170)
        DllCall ("user32.dll","int","ReleaseDC","int",$GUIHDC[0],"hwnd",$GUI)
        $curSecX = 250 + Cos (TimeToRad("sec", @SEC))*210
        $curSecY = 250 - Sin (TimeToRad("sec", @SEC))*210
        $Sec = @SEC
    EndIf
WEnd

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

Actually, thank you for no flicker. I couldn't get that pen thing to work....

Here's what I have so far. I'll add more to it soon.

#include <guiconstants.au3>
Global $Labels[13], $Sec
Global Const $PI = 3.1415926535897932384626433832795
Global $gdi_dll = DllOpen ("gdi32.dll"), $user32_dll = DllOpen ("user32.dll")

$GUI = GUICreate("Clock",500,500,-1,-1,$WS_POPUP)
GUISetFont (18)

$Labels[12] = GUICtrlCreateLabel (12, 235, 0, 30, 30, $SS_CENTER)
$Labels[1] = GUICtrlCreateLabel (1, 229 + Cos ($PI/3)*250, 250 - Sin ($PI/3)*250, 30, 30, $SS_CENTER)
$Labels[2] = GUICtrlCreateLabel (2, 222 + Cos ($PI/6)*250, 248 - Sin ($PI/6)*250, 30, 30, $SS_CENTER)
$Labels[3] = GUICtrlCreateLabel (3, 470, 237, 30, 30, $SS_CENTER)
$Labels[4] = GUICtrlCreateLabel (4, 228 + Cos (-$PI/6)*250, 227 - Sin (-$PI/6)*250, 30, 30, $SS_CENTER)
$Labels[5] = GUICtrlCreateLabel (5, 230 + Cos (-$PI/3)*250, 222 - Sin (-$PI/3)*250, 30, 30, $SS_CENTER)
$Labels[6] = GUICtrlCreateLabel (6, 235, 470, 30, 30, $SS_CENTER)
$Labels[7] = GUICtrlCreateLabel (7, 242 + Cos (-2*$PI/3)*250, 223 - Sin (-2*$PI/3)*250, 30, 30, $SS_CENTER)
$Labels[8] = GUICtrlCreateLabel (8, 248 + Cos (-5*$PI/6)*250, 228 - Sin (-5*$PI/6)*250, 30, 30, $SS_CENTER)
$Labels[9] = GUICtrlCreateLabel (9, 0, 237, 30, 30, $SS_CENTER)
$Labels[10] = GUICtrlCreateLabel (10, 248 + Cos (5*$PI/6)*250, 247 - Sin (5*$PI/6)*250, 30, 30, $SS_CENTER)
$Labels[11] = GUICtrlCreateLabel (11, 240 + Cos (2*$PI/3)*250, 250 - Sin (2*$PI/3)*250, 30, 30, $SS_CENTER)
For $i = 1 To 12
    GUICtrlSetState ($Labels[$i], $GUI_DISABLE)
Next

SetWindowRgn($GUI, CreateRoundRectRgn(0,0,500,500,500,500))

$curSecX = 250 + Cos (TimeToRad("sec", @SEC))*210
$curSecY = 250 - Sin (TimeToRad("sec", @SEC))*210
$curMinX = 250 + Cos (TimeToRad("min", @MIN))*190
$curMinY = 250 - Sin (TimeToRad("min", @MIN))*190
$curHourX = 250 + Cos (TimeToRad("hour", @HOUR))*170
$curHourY = 250 - Sin (TimeToRad("hour", @HOUR))*170
GUISetState ()
AllThatGoodStuff()

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit
    If $Sec <> @SEC Then
        AllThatGoodStuff()
    EndIf
WEnd

Func AllThatGoodStuff()
    $GUIHDC = DllCall ($user32_dll,"int","GetDC","hwnd", $GUI)
    $BkgrndPen = DllCall($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", "0x00D8E9EC")
    $BkgrndPen = $BkgrndPen[0]
    $BlackPen = DllCall($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", "0x00000000")
    $BlackPen = $BlackPen[0]
    DllCall($gdi_dll, "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BkgrndPen)
    DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", $curSecX, "int", $curSecY)
    If $curMinX <> 250 + Cos (TimeToRad("min", @MIN))*190 Or $curMinY <> 250 - Sin (TimeToRad("min", @MIN))*190 Then
        DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
        DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", $curMinX, "int", $curMinY)
        $curMinX = 250 + Cos (TimeToRad("min", @MIN))*190
        $curMinY = 250 - Sin (TimeToRad("min", @MIN))*190
    EndIf
    If $curHourX <> 250 + Cos (TimeToRad("hour", @HOUR))*170 Or $curHourY <> 250 - Sin (TimeToRad("hour", @HOUR))*170 Then
        DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
        DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", $curHourX, "int", $curHourY)
        $curHourX = 250 + Cos (TimeToRad("hour", @HOUR))*170
        $curHourY = 250 - Sin (TimeToRad("hour", @HOUR))*170
    EndIf
    DllCall($gdi_dll, "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BlackPen)
    DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", 250 + Cos (TimeToRad("sec", @SEC))*210, "int", 250 - Sin (TimeToRad("sec", @SEC))*210)
    DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", 250 + Cos (TimeToRad("min", @MIN))*190, "int", 250 - Sin (TimeToRad("min", @MIN))*190)
    DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", 250, "int", 250, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", 250 + Cos (TimeToRad("hour", @HOUR))*170, "int", 250 - Sin (TimeToRad("hour", @HOUR))*170)
    DllCall ($user32_dll,"int","ReleaseDC","int",$GUIHDC[0],"hwnd",$GUI)
    $curSecX = 250 + Cos (TimeToRad("sec", @SEC))*210
    $curSecY = 250 - Sin (TimeToRad("sec", @SEC))*210
    $Sec = @SEC
EndFunc

Func TimeToRad($TimeType, $TimeVal = @SEC)
    Local $Rads
    Switch $TimeType
        Case "sec"
        ; 0 secs = pi/2, 7-8 secs = pi/4, 15 secs = 0, 22-23 secs = -pi/4 = 7pi/4, 30 secs = 3pi/2, 37-38 secs = 5pi/4, 45 secs = pi
        ; 5 secs = pi/3, 10 secs = pi/6, 20 secs = -pi/6, 25 secs = -pi/3
            $Rads = $PI/2 - ($TimeVal * $PI/30)
        Case "min"
            $Rads = $PI/2 - ($TimeVal * $PI/30) - Int (@SEC / 10)*$PI/180
        Case "hour"
            $Rads = $PI/2 - ($TimeVal * $PI/6) - (@MIN / 12)*$PI/30
    EndSwitch
    Return $Rads
EndFunc

Func SetWindowRgn($h_win, $rgn)
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $rgn, "int", 1)
EndFunc

Func CreateRoundRectRgn($l, $t, $w, $h, $e1, $e2)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $l, "long", $t, "long", $l + $w, "long", $t + $h, "long", $e1, "long", $e2)
    Return $ret[0]
EndFunc

Func OnAutoItExit()
    DllClose ($gdi_dll)
    DllClose ($user32_dll)
EndFunc

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Why isn't this in scripts & scrapts :think:

Edited by Infinitex0

The below statement is False.The above statement is True.a lesson I learned from Greenmachine; give a man a code and he'll solve one problem. Teach a man to code and he'll solve all his problems.P.S please don't use autoIt as a virus creator/spyware maker(keyLogger especially)Cick this and help me[center]My Scripts:[/center][center]Port Scanner[/center]

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Actually, thank you for no flicker. I couldn't get that pen thing to work....

You mean you couldn't until now? Because what you just posted works fine on my comp. Or are you saying it works now, but you couldn't figure it out before?

Why is this in scripts & scrapts :think:

It's not. I'm not sure what you're asking... Edited by neogia

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

I got it, what you do is create a pen for each color, Background and Black, and then just switch between the two to change colors. Congratulations on the no flicker!

Fantastic!, Now, I can draw lines without it redrawing the whole GUI.

Would be helpful if you could add some comments to the Dll call though, or have an example where the variables are something like: $OriginX $OriginY $EndPointX $EndpointY $BKColor $Color $PenDown $Penup

This would help a lot.

Thanks!

BTW the Background (erase color) is white instead of gray...


2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

You mean you couldn't until now? Because what you just posted works fine on my comp. Or are you saying it works now, but you couldn't figure it out before?

I was trying to do the pen things at the same time as you, but you figured it out first. Now that I look at it, it was pretty much just that I wasn't putting the calls in the right place, and I wasn't using hwnd for the COLORREF.

@Infinitex0: It's not in Scripts and Scraps because I'm not done. I'll post it when I'm done.

Share this post


Link to post
Share on other sites

I was trying to do the pen things at the same time as you, but you figured it out first. Now that I look at it, it was pretty much just that I wasn't putting the calls in the right place, and I wasn't using hwnd for the COLORREF.

@Infinitex0: It's not in Scripts and Scraps because I'm not done. I'll post it when I'm done.

Good job!, look forward to the next installment. :think:


2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

@Lakes: Here's some wrapper functions that should show you what you asked for.

#include <GUIConstants.au3>

$GUI = GUICreate("Drawing", 280, 280, -1, -1)
GUISetState()

DrawingStartUp($GUI)
$red = CreateColor(255, 0, 0)
$blue = CreateColor(0, 255, 0)
$green = CreateColor(0, 0, 255)

DrawLine(20, 20, 80, 80)
SelectColor($red)
DrawLine(80, 80, 140, 140)
SelectColor($blue)
DrawLine(140, 140, 200, 200)
SelectColor($green)
DrawLine(200, 200, 260, 260)

DrawingShutDown($GUI)

$msg = GUIGetMsg()
While $msg <> $GUI_EVENT_CLOSE
    Sleep(100)
    $msg = GUIGetMsg()
WEnd


Func DrawingStartUp($GUI)
    Global $gdi_dll = DllOpen ("gdi32.dll"), $user32_dll = DllOpen ("user32.dll"); Thanks greenmachine
    Global $hWnd = DllCall ($user32_dll,"int","GetDC","hwnd", $GUI)
    $hWnd = $hWnd[0]
EndFunc

Func DrawingShutDown($GUI)
    DllCall ($user32_dll,"int","ReleaseDC","int",$hWnd,"hwnd",$GUI)
    DllClose($gdi_dll)
    DllClose($user32_dll)
EndFunc

Func CreateColor($R, $G, $B)
    $hPen = DllCall($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", "0x00" & Hex($B, 2) & Hex($G, 2) & hex($R, 2))
    Return $hPen[0]
EndFunc

Func SelectColor($hPen)
    DllCall($gdi_dll, "hwnd", "SelectObject", "hwnd", $hWnd, "hwnd", $hPen)
EndFunc

Func DrawLine($x0, $y0, $x1, $y1)
    DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $hWnd, "int", $x0, "int", $y0, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $hWnd, "int", $x1, "int", $y1)
EndFunc

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

@Lakes: Here's some wrapper functions that should show you what you asked for.

Fantastic!, Thanks very much! :think:

In the original clock code, you created two pens, one to draw the line and one in the background colour to erase the line.

Can I ask why you created two pens?

Is it faster to do it this way instead of changing the one pen colour?

Thanks!


2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

Fantastic!, Thanks very much! :think:

In the original clock code, you created two pens, one to draw the line and one in the background colour to erase the line.

Can I ask why you created two pens?

Is it faster to do it this way instead of changing the one pen colour?

Thanks!

I like the idea of multiple pens because they're easy to keep track of (one per var), and it's an easy DllCall. You could change the single pen's color (I think with SetDCPenColor), but I like this way. I don't know which is faster, but I think this way is easier.

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

I timed it, and it looks like changing colors is slightly faster, but only very marginally (on the order of ~.5 ms). If you don't create the pens each time the hands move, but rather create them outside the loop, it's even faster, because then you aren't opening and closing things all the time.

creating 2 pens each second ~ 3.05 ms average

creating 1 pen and changing colors ~ 2.57 ms average

using GetStockPen() and changing colors ~ 2.45 ms average

creating HDC and 2 pens once and changing between them ~ 1.45 ms average

Edit: Of course, these times are on my computer, but they should be similar relative to eachother on your comp.

Processor: Pentium D 2.80 GHz

Memory: 2Gb DDR2 667 MHz

Edited by neogia

[u]My UDFs[/u]Coroutine Multithreading UDF LibraryStringRegExp GuideRandom EncryptorArrayToDisplayString"The Brain, expecting disaster, fails to find the obvious solution." -- neogia

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Idea: Use Larry`s polygon code to create better "clock hands"

http://www.autoitscript.com/forum/index.php?showtopic=12827

But then you would have to redraw them when the seconds pointer sweeps over the main hands...

I would guess redraw the polygon with the seconds hand over it, but only when they conflict.

Just ideas..

Edited by Lakes

2015 - Still no flying cars, instead blankets with sleeves.

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