Results 1 to 12 of 12

Thread: [VB6] Clone ListView

  1. #1

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Arrow [VB6] Clone ListView

    The attached demo project below shows how to duplicate the textual contents of another ListView control, even if it's from another process (32-bit processes only).

    Name:  Clone ListView.png
Views: 5058
Size:  23.1 KB

    EDIT

    Here's the updated version from Post #4:

    Attached Files Attached Files
    Last edited by Bonnie West; Jan 17th, 2015 at 08:20 AM.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  2. #2
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: [VB6] Clone ListView

    Nice. I finally figured out that you need to hold F12 down while moving the mouse over another LV.
    Works fine with explorer's LV.

    I added
    If hWndLV = ListView1.hWnd Then Exit Sub
    to the CloneListView routine to keep it from reloading when you move the cursor over the form's LV.

  3. #3

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [VB6] Clone ListView

    Quote Originally Posted by VBClassicRocks View Post
    Nice.
    Thanks!

    Quote Originally Posted by VBClassicRocks View Post
    I finally figured out that you need to hold F12 down while moving the mouse over another LV.
    The F12 key can be replaced with any other key by changing the GetAsyncKeyState(vbKeyF12) line.

    Quote Originally Posted by VBClassicRocks View Post
    Works fine with explorer's LV.
    I've just tested it with Explorer's windows in Win 7 and unfortunately, it could not retrieve any text. Although, the Desktop items can be enumerated. I've yet to fully investigate this issue.

    Quote Originally Posted by VBClassicRocks View Post
    I added
    If hWndLV = ListView1.hWnd Then Exit Sub
    to the CloneListView routine to keep it from reloading when you move the cursor over the form's LV.
    Yeah, I forgot that. Thanks!


    I'll most likely be updating this again when I have managed to figure out how to retrieve the header control's captions and maybe the icons as well.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  4. #4

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [VB6] Clone ListView

    As promised, attached here is the updated version. I, however, have decided not to copy the items' icons anymore because it turned out to be more complicated than I thought.

    Quote Originally Posted by Bonnie West View Post
    I've just tested it with Explorer's windows in Win 7 and unfortunately, it could not retrieve any text.
    After a bit more testing, I found out that the List View control used in Win 7's Explorer windows had the classname "DirectUIHWND". It does not seem to respond as expected to some of the List View messages I've sent to it.

    Windows Vista's Explorer windows, on the other hand, still uses the old List View classname, as can be seen in the screenshot below:

    Name:  Clone ListView.png
Views: 3298
Size:  39.6 KB
    Attached Files Attached Files
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  5. #5
    Addicted Member
    Join Date
    Sep 2008
    Posts
    141

    Re: [VB6] Clone ListView

    You know. Some reason this doesn't work on 64bit OS

  6. #6

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [VB6] Clone ListView

    Quote Originally Posted by brandoncampbell View Post
    You know. Some reason this doesn't work on 64bit OS
    Is the target process 64-bit? If so, it really won't work because pointers in VB6 are just 32 bits wide. That code dim's a few pointers that points to some allocated memory on the target process. There's nothing I can do about it, I'm afraid. If the target process however, is 32-bits, at which line does that code fail?
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  7. #7
    Addicted Member
    Join Date
    Sep 2008
    Posts
    141

    Re: [VB6] Clone ListView

    Quote Originally Posted by Bonnie West View Post
    Is the target process 64-bit? If so, it really won't work because pointers in VB6 are just 32 bits wide. That code dim's a few pointers that points to some allocated memory on the target process. There's nothing I can do about it, I'm afraid. If the target process however, is 32-bits, at which line does that code fail?
    It's Windows property for security groups listview.

  8. #8

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [VB6] Clone ListView

    That code is probably being denied access because the dialog box where the ListView is located was likely created by an elevated process. Try running that code as administrator. If you still encounter additional issues, please provide more details next time.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  9. #9
    Addicted Member
    Join Date
    Sep 2008
    Posts
    141

    Re: [VB6] Clone ListView

    your post #4 is similar to what I am trying to do. It will not pick up whats in the list on Windows 7 64bit

  10. #10

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [VB6] Clone ListView

    Quote Originally Posted by brandoncampbell View Post
    It will not pick up whats in the list on Windows 7 64bit
    As I've already explained, pointers in 32-bit and 64-bit processes have different sizes. That code uses a few pointers and it won't be able to access any memory address beyond 4 GB. Sorry, but I don't think there's anything I can do about it.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  11. #11
    Addicted Member
    Join Date
    Sep 2008
    Posts
    141

    Re: [VB6] Clone ListView

    Quote Originally Posted by Bonnie West View Post
    As I've already explained, pointers in 32-bit and 64-bit processes have different sizes. That code uses a few pointers and it won't be able to access any memory address beyond 4 GB. Sorry, but I don't think there's anything I can do about it.
    Bummer.. I needed this again today and decided to revisit it. It's funny because it builds the list columns without the text and even enters the amount of list entries without the text. So I guess it is reading the listview fine.. just not the text that's there.

  12. #12

    Thread Starter
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [VB6] Clone ListView

    Quote Originally Posted by brandoncampbell View Post
    So I guess it is reading the listview fine.. just not the text that's there.
    Unfortunately, that's just the way it is; 32-bit and 64-bit processes don't play well together especially when pointers and memory addresses are involved.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

Tags for this Thread

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