CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 14 of 14
  1. #1
    Join Date
    Apr 2004
    Posts
    6

    How can I get text of ListCtrl in another window when I put mouse on the list?

    Hi all,

    I want to get text of ListCtrl in another window when I put mouse on the ListCtrl.

    I got CListCtrl* but I can't get text of specified (row, col).

    //
    CListCtrl* pListCtrl = (CListCtrl*)WindowFromPoint(ScreenPoint);
    //
    LVITEM lvi;
    lvi.iItem = 0;
    lvi.iSubItem = 3;
    lvi.pszText = szBuffer;
    lvi.cchTextMax = 255;
    pListCtrl->GetItem(&lvi);
    //

    Here, the szBuffer is empty.

    Please help me.

    Thanks in advance,
    Kim, YoungHwan.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430
    Add this line before calling GetItem:
    Code:
    lvi.mask = LVIF_TEXT;

  3. #3
    Join Date
    Apr 2004
    Posts
    6
    Originally posted by VictorN
    Add this line before calling GetItem:
    Code:
    lvi.mask = LVIF_TEXT;
    I did it, but the result was same.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430
    I want to get text of ListCtrl in another window when I put mouse on the ListCtrl.
    Is this "another window" in the same application or in some other?

    If in the same - it should work. Anyway, try to use CListCtrl::GetItemText method and look at the return value. (BTW, have you allocated the buffer for szBuffer?)

    If in the other - IMHO, it is impossible.

  5. #5
    Join Date
    Jul 2003
    Posts
    116
    originally posted by VictorN

    If in the other - IMHO, it is impossible.
    its not impossible if its in another process there are ways for that.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430
    Hi, siawos !
    its not impossible if its in another process there are ways for that.
    ...using CListCtrl::GetItemText / CListCtrl::GetItem methods ?

  7. #7
    Join Date
    Jul 2003
    Posts
    116
    originally posted by VictorN

    using CListCtrl::GetItemText / CListCtrl::GetItem methods ?
    yes with these calls or the calls behind these calls, i mean the messages that are sent behind these calls.
    the only thing u need to cater are the process boundries for which there are several ways.

  8. #8
    Join Date
    Apr 2004
    Posts
    6
    Originally posted by siawos
    yes with these calls or the calls behind these calls, i mean the messages that are sent behind these calls.
    the only thing u need to cater are the process boundries for which there are several ways.
    Hi siawos,

    I had tried sending a message to get text, but it was failed.
    SendMessage() didn't work.

  9. #9
    Join Date
    Apr 2004
    Posts
    6
    Originally posted by VictorN
    Is this "another window" in the same application or in some other?

    If in the same - it should work. Anyway, try to use CListCtrl::GetItemText method and look at the return value. (BTW, have you allocated the buffer for szBuffer?)

    If in the other - IMHO, it is impossible.
    I meant it is of different application.

    By the way, I can get selected item count but can't for texts.
    Is there any differences between them?

  10. #10
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354
    if it is a different app, you need to hook into that.
    There are ways to do it.

    The reason why it works for count is the count is the return value of SendMessage(LVM_GETITEMCOUNT).

    However, for getting the text, you pass a buffer, which is not a valid address in another process space ( exception being WM_GETTEXT across processes, which is handled differently ).

    This article would probaly help
    Last edited by kirants; April 14th, 2004 at 10:52 AM.

  11. #11
    Join Date
    Apr 2004
    Posts
    6
    Originally posted by kirants
    if it is a different app, you need to hook into that.
    There are ways to do it.

    The reason why it works for count is the count is the return value of SendMessage(LVM_GETITEMCOUNT).

    However, for getting the text, you pass a buffer, which is not a valid address in another process space ( exception being WM_GETTEXT across processes, which is handled differently ).

    This article would probaly help
    I appreciate your reply very much, and I understand your explanations. BTW here, let me ask one more.
    I could get edit controls' text of another process's window with sendmessage(WM_GETTEXT). Is this different form ListCtrl?

    Thanks.

  12. #12
    Join Date
    Feb 2000
    Location
    San Diego, CA
    Posts
    10,354
    Originally posted by yhkim47
    I could get edit controls' text of another process's window with sendmessage(WM_GETTEXT). Is this different form ListCtrl?
    Yes. And I guess I did mention that as an exception.

  13. #13
    Join Date
    Apr 2004
    Posts
    6
    Originally posted by kirants
    Yes. And I guess I did mention that as an exception.
    Oops, sorry I missed it.
    Thanks anyway, and I'll read the article you suggested.

    Thanks again.

  14. #14
    Join Date
    Jul 2003
    Posts
    116
    posted by yhkim47

    I could get edit controls' text of another process's window with sendmessage(WM_GETTEXT).
    using sendmessage across process can cause blocking, for that u can either use PostMessage() or sendmessageTimeOut(), they dont cause blocking, and of these two SendMessageTimeOut() is a better option as long as the messages are not related to keyboard or mouse because they are normally posted.

    theres another way besides those "three ways" check this article as well

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