---- 奏乐和闪烁功能是通过调用Windows API 函数mciExecute和FlashWindow来实现的。为了实现窗口标题栏和任务栏图标的闪烁,需另外添加一个窗体Form2,并设置Form2为启动窗体,程序启动并实现闪烁后,使Form2关闭,为了不影响其它工作,Form1窗口运行状态缺省设置为最小,即只在任务栏闪烁,到时(10分钟)会奏乐。
Option Explicit Private StartTime As Single Private Declare Function FlashWindow Lib "user32" (ByVal hwnd As Long, ByVal bInvert As Long) As Long Private Declare Function mciExecute Lib "winmm.dll" (ByVal lpstrCommand As String) As Long Private Sub cmdExit_Click() Dim y y = mciExecute("close c:\windows\media\canyon.mid") End End Sub
Private Sub cmdStart_Click() prb.Value = 0 StartTime = 0 tmrCount.Enabled = True Label3.Caption = Time End Sub
Private Sub Form_Load() Left = (Screen.Width - Width) \ 2 Top = (Screen.Height - Height) \ 2 Label3.Caption = Time End Sub
Private Sub Tmrflash_Timer() Dim Rt As Long Rt = FlashWindow(hwnd, CLng(True)) End Sub
Private Sub tmrCount_Timer() Form2.Hide Dim Percent If StartTime = 0! Then StartTime = Timer End If Label5.Caption = Time Dim TimeNeed As Integer TimeNeed = 600 Percent = 100 * (Timer - StartTime) / TimeNeed If Percent < 100 Then Dim TimePassed prb.Value = Percent TimePassed = Int(Percent * TimeNeed / 6000) Label1.Caption = "已焖 " & TimePassed & " 分" lblInfo.Caption = "正在焖着..请不要外出" Else prb.Value = 100 lblInfo.Caption = "大米已焖熟,立即关火!" lblInfo.FontBold = True lblInfo.ForeColor = vbRed Label1.Caption = " 已焖 " & CInt(Percent * TimeNeed / 6000) & " 分" Dim x x = mciExecute("play c:\windows\media\canyon.mid") tmrCount.Enabled = False End If End Sub
---- Form2窗口不放置任何控件,将WindowsState属性设置为最小,其代码如下:
Option Explicit Private Sub Form_Load() Form1.Show End Sub