如何取得无标题的窗口句柄
1个回答
展开全部
枚举所有进程, 然后找到你的进程的ID
然后用这几个API函数
openprocess
terminateprocess
closehandle
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) 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 Const WM_CLOSE = &H10
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDFIRST = 0
Public Sub findrunningprogram()
Dim RenHWND
Dim HD
RenHWND = GetWindow(Form1.hwnd, GW_HWNDFIRST)
Do
RetValue = GetWindowText(RenHWND, WinText, 256)
If RetValue <> 0 Then
WinTextLength = GetWindowTextLength(RenHWND)
If Left$(WinText, WinTextLength) <> Form1.Caption And Left$(WinText, WinTextLength) <> App.Title Then
Text = WinText
If Text = "" Then
HD = RenHWND
End If
End If
End If
RenHWND = GetWindow(RenHWND, GW_HWNDNEXT)
Loop Until Text = ""
findrunningprogram = HD
End Sub
HD的返回值就是Handle了!
然后用这几个API函数
openprocess
terminateprocess
closehandle
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) 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 Const WM_CLOSE = &H10
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDFIRST = 0
Public Sub findrunningprogram()
Dim RenHWND
Dim HD
RenHWND = GetWindow(Form1.hwnd, GW_HWNDFIRST)
Do
RetValue = GetWindowText(RenHWND, WinText, 256)
If RetValue <> 0 Then
WinTextLength = GetWindowTextLength(RenHWND)
If Left$(WinText, WinTextLength) <> Form1.Caption And Left$(WinText, WinTextLength) <> App.Title Then
Text = WinText
If Text = "" Then
HD = RenHWND
End If
End If
End If
RenHWND = GetWindow(RenHWND, GW_HWNDNEXT)
Loop Until Text = ""
findrunningprogram = HD
End Sub
HD的返回值就是Handle了!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询