Jump to content

I've done it again


seandisanti
 Share

Recommended Posts

here it is. the last thing you ever needed: a green binary clock that sits in the top left corner of the screen and confuses your co-workers...

#include <GUIConstants.au3>
HotKeySet("!{capslock}", "OkIveWastedEnoughTimeLookingAtThisStupidThing")
$hwnd = GUICreate("Text Region", @DesktopWidth, 50, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
GUISetBkColor(0x00FF00)

GUISetState()
While 1
    Sleep(1000)
    $rgn = CreateTextRgn($hwnd, tobin(@HOUR) & "." & tobin(@MIN) & "." & tobin(@SEC), 50, "Arial", 1000)
    SetWindowRgn($hwnd, $rgn)
WEnd

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


Func CreateTextRgn(ByRef $CTR_hwnd, $CTR_Text, $CTR_height, $CTR_font = "Microsoft Sans Serif", $CTR_weight = 1000)
    Local Const $ANSI_CHARSET = 0
    Local Const $OUT_CHARACTER_PRECIS = 2
    Local Const $CLIP_DEFAULT_PRECIS = 0
    Local Const $PROOF_QUALITY = 4
    Local Const $FIXED_PITCH = 1
    Local Const $RGN_XOR = 3
    Local $gdi_dll = DllOpen("gdi32.dll")
    Local $CTR_hDC = DllCall("user32.dll", "int", "GetDC", "hwnd", $CTR_hwnd)
    Local $CTR_hMyFont = DllCall($gdi_dll, "hwnd", "CreateFont", "int", $CTR_height, "int", 0, "int", 0, "int", 0, _
            "int", $CTR_weight, "int", 0, "int", 0, "int", 0, "int", $ANSI_CHARSET, "int", $OUT_CHARACTER_PRECIS, _
            "int", $CLIP_DEFAULT_PRECIS, "int", $PROOF_QUALITY, "int", $FIXED_PITCH, "str", $CTR_font)
    Local $CTR_hOldFont = DllCall($gdi_dll, "hwnd", "SelectObject", "int", $CTR_hDC[0], "hwnd", $CTR_hMyFont[0])
    DllCall($gdi_dll, "int", "BeginPath", "int", $CTR_hDC[0])
    DllCall($gdi_dll, "int", "TextOut", "int", $CTR_hDC[0], "int", 0, "int", 0, "str", $CTR_Text, "int", StringLen($CTR_Text))
    DllCall($gdi_dll, "int", "EndPath", "int", $CTR_hDC[0])
    Local $CTR_hRgn1 = DllCall($gdi_dll, "hwnd", "PathToRegion", "int", $CTR_hDC[0])
    Local $CTR_rc = DllStructCreate("int;int;int;int")
    DllCall($gdi_dll, "int", "GetRgnBox", "hwnd", $CTR_hRgn1[0], "ptr", DllStructGetPtr($CTR_rc))
    Local $CTR_hRgn2 = DllCall($gdi_dll, "hwnd", "CreateRectRgnIndirect", "ptr", DllStructGetPtr($CTR_rc))
    DllCall($gdi_dll, "int", "CombineRgn", "hwnd", $CTR_hRgn2[0], "hwnd", $CTR_hRgn2[0], "hwnd", $CTR_hRgn1[0], "int", $RGN_XOR)
    DllCall($gdi_dll, "int", "DeleteObject", "hwnd", $CTR_hRgn1[0])
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $CTR_hwnd, "int", $CTR_hDC[0])
    DllCall($gdi_dll, "int", "SelectObject", "int", $CTR_hDC[0], "hwnd", $CTR_hOldFont[0])
    DllClose($gdi_dll)
    Return $CTR_hRgn2[0]
EndFunc ;==>CreateTextRgn
Func tobin($number)
    $result = ""
    $power = 7
    While $number > 0
        If BitAND(2 ^ $power, $number) Then
            $result = $result & "1"
            $number = $number - 2 ^ $power
        Else
            $result = $result & "0"
        EndIf
        $power = $power - 1
    WEnd
    While StringLen($result) < 8
        If StringLen($result) < 8 Then $result = $result & "0"
    WEnd
    Return String($result)
EndFunc ;==>tobin
Func OkIveWastedEnoughTimeLookingAtThisStupidThing()
    Exit
EndFunc ;==>OkIveWastedEnoughTimeLookingAtThisStupidThing

***edit*** the tooltip saying alt capslock to exit wasn't going away, so i took it out...

Edited by cameronsdad
Link to comment
Share on other sites

At first glance, I like the name of the exit function. Now to try it....

Other than the fact that it partially blocks the menus while it's running, I like it. Binary is amusing.

Brainstorming...

It could be centered. Or.. it could be placed strategically at the top of the screen to fit "within" the menu bar - between title and close buttons.

The first three 0's (in hour) could be removed to save space.

[ EDIT ]

Changed region to the upper right half of the screen, fitting between title and buttons on a full-sized window (such as SciTE). Text is smaller too. My screen dimensions are 1024 by 768 pixels, so bigger and smaller screens would have to adjust.

Only two lines I changed:

$hwnd = GUICreate("Text Region", 360, 30, 590, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
$rgn = CreateTextRgn($hwnd, tobin(@HOUR) & "." & tobin(@MIN) & "." & tobin(@SEC), 30, "Arial", 800)
Edited by greenmachine
Link to comment
Share on other sites

At first glance, I like the name of the exit function. Now to try it....

Other than the fact that it partially blocks the menus while it's running, I like it. Binary is amusing.

Brainstorming...

It could be centered. Or.. it could be placed strategically at the top of the screen to fit "within" the menu bar - between title and close buttons.

The first three 0's (in hour) could be removed to save space.

yeah i was thinking about trimming it down, 7 spots could be trimmed, which would take about 30% of the length off of it, but decided against it just out of laziness... :P it's good for work though, because i can disable my systray clock and use that for time, then i won't watch the clock as closely, and by the time i've worked out the time i'm 30 seconds closer to the end of my day...
Link to comment
Share on other sites

Does this require beta? It compiles for me but I get "C:\*********\******\******\binaryclock.au3 (35) : ==> Unknown function name.: Local $CTR_rc = DllStructCreate("int;int;int;int")

Local $CTR_rc = ^ ERROR" on execution.

Granted, I'm a newbie. Thanks!

Edited by msa2004
Link to comment
Share on other sites

Does this require beta? It compiles for me but I get "C:\*********\******\******\binaryclock.au3 (35) : ==> Unknown function name.: Local $CTR_rc = DllStructCreate("int;int;int;int")

Local $CTR_rc = ^ ERROR" on execution.

Granted, I'm a newbie. Thanks!

Yep needs Beta, see link in my sig for download.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

Does this require beta? It compiles for me but I get "C:\*********\******\******\binaryclock.au3 (35) : ==> Unknown function name.: Local $CTR_rc = DllStructCreate("int;int;int;int")

Local $CTR_rc = ^ ERROR" on execution.

Granted, I'm a newbie. Thanks!

yes, beta is required, and no worries about being new, everyone on these forums was at one point or another. welcome to the forums.
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...