Jump to content

Always on top little clock


jdickens
 Share

Recommended Posts

It's a scrap, but cool:

$ToD = ""
SplashTextOn("ToD", $ToD, 100, 36, 800, -1, 17, "", 24, 800)
$minute = 61
While 1
  If $minute <> @MIN Then
    $minute = @MIN
    If @HOUR > 12 Then
      $TheHour = @HOUR - 12
    Else
      $TheHour = @HOUR
    EndIf
    $ToD = $TheHour & ":" & $minute
    ControlSetText("ToD", "", "Static1", $ToD)
  EndIf
  Sleep(250)
WEnd

You can move it only by changing code parms in SplashTextOn.

If anyone knows how to change the color (of the font or window) to a nice squash-blossom yellow, let me know. :)

J

If I am too verbose, just say so. You don't need to run on and on.

Link to comment
Share on other sites

Then it blocks out your minimize and maximize buttons of windows underneath.

You can make one that has a normal windows title bar (which permits moving also) by changing the SplashTextOn parms, but I needed this for a special project so I just present it here the way I use it.

You can experiment with SplashTextOn to see what options it provides.

J

If I am too verbose, just say so. You don't need to run on and on.

Link to comment
Share on other sites

Liked the clock, I've made it draggable (hold down left mouse key) using ezzetabi's _IsPressed function.

Const $WIDTH = 100
Const $HEIGHT = 36
Dim $MousePos[2]

$XPOS = 0
$YPOS = 0
$ToD = ""

SplashTextOn("ToD", $ToD, $WIDTH, $HEIGHT, $XPOS, $YPOS, 17, "", 24, 800)
$minute = 61
While 1
  If $minute <> @MIN Then
    $minute = @MIN
    If @HOUR > 12 Then
      $TheHour = @HOUR - 12
    Else
      $TheHour = @HOUR
    EndIf
    $ToD = $TheHour & ":" & $minute
    ControlSetText("ToD", "", "Static1", $ToD)
    EndIf
    $MousePos=MouseGetPos()
    If $MousePos[0] >= $XPOS And $MousePos[0] <= $XPOS+$WIDTH And $MousePos[1] >= $YPOS And $MousePos[1] <= $YPOS+$HEIGHT And _IsPressed("01") Then
        $MousePos=MouseGetPos()
        $XOFFSET=$MousePos[0]-$XPOS
        $YOFFSET=$MousePos[1]-$YPOS
        While _IsPressed("01")
            $MousePos=MouseGetPos()
            $XPOS=$MousePos[0]-$XOFFSET
            $YPOS=$MousePos[1]-$YOFFSET
            SplashTextOn("ToD", $ToD, $WIDTH, $HEIGHT, $XPOS, $YPOS, 17, "", 24, 800)
        WEnd
    EndIf
    Sleep(20)
WEnd

Func _IsPressed($hexKey)
; $hexKey must be the value of one of the keys.
; _IsPressed will return 0 if the key is not pressed, 1 if it is.
; $hexKey should entered as a string, don't forget the quotes!
; (yeah, layer. This is for you)
  
  Local $aR, $bO
  
  $hexKey = '0x' & $hexKey
  $aR = DllCall("user32", "int", "GetAsyncKeyState", "int", $hexKey)
  If Not @error And BitAND($aR[0], 0x8000) = 0x8000 Then
     $bO = 1
  Else
     $bO = 0
  EndIf
  
  Return $bO
EndFunc ;==>_IsPressed

When I get a moment I'll get it to save last position in the registry..

Steph

Link to comment
Share on other sites

i'm gonna give a go at making a clock

edit: done :) the resizing is supposed to change the font size but it has problems so i don't recommed you do it my clock also has a right click menu

#include <guiconstants.au3>
Global Const $HTCAPTION = 2
Global Const $WM_NCLBUTTONDOWN = 0xA1
Opt ( "GUIOnEventMode", 1 )
$hwnd = GUICreate ( "Xen's Clock", 100, 36, 0, 0, $WS_POPUP + $WS_BORDER + $WS_SiZEBOX, $WS_EX_TOPMOST + $WS_EX_TOOLWINDOW)
GUISetOnEvent ( -3, "Quit" )
$time = GUICtrlCreateLabel ( "", 0, 0, 100, 36, $SS_CENTER )
GUICtrlSetOnEvent ( -1, "Drag" )
$menu = GUICtrlCreateContextMenu ( $time )
GUICtrlCreateMenuitem ( "Default Position", $menu )
GUICtrlSetOnEvent ( -1, "Default" ) 
GUICtrlCreateMenuitem ( "", $menu )
$military = GUICtrlCreateMenuitem ( "Military Time", $menu, 3, 1 )
GUICtrlCreateMenuitem ( "Normal Time", $menu, 4, 1 )
GUICtrlSetState ( -1, $GUI_CHECKED )
GUICtrlCreateMenuitem ( "", $menu )
GUICtrlCreateMenuitem ( "Exit", $menu )
GUICtrlSetOnEvent ( -1, "Quit" )
GUISetState ( )
While 1
    If BitAND ( GUICtrlRead ( $military ), $GUI_CHECKED ) = $GUI_CHECKED Then
        $data = @HOUR & ":" & @MIN
    Else
        If @HOUR > 12 Then
            $h = @HOUR - 12
            $pa = " PM"
        Else
            $h = StringTrimLeft ( @HOUR, 1 )
            $pa = " AM"
        EndIf
        $data = $h & ":" & @MIN & $pa
    EndIf
    GUICtrlSetData ( $time, $data )
    $pos = WinGetPos ( $hwnd )
    GUICtrlSetFont ( $time, ($pos[3]-($pos[2]-25))/2 )
    Sleep ( 500 )
