Jump to content

Analog Clock


greenmachine
 Share

Recommended Posts

1. The ability to choose color of face / hands

Here's my version to change the color of the face. It uses a much simpler method of picking the color for the background (thanks to Chris95219). I also had to #include misc for the windows color picker, and remove the _ispressed code which threw an error when I included misc.au3:
; Analog Clock
; Created April 2006
; By greenmachine
; Credit - Larry (region funcs), neogia (anti-flicker, erasing old lines), Valuater (tray, transparency)
#include <misc.au3>

#region - Constants and funcs from includes
Global Const $GUI_EVENT_CLOSE       = -3
Global Const $GUI_CHECKED           = 1
Global Const $GUI_UNCHECKED         = 4
Global Const $GUI_ENABLE            = 64
Global Const $GUI_DISABLE           = 128
Global Const $GUI_FOCUS             = 256
Global Const $WS_POPUP              = 0x80000000
Global Const $WS_MINIMIZEBOX        = 0x00020000
Global Const $WS_CAPTION            = 0x00C00000
Global Const $WS_EX_TOPMOST         = 0x00000008
Global Const $SS_CENTER             = 1

;~ Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')
;~   Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)
;~   If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1
;~   Return 0
;~ EndFunc;==>_IsPressed

Global Const $TRAY_CHECKED              = 1
Global Const $TRAY_UNCHECKED            = 4
Global Const $TRAY_ENABLE               = 64
Global Const $TRAY_DISABLE              = 128
#endregion

Opt ("GUIOnEventMode", 1)
Opt ("TrayMenuMode", 1)
Opt ("TrayOnEventMode", 1)

Global $ver = "1.0.4"
Global $Labels[13], $Sec, $ClockActive = 1, $OnTop = 0, $WinTrans = 0, $WaitingForMin = 0
Global Const $PI = 3.1415926535897932384626433832795
Global $gdi_dll = DllOpen ("gdi32.dll"), $user32_dll = DllOpen ("user32.dll")
Global $LabW = 30, $LabH = 30, $Mid = 300, $Radius = $Mid, $SecRad = 210, $MinRad = 190, $HourRad = 170, $OldFontSize
Global $BackgroundPens[3], $BlackPens[4]
Global $MousePos, $WinPos, $PosDiff[2]
Global $AlarmTime[7] = ["Daily", "12", "00", "PM"]; when (daily, weekdays, weekends, one date), hour, min, part of day (AM or PM), mon, day, year
Global $AlarmStatus[3] = ["Off", "On", 0]; off, on, and currently selected
Global $AlarmSave[3] = ["No", "Yes", 0]
Global $INI = @ScriptDir & "\AnalogClock.ini"
Global $facecolor = "0xFFFFFF"
Global $r, $g, $b, $Red, $Green,$Blue
Global $rgb2bgr = "0x00" & StringRight($facecolor,2) & StringMid($facecolor,5,2) & StringMid($facecolor,3,2)


If FileExists ($INI) Then
    $AlarmSave[2] = 1
    $AlarmTime[0] = IniRead ($INI, "Alarm", "Dates", "Daily")
    If $AlarmTime[0] <> "Daily" And $AlarmTime[0] <> "Weekdays" And _ 
        $AlarmTime[0] <> "Weekends" And $AlarmTime[0] <> "One Date" Then $AlarmTime[0] = "Daily"
    $AlarmTime[1] = IniRead ($INI, "Alarm", "Hour", "12")
    If $AlarmTime[1] < 1 Or $AlarmTime[1] > 12 Then $AlarmTime[1] = "12"
    $AlarmTime[2] = IniRead ($INI, "Alarm", "Min", "00")
    If $AlarmTime[2] < 0 Or $AlarmTime[2] > 59 Then $AlarmTime[2] = "00"
    $AlarmTime[3] = IniRead ($INI, "Alarm", "AMPM", "PM")
    If StringUpper ($AlarmTime[3]) <> "AM" And StringUpper ($AlarmTime[3]) <> "PM" Then $AlarmTime[3] = "PM"
    If $AlarmTime[0] = "One Date" Then
        $AlarmTime[4] = IniRead ($INI, "Alarm", "Month", "")
        If Number ($AlarmTime[4]) < 1 Or Number ($AlarmTime[4]) > 12 Then $AlarmTime[4] = ""
        $AlarmTime[5] = IniRead ($INI, "Alarm", "Day", "")
        If Number ($AlarmTime[5]) < 1 Or Number ($AlarmTime[5]) > 31 Then $AlarmTime[5] = ""
        $AlarmTime[6] = IniRead ($INI, "Alarm", "Year", "")
        If Number ($AlarmTime[6]) < Number (@YEAR) Then $AlarmTime[6] = ""
    EndIf
EndIf   

$GUI_Clock = GUICreate ("Analog Clock", $Mid*2, $Mid*2, @DesktopWidth/2 - $Mid, @DesktopHeight/2 - $Mid, BitOR ($WS_POPUP, $WS_MINIMIZEBOX))
GUISetBkColor ($facecolor)
GUISetFont ($Mid/15, 800)

$ContextMenu = GUICtrlCreateContextMenu ()
$MenuItemMoveClock = GUICtrlCreateMenuitem ("Move Clock", $ContextMenu, 0)
GUICtrlSetOnEvent ($MenuItemMoveClock, "MoveTheClock")

$MenuItemResizeClock = GUICtrlCreateMenuitem ("Resize Clock", $ContextMenu, 1)
GUICtrlSetOnEvent ($MenuItemResizeClock, "ResizeTheClock")

$MenuItemOnTop = GUICtrlCreateMenuitem ("Always On Top", $ContextMenu, 2)
GUICtrlSetOnEvent ($MenuItemOnTop, "ToggleOnTop")

GUICtrlCreateMenuitem ("", $ContextMenu, 3)

$MenuAlarm = GUICtrlCreateMenu ("Alarm", $ContextMenu, 4)
$MenuItemAlarmTime = GUICtrlCreateMenuitem ("Alarm Time", $MenuAlarm, 0)
If $AlarmTime[0] = "One Date" Then
    GUICtrlSetData ($MenuItemAlarmTime, $AlarmTime[1] & ":" & $AlarmTime[2] & " " & _ 
    $AlarmTime[3] & " on " & $AlarmTime[4] & "/" & $AlarmTime[5] & "/" & $AlarmTime[6])
Else
    GUICtrlSetData ($MenuItemAlarmTime, $AlarmTime[0] & " at " & $AlarmTime[1] & ":" & $AlarmTime[2] & " " & $AlarmTime[3])
EndIf
GUICtrlSetState ($MenuItemAlarmTime, $GUI_DISABLE)
$MenuItemAlarmStatus = GUICtrlCreateMenuitem ("Alarm is: " & $AlarmStatus[$AlarmStatus[2]], $MenuAlarm, 1)
GUICtrlSetOnEvent ($MenuItemAlarmStatus, "ToggleAlarm")
$MenuItemSaveAlarm = GUICtrlCreateMenuitem ("Save Alarm: " & $AlarmSave[$AlarmSave[2]], $MenuAlarm, 2)
GUICtrlSetOnEvent ($MenuItemSaveAlarm, "ToggleSave")
GUICtrlCreateMenuitem ("", $MenuAlarm, 3)
$MenuItemSetAlarm = GUICtrlCreateMenuitem ("Set Alarm", $MenuAlarm, 4)
GUICtrlSetOnEvent ($MenuItemSetAlarm, "SetAlarm")

$MenuChangeColor = GUICtrlCreateMenuitem ("Change face color", $ContextMenu, 5)
GUICtrlSetOnEvent ($MenuChangeColor, "ChangeFaceColor")

$MenuItemTransparency = GUICtrlCreateMenuitem ("Set Analog Clock Transparency", $ContextMenu, 6)
GUICtrlSetOnEvent ($MenuItemTransparency, "Set_Trans")

GUICtrlCreateMenuitem ("", $ContextMenu, 7)

$MenuItemAbout = GUICtrlCreateMenuitem ("About Analog Clock", $ContextMenu, 8)
GUICtrlSetOnEvent ($MenuItemAbout, "Set_About")

GUICtrlCreateMenuitem ("", $ContextMenu, 9)

$MenuItemExit = GUICtrlCreateMenuitem ("Exit Analog Clock", $ContextMenu, 10)
GUICtrlSetOnEvent ($MenuItemExit, "quitme")

$Labels[12] = GUICtrlCreateLabel (12, $Mid - 15, $Mid - Sin ($PI/2)*($Radius - 10), $LabW, $LabH, $SS_CENTER)
$Labels[1] = GUICtrlCreateLabel (1, $Mid - 21 + Cos ($PI/3)*($Radius - 10), $Mid - Sin ($PI/3)*($Radius - 10), $LabW, $LabH, $SS_CENTER)
$Labels[2] = GUICtrlCreateLabel (2, $Mid - 28 + Cos ($PI/6)*($Radius - 10), $Mid - 2 - Sin ($PI/6)*($Radius - 10), $LabW, $LabH, $SS_CENTER)
$Labels[3] = GUICtrlCreateLabel (3, $Mid - 30 + Cos (0)*($Radius - 10), $Mid - 13, $LabW, $LabH, $SS_CENTER)
$Labels[4] = GUICtrlCreateLabel (4, $Mid - 25 + Cos (-$PI/6)*($Radius - 10), $Mid - 20 - Sin (-$PI/6)*($Radius - 10), $LabW, $LabH, $SS_CENTER)
$Labels[5] = GUICtrlCreateLabel (5, $Mid - 20 + Cos (-$PI/3)*($Radius - 10), $Mid - 28 - Sin (-$PI/3)*($Radius - 10), $LabW, $LabH, $SS_CENTER)
$Labels[6] = GUICtrlCreateLabel (6, $Mid - 15, $Mid - 30 - Sin (3*$PI/2)*($Radius - 10), $LabW, $LabH, $SS_CENTER)
$Labels[7] = GUICtrlCreateLabel (7, $Mid - 8 + Cos (-2*$PI/3)*($Radius - 10), $Mid - 27 - Sin (-2*$PI/3)*($Radius - 10), $LabW, $LabH, $SS_CENTER)
$Labels[8] = GUICtrlCreateLabel (8, $Mid - 2 + Cos (-5*$PI/6)*($Radius - 10), $Mid - 22 - Sin (-5*$PI/6)*($Radius - 10), $LabW, $LabH, $SS_CENTER)
$Labels[9] = GUICtrlCreateLabel (9, $Mid + Cos ($PI)*($Radius - 10), $Mid - 13, $LabW, $LabH, $SS_CENTER)
$Labels[10] = GUICtrlCreateLabel (10, $Mid - 2 + Cos (5*$PI/6)*($Radius - 10), $Mid - 13 - Sin (5*$PI/6)*($Radius - 10), $LabW, $LabH, $SS_CENTER)
$Labels[11] = GUICtrlCreateLabel (11, $Mid - 10 + Cos (2*$PI/3)*($Radius - 10), $Mid - Sin (2*$PI/3)*($Radius - 10), $LabW, $LabH, $SS_CENTER)
For $i = 1 To 12
    GUICtrlSetColor ($Labels[$i], 0xFF0000)
Next

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

SetWindowRgn($GUI_Clock, $a)

$TrayItemMove = TrayCreateItem ("Move Clock", -1, 0)
TrayItemSetOnEvent ($TrayItemMove, "MoveTheClock")

$TrayItemResize = TrayCreateItem ("Resize Clock", -1, 1)
TrayItemSetOnEvent ($TrayItemResize, "ResizeTheClock")

$TrayItemOnTop = TrayCreateItem ("Always On Top", -1, 2)
TrayItemSetOnEvent ($TrayItemOnTop, "ToggleOnTop")

TrayCreateItem ("", -1, 3)

$TrayMenuAlarm = TrayCreateMenu ("Alarm", -1, 4)
$TrayItemAlarmTime = TrayCreateItem ("Alarm Time", $TrayMenuAlarm, 0)
TrayItemSetState ($TrayItemAlarmTime, $TRAY_DISABLE)
If $AlarmTime[0] = "One Date" Then
    TrayItemSetText ($TrayItemAlarmTime, $AlarmTime[1] & ":" & $AlarmTime[2] & " " & _ 
    $AlarmTime[3] & " on " & $AlarmTime[4] & "/" & $AlarmTime[5] & "/" & $AlarmTime[6])
Else
    TrayItemSetText ($TrayItemAlarmTime, $AlarmTime[0] & " at " & $AlarmTime[1] & ":" & $AlarmTime[2] & " " & $AlarmTime[3])
EndIf
$TrayItemAlarmStatus = TrayCreateItem ("Alarm is: " & $AlarmStatus[$AlarmStatus[2]], $TrayMenuAlarm, 1)
TrayItemSetOnEvent ($TrayItemAlarmStatus, "ToggleAlarm")
$TrayItemSaveAlarm = TrayCreateItem ("Save Alarm: " & $AlarmSave[$AlarmSave[2]], $TrayMenuAlarm, 2)
TrayItemSetOnEvent ($TrayItemSaveAlarm, "ToggleSave")
TrayCreateItem ("", $TrayMenuAlarm, 3)
$TrayItemSetAlarm = TrayCreateItem ("Set Alarm", $TrayMenuAlarm, 4)
TrayItemSetOnEvent ($TrayItemSetAlarm, "SetAlarm")

TrayCreateItem ("", -1, 5)

$TrayItemTransparency = TrayCreateItem ("Set Analog Clock Transparency", -1, 6)
TrayItemSetOnEvent ($TrayItemTransparency, "Set_Trans")

TrayCreateItem ("", -1, 7)

