计算机二级考试VisualBasic辅导:VB关闭已知标题窗口代码
来源:优易学  2010-1-15 16:06:10   【优易学:中国教育考试门户网】   资料下载   IT书店
  使用API函数。先通过FindWindow得到窗口的句柄,然后对窗口发送关闭消息。
  Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  Const WM_CLOSE = &H10  
   Private Sub Command1_Click()
   Dim hwnd, result As Long
   hwnd = FindWindow(vbNullString, "迅雷5") '查找窗体标题
  If hwnd = 0 Then
   MsgBox "未找到窗口"
   Else
   result = PostMessage(hwnd, WM_CLOSE, 0&, 0&)
   If result = 0 Then
   MsgBox "关闭窗口失败"
   Else
   MsgBox "关闭OK"
   End If
   End If
  End Sub

责任编辑:cyth

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训