Jump to content
Sign in to follow this  
Qousio

How to stop the damn WinAPIDraw(something) from blinking?

Recommended Posts

Qousio

Hey. Lets be quick and precise shall we? Heres my code:

#NoTrayIcon
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <FontConstants.au3>
Global $tRECT, $hFont, $hOldFont, $hDC, $Hour, $Min
Global $Time = 0
    $tRECT = DllStructCreate($tagRect)
DllStructSetData($tRECT, "Left", @DesktopWidth/2 - 25)
DllStructSetData($tRECT, "Top", 0)
DllStructSetData($tRECT, "Right", @DesktopWidth/2 + 25)
DllStructSetData($tRECT, "Bottom", 100)
    $hDC = _WinAPI_GetWindowDC(0)
$hFont = _WinAPI_CreateFont(18, 0, 0, 0, 400, False, False, False, $DEFAULT_CHARSET, _
$OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
$hOldFont = _WinAPI_SelectObject($hDC, $hFont)
While 1
    do
    _WinAPI_DrawText($hDC, $Hour & ":" & $Min, $tRECT, $DT_CENTER)
    $ping = ping("www.google.com")
    sleep(1000)
until $ping > 1
    $Hour = @HOUR
    $Min = @MIN
    Do 
    _WinAPI_DrawText($hDC, $Hour & ":" & $Min, $tRECT, $DT_CENTER)
    $Time = $Time+1
    sleep(1000)
Until $Time = 3600
$Time = 0
$Ping = 0
    WEnd

It works as intended, but the WinAPI_DrawText is -CONSTANTLY- blinking instead of just being plain text. Any way to solve this? Because its kinda anoying. A few notes though, I can't increase the sleeptime and no sleep(3600000) is not the same as sleep(1000) 3600 times.

Thank you in advance!

Edited by Qousio

Share this post


Link to post
Share on other sites
Valuater

Looks fine on my Win Xp Home SP3, however the time does not update. Is that wahat you wanted?

If not, maybe use...

_WinAPI_DrawText($hDC, @HOUR & ":" & @MIN, $tRECT, $DT_CENTER)

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
SkinnyWhiteGuy

Just a simple question on my part, and I may not be all the bright, but why are you redrawing something every second that won't change but once a minute? Why not keep two sets of variables, current time and new time, and just read the time into new time once a second, check to see if it changed (if new time <> current time), and then redraw only when different, update current time, and then repeat. I know that would solve the flicker problem, and also reduce some of the load on the CPU to constantly redraw something that isn't changing.

Share this post


Link to post
Share on other sites
Valuater

Just a simple question on my part, and I may not be all the bright, but why are you redrawing something every second that won't change but once a minute? Why not keep two sets of variables, current time and new time, and just read the time into new time once a second, check to see if it changed (if new time <> current time), and then redraw only when different, update current time, and then repeat. I know that would solve the flicker problem, and also reduce some of the load on the CPU to constantly redraw something that isn't changing.

(if new time <> current time)

good point!

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites
Qousio

Looks fine on my Win Xp Home SP3, however the time does not update. Is that wahat you wanted?

If not, maybe use...

_WinAPI_DrawText($hDC, @HOUR & ":" & @MIN, $tRECT, $DT_CENTER)

8)

Weird, I'm using XP Pro SP3 and its blinking ;) And no, I can't use @HOUR and @MIN instead of $Hour and $Min, the purpose of my script is to change the time only once an hour when the loop ends.

Just a simple question on my part, and I may not be all the bright, but why are you redrawing something every second that won't change but once a minute? Why not keep two sets of variables, current time and new time, and just read the time into new time once a second, check to see if it changed (if new time <> current time), and then redraw only when different, update current time, and then repeat. I know that would solve the flicker problem, and also reduce some of the load on the CPU to constantly redraw something that isn't changing.

You see, the thing is, I'm repeating it constantly because I constantly close and open windows, if it doesnt loop itself all the time then it disapears after opening a new window. The time itself must change only once an hour if google is pinged.

(if new time <> current time)

good point!

8)

^_^ Rawr. If I do that it will stop refreshing when I open new windows.

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  

×