-
Oct 22nd, 2013, 09:11 AM
#1
Thread Starter
Addicted Member
findwindowEX tricky external program
Hey all i am trying to figure out how to get all the way down where it says:
Window 00211286 "" QWidget
http://i.stack.imgur.com/wE2HM.png
Currently i have this:
Code:
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, vbNullString, "content")
hwndButton = FindWindowEx(hwndParent, IntPtr.Zero, "QWidget", vbNullString)
hwndButton = FindWindowEx(hwndParent, IntPtr.Zero, "QWidget", "content")
hwndButton = FindWindowEx(hwndParent, IntPtr.Zero, "QWidget", "mainFrame")
hwndButton = FindWindowEx(hwndParent, IntPtr.Zero, "QWidget", "qt_scrollarea_viewport")
hwndButton = FindWindowEx(hwndParent, IntPtr.Zero, "QWidget", vbNullString)
Call SendMessageLong(hwndButton, WM_CHAR, ENTER_KEY, 0&)
Call SendMessageLong(hwndButton, WM_CHAR, ENTER_KEY, 0&)
Debug.Print("Clicked: " & hwndButton)
End Sub
I get a value for FindWindow and then also for the first findwindowEx.... but after that i get a big fat 0. Then for the last FindWindowEx i get the same number as i did on the first findwindowEx.
Any help would be great!
-
Oct 22nd, 2013, 09:37 AM
#2
Re: findwindowEX tricky external program
You're specifying the same parent every time, indicating all the windows are siblings, which they're not. Once you've got the top-level parent you need to call FindWindowEx with that as the parent twice to get the third item down, then that becomes the parent to get the "content" window, then that becomes the parent to get the "mainFrame" window and so on. If you never use a different parent then you never go deeper into the hierarchy.
-
Oct 22nd, 2013, 09:42 AM
#3
Thread Starter
Addicted Member
Re: findwindowEX tricky external program
Can you show me an example of that in code, jmcihinney?
-
Oct 22nd, 2013, 09:49 AM
#4
Re: findwindowEX tricky external program
You've already got examples. You posted them yourself. All you have to do is pass the correct value as the parent when you call FindWindowEx. Just think about it. The first call gives you the handle of the first node and that is the parent of the second and third nodes. The third node is the parent of the sixth node, the sixth is the parent of the seventh, the seventh the parent of the eighth, the eighth the parent of the eleventh and the eleventh the parent of the twelfth. It's that simple. Pass the actual handle of the direct parent window each time, not just the top window every time.
-
Oct 22nd, 2013, 09:55 AM
#5
Thread Starter
Addicted Member
Re: findwindowEX tricky external program
Ah, right. I was thinking i was passing the hwndButton each time but it looks like i only pass hwndParent.
-
Oct 22nd, 2013, 07:06 PM
#6
Thread Starter
Addicted Member
Re: findwindowEX tricky external program
Ok running this:
Code:
hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "") 'Has a value (264778)
hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "") 'Does not have a value
hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "content") 'Does not have a value
hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "mainFrame") 'Does not have a value
hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "") 'Has a value (264778)
hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "qt_scrollarea_viewport") 'Does not have a value
hwndButton = FindWindowEx(hwndButton, IntPtr.Zero, "QWidget", "") 'Has a value (264778)
So it still doesnt seem to be working??
-
Oct 22nd, 2013, 07:28 PM
#7
Re: findwindowEX tricky external program
It's still not working because you're still not doing what I said.
Originally Posted by jmcilhinney
The first call gives you the handle of the first node and that is the parent of the second and third nodes.
The second node is NOT the parent of the third node so why are you using the handle of the second window as the parent when finding the handle of the third window? Look at the diagram. It's quite obvious which node is the parent of which other nodes. Use the right parent when calling FindWindowEx and it will work. Don't and it won't. Exactly as you'd expect.
-
Oct 22nd, 2013, 07:59 PM
#8
Thread Starter
Addicted Member
Re: findwindowEX tricky external program
The image below is what i am using in my code (highlighted in green):
Code:
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", "")
Last edited by Stealthrt; Oct 22nd, 2013 at 08:02 PM.
-
Oct 22nd, 2013, 08:36 PM
#9
Re: findwindowEX tricky external program
Let me spell it out.
1. Make one call to get the handle of the "Genymotion" window, which is the first node in that tree. That then becomes the parent for the next call.
2. You cannot get the handle for the third node without first getting the handle for the second node because there's no way to distinguish them. Make one call with the handle from step 1 as the parent and IntPtr.Zero as the starting point to get the handle of the second node.
3. Make one more call with the handle from step 1 as the parent and the handle from step 2 as the starting point to get the handle of the third node. This then becomes the parent for the next call, because we want to go one level deeper into the hierarchy.
4. Make one call with the handle from step 3 as the parent to get the sixth node, which then becomes the parent for the next call.
Etc.
Each time you want to go a level deeper into the hierarchy you need to use the handle of the previous window as the parent.
Each time you want to get the Nth of undistinguishable siblings, i.e. same class and window names, you need to make N calls with the same parent. For the first sibling you use IntPtr.Zero as the starting point and for each subsequent sibling you use the (N - 1)th sibling as the starting point. By doing so you are saying "get me the handle of the window that has this parent, this class name and this window name after this sibling.
-
Oct 23rd, 2013, 11:55 AM
#10
Thread Starter
Addicted Member
Re: findwindowEX tricky external program
Code example would be more helpful then just text, jmcilginney.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|