VB 关闭指定标题窗口

前端之家收集整理的这篇文章主要介绍了VB 关闭指定标题窗口前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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,"新建 文本文档.txt - 记事本") '获得指定窗体标题的窗体的句柄

If hwnd = 0 Then
MsgBox "未找到窗口"
Else
result = PostMessage(hwnd,WM_CLOSE,0&,0&)'向目标程序发送消息
If result = 0 Then
MsgBox "关闭窗口失败!"
Else
MsgBox "成功关闭窗口!"
End If
End If

End Sub

猜你在找的VB相关文章