VB API关闭一个句柄
1个回答
展开全部
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private 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
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
Const WM_CLOSE = &H10
Private Sub Form_Load()
Command1.Width = 3333
Command1.Caption = "去掉计算器上按钮数字1"
Shell "calc.exe", vbNormalNoFocus
End Sub
Private Sub Command1_Click()
Dim Hwnd1 As Long
Dim Hwnd2 As Long
Hwnd1 = FindWindow("SciCalc", "计算器")
Hwnd2 = FindWindowEx(Hwnd1, 0, "Button", "1")
SendMessage Hwnd2, WM_CLOSE, 0, 0
End Sub
关键是看你能不能找到窗口中按钮的句柄
Private 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
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
Const WM_CLOSE = &H10
Private Sub Form_Load()
Command1.Width = 3333
Command1.Caption = "去掉计算器上按钮数字1"
Shell "calc.exe", vbNormalNoFocus
End Sub
Private Sub Command1_Click()
Dim Hwnd1 As Long
Dim Hwnd2 As Long
Hwnd1 = FindWindow("SciCalc", "计算器")
Hwnd2 = FindWindowEx(Hwnd1, 0, "Button", "1")
SendMessage Hwnd2, WM_CLOSE, 0, 0
End Sub
关键是看你能不能找到窗口中按钮的句柄
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询