How to get hWnd of an external listview in hex just like spy++?
Hi all . could any one show me how i can get the hWnd of a listview in external application just the way spy++ dispaly the hWnd in hex. Looking forward for replies.Thanks
Re: How to get hWnd of an external listview in hex just like spy++?
Thanks for you reply. This thread is dealing with diffrent listview,the code in those thread doesn't work here.The spy++ produces the right listview handle which is suppose to be Decimal:329204(Hexadecimal:000505F4).But my code produces handle=2491180 in decimal. I used PAT or JK's API SPY 5.1 to get the code for getting handle of listview but for some reason it doesn't produce right value!!
Handle produced by spy++:
Hexadecimal:000505F4
Decimal:329204
class name :SysListView32
Caption:""
Handle produced by my code:
Handle in decimal :2491180
So could you look at the image of listview and let me know what i am doing wrong that my code doesn't produces same listview handle as spy++ which is
Decimal:329204? Looking forward for replies.Thanks
Note:code produced by PAT or JK's API SPY 5.1:
Code:
Private Sub Command4_Click()
Dim x As Long, button As Long
x = FindWindow("#32770", vbNullString)
button = FindWindowEx(x, 0&, "button", vbNullString)
button = FindWindowEx(x, button, "button", vbNullString)
button = FindWindowEx(x, button, "button", vbNullString)
button = FindWindowEx(x, button, "button", vbNullString)
MsgBox button
End Sub
Last edited by tony007; Apr 24th, 2010 at 03:47 PM.
Re: How to get hWnd of an external listview in hex just like spy++?
What if you Enumerate the children, can you find the correct handle then?
Heres an example that stores all the child info into a type array so you can loop threw it and search by a controls ID#, classname, title, etc. In the example it finds the parent window, stores the child info into a array, then displays only the controls that have the word text in them., try to modify iy for your window and control you are trying to find, I believe once you know the ID # of a control you can reuse it as that wont change.
Last edited by Edgemeal; Apr 24th, 2010 at 06:36 PM.
Reason: remove exe from .Zip
Re: How to get hWnd of an external listview in hex just like spy++?
Edgemeal thanks for your reply. But i am dealing with an external window how i can find and store all the child info into a type array ... ?
i found another spy++ type program with its source code but unfortuanelty that program couldn't select the listview by dragging it over listview. it could only select the outer frame which holds the buttons as well .While spy++ could select the listview alone and give me correct handle!!
I use that correct listview handle value to actually copy all listview data ...
Hope i some how get the handle programatically instead of using spy++ each time...
Re: How to get hWnd of an external listview in hex just like spy++?
Originally Posted by tony007
Edgemeal thanks for your reply. But i am dealing with an external window how i can find and store all the child info into a type array ... ?
i found another spy++ type program with its source code but unfortuanelty that program couldn't select the listview by dragging it over listview it couldn't only select the outer frame which holds the buttons as well .While spy++ could select the listview exact and give me correct handle!!
I use that correct listview handle value to actually copy all listview data ...
Hope i some how get the handle programatically instead of using spy++ each time...
In that program change the FindWindow parameters in Form1 (OK button) to the parent windows classname, titletext you are trying to access controls on.
Re: How to get hWnd of an external listview in hex just like spy++?
If there is only one window open with the title bar named "Add" then just use vbNullString for the classname till you figure out what it really is. I've used the code a few apps and has worked well , but maybe your app is hiding stuff????
, windows task manager in XP....
Code:
LhWnd = FindWindow(vbNullString, "Windows Task Manager")
' if window found then...
If LhWnd > 0 Then
' get child info
GetChildrenInfo LhWnd
For i = 0 To UBound(AppChild) - 1
List1.AddItem _
AppChild(i).ID & vbTab & _
AppChild(i).hwnd & vbTab & _
AppChild(i).Type & vbTab & _
AppChild(i).Title & vbTab & _
AppChild(i).ClassName
Next i
Else
MsgBox "Window not found!", vbInformation
End If
Re: How to get hWnd of an external listview in hex just like spy++?
I tried that didn't work.But Strange it didn't evnen work for Windows Task Manger !!
I used this tool called Window Analyzer and gave me correct handle but don't have its source code. I found another progmra from this site but unfortuenelty it doesnt allow me select the listview alone : http://www.vbforums.com/showpost.php...80&postcount=1
Last edited by tony007; Apr 24th, 2010 at 07:14 PM.
Re: How to get hWnd of an external listview in hex just like spy++?
Many Many Thanks .After copying and pasting your code over the attached project now it works. It even give me the right handle and all information about the list view. So now could you tell me how i should use your code so i only get the handle of listview and use it for my project.
I have a button inside that button after getting the handle of listview i want to send it to a funciton that uses that handle like this:
Code:
Private Sub Command1_Click()
'Get handle of listview then
Call GetListviewItem(ListViewHandle)
End Sub
LhWnd = FindWindow(vbNullString, "Windows Task Manager")
' if window found then...
If LhWnd > 0 Then
' get child info
GetChildrenInfo LhWnd
For i = 0 To UBound(AppChild) - 1
List1.AddItem _
AppChild(i).ID & vbTab & _
AppChild(i).hwnd & vbTab & _
AppChild(i).Type & vbTab & _
AppChild(i).Title & vbTab & _
AppChild(i).ClassName
Next i
Else
MsgBox "Window not found!", vbInformation
End If
Last edited by tony007; Apr 24th, 2010 at 07:35 PM.
Re: How to get hWnd of an external listview in hex just like spy++?
If the ID# for that control is always the same use the ID.
Run and exit your app a few time and test, if the ID for the control is always say 123, then loop the IDs for a match and pass the handle or what ever you need.... maybe something like,
Code:
'LhWnd = FindWindow(...
If LhWnd Then
GetChildrenInfo LhWnd
' loop till we find matching ID #
For i = 0 To UBound(AppChild) - 1
If AppChild(i).ID = 123 Then ' match found
ListViewHandle = AppChild(i).hWnd ' store handle
Call GetListviewItem(ListViewHandle) ' call your sub here or not?
Exit For ' exit for loop
End If
Next i
Else
MsgBox "Window not found!", vbInformation
End If
Last edited by Edgemeal; Apr 24th, 2010 at 07:58 PM.