网页功能: 加入收藏 设为首页 网站搜索  
让messagebox自动消失
发表日期:2003-03-31作者:jennyvenus[] 出处:  

利用多线程解决对话框自动消失的办法,虽然有点乱,但是完全正确,自己使用的时候把command1_click的执行动作封装成自己的函数就行了,运行过程,点command1,出现对话框,10秒后对话框消失。(因为我这个程序多次用于测试,所以没用的API声明太多了,去掉没用的就行了)

'窗体代码

Option Explicit

Private Sub Command1_Click()

  Command1.Enabled = False

  id = CreateThread(ByVal 0&, ByVal 2000&, AddressOf closemessagebox, 0, ByVal 0&, id1)

  MsgBox "a"

  TerminateThread id, 0

  Command1.Enabled = True

End Sub

Private Sub Form_Load()

  ProcOld = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf WindowProc)

End Sub

Private Sub Form_Unload(Cancel As Integer)

  SetWindowLong Me.hwnd, GWL_WNDPROC, ProcOld

End Sub

'模块代码

Option Explicit

Public 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

Public Declare Function TrackPopupMenu Lib "user32" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal x As Long, ByVal y As Long, ByVal nReserved As Long, ByVal hwnd As Long, lprc As RECT) As Long

Public Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long

Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long

Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Declare Function AppendMenu Lib "user32" Alias "AppendMenuA" (ByVal hMenu As Long, ByVal wFlags As Long, ByVal wIDNewItem As Long, ByVal lpNewItem As String) As Long

Public Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long

Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long

Public Declare Function GetCurrentProcessId Lib "kernel32" () As Long

Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Public Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long

Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Public Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Public Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long

Public Declare Function CreateThread Lib "kernel32" (lpThreadAttributes As Any, ByVal dwStackSize As Long, ByVal lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpThreadID As Long) As Long

Public Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long

Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Type RECT

    Left As Long

    Top As Long

    Right As Long

    Bottom As Long

End Type

Public Type POINTAPI

    x As Long

    y As Long

End Type

Public ProcOld As Long

Public Const TPM_LEFTALIGN = &H0&

Public Const WM_SYSCOMMAND = &H112

Public Const MF_SEPARATOR = &H800&

Public Const MF_STRING = &H0&

Public Const GWL_WNDPROC = (-4)

Public Const IDM_ABOUT As Long = 1010

Public Const WM_COMMAND = &H111

Public Const WM_ACTIVATE = &H6

Public Const WA_INACTIVE = 0

Public Const SRCCOPY = &HCC0020 ' (DWORD) dest = source

Public Const WM_CLOSE = &H10

Public Const INFINITE = &HFFFF

Public g__thread As Long

Public id As Long

Public id1 As Long

Public Function WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

  Select Case iMsg

  Case WM_ACTIVATE

    If wParam = WA_INACTIVE Then

      Dim mywnd As Long

      Dim buf As String * 64

      Dim oldrect As RECT

      GetWindowRect hwnd, oldrect

      mywnd = lParam

      GetClassName mywnd, buf, 64

      If Mid(buf, 1, 6) = "#32770" Then

        Dim processid As Long

        GetWindowThreadProcessId mywnd, processid

        If processid = GetCurrentProcessId Then

          g__thread = mywnd

        End If

      End If

    End If

  End Select

  WindowProc = CallWindowProc(ProcOld, hwnd, iMsg, wParam, lParam)

End Function

Public Sub closemessagebox()

  Sleep 10000

  If g__thread <> 0 Then

    SendMessage g__thread, WM_CLOSE, 0, 0

    g__thread = 0

  End If

End Sub

我来说两句】 【加入收藏】 【返加顶部】 【打印本页】 【关闭窗口
中搜索 让messagebox自动消失
本类热点文章
  用VB制作软键盘
  让messagebox自动消失
  制作半透明窗体
  给Listview做个背景
  VB程序实现WindowsXP效果的界面
  VB打造超酷个性化菜单
  用VB实现“百叶窗”的图形特效
  用VB绘制正弦动画曲线
  获取所有打印纸张格式的方法
  如何使Form的背景图随Form大小改变
  VB实现立体文字
  使用文字做为窗体的形状
最新分类信息我要发布 
最新招聘信息

关于我们 / 合作推广 / 给我留言 / 版权举报 / 意见建议 / 广告投放  
Copyright ©2003-2018 Lihuasoft.net webmaster(at)lihuasoft.net
网站编程QQ群   京ICP备05001064号 页面生成时间:0.00445