1,451
社区成员
发帖
与我相关
我的任务
分享
Option Explicit
'Form1上添加一个Command1、一个Timer1
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Private Const WM_CLOSE = &H10
Private Const MsgTitle As String = "Test Message"
Dim TestHwnd As Long
Private Sub Command1_Click()
Timer1.Interval = 3000
Timer1.Enabled = True
MessageBox Me.hwnd, "如果您不回应的话,本窗口 3 秒钟后此 MsgBox 会自动关闭", MsgTitle, 64
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
TestHwnd = FindWindow(vbNullString, MsgTitle)
If TestHwnd > 0 Then Call SendMessage(TestHwnd, WM_CLOSE, 0, ByVal 0&)
End Sub
Option Explicit
Private Sub Command1_Click()
CreateObject("Wscript.Shell").Popup "本窗口将在三秒钟后自动关闭……", 3, "MsgBox", 64
End Sub
'窗体上添加一个 Label、一个 ProgressBar、一个 CommandButton(Name = cmdOK)
Option Explicit
Private Sub cmdOK_Click()
Unload Me
End Sub
Private Sub Form_Load()
With ProgressBar1
.Min = 0
.Max = 30
.Value = 0
Label1.Caption = "还有 " & (.Max - .Value) & " 秒自动关闭。"
End With
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
With ProgressBar1
.Value = .Value + 1
Label1.Caption = "还有 " & (.Max - .Value) & " 秒自动关闭。"
If .Value = .Max Then
Timer1.Enabled = False
Call cmdOK_Click
End If
End With
End Sub
Option Explicit
Private Declare Function LoadLibrary Lib "kernel32.dll" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Public Declare Function FreeLibrary Lib "kernel32.dll" (ByVal hLibModule As Long) As Long
Public Declare Function CreateDialogParam Lib "user32.dll" Alias "CreateDialogParamA" (ByVal hInstance As Long, ByVal lpName As Long, ByVal hWndParent As Long, ByVal lpDialogFunc As Long, ByVal lParamInit As Long) As Long
Public Const SW_SHOW As Long = 5
Public Declare Function ShowWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Const WM_SYSCOMMAND As Long = &H112
Public Const SC_CLOSE As Long = &HF060&
Public Declare Function EndDialog Lib "user32.dll" (ByVal hDlg As Long, ByVal nResult As Long) As Long
Public Declare Function GetMessage Lib "user32.dll" Alias "GetMessageA" (ByRef lpMsg As MSG, ByVal hwnd As Long, ByVal wMsgFilterMin As Long, ByVal wMsgFilterMax As Long) As Long
Public Declare Function TranslateMessage Lib "user32.dll" (ByRef lpMsg As MSG) As Long
Public Declare Function DispatchMessage Lib "user32.dll" Alias "DispatchMessageA" (ByRef lpMsg As MSG) As Long
Public Declare Sub PostQuitMessage Lib "user32.dll" (ByVal nExitCode As Long)
Public Type POINTAPI
x As Long
y As Long
End Type
Public Type MSG
hwnd As Long
message As Long
wParam As Long
lParam As Long
time As Long
pt As POINTAPI
End Type
Public Function DialogProc(ByVal hwndDlg&, ByVal uMsg&, ByVal wParam&, ByVal lParam&) As Long
If uMsg = WM_SYSCOMMAND Then
If wParam = SC_CLOSE Then
Call EndDialog(hwndDlg, 0)
PostQuitMessage 0
DialogProc = 0
End If
End If
End Function
Public Sub Main()
Dim hDlg As Long
Dim tMsg As MSG
Dim hIns As Long
hIns = LoadLibrary("shdoclc.dll")
hDlg = CreateDialogParam(hIns, 24581, 0, AddressOf DialogProc, 0)
FreeLibrary hIns
ShowWindow hDlg, SW_SHOW
While GetMessage(tMsg, 0, 0, 0)
Call TranslateMessage(tMsg)
Call DispatchMessage(tMsg)
Wend
End Sub