 |

08-14-2002, 04:21 AM
|
|
|
Analog Clock
|
Hi,
i have some limited experience in VB, i am interested in making an analog clock for my desktop.
i havent got a clue how?
i'll real appreciate, if any one could give some suggestions.
thanks in advance.
Ali
|
|

08-14-2002, 05:34 AM
|
 |
Gaming God
Retired Leader * Expert *
|
|
Join Date: Feb 2002
Location: Brisbane, Australia
Posts: 2,363
|
|
__________________
. <--- Photo of me viewed from the Hubble telescope
|

08-14-2002, 07:52 AM
|
 |
Ultimate Contributor
* Guru *
|
|
Join Date: Sep 2001
Location: Dublin, Ireland
Posts: 1,828
|
|
|

08-14-2002, 08:30 AM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
An anologue clock is a good simple application to make. A timer control and a bit of smart math is all it takes. You could create a small form and then use SetWindowPos API to make it float on top of all other windows.

|
|

08-14-2002, 09:19 AM
|
|
Just another Excel nerd
Retired Moderator * Guru *
|
|
Join Date: Feb 2000
Location: Michigan, USA
Posts: 2,624
|
|
__________________
"The face of a child can say it all, especially the mouth part of the face." - Jack Handey
|

08-14-2002, 09:26 AM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Okay, I just couldn't resist. Here's the code to be put into a form. Add 3 line controls and a timer control to the form.
Code:
Option Explicit
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Const HWND_TOPMOST = -1
Const SWP_NOMOVE = &H2
Const SWP_NOSIZE = &H1
Const MYHOUR As Double = 1 / 24
Const MYMIN As Double = MYHOUR / 60
Const MYSEC As Double = MYMIN / 60
Const PI As Double = 3.14159276
Const RAD As Double = PI / 180
Dim CentreX As Single, CentreY As Single
Dim Radius As Single
Private Sub Form_Load()
Timer1_Timer
Me.Show
Me.DrawWidth = 1
SetWindowPos Me.hwnd, HWND_TOPMOST, 0&, 0&, 0&, 0&, SWP_NOMOVE Or SWP_NOSIZE
End Sub
Private Sub Form_Paint()
If Me.WindowState = vbMinimized Then Exit Sub
CentreX = Me.ScaleWidth / 2
CentreY = Me.ScaleHeight / 2
If Me.ScaleWidth < Me.ScaleHeight Then
Radius = (Me.ScaleWidth - 30) / 2
Else
Radius = (Me.ScaleHeight - 30) / 2
End If
Me.Cls
Me.Circle (CentreX, CentreY), Radius
Dim i As Integer
Dim iRad As Integer
For i = 0 To 359 Step 6
If i Mod 5 Then iRad = Radius / 80 Else iRad = Radius / 35
Me.Circle (CentreX + Sin(i * RAD) * (Radius / 1.1), CentreY + Cos(i * RAD) * (Radius / 1.1)), iRad
Next i
End Sub
Private Sub Form_Resize()
Form_Paint
End Sub
Private Sub Timer1_Timer()
Dim dTime As Double
Dim X As Single, Y As Single
Dim Angle As Single
dTime = Time
If dTime > 0.5 Then dTime = dTime - 0.5
Angle = ((dTime / MYHOUR) * (PI / 6)) - PI / 2
X = (Cos(Angle) * (Radius / 1.5)) + CentreX
Y = (Sin(Angle) * (Radius / 1.5)) + CentreY
Line1.X1 = CentreX
Line1.Y1 = CentreY
Line1.X2 = X
Line1.Y2 = Y
dTime = (Minute(Time) * MYMIN) + (Second(Time) * MYSEC)
Angle = ((dTime / MYMIN) * (PI / 30)) - PI / 2
X = (Cos(Angle) * (Radius / 1.2)) + CentreX
Y = (Sin(Angle) * (Radius / 1.2)) + CentreY
Line2.X1 = CentreX
Line2.Y1 = CentreY
Line2.X2 = X
Line2.Y2 = Y
dTime = Second(Time) * MYSEC
Angle = ((dTime / MYSEC) * (PI / 30)) - PI / 2
X = (Cos(Angle) * Radius) + CentreX
Y = (Sin(Angle) * Radius) + CentreY
Line3.X1 = CentreX
Line3.Y1 = CentreY
Line3.X2 = X
Line3.Y2 = Y
End Sub
|
|

08-14-2002, 09:28 AM
|
|
Just another Excel nerd
Retired Moderator * Guru *
|
|
Join Date: Feb 2000
Location: Michigan, USA
Posts: 2,624
|
|
|
Since when can you define constants with equations?
|
__________________
"The face of a child can say it all, especially the mouth part of the face." - Jack Handey
|

08-14-2002, 09:31 AM
|
 |
Political Coder
Retired Moderator * Guru *
|
|
Join Date: Mar 2001
Location: London, England
Posts: 8,037
|
|
Since...... forever. As long as the constant doesnt involve a function call, then it's fine. 
|
|

08-14-2002, 09:33 AM
|
|
Just another Excel nerd
Retired Moderator * Guru *
|
|
Join Date: Feb 2000
Location: Michigan, USA
Posts: 2,624
|
|
|
Hmmmm... I mainly only program with VBA these days, but I didn't think you could do that.
|
__________________
"The face of a child can say it all, especially the mouth part of the face." - Jack Handey
|

08-14-2002, 09:59 AM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
API Windows messages are sometimes defined as "WM_USER + someoffset". There are other examples as well....
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

08-14-2002, 02:05 PM
|
 |
Junior Contributor
|
|
Join Date: Apr 2002
Location: Newcastle
Posts: 289
|
|
love that one you posed squirm - i think i might make my own one to put into my A-level coursework - bit classier ofcourse but prib built on same math 
|
__________________
As technology develops, so does our imagination
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|