用VB6.0写的简单实用的小闹钟,可以指定时间也可以选择倒计时模式,设定时间后即刻生效;倒计时模式设置后点开始.闹钟的声音(beep)默认开启.
下载:小闹钟.rar 程序大小:9K
(.NET本版:Clock.rar 2012-1-31)
最新改动:2009-09-14 增加到时关机功能
更新:以下是vb6.0小闹钟的全部代码
折叠ASP/Visual Basic Code复制内容到剪贴板
- '================================================================
- 'By kfCalf www.spersky.com;勾月http://download.csdn.net/user/gouyue
- '================================================================
- 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 HWND_NOTOPMOST = -2
- Const LWA_ALPHA = &H2&
- Const LWA_COLORKEY = &H1&
- Const GWL_EXSTYLE = (-20)
- Const WS_EX_LAYERED = &H80000
- Const WS_EX_TRANSPARENT = &H20&
- 'icon
- Const MAX_TOOLTIP As Integer = 64
- Const NIF_ICON = &H2 '删除图标
- Const NIF_MESSAGE = &H1
- Const NIF_TIP = &H4
- Const NIM_ADD = &H0 '添加图标到任务栏提示区
- Const NIM_DELETE = &H2
- Const WM_MOUSEMOVE = &H200
- Const WM_LBUTTONDOWN = &H201
- Const WM_LBUTTONUP = &H202
- Const WM_LBUTTONDBLCLK = &H203
- Const WM_RBUTTONDOWN = &H204
- Const WM_RBUTTONUP = &H205
- Const WM_RBUTTONDBLCLK = &H206
- Const SW_RESTORE = 9
- Const SW_HIDE = 0
- Private Type NOTIFYICONDATA
- cbSize As Long
- hwnd As Long
- uID As Long
- uFlags As Long
- uCallbackMessage As Long
- hIcon As Long
- szTip As String * MAX_TOOLTIP
- End Type
- Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, _
- ByVal nCmdShow As Long) As Long
- Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" _
- (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
- Private nfIconData As NOTIFYICONDATA 'icon
- 'flash
- Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long
- 'sound
- Dim a, b, c As String
- Dim ok, Dok As Boolean '时间到
- Dim MyTime, systime
- Dim info As String
- Dim Shour, Smin, Ssec, PosiH
- Dim Dh, Dm, Ds '倒计时参数声明
- Dim Time As Date '倒计时
- Private Sub cmdDreset_Click()
- Dh = 0
- Dm = 0
- Ds = 0
- Time = 0
- txtDh.Text = " "
- txtDm.Text = " "
- txtDs.Text = " "
- txtDh.SetFocus '获得焦点
- Dok = False
- cmdDstart.Enabled = True
- Shell "shutdown -a" '取消关机
- End Sub
- Private Sub cmdDstart_Click()
- TimCount.Enabled = True
- If Not Lblcount.Caption = "00:00:00" Then
- Dok = True
- End If
- cmdDstart.Enabled = False
- End Sub
- Private Sub Command1_Click()
- Call Shell_NotifyIcon(NIM_DELETE, nfIconData)
- End
- End Sub
- Private Sub Command2_Click()
- systime = Format(Now, "hh:mm:ss")
- PosiH = InStr(1, systime, ":")
- Shour = Mid(systime, 1, PosiH - 1)
- Text1.Text = Shour
- Smin = Mid(systime, 4, 2)
- Text2.Text = Smin
- Text3.Text = "00"
- ok = False
- Shell "shutdown -a" '取消关机
- End Sub
- Private Sub Form_Load()
- SetWindowPos Me.hwnd, HWND_TOPMOST, Me.Left / Screen.TwipsPerPixelX, _
- Me.Top \ Screen.TwipsPerPixelY, Me.Width \ Screen.TwipsPerPixelX, _
- Me.Height \ Screen.TwipsPerPixelY, 0
- nfIconData.hwnd = Me.hwnd
- nfIconData.uID = Me.Icon
- nfIconData.uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP
- nfIconData.uCallbackMessage = WM_MOUSEMOVE
- nfIconData.hIcon = Me.Icon.Handle
- nfIconData.szTip = "小闹钟" & vbNullChar
- nfIconData.cbSize = Len(nfIconData)
- Call Shell_NotifyIcon(NIM_ADD, nfIconData)
- ok = False
- Dok = False
- Timer2.Interval = 1000
- systime = Format(Now, "hh:mm:ss")
- PosiH = InStr(1, systime, ":")
- Shour = Mid(systime, 1, PosiH - 1)
- Text1.Text = Shour
- Smin = Mid(systime, 4, 2)
- Text2.Text = Smin
- Dh = 0 '倒计时部分
- Dm = 0
- Ds = 0
- Time = 0
- End Sub
- Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- Dim d As Single
- d = X / Screen.TwipsPerPixelX
- If d = WM_LBUTTONUP Then
- If Me.WindowState = vbNormal Then
- Me.WindowState = vbMinimized
- Me.Visible = False
- Else
- Me.WindowState = vbNormal
- Me.Visible = True
- End If
- End If
- End Sub
- Private Sub Form_Resize()
- If Me.WindowState = vbNormal Then
- Me.Visible = True
- Else
- Me.Visible = False
- End If
- End Sub
- Private Sub Form_Unload(Cancel As Integer)
- Call Shell_NotifyIcon(NIM_DELETE, nfIconData)
- End
- End Sub
- Private Sub Label8_Click()
- Shell "explorer http://www.spersky.com/post/vb6Miniclock.html", 1
- End Sub
- Private Sub Text1_Click()
- Text1.SelStart = 0
- Text1.SelLength = Len(Text1.Text)
- End Sub
- Private Sub Text2_Click()
- Text2.SelStart = 0
- Text2.SelLength = Len(Text2.Text)
- End Sub
- Private Sub Text3_Click()
- Text3.SelStart = 0
- Text3.SelLength = Len(Text3.Text)
- End Sub
- Private Sub TimCount_Timer()
- 'Count down loop
- TimCount.Enabled = False
- If (VBA.Format(Time, "hh") & ":" & VBA.Format(Time, "nn") & ":" & VBA.Format(Time, "ss")) <> "00:00:00" Then 'Counter to continue loop until 0
- Time = DateAdd("s", -1, Time)
- 'Lblcount.Visible = False
- Lblcount.Caption = VBA.Format(Time, "hh") & ":" & VBA.Format(Time, "nn") & ":" & VBA.Format(Time, "ss")
- 'Lblcount.Visible = True
- TimCount.Enabled = True
- Else
- 'Turn off timer, set off alarm, and enable reset.
- TimCount.Enabled = False
- Beep
- End If
- End Sub
- Private Sub Timer1_Timer()
- a = Text1.Text
- b = Text2.Text
- c = Text3.Text
- MyTime = a & ":" & b & ":" & c
- systime = Format(Now, "hh:mm:ss")
- 'MsgBox systime
- If MyTime = systime Then
- ok = True
- End If
- End Sub
- Private Sub Timer2_Timer()
- Me.Caption = "小闹钟 " & systime
- End Sub
- Private Sub Timer3_Timer()
- info = Text4.Text
- If ok = True Or (Dok = True And Lblcount.Caption = "00:00:00") Then
- Call FlashWindow(Me.hwnd, True)
- Me.Caption = "小闹钟1.0 " & info
- Me.WindowState = vbNormal
- Me.Visible = True
- If chkSound.Value = 1 Then
- Beep
- End If
- If chkShut.Value = 1 Then
- Shell "shutdown -s -t 10" '执行这代码后,10秒内关机
- End If
- End If
- End Sub
- Private Sub TxtToLbl()
- Dh = Val(txtDh.Text)
- Dm = Val(txtDm.Text)
- Ds = Val(txtDs.Text)
- Time = TimeSerial(Dh, Dm, Ds)
- Lblcount.Caption = VBA.Format(Time, "hh") & ":" & VBA.Format(Time, "nn") & ":" & VBA.Format(Time, "ss")
- End Sub
- Private Sub txtDh_Change()
- TxtToLbl
- End Sub
- Private Sub txtDm_Change()
- TxtToLbl
- End Sub
- Private Sub txtDs_Change()
- TxtToLbl
- End Sub