WEnd
func Drag()
    dllcall("user32.dll","int","ReleaseCapture")
    dllcall("user32.dll","int","SendMessage","hWnd", $hwnd,"int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0)
EndFunc
Func Quit()
    Exit
EndFunc
Func Default()
    WinMove ( $hwnd, '', 0, 0 )
EndFunc
Edited by Xenogis

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Link to comment
Share on other sites

Okay! I like the clocks... but...

I don't see any squash-blossom yellow yet.

Alternately, some way to make it go nuts at 4 pm would give the kids standing by the timeclock a hoot.

J

PS: I know there are multiple ways to do the above, so I am only being lazy/"efficient" with my time.:)

Such as Xen's clock use:

GUICtrlSetColor(-1,0xffee00)

PS: Dragging Steph's clock to the edge of the screen breaks my monitor display in really cool ways. (Save your work before trying)(PS: Only seems to blow up from within Scite -- Ha!)

slight improvements (see later post):

Edited by Jon

If I am too verbose, just say so. You don't need to run on and on.

Link to comment
Share on other sites

PS: Dragging Steph's clock to the edge of the screen breaks my monitor display in really cool ways.  (Save your work before trying)

So it does ... something to do with negative co-ordinates I suppose. Never one to ignore a bug-fix I would suggest not moving it over there. I think Xenogis' clock has more potential for customising with pretty colours.

Steph

Link to comment
Share on other sites

This may be premature, because I am trying to synthesize the three versions, but this is ok for the part getting the times:

Else
        If @HOUR > 12 Then
            $h = @HOUR - 12
            $pa = " PM"
        Else
            $h = @HOUR
            $pa = " AM"
        EndIf
        If int($h) < 10 Then
            $h = StringRight($h, 1)
        EndIf
        $data = $h & ":" & @MIN & $pa
        If ($pa = " PM") And ($h = 4) And (@MIN = 0) Then
            GUICtrlSetBkColor($time,0x00ff00); Green
        Else
            GUICtrlSetBkColor($time,0xD4D0C8); gray
        EndIf
    EndIf

Throw this in too:

ControlFocus("", "", "Shell_TrayWnd"); Eliminates extra icons that accumulate in the system tray

If I get away with this without my boss catching me, I will make this clock count down from 3:59:30 to 4 pm.

Don't sweat it, Steph :) , I enjoy breaking my computer. Keep 'em coming.

J

Edit: corrected code (twice) for times between 10-12.

Edited by jdickens

If I am too verbose, just say so. You don't need to run on and on.

Link to comment
Share on other sites

@Xenogis;

There seems to be an error in this logic because on Central time of 12:30pm the clock reads 2:30am.

If @HOUR > 12 Then
            $h = @HOUR - 12
            $pa = " PM"
        Else
            $h = StringTrimLeft ( @HOUR, 1 )
            $pa = " AM"
        EndIf

It seems like it does not take into account that 12:30pm is "not" greater than 12 and therefore falls throuth to the Else statement which ends up triming the "1" from the 12 and ends up being AM instead of PM.

However, jdickens code works well.

If $minute <> @MIN Then
    $minute = @MIN
    If @HOUR > 12 Then
      $TheHour = @HOUR - 12
    Else
      $TheHour = @HOUR
    EndIf

I know it's fixable, just thought I'd point that out. :)

RocTx

Link to comment
Share on other sites

my XP Control Panel, Regional Setttings, specify time as HH:mm:ss, thus applications display time as in normal 24-Hour format, this script does not and incorrectly shows 2:34 when the real time is 14:34 :)

just comment this out (or how about automatically reading the values from the registry?)

; $TheHour = @HOUR - 12

; Else

Edited by Nina
Link to comment
Share on other sites

i never said my clock was perfect :) i might add something to it and fix some stuff later.

[font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]

Link to comment
Share on other sites

There is prob a good technical explanation, but I've seen with AutoIt scripts (and some other progs), if they don't shut down gracefully, they don't clear out their icon in the task bar. Putting focus on the task bar lets the task bar clean up itself apparently. So the issue is only applicable to multiple instances of AutoIt scripts.

J

If I am too verbose, just say so. You don't need to run on and on.

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...