定时关闭MSGBOX问题,我记得在某一期的<程序员>杂志中"专家门诊"中看到过解决办法,好像是调用一个脚本实现的,但我忘记了,不知道有没有人还记得?,这个脚本没有调用API函数,仅是脚本调用的方式,有人记得吗?
解决方案 »
- VBA SQL语句求助
- 如何得到某个字符,在整个字符串中的具体位置?
- 怎么按行读取文件,每次读一行,直到读完,不是一次读完,是一次click事件往下读一行
- vb循环的问题!在线等!!!
- 怎样用API来判断一个进程是否还存在?
- 对回调函数的理解?
- 怎么使鼠标横着“走”? 特急!!!!!
- 调出IE的问题,请帮忙~,很简单得50分哦!
- 这个问题好象只有高手才能解决啦!!!!!!!
- filelen()返回文件打开前的长度,LOF返回文件打开后的长度,两个究竟有什么区别?
- 关于声音文件图形编辑控件NCTWavplayer(收费控件),请问各位大哥,如何去掉烦人的弹出窗口
- VC写的DLL其中一个接口的参数是char **,VB需要调用的时候应该怎么声明该参数
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const BM_CLICK = &HF5
const ts="提示框名"
const an ="按钮名"Private Sub Timer1_Timer()
pk = FindWindow(vbNullString, ts)
pp = FindWindowEx(pk, ByVal 0&, "Button", an)
SendMessage pp, BM_CLICK, 0, 0
End Sub
(ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As LongPrivate Const WM_CLOSE = &H10
Private Const MsgTitle As String = "Test Message"'在表单中加入一个 CommandButton 及一个 Timer 控制项,加入以下程序码:Private Sub Command1_Click()
Dim nRet As Long
Timer1.Interval = 3000
Timer1.Enabled = True
nRet = MsgBox("若您不回应的话,3 秒后此 MsgBox 会自动关闭", 64, MsgTitle)
Timer1.Enabled = False
End SubPrivate Sub Timer1_Timer()
Dim hWnd As Long
hWnd = FindWindow(vbNullString, MsgTitle)
Call SendMessage(hWnd, WM_CLOSE, 0, ByVal 0&)
End Sub此方法的限制说明:1、当常数设定为 VbAbortRetryIgnore 或 VbYesNo 时,无效!
2、在 Design Time 时,无效,必须 Make EXE 之后才有效!
可以参考一下.
' Copyright ?998 Karl E. Peterson, All Rights Reserved
' http://www.mvps.org/vb
' *********************************************************************
' Warning: This computer program is protected by copyright law and
' international treaties. Unauthorized reproduction or distribution
' of this program, or any portion of it, may result in severe civil
' and criminal penalties, and will be prosecuted to the maximum
' extent possible under the law.
' *********************************************************************
Option ExplicitPrivate 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 LongPrivate Const WM_CLOSE = &H10Private Const MsgTitle As String = "Test Message"Private Sub cmdTest_Click()
Dim msg As String
Dim nRet As Long
'
' Adjust timeout to match user's spec.
'
With Timer1
.Interval = HScroll1.Value * 1000
.Enabled = True
End With
'
' Message should reflect whether compiled.
'
If Compiled Then
msg = "I should disappear in " & HScroll1.Value & " seconds."
Else
msg = "I whould disappear in " & HScroll1.Value & _
" seconds," & vbCrLf & "if this demo were compiled."
End If
'
' Return value, after a timeout, is the same as if
' the user had pressed the Close (X) button.
'
nRet = MsgBox(msg, Combo1.ItemData(Combo1.ListIndex), MsgTitle)
Select Case nRet
Case vbOK: msg = "vbOK ["
Case vbCancel: msg = "vbCancel ["
Case vbAbort: msg = "vbAbort ["
Case vbRetry: msg = "vbRetry ["
Case vbIgnore: msg = "vbIgnore ["
Case vbYes: msg = "vbYes ["
Case vbNo: msg = "vbNo ["
Case Else: msg = "Unknown ["
End Select
txtReturn.Text = msg & nRet & "]"
Timer1.Enabled = False
End SubPrivate Sub Form_Load()
With Combo1
.AddItem "vbAbortRetryIgnore"
.ItemData(.NewIndex) = 2
.AddItem "vbOKCancel"
.ItemData(.NewIndex) = 1
.AddItem "vbOKOnly"
.ItemData(.NewIndex) = 0
.AddItem "vbRetryCancel"
.ItemData(.NewIndex) = 5
.AddItem "vbYesNo"
.ItemData(.NewIndex) = 4
.AddItem "vbYesNoCancel"
.ItemData(.NewIndex) = 3
.ListIndex = .NewIndex
End With
txtReturn.Text = ""
Set Me.Icon = Nothing
End SubPrivate Sub HScroll1_Change()
cmdTest.Caption = "Test " & HScroll1.Value & _
" Second MsgBox"
End SubPrivate Sub Timer1_Timer()
Dim hWnd As Long
'
' The following works for all *except*
' vbAbortRetryIgnore, which any responsible
' programmer must let the user answer.
'
hWnd = FindWindow(vbNullString, MsgTitle)
Call SendMessage(hWnd, WM_CLOSE, 0, ByVal 0&)
End SubPrivate Function Compiled() As Boolean
On Error GoTo NotCompiled
Debug.Print 1 / 0
Compiled = True
NotCompiled:
End Function
Set WsShell = CreateObject("Wscript.Shell")
WsShell.Popup "你TMD怎么还不睡?!", 1, "PowerBASIC温馨提示"
End Sub
'在IDE环境下可能不正常,编译为exe文件就没问题了。