Results 1 to 15 of 15

Thread: How to get hWnd of an external listview in hex just like spy++?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How to get hWnd of an external listview in hex just like spy++?

    Isn't this like a thread you created earlier? http://www.vbforums.com/showthread.php?t=565577

    Also look at this http://www.vbforums.com/showthread.p...+listview+hwnd

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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
    Attached Images Attached Images  
    Last edited by tony007; Apr 24th, 2010 at 03:47 PM.

  4. #4
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: How to get hWnd of an external listview in hex just like spy++?


  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to get hWnd of an external listview in hex just like spy++?

    Quote Originally Posted by whatsup View Post
    thanks for your reply. Even that program didn't produce the right handle !! Only spy++ produce right handle but how i write the code to get same code?

    i think the listview is inside a frame that hard to reach !!

  6. #6
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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.
    Attached Files Attached Files
    Last edited by Edgemeal; Apr 24th, 2010 at 06:36 PM. Reason: remove exe from .Zip

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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...

  8. #8
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: How to get hWnd of an external listview in hex just like spy++?

    Quote Originally Posted by tony007 View Post
    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.

    LhWnd = FindWindow(vbNullString, "TheProgramTitleHere")

    Then change the loop below it so it shows you everything for now, remove the If InStr( .... line and it's End If line.

    no need for form2, its just in the example so it has something to find.
    Last edited by Edgemeal; Apr 24th, 2010 at 06:48 PM.

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How to get hWnd of an external listview in hex just like spy++?

    i changed it to this but nothing has filled the listbox !!

    Code:
      LhWnd = FindWindow("#32770", "Add")
    where the #32770 is class name.

    Spy++ gives this information about the window that holds this listview :

    caption"Add"
    Class:#32770 (Dialog)

    Spy++ gives information about the listview itself:

    Caption:""
    class:SysListView32
    Last edited by tony007; Apr 24th, 2010 at 06:58 PM.

  10. #10
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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

  11. #11

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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.

  12. #12
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: How to get hWnd of an external listview in hex just like spy++?

    Quote Originally Posted by tony007 View Post
    I tried that didn't work.But Strange it didn't evnen work for Windows Task Manger !!
    That just weird, don't know what to tell you, I've never seen that happen.

  13. #13

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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
    Id:1462
    hWnd:132894
    type:class
    title:SysListView32
    Class:SysListview32
    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
    Last edited by tony007; Apr 24th, 2010 at 07:35 PM.

  14. #14
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    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.

  15. #15
    Hyperactive Member
    Join Date
    Jul 2009
    Posts
    489

    Re: How to get hWnd of an external listview in hex just like spy++?

    did you select components as in the picture ?
    that should list all the components in indent column

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width