• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

关于定时关闭询问对话框的一点体会

发布: 2007-7-01 21:48 | 作者: admin | 来源: | 查看: 75次 | 进入软件测试论坛讨论

领测软件测试网

       用过瑞星杀毒软件的朋友都知道,他可以定时关闭询问对话框。询问对话框的实现很简单,调用vb中提供的msgbox就可以实现了,可是问题是询问对话框是模式对话框,不关闭它的话,下面的代码无法继续执行,这一点也多多少少给朋友们造成了一些困饶。那么怎么解决呢,我的方案是调用api函数messagebox代替msgbox,结合timer控件实现自动关闭,闲话少说,看代码,下面的代码演示了如何在10秒中之后关闭对话框(窗体上一个按钮,一个timer控件):

Option Explicit

Const MB_DEFBUTTON1 = &H0&
Const MB_DEFBUTTON2 = &H100&
Const MB_DEFBUTTON3 = &H200&
Const MB_ICONASTERISK = &H40&
Const MB_ICONEXCLAMATION = &H30&
Const MB_ICONHAND = &H10&
Const MB_ICONINFORMATION = MB_ICONASTERISK
Const MB_ICONQUESTION = &H20&
Const MB_ICONSTOP = MB_ICONHAND
Const MB_OK = &H0&
Const MB_OKCANCEL = &H1&
Const MB_YESNO = &H4&
Const MB_YESNOCANCEL = &H3&
Const MB_ABORTRETRYIGNORE = &H2&
Const MB_RETRYCANCEL = &H5&
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 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) 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 Const BM_CLICK = &HF5
Dim i As Long
Private Sub Command1_Click()
     Timer1.Enabled = True
     MessageBox Me.hwnd, "this is test", App.Title, MB_OK
     Timer1.Enabled = False
End Sub

Private Sub Form_Load()
    Timer1.Enabled = False
    Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()

    i = i + 1
    If i >= 10 Then
        Dim dlghwnd As Long
        Dim buttonhwnd As Long
        dlghwnd = FindWindow("#32770", App.Title)
        buttonhwnd = GetDlgItem(dlghwnd, 2) ´其中的2,用spy++获得
        SendMessage buttonhwnd, BM_CLICK, 0&, ByVal 0&
    End If
   
End Sub


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网