Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Visual Basic [VB] (http://www.go4expert.com/articles/visual-basic-tutorials/)
-   -   For those Who Like Clocks. : ) (http://www.go4expert.com/articles/clocks-t604/)

Aether 22Feb2006 13:02

For those Who Like Clocks. : )
 
Here is a good code for you all. Toss it in a black form, and make all text lime green. K?
It Is A Big Code. Here Are Your Objects:
8 labels(label1-label8)
3 Timers(timer1-timer3)
and two textboxes(text1 is disabled on formload, please.. :) text2 enabled always....)

--------------------------------------------------------------------------------------
Code: VB

Const LWA_COLORKEY = &H1
Const LWA_ALPHA = &H2
Const GWL_EXSTYLE = (-20)
Const WS_EX_LAYERED = &H80000
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private MouseDownForm
Private MouseDownFormX
Private MouseDownFormY
Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Sub Form_Load()
Timer1.Enabled = True
Label2.Caption = "Turn Off"                                               'You'll Get A Kick Outta The
    Dim Ret As Long                                                           'Form load. its hawt.
    Ret = GetWindowLong(Me.hWnd, GWL_EXSTYLE)
    Ret = Ret Or WS_EX_LAYERED
    SetWindowLong Me.hWnd, GWL_EXSTYLE, Ret
    Me.Width = 0 'Starting Size Can Be Changed To What You Want
    Me.Height = 0
    Me.Move (Screen.Width - Me.Width) \ 2, (Screen.Height - Me.Height) \ 2
    Timer3.Enabled = True

End Sub



Private Sub Label1_Change()           'This is for when the alarm is active.
If Text1.Enabled = True Then
If Label1.Caption = Text1.Text & Text2.Text Then
Timer2.Enabled = True
End If
End If
End Sub

Private Sub Label2_Click()  'Turns off clock. (Label Caption = Turn Off)
If Label2.Caption = "Turn Off" Then
Timer1.Enabled = False
Label3.Caption = "Turn On"
End If
End Sub

Private Sub Label3_Click()           'Turns on clock(Turn On)
If Label2.Caption = "Turn Off" Then
Timer1.Enabled = True
End If

End Sub

Private Sub Label4_Click() (Label caption is Enable Alarm)
Text1.Enabled = True
End Sub

Private Sub Label5_Click()    'Disables alarm caption is Disable Alarm
Timer2.Enabled = False
Text1.Enabled = False
End Sub

Private Sub Label7_Click()    'End Program caption is X
End
End Sub

Private Sub Label8_Click()         ' Minimizes & caption = ____
Form1.WindowState = vbMinimized
End Sub

Private Sub Text1_Click()          'Clears text
Text1.Text = ""
End Sub
Private Sub Text2_Click()     'Changes from AM to PM
Text2.Text = " PM"
End Sub
Private Sub Text2_DblClick()   'Changes from Pm to Am
Text2.Text = " AM"
End Sub
Private Sub Timer1_Timer()    ' Makes label1 show the time
Label1.Caption = Time

End Sub

Private Sub Timer2_Timer()   ' The Alarm
Beep
End Sub
Private Sub form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As     Single)    'Move The Form On Form1_Mousedown
MouseDownForm = 1
MouseDownFormX = X
MouseDownFormY = Y
End Sub
Private Sub form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) ' Ends Moving The Form
MouseDownForm = 0
End Sub
Private Sub form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As  Single)           'More Form movement
If MouseDownForm <> 1 Then
Exit Sub
End If
Dim Z As POINTAPI
Call GetCursorPos(Z)
Form1.Top = (Z.Y * 15) - MouseDownFormY
Form1.Left = (Z.X * 15) - MouseDownFormX
End Sub

Private Sub Form_Activate()    'Form fades into view
Dim Alpha As Byte
Dim Delay As Single
Do
    Delay = Timer
    Do While (Timer - Delay) < 0.01
        DoEvents
    Loop
    Alpha = Alpha + 1
    SetLayeredWindowAttributes Me.hWnd, 0, Alpha, LWA_ALPHA
Loop Until Alpha = 255
End Sub


Private Sub Timer3_Timer()              'Form Sizes up as it loads.
    Me.Height = Me.Height + 18
         Me.Width = Me.Width + 150
    If Me.Width > 6350 Then  'Can be change accordingly
         Timer3.Enabled = False
    End If
    If Me.Height > 1000 Then
    Timer3.Enabled = False
    End If
   
End Sub







I Hope You All Like. : )

shabbir 22Feb2006 14:52

Re: For those Who Like Clocks. : )
 
Moved to VB6 Tutorials and Articles section.

Aether 22Feb2006 15:05

Re: For those Who Like Clocks. : )
 
Sorry... Lol.. Didn't See The Section.. I Guess At this Time Of Night My Eyes Sorta Go All Outta Whack On Me.. Sorta Like Almost Being Blind..... Lol>!
But yah, enjoy : )

shabbir 22Feb2006 22:15

Re: For those Who Like Clocks. : )
 
Quote:

Originally Posted by Aether
Sorry... Lol.. Didn't See The Section.. I Guess At this Time Of Night My Eyes Sorta Go All Outta Whack On Me.. Sorta Like Almost Being Blind..... Lol>!
But yah, enjoy : )

Thats understable by a fellow programmer.

Aether 23Feb2006 06:50

Re: For those Who Like Clocks. : )
 
: )
------------Alas-----------------
-Someone Who Understands-
-That Alone Is Worth 10000--
-Thanks . : P -----------------
----------------------------------

coderzone 23Feb2006 07:02

Re: For those Who Like Clocks. : )
 
Really a nice one.

Saket 21Jul2009 11:59

Re: For those Who Like Clocks. : )
 
Thanks for the code.


All times are GMT +5.5. The time now is 19:06.