VB 找窗口 答对在加50分

来源:百度知道 编辑:UC知道 时间:2024/09/21 16:36:18
我知道这个窗口ID是
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, 2314)
怎么根据这个2314找到他的窗口,
回答正确在加50分谢谢
我想在这个进程ID的窗口上发送按键消息有别的方法也可以

获取属于某进程的顶层可见窗体,
窗体句柄 记录到数组 nhWnd

'模块代码

Private Declare Function GetParent Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function IsWindowVisible Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, lParam As Long) As Long

Dim count As Long
Dim nhWnd(1 To 10) As Long

Public Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Boolean
Dim dwID As Long
GetWindowThreadProcessId hWnd, dwID
If dwID = lParam And IsWindowVisible(hWnd) And GetParent(hWnd) = 0 Then
count = count + 1
nhWnd(count) = hWnd
End If

If count = 10 Then EnumWindowsProc = False Else EnumWindowsProc = True
End Function

'窗体代码