$TrayItemAbout = TrayCreateItem ("About Analog Clock", -1, 8)
TrayItemSetOnEvent ($TrayItemAbout, "Set_About")

TrayCreateItem ("", -1, 9)

$TrayItemExit = TrayCreateItem ("Exit Analog Clock", -1, 10)
TrayItemSetOnEvent ($TrayItemExit, "quitme")

$curSecX = $Mid + Cos (TimeToRad("sec", @SEC))*$SecRad
$curSecY = $Mid - Sin (TimeToRad("sec", @SEC))*$SecRad
$curMinX = $Mid + Cos (TimeToRad("min", @MIN))*$MinRad
$curMinY = $Mid - Sin (TimeToRad("min", @MIN))*$MinRad
$curHourX = $Mid + Cos (TimeToRad("hour", @HOUR))*$HourRad
$curHourY = $Mid - Sin (TimeToRad("hour", @HOUR))*$HourRad
GUISetState ()
AllThatGoodStuff(1)

While 1
    CheckClockStuff()
    Sleep (10)
WEnd

Func AllThatGoodStuff($FirstRun = 0)
    $GUIHDC = DllCall ($user32_dll,"int","GetDC","hwnd", $GUI_Clock)
    If $FirstRun = 1 Then
        $BkgrndPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", $rgb2bgr); small background pen
        $BackgroundPens[0] = $BkgrndPen[0]
        $BkgrndPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "2", "hwnd", $rgb2bgr); medium background pen
        $BackgroundPens[1] = $BkgrndPen[0]
        $BkgrndPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "3", "hwnd", $rgb2bgr); large background pen
        $BackgroundPens[2] = $BkgrndPen[0]
        $BlackPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", "0x0000f0fF"); small red pen (second hand)
        $BlackPens[0] = $BlackPen[0]
        $BlackPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "2", "hwnd", "0x00000000"); medium black pen
        $BlackPens[1] = $BlackPen[0]
        $BlackPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "3", "hwnd", "0x00000000"); large black pen
        $BlackPens[2] = $BlackPen[0]
        $BlackPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", "0x00000000"); small black pen
        $BlackPens[3] = $BlackPen[0]
    EndIf
