标题:如何用程序自动关闲MSGBOX框
只看楼主
zsolong
Rank: 1
等 级:新手上路
威 望:1
帖 子:193
专家分:0
注 册:2006-12-15
得分:0 

对啊,其实只要对原来的代码稍作一点改动,问题就解决了,不需要苦苦追寻很难实现的方法的。


2007-01-22 17:34
tang688
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1219
专家分:35
注 册:2004-12-25
得分:0 
哎,我有好几十个窗口,每个窗口又大同小易的,因为有易,所以只能是一个窗口一个窗口地写了。
写完了后发现,还需要一个联动的问题,也就是当一个窗口数值改变后,可能有三四个窗口甚至十多个窗口内的数据也得进行改变,因为改变的计算方法已经在那个窗口中有了,所以我想只调用一下就完成了,可一调用它有二个提示的MSGBOX。我一次调用了三四个窗口内的SUB后,它给我提示个7、8次,我晕啊。
程序是没问题的,就是这个提示烦死人了。
因为程序已经写完成了,要去改每个窗口那也太烦了吧?
所以我想用程序把这个提示给默认掉,那不就万事大吉了?

2007-01-22 17:34
slore
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1108
专家分:0
注 册:2005-7-1
得分:0 
sendkeys "{Enter}"前sleep下?是不是msgbox还没出来就……

快上课了……
2007-01-22 17:53
tang688
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1219
专家分:35
注 册:2004-12-25
得分:0 
我试试

2007-01-22 18:58
atomhdp
Rank: 1
等 级:新手上路
帖 子:97
专家分:0
注 册:2005-10-2
得分:0 

弹出对话框后,程序里所有的程序都暂停运行了.包括Timer. 如果 sendkeys 代码都不执行,当然不能自己动关闭对话框了.
建议LZ修改程序吧.


2007-01-23 10:16
Kendy123456
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:62
帖 子:2720
专家分:0
注 册:2007-1-3
得分:0 

用class吧 添加一个bool属性ShowMsgbox 不管是本form调用还是外部调用 都预设一下值.和全局变量的作用相同 好处在于每个class都有自己的属性 不会互相冲突.全局变量你要是同时打开的form过多 会被改来改去的.

既然每个窗口都大同小异 干嘛不定义一个基类 用继承来做呢


2007-01-23 13:50
griefforyou
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:3336
专家分:0
注 册:2004-4-15
得分:0 

'以下放到Moudle中

'**************************************
' Name: Auto close messagebox
' Description:This function replaces VB'
' s msgbox function and closes itself afte
' r the parameter provided number of secon
' ds. The syntax and return values are exa
' ctly the same as msgbox except the first
' parameter is the number of seconds to di
' splay. Just add this code to a module (n
' ot a cls or frm) in your project and cal
' l ACmsgbox. Thanks to Sparq's submission
' here for help in writing this.

'With the added parameter of
' By: Daniel Biener
'
'This code is copyrighted and has' limited warranties.Please see http://w
' ww.Planet-Source-Code.com/vb/scripts/Sho
' wCode.asp?txtCodeId=27940&lngWId=1'for details.'**************************************

'**************************************
'Windows API/Global Declarations for :Au
' to close messagebox
'**************************************


Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long


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 Declare Function SetForegroundWindow Lib "user32" (ByVal hWnd As Long) As Long
Private Const NV_CLOSEMSGBOX As Long = &H5000&
Private sLastTitle As String

Public Function ACmsgbox(AutoCloseSeconds As Long, prompt As String, Optional buttons As Long, _
Optional title As String, Optional helpfile As String, _
Optional context As Long) As Long
sLastTitle = title
SetTimer Screen.ActiveForm.hWnd, NV_CLOSEMSGBOX, AutoCloseSeconds * 1000, AddressOf TimerProc
ACmsgbox = MsgBox(prompt, buttons, title, helpfile, context)
End Function


Private Sub TimerProc(ByVal hWnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
Dim hMessageBox As Long
KillTimer hWnd, idEvent


Select Case idEvent
Case NV_CLOSEMSGBOX
hMessageBox = FindWindow("#32770", sLastTitle)


If hMessageBox Then
Call SetForegroundWindow(hMessageBox)
SendKeys "{enter}"
End If
sLastTitle = vbNullString
End Select
End Sub

'调用代码

Private Sub Command1_Click()
ACmsgbox 3, "test", vbYes, "test"
End Sub


天津网站建设 http://www./
2007-01-24 09:28
tang688
Rank: 5Rank: 5
等 级:贵宾
威 望:16
帖 子:1219
专家分:35
注 册:2004-12-25
得分:0 
哎,最后还是改程序了.
化了我一天的时间

2007-01-24 16:58
PcrazyC
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:5652
专家分:0
注 册:2006-10-20
得分:0 
要那么久吗

雁无留踪之意,水无取影之心
2007-01-24 17:07
Kendy123456
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:62
帖 子:2720
专家分:0
注 册:2007-1-3
得分:0 

发现楼主输入法是用的五笔


2007-01-24 17:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-117458-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031296 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved