findwindowEX棘手的外部程序

时间:2013-10-22 01:17:55

标签: vb.net spy++ findwindow findwindowex

嘿所有我想弄清楚如何在它所说的地方一路走下去:

Window 00211286“”QWidget

enter image description here

以绿色突出显示我正在尝试使用以下代码找到:

enter image description here 目前我有这个:

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWndParent As IntPtr, ByVal hWndChildAfter As Integer, ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As IntPtr
Private Declare Function PostMessage Lib "user32.dll" Alias "PostMessageA" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As IntPtr
Public Declare Function SendMessageLong& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)

Public Const WM_CHAR = &H102
Private Const BM_CLICK = &HF5
Public Const WM_LBUTTONDBLCLK = &H203
Public Const ENTER_KEY = 13

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim hwndParent As Long = FindWindow(vbNullString, "Genymotion")
    Dim hwndButton As Long = FindWindowEx(hwndParent, IntPtr.Zero, "QWidget", "")
    hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "content")
    hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "mainFrame")
    hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "")
    hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "qt_scrollarea_viewport")
    hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "")
End Sub

我得到FindWindow的值,然后是第一个findwindowEx ....但之后我得到一个大胖子0.然后对于最后一个FindWindowEx我得到的数字与我在第一个findwindowEx上的数字相同。

任何帮助都会很棒!

1 个答案:

答案 0 :(得分:1)

试试这个:

    Dim hwndParent As Long = FindWindow(vbNullString, "Genymotion") ' Parent Window by Caption
    Dim hwndButton As Long = FindWindowEx(hwndParent, IntPtr.Zero, "QWidget", "") ' First Child QWidget
    hwndButton = FindWindowEx(hwndParent, hwndButton, "QWidget", "") ' Second Child QWidget
    hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "content") ' "content" QWidget
    hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "mainFrame") ' "mainFrame" QWidget
    hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "") ' First Child QWidget
    hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "qt_scrollarea_viewport") ' "qt_scrollarea_viewport" QWidget
    hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "") ' First Child QWidget

注意这两行中会发生什么:

    Dim hwndButton As Long = FindWindowEx(hwndParent, IntPtr.Zero, "QWidget", "") ' First Child QWidget
    hwndButton = FindWindowEx(hwndParent, hwndButton, "QWidget", "") ' Second Child QWidget

第一行获得第一个句柄为001816EC的QWidget。在第二行中,我们使用相同的父句柄,但是我们将先前找到的窗口小部件的句柄传递给名为“hWndChildAfter”的第二个参数。这将获得第二个QWidget,其句柄为0011686A。这两个窗口是彼此的“兄弟姐妹”。