; erase old hands
    If $curHourX <> $Mid + Cos (TimeToRad("hour", @HOUR))*$HourRad Or $curHourY <> $Mid - Sin (TimeToRad("hour", @HOUR))*$HourRad Then
        DllCall ($gdi_dll, "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BackgroundPens[2])
        DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", $Mid, "int", $Mid, "ptr", 0)
        DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", $curHourX, "int", $curHourY)
        $curHourX = $Mid + Cos (TimeToRad("hour", @HOUR))*$HourRad
        $curHourY = $Mid - Sin (TimeToRad("hour", @HOUR))*$HourRad
    EndIf
    If $curMinX <> $Mid + Cos (TimeToRad("min", @MIN))*$MinRad Or $curMinY <> $Mid - Sin (TimeToRad("min", @MIN))*$MinRad Then
        DllCall ($gdi_dll, "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BackgroundPens[1])
        DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", $Mid, "int", $Mid, "ptr", 0)
        DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", $curMinX, "int", $curMinY)
        $curMinX = $Mid + Cos (TimeToRad("min", @MIN))*$MinRad
        $curMinY = $Mid - Sin (TimeToRad("min", @MIN))*$MinRad
    EndIf
    DllCall ($gdi_dll, "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BackgroundPens[0])
    DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", $Mid, "int", $Mid, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", $curSecX, "int", $curSecY)
; draw new hands
    DllCall ($gdi_dll, "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BlackPens[2])
    DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", $Mid, "int", $Mid, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", $Mid + Cos (TimeToRad("hour", @HOUR))*$HourRad, "int", $Mid - Sin (TimeToRad("hour", @HOUR))*$HourRad)
    DllCall ($gdi_dll, "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BlackPens[1])
    DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", $Mid, "int", $Mid, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", $Mid + Cos (TimeToRad("min", @MIN))*$MinRad, "int", $Mid - Sin (TimeToRad("min", @MIN))*$MinRad)
    DllCall ($gdi_dll, "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BlackPens[0])
    DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", $Mid, "int", $Mid, "ptr", 0)
    DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", $Mid + Cos (TimeToRad("sec", @SEC))*$SecRad, "int", $Mid - Sin (TimeToRad("sec", @SEC))*$SecRad)
    If $FirstRun Then
        DllCall ($gdi_dll, "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BlackPens[3])
        $Tempcounter = 0
        For $i = 0 To 2*$PI Step $PI/30
            If Mod ($Tempcounter, 5) = 0 Then
                DllCall ($gdi_dll, "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BlackPens[2])
                DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", $Mid + Cos ($i)*($Radius*47/60), "int", $Mid - Sin ($i)*($Radius*47/60), "ptr", 0)
                DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", $Mid + Cos ($i)*($Radius*5/6), "int", $Mid - Sin ($i)*($Radius*5/6))
                DllCall ($gdi_dll, "hwnd", "SelectObject", "hwnd", $GUIHDC[0], "hwnd", $BlackPens[3])
            Else
                DllCall ($gdi_dll, "int", "MoveToEx", "hwnd", $GUIHDC[0], "int", $Mid + Cos ($i)*($Radius*4/5), "int", $Mid - Sin ($i)*($Radius*4/5), "ptr", 0)
                DllCall ($gdi_dll, "int", "LineTo", "hwnd", $GUIHDC[0], "int", $Mid + Cos ($i)*($Radius*5/6), "int", $Mid - Sin ($i)*($Radius*5/6))
            EndIf
            $Tempcounter += 1
        Next
    EndIf
    DllCall ($user32_dll,"int","ReleaseDC","int",$GUIHDC[0],"hwnd",$GUI_Clock)
    $curSecX = $Mid + Cos (TimeToRad("sec", @SEC))*$SecRad
    $curSecY = $Mid - Sin (TimeToRad("sec", @SEC))*$SecRad
    $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 ResizeTheClock()
    Opt ("MouseCoordMode", 2)
    GUISetCursor (13, 1, $GUI_Clock)
    ToolTip ("Click and drag to resize the clock.  Release to set size.")
    While 1
        $MousePos = MouseGetPos ()
        $WinPos = WinGetPos ("Analog Clock")
        $PosDiff[0] = $WinPos[2] - $MousePos[0]
        $PosDiff[1] = $WinPos[1] - $MousePos[1]
        If _IsPressed ("01", $user32_dll) Then
            While _IsPressed ("01", $user32_dll)
                $MousePos = MouseGetPos ()
                WinMove ("Analog Clock", "", $WinPos[0], $WinPos[1], $MousePos[0] + $PosDiff[0], _
                $MousePos[0] + $PosDiff[0])
                $WinPos = WinGetPos ("Analog Clock")
                $a = CreateRoundRectRgn (0, 0, $WinPos[2], $WinPos[3], $WinPos[2], $WinPos[3])
                SetWindowRgn($GUI_Clock, $a)
                $Mid = $WinPos[2]/2
                $Radius = $Mid
                $SecRad = $Mid * (21/30)
                $MinRad = $Mid * (19/30)
                $HourRad = $Mid * (17/30)
                If $OldFontSize <> Int ($Mid/15) Then
                    For $i = 1 To 12
                        GUICtrlSetFont ($Labels[$i], Int ($Mid/15), 800)
                    Next
                    $OldFontSize = Int ($Mid/15)
                EndIf
                CheckClockStuff(2)
                Sleep (10)
            WEnd
            ExitLoop
        EndIf
        CheckClockStuff()
        Sleep (10)
    WEnd
    ToolTip ("")
    GUISetCursor ()
    AllThatGoodStuff(2)
    Opt ("MouseCoordMode", 1)
EndFunc

Func MoveTheClock()
    GUISetCursor (9, 1, $GUI_Clock)
    ToolTip ("Click and drag to move the clock.  Release to set position.")
    While 1
        $MousePos = MouseGetPos ()
        $WinPos = WinGetPos ("Analog Clock")
        $PosDiff[0] = $WinPos[0] - $MousePos[0]
        $PosDiff[1] = $WinPos[1] - $MousePos[1]
        If _IsPressed ("01", $user32_dll) Then
            While _IsPressed ("01", $user32_dll)
                $MousePos = MouseGetPos ()
                WinMove ("Analog Clock", "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])
                $WinPos = WinGetPos ("Analog Clock")
                If ($WinPos[0] < -10) Or ($WinPos[1] < -10) Or ($WinPos[0] + $WinPos[2] > @DesktopWidth + 10) Or _
                    ($WinPos[1] + $WinPos[3] > @DesktopHeight + 10) Then
                    CheckClockStuff(2)
                Else
                    CheckClockStuff()
                EndIf
                Sleep (10)
            WEnd
            ExitLoop
        EndIf
        CheckClockStuff()
        Sleep (10)
    WEnd
    ToolTip ("")
    GUISetCursor ()
    AllThatGoodStuff(2)
EndFunc

Func ToggleOnTop()
    $OnTop = Not $OnTop
    WinSetOnTop ("Analog Clock", "", $OnTop)
    If $OnTop Then
        GUICtrlSetState ($MenuItemOnTop, $GUI_CHECKED)
        TrayItemSetState ($TrayItemOnTop, $TRAY_CHECKED)
    Else
        GUICtrlSetState ($MenuItemOnTop, $GUI_UNCHECKED)
        TrayItemSetState ($TrayItemOnTop, $TRAY_UNCHECKED)
    EndIf
EndFunc

Func CheckClockStuff($special = 0)
    If Not WinActive ("Analog Clock") Then $ClockActive = 0
    If WinActive ("Analog Clock") And $ClockActive = 0 Then
        AllThatGoodStuff(2)
        $ClockActive = 1
    EndIf
    If $Sec <> @SEC Then
        AllThatGoodStuff($special)
    EndIf
    If $AlarmStatus[$AlarmStatus[2]] And $WaitingForMin = 0 Then
        If $AlarmTime[0] = "One Date" Then
            If @YEAR = $AlarmTime[6] And @MON = $AlarmTime[4] And @MDAY = $AlarmTime[5] And _ 
                @MIN = $AlarmTime[2] Then
                CheckTheHour()
            EndIf
        ElseIf $AlarmTime[0] = "Weekdays" Then
            If _DateToDayOfWeekSpecial (@YEAR, @MON, @MDAY) <= 4 And @MIN = $AlarmTime[2] Then
                CheckTheHour()
            EndIf
        ElseIf $AlarmTime[0] = "Weekends" Then
            If _DateToDayOfWeekSpecial (@YEAR, @MON, @MDAY) > 4 And @MIN = $AlarmTime[2] Then
                CheckTheHour()
            EndIf
        Else
            If @MIN = $AlarmTime[2] Then
                CheckTheHour()
            EndIf
        EndIf
    EndIf
    If $WaitingForMin = 1 And $AlarmTime[2] <> @MIN Then $WaitingForMin = 0
EndFunc

Func CheckTheHour()
    If $AlarmTime[3] = "AM" Then
        If Number ($AlarmTime[1]) = Number (@HOUR) Then
            IGuessItsAlarmTime()
        ElseIf $AlarmTime[1] = "12" And @HOUR = "00" Then
            IGuessItsAlarmTime()
        EndIf
    Else
        If Number ($AlarmTime[1]) = Number (@HOUR - 12) Then
            IGuessItsAlarmTime()
        ElseIf $AlarmTime[1] = "12" And @HOUR = "12" Then
            IGuessItsAlarmTime()
        EndIf
    EndIf
EndFunc

Func Set_About()
    Opt ("GUIOnEventMode", 0)
    $GUI_About = GUICreate ("About", 200, 100, Default, Default, $WS_CAPTION, $WS_EX_TOPMOST)
    GUICtrlCreateLabel ("Analog Clock, Version " & $ver & @CRLF & @CRLF & "By greenmachine", 60, 10)
    GUICtrlCreateIcon ("shell32.dll", 221, 10, 10)
    $GUI_About_OK = GUICtrlCreateButton ("OK", 63, 67, 75, 23)
    GUICtrlSetState ($GUI_About_OK, $GUI_FOCUS)
    GUISetState ()
    While 1
        $msg = GUIGetMsg ()
        Switch $msg
            Case $GUI_EVENT_CLOSE, $GUI_About_OK
                GUIDelete ($GUI_About)
                ExitLoop
        EndSwitch
        CheckClockStuff(2)
    WEnd
    Opt ("GUIOnEventMode", 1)
EndFunc

Func Set_Trans()
    Opt ("GUIOnEventMode", 0)
    $GUI_Trans = GUICreate ("Set Analog Clock Transparency", 300, 100)
    $GUI_Trans_Slider = GUICtrlCreateSlider (10, 10, 290, 35)
    GUICtrlSetLimit ($GUI_Trans_Slider, 100, 0)
    GUICtrlSetData ($GUI_Trans_Slider, $WinTrans)
    $GUI_Trans_OK = GUICtrlCreateButton ("OK", 100, 60, 100, 25)
    GUISetState ()
    While 1
        $msg = GUIGetMsg ()
        Switch $msg
            Case $GUI_EVENT_CLOSE, $GUI_Trans_OK
                $WinTrans = GUICtrlRead ($GUI_Trans_Slider)
                GUIDelete ($GUI_Trans)
                ExitLoop
        EndSwitch
        WinSetTrans ($GUI_Clock, "", (100 - GUICtrlRead ($GUI_Trans_Slider))*2.5)
        CheckClockStuff(2)
    WEnd
    Opt ("GUIOnEventMode", 1)
EndFunc

Func ToggleAlarm()
    $AlarmStatus[2] = Not $AlarmStatus[2]
    GUICtrlSetData ($MenuItemAlarmStatus, "Alarm is: " & $AlarmStatus[$AlarmStatus[2]])
    TrayItemSetText ($TrayItemAlarmStatus, "Alarm is: " & $AlarmStatus[$AlarmStatus[2]])
EndFunc

Func SetAlarm()
    Local $GUI_Alarm, $GUI_Alarm_AMPM, $GUI_Alarm_Cal, $GUI_Alarm_Dates[4], $GUI_Alarm_Hour
    Local $GUI_Alarm_Min, $GUI_Alarm_SetAlarm
    Opt ("GUIOnEventMode", 0)
    $GUI_Alarm = GUICreate ("Set Alarm", 310, 290)
    GUICtrlCreateGroup ("Alarm Time", 5, 5, 210, 45)
    GUICtrlCreateGroup ("Date", 5, 60, 210, 190)
    GUICtrlCreateGroup ("Options", 220, 5, 85, 140)
    $GUI_Alarm_Hour = GUICtrlCreateCombo ("", 10, 22, 48, 20)
    GUICtrlCreateLabel (":", 67, 22)
    GUICtrlSetFont (-1, 12, 700)
    $GUI_Alarm_Min = GUICtrlCreateCombo ("", 80, 22, 48, 20)
    $GUI_Alarm_AMPM = GUICtrlCreateCombo ("", 160, 22, 48, 20)
    GUICtrlSetData ($GUI_Alarm_Hour, "1|2|3|4|5|6|7|8|9|10|11|12", $AlarmTime[1])
    GUICtrlSetData ($GUI_Alarm_Min, "00|01|02|03|04|05|06|07|08|09|")
    For $i = 10 To 58
        GUICtrlSetData ($GUI_Alarm_Min, $i & "|")
    Next
    GUICtrlSetData ($GUI_Alarm_Min, "59", $AlarmTime[2])
    GUICtrlSetData ($GUI_Alarm_AMPM, "AM|PM", $AlarmTime[3])
    
    $GUI_Alarm_Cal = GUICtrlCreateMonthCal ("", 10, 77, 200, 165)
    
    $GUI_Alarm_Dates[0] = GUICtrlCreateRadio ("Daily", 230, 20)
    $GUI_Alarm_Dates[1] = GUICtrlCreateRadio ("Weekdays", 230, 45)
    $GUI_Alarm_Dates[2] = GUICtrlCreateRadio ("Weekends", 230, 70)
    $GUI_Alarm_Dates[3] = GUICtrlCreateRadio ("One Date", 230, 95)
    $GUI_Alarm_SaveAlarm = GUICtrlCreateCheckbox ("Save Alarm", 230, 120)
    For $i = 0 To 3
        $GUI_Alarm_RadioText = GUICtrlRead ($GUI_Alarm_Dates[$i], 1)
        If $AlarmTime[0] = $GUI_Alarm_RadioText[0] Then
            GUICtrlSetState ($GUI_Alarm_Dates[$i], $GUI_CHECKED)
            ExitLoop
        EndIf
    Next
    If BitAND (GUICtrlRead ($GUI_Alarm_Dates[3]), $GUI_CHECKED) <> $GUI_CHECKED Then
        GUICtrlSetState ($GUI_Alarm_Cal, $GUI_DISABLE)
    EndIf
    If $AlarmSave[2] Then GUICtrlSetState ($GUI_Alarm_SaveAlarm, $GUI_CHECKED)
    $GUI_Alarm_SetAlarm = GUICtrlCreateButton ("Set Alarm", 110, 255, 90, 30)
    GUISetState ()
    While 1
        $msg = GUIGetMsg ()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                GUIDelete ($GUI_Alarm)
                ExitLoop
            Case $GUI_Alarm_Dates[3]
                GUICtrlSetState ($GUI_Alarm_Cal, $GUI_ENABLE)
            Case $GUI_Alarm_Dates[0], $GUI_Alarm_Dates[1], $GUI_Alarm_Dates[2]
                GUICtrlSetState ($GUI_Alarm_Cal, $GUI_DISABLE)
            Case $GUI_Alarm_SetAlarm
                For $i = 0 To 3
                    If BitAND (GUICtrlRead ($GUI_Alarm_Dates[$i]), $GUI_CHECKED) = $GUI_CHECKED Then
                        $GUI_Alarm_RadioText = GUICtrlRead ($GUI_Alarm_Dates[$i], 1)
                        $AlarmTime[0] = $GUI_Alarm_RadioText[0]
                        $AlarmTime[1] = GUICtrlRead ($GUI_Alarm_Hour)
                        $AlarmTime[2] = GUICtrlRead ($GUI_Alarm_Min)
                        $AlarmTime[3] = GUICtrlRead ($GUI_Alarm_AMPM)
                        If $i = 3 Then
                            $GUI_Alarm_MonthCalDate = StringSplit (GUICtrlRead ($GUI_Alarm_Cal), "/")
                            $AlarmTime[4] = $GUI_Alarm_MonthCalDate[2]
                            $AlarmTime[5] = $GUI_Alarm_MonthCalDate[3]
                            $AlarmTime[6] = $GUI_Alarm_MonthCalDate[1]
                        EndIf
                        ExitLoop
                    EndIf
                Next
                $WaitingForMin = 0
                $AlarmStatus[2] = 0
                ToggleAlarm()
                If GUICtrlRead ($GUI_Alarm_SaveAlarm) = $GUI_CHECKED Then
                    $AlarmSave[2] = 0
                Else
                    $AlarmSave[2] = 1
                EndIf
                ToggleSave()
                GUIDelete ($GUI_Alarm)
                If $AlarmTime[0] = "One Date" Then
                    GUICtrlSetData ($MenuItemAlarmTime, $AlarmTime[1] & ":" & $AlarmTime[2] & " " & _ 
                    $AlarmTime[3] & " on " & $AlarmTime[4] & "/" & $AlarmTime[5] & "/" & $AlarmTime[6])
                Else
                    GUICtrlSetData ($MenuItemAlarmTime, $AlarmTime[0] & " at " & $AlarmTime[1] & ":" & $AlarmTime[2] & " " & $AlarmTime[3])
                EndIf
                ExitLoop
        EndSwitch
        CheckClockStuff(2)
    WEnd
    Opt ("GUIOnEventMode", 1)
EndFunc

Func IGuessItsAlarmTime()
    $WaitingForMin = 1
    For $i = 1 To 10
        Beep (400, 500)
        $Timer = TimerInit()
        AllThatGoodStuff(2)
        If TimerDiff ($Timer) < 250 Then
            Sleep (300 - TimerDiff ($Timer))
        EndIf
    Next
EndFunc

Func ToggleSave()
    $AlarmSave[2] = Not $AlarmSave[2]
    GUICtrlSetData ($MenuItemSaveAlarm, "Save Alarm: " & $AlarmSave[$AlarmSave[2]])
    TrayItemSetText ($TrayItemSaveAlarm, "Save Alarm: " & $AlarmSave[$AlarmSave[2]])
    If $AlarmSave[2] Then
        IniWrite ($INI, "Alarm", "Dates", $AlarmTime[0])
        IniWrite ($INI, "Alarm", "Hour", $AlarmTime[1])
        IniWrite ($INI, "Alarm", "Min", $AlarmTime[2])
        IniWrite ($INI, "Alarm", "AMPM", $AlarmTime[3])
        IniWrite ($INI, "Alarm", "Month", $AlarmTime[4])
        IniWrite ($INI, "Alarm", "Day", $AlarmTime[5])
        IniWrite ($INI, "Alarm", "Year", $AlarmTime[6])
    Else
        If FileExists ($INI) Then FileDelete ($INI)
    EndIf
EndFunc

Func _DateToDayOfWeekSpecial($iYear, $iMonth, $iDay)
    Local $i_aFactor, $i_yFactor, $i_mFactor, $i_dFactor
    $i_aFactor = Int((14 - $iMonth) / 12)
    $i_yFactor = $iYear - $i_aFactor
    $i_mFactor = $iMonth + (12 * $i_aFactor) - 2
    $i_dFactor = Mod($iDay + $i_yFactor + Int($i_yFactor / 4) - Int($i_yFactor / 100) + Int($i_yFactor / 400) + Int((31 * $i_mFactor) / 12), 7)
    If $i_dFactor >= 1 Then Return $i_dFactor - 1
    Return 6
EndFunc; _DateToDayOfWeekISO all-in-one

Func quitme()
    Exit
EndFunc

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

;~ Func ChangeFaceColor()
;~ Opt("GUIOnEventMode", 0)
;~;#include <GUIConstants.au3>
;~ $ColorPicker = GUICreate("Face Color Chooser", 579, 200, 192, 125)
;~ GUISetBkColor(0xF1EFE2)
;~ $color1 = GUICtrlCreateLabel("", 24, 16, 84, 84)
;~ GUICtrlSetBkColor(-1, 0xF1EFE2)
;~ $choose1 = 3
;~ GUICtrlSetBkColor(-1, 0xF1EFE2)
;~ $input1 = GUICtrlCreateInput("", 24, 105, 84, 21, -1)
;~ GUICtrlCreateLabel("Red", 116, 15, 24, 17)
;~ GUICtrlSetBkColor(-1, 0xF1EFE2)
;~ GUICtrlCreateLabel("Green", 116, 39, 33, 17)
;~ GUICtrlSetBkColor(-1, 0xF1EFE2)
;~ GUICtrlCreateLabel("Blue", 116, 63, 25, 17)
;~ GUICtrlSetBkColor(-1, 0xF1EFE2)
;~ $Red = GUICtrlCreateSlider(156, 15, 370, 21)
;~ GUICtrlSetLimit(-1,255,0)
;~ $r = GUICtrlCreateLabel("",530,15,20,20)
;~ $Green = GUICtrlCreateSlider(156, 39, 370, 21)
;~ GUICtrlSetLimit(-1,255,0)
;~ $g = GUICtrlCreateLabel("",530,39,20,20)
;~ $Blue = GUICtrlCreateSlider(156, 63, 370, 21)
;~ GUICtrlSetLimit(-1,255,0)
;~ $b = GUICtrlCreateLabel("",530,63,20,20)
;~ $ok = GUICtrlCreateButton("OK",24,136,84,42)
;~ GUISetState(@SW_SHOW)
;~ Red()
;~ Green()
;~ Blue()
;~ WHile 1
;~ $msg = GUIGetMsg()
;~ If $msg = $Red Then
;~   AdlibEnable("Red",150)
;~ ElseIf $msg = $Green Then
;~   AdlibEnable("Green",150)
;~ ElseIf $msg = $Blue Then
;~   AdlibEnable("Blue",150)
;~ EndIf
;~ If $msg = $GUI_EVENT_CLOSE Then 
;~   $facecolor = GUICtrlRead($input1)
;~   MsgBox(1,"$facecolor",$facecolor)
;~;WinClose("Face Color Chooser")
;~  Exit
;~ EndIf
;~ If $msg = $ok Then
;~   $facecolor = GUICtrlRead($input1)
;~;MsgBox(1,"$facecolor",$facecolor)
;~;Exit
;~  GUISetState(@SW_HIDE,$ColorPicker)
;~  GUISwitch($GUI_Clock)
;~  GUISetState(@SW_SHOW,$GUI_Clock)
;~  Opt("GUIOnEventMode", 1)
;~   GUISetBkColor ($facecolor)
;~   $rgb2bgr = "0x00" & StringRight($facecolor,2) & StringMid($facecolor,5,2) & StringMid($facecolor,3,2)
;~;MsgBox(1,"$rgb2bgr",$rgb2bgr)
;~;AllThatGoodStuff(1)
;~  CheckClockStuff(1)
;~   $BkgrndPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", $rgb2bgr); small background pen
;~   $BackgroundPens[0] = $BkgrndPen[0]
;~   $BkgrndPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "2", "hwnd", $rgb2bgr); medium background pen
;~   $BackgroundPens[1] = $BkgrndPen[0]
;~   $BkgrndPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "3", "hwnd", $rgb2bgr); large background pen
;~   $BackgroundPens[2] = $BkgrndPen[0]
;~  ExitLoop
;~ EndIf
;~   GUICtrlSetBkColor($color1,"0x" & Hex(GUICtrlRead($Red),2) & Hex(GUICtrlRead($Green),2) & Hex(GUICtrlRead($Blue),2))    
;~   GUICtrlSetData($input1,"0x" & Hex(GUICtrlRead($Red),2) & Hex(GUICtrlRead($Green),2) & Hex(GUICtrlRead($Blue),2))
;~ WEnd
;~;Sleep (10)
;~;GUISetCursor ()
;~;Return $facecolor
;~ EndFunc


Func ChangeFaceColor()
$facecolor = _ChooseColor(2)
;GUISetBkColor($dColor)
;MsgBox(1,"$dColor",$facecolor) 
    GUISwitch($GUI_Clock)
    GUISetState(@SW_SHOW,$GUI_Clock)
    Opt("GUIOnEventMode", 1)
    GUISetBkColor ($facecolor)
    $rgb2bgr = "0x00" & StringRight($facecolor,2) & StringMid($facecolor,5,2) & StringMid($facecolor,3,2)
  ;MsgBox(1,"$rgb2bgr",$rgb2bgr)
  ;AllThatGoodStuff(1)
    CheckClockStuff(1)
    $BkgrndPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "0", "hwnd", $rgb2bgr); small background pen
    $BackgroundPens[0] = $BkgrndPen[0]
    $BkgrndPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "2", "hwnd", $rgb2bgr); medium background pen
    $BackgroundPens[1] = $BkgrndPen[0]
    $BkgrndPen = DllCall ($gdi_dll, "hwnd", "CreatePen", "int", "0", "int", "3", "hwnd", $rgb2bgr); large background pen
    $BackgroundPens[2] = $BkgrndPen[0]
  ;GUICtrlSetBkColor($color1,"0x" & Hex(GUICtrlRead($Red),2) & Hex(GUICtrlRead($Green),2) & Hex(GUICtrlRead($Blue),2))  
  ;GUICtrlSetData($input1,"0x" & Hex(GUICtrlRead($Red),2) & Hex(GUICtrlRead($Green),2) & Hex(GUICtrlRead($Blue),2))
EndFunc
Edited by jefhal
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

  • Replies 58
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

man post your code with

thats too long

--------------------------------------------------------------------------------------------------------------------------------Scripts : _Encrypt UDF_UniquePCCode UDF MS like calculatorInstall programm *UPDATED* --------------------------------------------------------------------------------------------------------------------------------[quote name='Helge' post='213117' date='Jul 26 2006, 10:22 AM']Have you ever tried surfing the internet with a milk-carton ?This is similar to what you're trying to do.[/quote]

Link to comment
Share on other sites

name='Daniel W.' post='192202' date='Jun 4 2006, 12:32 PM']man post your code with

thats too long

Hi Daniel W.

I tried using the -autoit- and -/autoit- tags, but unfortunately, if I use those and someone tries to copy and paste my code, they end up with NO cr's or lf's. The code comes into Scite or Notepad as ONE LONNNNNNG line. I don't know if this is a bug only on my machine or widespread. I use IE7 with Slimbrowser, AutoIT beta 125 and the Scite that came with beta 125. jefhal

Edited by jefhal
...by the way, it's pronounced: "JIF"... Bob Berry --- inventor of the GIF format
Link to comment
Share on other sites

@mr.underperson - Click+Drag to move, Ctrl+Click+Drag to resize, maybe Alt+Click+Drag to change transparency? I could do that with Larry's Mouse Hook dll... but if there's a way to do it without relying on third-party scripts I'd really like to know. INI saving is a piece of cake, I agree. I'll get to that too.

Here is simple code for Drag functionality:

Global Const $GUI_EVENT_PRIMARYDOWN     = -7
Global Const $HTCAPTION = 2
Global Const $WM_NCLBUTTONDOWN = 0xA1

GUISetOnEvent ($GUI_EVENT_PRIMARYDOWN, "Drag" )

Func Drag()
    dllcall("user32.dll","int","ReleaseCapture")
    dllcall("user32.dll","int","SendMessage","hWnd", $GUI_Clock ,"int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0)
EndFunc

Note: GUISetOnEvent() must be right after GUICreate

Really nice clock :D

EDIT: All your painting stuff could be mapped via GUIRegisterMsg to WM_DRAW or WM_PAINT message and then will not be any problem with (not) repainting of ticks when clock is not active and under another app

Edited by Zedna
Link to comment
Share on other sites

I made an analog clock. You know, the one with the hands that move? It has numbers, minute marks, and hands, plus a few colors. I still need to figure out how to add a border to it, and how to interact with the window.

greenmachine,

Thanks for a great clock and for giving me an idea on how to teach a 5-year-old how to tell time.

I would like to add funcitionality to your clock that would allow a user to click a button that would speak the time (in hours and minutes) and show it at the same time in digital form for about 4 or 5 seconds.

Talking clocks are available, but I like yours using AutoIt.

This should not be hard to do.

I will post the additions when I create them, but I am pretty busy right now.

Thanks again.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to comment
Share on other sites

Created a quick digital clock based off the one in my room. It's really simplified right now, but I plan to combine it with the analog clock and have both work together. The alarm notification doesn't do anything right now because there is no alarm attached to it (it is on the analog clock).

Global Const $SS_RIGHT = 2

HotKeySet ("{SPACE}", "SpeakTime")

Global $Mid = 300, $MidStep = $Mid/3, $Alarm_OnOff = 0, $IsMilitary = 0
Global $Digital_Clock, $Alarm_Text, $PM_Text, $Military_Text, $Alarm_Light, $PM_Light, $Military_Light
Global $Time_TensHours, $Time_Hours, $Time_Colon, $Time_TensMins, $Time_Minutes, $Hour, $Min
$Digital_Clock = GUICreate ("Digital Clock", $Mid*2, 90, 100, 100, 0x80000000)
GUISetBkColor (0x000000)

$Alarm_Text = GUICtrlCreateLabel ("Alarm", 5, 10, 30, -1, $SS_RIGHT)
GUICtrlSetColor (-1, 0xFFFFFF)

$PM_Text = GUICtrlCreateLabel ("PM", 5, 40, 30, -1, $SS_RIGHT)
GUICtrlSetColor (-1, 0xFFFFFF)

$Military_Text = GUICtrlCreateLabel ("Military", 2, 70, 33, -1, $SS_RIGHT)
GUICtrlSetColor (-1, 0xFFFFFF)

GUISetFont (10, Default, Default, "Wingdings")
$Alarm_Light = GUICtrlCreateLabel ("l", 40, 10)
GUICtrlSetColor (-1, $Alarm_OnOff * 0xFF0000)

$PM_Light = GUICtrlCreateLabel ("l", 40, 40)
GUICtrlSetColor (-1, IsPM($IsMilitary) * 0xFF0000)

$Military_Light = GUICtrlCreateLabel ("l", 40, 70)
GUICtrlSetColor (-1, $IsMilitary * 0xFF0000)

GUISetFont (60, 400, Default, "Lucida Console")
$Time_TensHours = GUICtrlCreateLabel (GetTensHours($IsMilitary), $MidStep, 10)
GUICtrlSetColor (-1, GetTensHoursColor($IsMilitary))

$Time_Hours = GUICtrlCreateLabel (GetHours($IsMilitary), $MidStep*2, 10)
GUICtrlSetColor (-1, 0xFF0000)
$Time_Colon = GUICtrlCreateLabel (":", $MidStep*3, 5)
GUICtrlSetColor (-1, 0xFF0000)
$Time_TensMins = GUICtrlCreateLabel (Int (@MIN/10), $MidStep*4, 10)
GUICtrlSetColor (-1, 0xFF0000)
$Time_Minutes = GUICtrlCreateLabel (@MIN - Int (@MIN/10)*10, $MidStep*5, 10)
GUICtrlSetColor (-1, 0xFF0000)

GUISetState ()

$Hour = @HOUR
$Min = @MIN

While 1
    If @HOUR <> $Hour Then
        GUICtrlSetColor ($PM_Light, IsPM($IsMilitary) * 0xFF0000)
        GUICtrlSetData ($Time_TensHours, GetTensHours($IsMilitary))
        GUICtrlSetColor (-1, GetTensHoursColor($IsMilitary))
        GUICtrlSetData ($Time_Hours, GetHours($IsMilitary))
        GUICtrlSetColor (-1, 0xFF0000)
        $Hour = @HOUR
    EndIf
    If @MIN <> $Min Then
        GUICtrlSetData ($Time_TensMins, Int (@MIN/10))
        GUICtrlSetColor (-1, 0xFF0000)
        GUICtrlSetData ($Time_Minutes, @MIN - Int (@MIN/10)*10)
        GUICtrlSetColor (-1, 0xFF0000)
        $Min = @MIN
    EndIf
    Sleep (100)
WEnd

Func GetTensHours($MilitaryTime = 0)
    If @HOUR = "00" And Not $MilitaryTime Then Return 1
    If $MilitaryTime Or @HOUR <= 12 Then Return Int (@HOUR/10)
    Return Int ((@HOUR-12)/10)
EndFunc

Func GetHours($MilitaryTime = 0)
    If @HOUR = "00" Then Return 2
    If $MilitaryTime Or @HOUR <= 12 Then Return @HOUR - Int (@HOUR/10)*10
    Return @HOUR - Int ((@HOUR-12)/10)*10 - 12
EndFunc

Func GetTensHoursColor($MilitaryTime = 0)
    If $MilitaryTime Then Return 0xFF0000
    If GetTensHours(0) = 0 Then Return 0x000000
    Return 0xFF0000
EndFunc

Func IsPM($MilitaryTime = 0)
    If $MilitaryTime Then Return 0
    If @HOUR >= 12 Then Return 1
    Return 0
EndFunc

Func SpeakTime()
    Local $o_speech = ObjCreate("SAPI.SpVoice")
    If $IsMilitary Then
        $o_speech.Speak ("The time is " & @HOUR & @MIN)
    Else
        If @HOUR > 12 Then
            If @MIN = "00" Then
                $o_speech.Speak ("The time is " & @HOUR-12 & " O'Clock P M")
            Else
                $o_speech.Speak ("The time is " & @HOUR-12 & " " & @MIN & " P M")
            EndIf
        ElseIf @HOUR = "00" Then
            If @MIN = "00" Then
                $o_speech.Speak ("The time is 12 O'Clock A M")
            Else
                $o_speech.Speak ("The time is 12 " & @MIN & " A M")
            EndIf
        Else
            If @MIN = "00" Then
                $o_speech.Speak ("The time is " & @HOUR & " O'Clock A M")
            Else
                $o_speech.Speak ("The time is " & @HOUR & " " & @MIN & " A M")
            EndIf
        EndIf
    EndIf
    $o_speech = 0
EndFunc
Link to comment
Share on other sites

Created a quick digital clock based off the one in my room. It's really simplified right now, but I plan to combine it with the analog clock and have both work together. The alarm notification doesn't do anything right now because there is no alarm attached to it (it is on the analog clock).

greenmachine,

I like the direction you're going with your Analog/Digital Clock.

Keep up the good work. I look forward to seeing future version.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to comment
Share on other sites

Hi Daniel W.

I tried using the -autoit- and -/autoit- tags, but unfortunately, if I use those and someone tries to copy and paste my code, they end up with NO cr's or lf's. The code comes into Scite or Notepad as ONE LONNNNNNG line. I don't know if this is a bug only on my machine or widespread. I use IE7 with Slimbrowser, AutoIT beta 125 and the Scite that came with beta 125. jefhal

I just tried and i have the same problem. IE 6.0 to the latest SciTe.

Link to comment
Share on other sites

Hi Daniel W.

I tried using the -autoit- and -/autoit- tags, but unfortunately, if I use those and someone tries to copy and paste my code, they end up with NO cr's or lf's. The code comes into Scite or Notepad as ONE LONNNNNNG line. I don't know if this is a bug only on my machine or widespread. I use IE7 with Slimbrowser, AutoIT beta 125 and the Scite that came with beta 125. jefhal

@jefhal and @Manadar,

I had the same problem and was given the answer by RazerM.

If you see a script with the scrool, it was made with the -autoit- and -/autoit- tags.

Copy the code and paste it into Wordpad. Then copy that code and paste it into Scite or Notepad or whatever editor you use.

I always used Notepad to strip rich text, but didn't realize that Wordpad would add cr's or lf's.

I love this forum. I learn something everyday. It is a great positive environment of users.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to comment
Share on other sites

  • 1 month later...
Guest Beefteck

every time i try this i get an error saying "Case "sec" Case must be followed by a select statement i know wut it is but i can not find where the error is because of how long the file is...

Link to comment
Share on other sites

very nice!

10/10 :D

..maybe add some skins?

Also could you hide it from the taskbar? For full time use that can get kind of annoying/take up space.

Edited by B3TA_SCR1PT3R

[right][font="Courier New"]...Run these streets all day, I can sleep when I die.[/font] [/right]

Link to comment
Share on other sites

What a great clock!. well done to all involved.

Ttried to compile it and got a load of errors - realised I needed the beta...

Latest beta 3.1.1.131 causes a problem for the alarm function, seems the change to GUICtrlRead() has messed up the script.

Not sure if the script or auotIT beta needs a change... My guess is the script

Link to comment
Share on other sites

every time i try this i get an error saying "Case "sec" Case must be followed by a select statement i know wut it is but i can not find where the error is because of how long the file is...

Beefteck,

I get the same error if I try to run this script without using Beta.

I suggest you download Beta and try to run it again.

taurus905

"Never mistake kindness for weakness."-- Author Unknown --"The highest point to which a weak but experienced mind can rise is detecting the weakness of better men."-- Georg Lichtenberg --Simple Obfuscator (Beta not needed.), Random names for Vars and Funcs

Link to comment
Share on other sites

  • 7 months later...

Wow! it wery cool clock!

But when i trying to set the alarm, there is an error:

(496) : ==> Subscript used with non-Array variable.: 
If $AlarmTime[0] = $GUI_Alarm_RadioText[0] Then 
If $AlarmTime[0] = $GUI_Alarm_RadioText^ ERROR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 6 months later...

it would be nice if it could remember the last size it was when it was closed and open as that size the next time it opened, and a start with windows function would be cool too. Also, you can use my GuiPosition.au3 UDFs to have it start in the same location it was closed in:

http://www.autoitscript.com/forum/index.ph...;hl=guiposition

Nonetheless, very nice clock!

Edited by maqleod
[u]You can download my projects at:[/u] Pulsar Software
Link to comment
Share on other sites

This is awesome! Very good job. I love the job you did with the GUI and all the features.

It would be cool to use the exstyle $WS_EX_TOOLWINDOW so it doesn't show in the task bar.

I also get that error when trying to set up the alarm.

Link to comment
Share on other sites

This is awesome! Very good job. I love the job you did with the GUI and all the features.

It would be cool to use the exstyle $WS_EX_TOOLWINDOW so it doesn't show in the task bar.

I also get that error when trying to set up the alarm.

Nahuel, check my link.

[edit: maqleod too!]

;o)

(or

Edited by corz

nothing is foolproof to the sufficiently talented fool..

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