|
-
May 4th, 2000, 01:26 AM
#6
Addicted Member
Hey, I just noticed this thread now.
I did something just like this a while ago, so I did some
digging and found the code, so here it is:
Code:
VERSION 5.00
Begin VB.Form frmMain
Caption = "Alarm Clock Test"
ClientHeight = 3195
ClientLeft = 60
ClientTop = 345
ClientWidth = 4680
LinkTopic = "Form1"
ScaleHeight = 3195
ScaleWidth = 4680
StartUpPosition = 2 'CenterScreen
Begin VB.TextBox txtWakeUp
Height = 375
Left = 240
TabIndex = 0
Top = 360
Width = 4215
End
Begin VB.CommandButton cmdStop
Caption = "&Stop"
Height = 495
Left = 1680
TabIndex = 2
Top = 1680
Visible = 0 'False
Width = 1215
End
Begin VB.CommandButton cmdSleep
Caption = "&Sleep"
Default = -1 'True
Height = 495
Left = 1680
TabIndex = 1
Top = 1200
Width = 1215
End
Begin VB.Label lblWakeUp
AutoSize = -1 'True
BackStyle = 0 'Transparent
Caption = "Set Time To Wake Up"
Height = 195
Left = 240
TabIndex = 3
Top = 120
Width = 1605
End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'============================
'=== GENERAL DECLARATIONS ===
'============================
'<<< OPTION STATEMENTS >>>
Option Explicit
'<<< CONSTANTS >>>
Private Const miMAX_DAYS As Integer = 24
Private Const mlMILLISECONDS_IN_SEC As Long = 1000
Private Const mlSECONDS_IN_MIN As Long = 60
Private Const mlMINUTES_IN_HOUR As Long = 60
Private Const mlHOURS_IN_DAY As Long = 24
'<<< ENUMERATIONS >>>
Private Enum eSetWindowPos
SWP_NOSIZE = &H1
SWP_NOMOVE = &H2
SWP_NOZORDER = &H4
SWP_NOREDRAW = &H8
SWP_NOACTIVATE = &H10
SWP_DRAWFRAME = &H20
SWP_SHOWWINDOW = &H40
SWP_HIDEWINDOW = &H80
SWP_NOCOPYBITS = &H100
SWP_NOREPOSITION = &H200
End Enum
Private Enum eZOrder
HWND_TOP = 0
HWND_BOTTOM = 1
HWND_NOTOPMOST = -2
HWND_TOPMOST = -1
End Enum
'<<< API DECLARES >>>
Private Declare Function apiSetForegroundWindow _
Lib "user32" _
Alias "SetForegroundWindow" _
(ByVal hwnd As Long) As Long
Private Declare Function apiSetWindowPos _
Lib "user32" _
Alias "SetWindowPos" _
(ByVal hwnd As Long, ByVal hWndInsertAfter As eZOrder, _
ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, _
ByVal wFlags As eSetWindowPos) As Long
Private Declare Sub apiSleep _
Lib "kernel32" _
Alias "Sleep" _
(ByVal dwMilliseconds As Long)
'<<< VARIABLES >>>
Private mbStopAlarm As Boolean
'========================
'=== EVENT PROCEDURES ===
'========================
Private Sub cmdStop_Click()
mbStopAlarm = True
End Sub
Private Sub cmdSleep_Click()
Dim lSleepTime As Long
mbStopAlarm = False
lSleepTime = mlGetSleepCount(mdtValidateDate(txtWakeUp.Text))
Call Me.Hide
DoEvents
Call apiSleep(lSleepTime)
DoEvents
Call apiSetWindowPos(Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOSIZE Or SWP_NOMOVE Or SWP_SHOWWINDOW)
Call apiSetForegroundWindow(Me.hwnd)
Call mSoundAlarm
End Sub
'==========================
'=== PRIVATE PROCEDURES ===
'==========================
Private Function mdtValidateDate(ByVal vsDate As String) As Date
Dim dtReturnDate As Date
If IsDate(vsDate) = True Then
dtReturnDate = Format$(vsDate, "dd-mmm-yyyy Hh:NnAM/PM")
Else
dtReturnDate = Now
End If
mdtValidateDate = dtReturnDate
End Function
Private Function mlGetSleepCount(ByVal vdtWakeUpTime As Date) As Long
Dim lSeconds As Long
Dim lWakeUpTime As Long
'Maximum size of Long for milliseconds of time difference.
If DateDiff("d", Now, vdtWakeUpTime) < miMAX_DAYS Then
lSeconds = DateDiff("s", Now, vdtWakeUpTime)
If lSeconds > 0 Then
lWakeUpTime = lSeconds * mlMILLISECONDS_IN_SEC
End If
End If
mlGetSleepCount = lWakeUpTime
End Function
Private Sub mSoundAlarm()
cmdSleep.Visible = False
cmdStop.Visible = True
Call cmdStop.SetFocus
Do While mbStopAlarm = False
Beep
DoEvents
Loop
cmdSleep.Visible = True
cmdStop.Visible = False
End Sub
What you do is type in the date and time for the app to
wake up and press the Sleep button. When the time arrives
the app will popup above all windows and begin beeping
until the Stop button is pressed. It will even work through
the Screen Saver.
This was only a test that I did when developing a scheduler,
but it sounds like what you were looking for. You should
probably place the wake up time in the registry and provide
an app to set this time. Then you could put the alarm clock
into the StartUp folder. That way the program could read
the alarm time from the registry when the computer is
turned on and the app would automatically TSR until the
desired alarm time. Also, instead of running the Beep loop
it would be better to play a .wav file looped.
Sorry to come in so late, just wanted to add my 2¢
Dan PM
Analyst Programmer
VB6 SP3 (also VB4 16-bit sometimes  )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|