Option Explicit
'//****************************************************************************************************************************************
'//以下是窗體過程
'//****************************************************************************************************************************************
'//以下聲明API函數(shù)
'//用來設(shè)置Settimer過程。
Private Declare Function SetTimer _
Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerfunc As Long) _
As Long
'//結(jié)束Settimer過程
Private Declare Function KillTimer _
Lib "user32" ( _
ByVal hwnd As Long, _
ByVal nIDEvent As Long) _
As Long
'//查找窗體
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) _
As Long
'//以下定義變量
Private hwnd As Long, TID As Long
'//****************************************************************************************************************************************
'// 過程
'//****************************************************************************************************************************************
Private Sub UserForm_Initialize()
'//取得窗口句柄
hwnd = FindWindow(vbNullString, Me.Caption)
'//設(shè)置Settimer 過程
TID = SetTimer(hwnd, 0, 1000, AddressOf TimeOutProc)
End Sub
'//--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'//結(jié)束Settimer過程
If TID <> 0 Then KillTimer hwnd, TID
End Sub