CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Join Date
    Jun 2012
    Posts
    19

    Question ListView_GetItemRect Help

    I am new to Windows programming and I am trying to click an item in listview control for that I need to take the rect size of the listview.Can anyone help me regarding ListView_GetItemRect macro.

    I used like this:
    ListView_GetItemRect(e3Obj.eHwnd,3,&rec,LVIR_BOUNDS);
    But I am not getting any values in the RECT rect.Kindly help me

  2. #2
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: ListView_GetItemRect Help

    1. What value does this macro return? TRUE or FALSE?
    2. Is the e3Obj.eHwnd a correct control handle?
    3. Does an item with indesx 3 exist?

    Besides, please, use Code tags and white spaces within the parameter list:
    Code:
    BOOL bRet = ListView_GetItemRect(e3Obj.eHwnd, 3, &rec, LVIR_BOUNDS);
    Victor Nijegorodov

  3. #3
    Join Date
    Jun 2012
    Posts
    19

    Re: ListView_GetItemRect Help

    1.Macro returns false
    2.Yes eHwnd is the correct Handle as I checked with LVM_GETITEMCOUNT.
    3.Yes there are total 20 items

    b=ListView_GetItemRect(eHwnd, 3, &rec, LVIR_BOUNDS);

    Can you please give me a small example how to use &rec. Thanks in advance

  4. #4
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: ListView_GetItemRect Help

    Quote Originally Posted by haroonrulz View Post
    1.Macro returns false
    It means that the call was unsuccessful.
    Quote Originally Posted by haroonrulz View Post
    Can you please give me a small example how to use &rec. Thanks in advance
    Code:
    Rect rect;
    BOOL bRet = ListView_GetItemRect(e3Obj.eHwnd, 3, &rect, LVIR_BOUNDS);
    Victor Nijegorodov

  5. #5
    Join Date
    Jun 2012
    Posts
    19

    Re: ListView_GetItemRect Help

    The macro still returns FALSE.
    1.Can you please let me know what would be the possible mistakes I would have done.
    2.Is there any macro to click an item in listview or can you help/guide me regarding this.

  6. #6
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: ListView_GetItemRect Help

    1. There may be some reasons for ListView_GetItemRect to fail, like
    1. invalid window handle
    2. invalid item index
    3. perhaps, some others

    2. What are you trying to achieve?
    Victor Nijegorodov

  7. #7
    Join Date
    Jun 2012
    Posts
    19

    Re: ListView_GetItemRect Help

    Sir I am developing an automation tool for which I need to click on the item in the listview. As there is no macro for directly clicking on listview item.One of my colleague suggested me, " to get the listview item size using ListView_GetItemRect and then try to convert it to X,Y mouse point and click on it".But I am completely blank. Please help me and sorry for disturbing you a lot sir.

  8. #8
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: ListView_GetItemRect Help

    Are you calling these LVM_GETITEMCOUNT, ListView_GetItemRect from the same process where list control is placed or in some other process?
    Victor Nijegorodov

  9. #9
    Join Date
    Jun 2012
    Posts
    19

    Re: ListView_GetItemRect Help

    I am calling in the same process.
    Things I have done:
    Sample code:
    RECT rect;
    int ix;
    ix=ListView_GetItemCount(e3Obj.eHwnd);
    //I am getting 20 in ix.Also I have checked it manually.
    BOOL bRet = ListView_GetItemRect(e3Obj.eHwnd, 3, &rec, LVIR_BOUNDS);

    Sir also let me know am I following the correct way to click on the item in listview or is there some other way.
    Last edited by haroonrulz; January 10th, 2013 at 09:52 AM.

  10. #10
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: ListView_GetItemRect Help

    Quote Originally Posted by haroonrulz View Post
    I am calling in the same process.
    Again: is it the same process that does contain this list control or is it some other process?

    Quote Originally Posted by haroonrulz View Post
    Sir also let me know am I following the correct way to click on the item in listview or is there some other way.
    What do you mean by "click on the item in listview"? And what for?
    What actions is this listview control supposed to do in response to your "click"?
    Victor Nijegorodov

  11. #11
    Join Date
    Jun 2012
    Posts
    19

    Re: ListView_GetItemRect Help

    Sir I am developing an automation tool.For that I need to click on list view item.Kindly look at the picture attached.Hope you understand my question.

    Name:  1.JPG
Views: 1697
Size:  47.6 KB

  12. #12
    VictorN's Avatar
    VictorN is online now Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: ListView_GetItemRect Help

    Quote Originally Posted by haroonrulz View Post
    Sir I am developing an automation tool.For that I need to click on list view item.Kindly look at the picture attached.Hope you understand my question.
    No, I didn't.

    Instead of repeating again and again about "automation" you should have better explained what you mean by this "automation" and answered on my questions:
    Quote Originally Posted by VictorN View Post
    Again: is it the same process that does contain this list control or is it some other process?

    What do you mean by "click on the item in listview"? And what for?
    What actions is this listview control supposed to do in response to your "click"?
    Victor Nijegorodov

  13. #13
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: ListView_GetItemRect Help

    If you are automating, then the &rec pointer may be valid in the context of YOUR program
    but in the other program (WinSpy++) this address will not be valid.

    Only SOME windows message calls will work when used on controls that have been created in another program/process.

  14. #14
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: ListView_GetItemRect Help

    Should I say it that I already warned you in the other thread?

    Quote Originally Posted by haroonrulz View Post
    I am new to Windows programming and I am trying to click an item in listview control for that I need to take the rect size of the listview.Can anyone help me regarding ListView_GetItemRect macro.
    Your problem is not the macro. Your problem is that you hardly understand how Windows controls work. You're looking for some magic macro while there is no one in your specific case.

    Quote Originally Posted by haroonrulz View Post
    Sir I am developing an automation tool for which I need to click on the item in the listview. As there is no macro for directly clicking on listview item.One of my colleague suggested me, " to get the listview item size using ListView_GetItemRect and then try to convert it to X,Y mouse point and click on it".But I am completely blank.
    So you're not prepared enough for completing this task. You cannot develop anything complex in Windows being completely blank and new to Windows programming.

    Now to your assignment.

    It may be solved two different ways. First is code injection. This (writing code to remote process and creating remote thread) or that (injecting dll) way your code have to appear in the context of the process you to automate. Then by means of some IPC (inter-process communication) your code gets the command 'click on item 3', gets the corresponding item rect (by means of the macro, or sending LVM_GETITEMRECT, whatever), positions mouse cursor inside the rect, emulates left button down and button up events. I repeat: All this code is inside the victim process.

    Second way implies no code injection, but ability to read/write the victim process memory is mandatory anyway. The automation process allocates remote memory enough to fit RECT in and passes the remote address to the macro, then it reads the rect coordinates and emulates the mouse button click as explained above. And does not forget to deallocate later, of course.

    This is how it looks from "helicopter view". A special headache is acquiring rights enough to read/write remote process memory or inject dll, as since Vista times Microsoft decided to make this kind of tricks be much more tricky than it was before.

    Now can anybody explain me how this could be done by somebody who's completely blank and new to Windows programming? Guys, if you really need some automation engine, you'd better go with already proved solutions like AutoIt
    Last edited by Igor Vartanov; January 11th, 2013 at 08:45 AM.
    Best regards,
    Igor

  15. #15
    Join Date
    Jun 2012
    Posts
    19

    Re: ListView_GetItemRect Help

    Dear Igor, Thanks for your advise/warning/solution .Surely It will help me a lot.

Page 1 of 2 12 LastLast

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

Featured