Results 1 to 15 of 15

Thread: howto get text from listview with api?

  1. #1

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    Question _______________________________

    _______________________________
    Last edited by Y.P.Y; Apr 28th, 2012 at 05:16 PM.

  2. #2

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    Arrow howto get item in listview with api?

    hi
    this is my code
    and when use this code remote program is teminated
    Code:
    Option Explicit
    Private Type LV_ITEM
       mask As Long
       iItem As Long
       iSubItem As Long
       state As Long
       stateMask As Long
       pszText As String
       cchTextMax As Long
       iImage As Long
       lParam As Long
       iIndent As Long
    End Type
    
    Private Declare Function SendMessage Lib "user32" _
       Alias "SendMessageA" _
      (ByVal hwnd As Long, _
       ByVal wMsg As Long, _
       ByVal wParam As Long, _
       lParam As Any) As Long
    
    Const LVM_FIRST = &H1000
    Const LVM_GETITEM = (LVM_FIRST + 5)
    Const LVIF_IMAGE = &H2
    Const LVIF_TEXT = &H1
    
    
    Private Sub Command1_Click()
     Dim myItem As LV_ITEM
    
        With myItem
            .iItem = 0 '<-- 1'st Listitem (zero based index)
            .iSubItem = 0 '<-- one based; set to 0 to refer to Item
         .pszText = String(256, vbNullChar) '<-- Allocate buffer space for Item text 
         .cchTextMax = 256 '<-- Length of buffer
          .mask = LVIF_IMAGE Or LVIF_TEXT
        End With
        
        SendMessage (hwn of remote program), LVM_GETITEM, 0&, myItem
        
        'Remove null char's from Item text string
       myItem.pszText = Replace(myItem.pszText, vbNullChar, "")
        
        MsgBox "Item Text: " & myItem.pszText
    End Sub
    can anyone help me?

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: howto get text from listview with api?

    Threads merged - please post each question (or variation of it) only once.

  4. #4
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: howto get text from listview with api?

    Processes are running i virtual memory, i.e. all starts at address &H400000. You har requesting information from a remote process which will retrieve the data from a non existing listview structure. As I understand you have got the remote window handle already. This is how you do it.

    1. Allocate memory in remote process
    2. Fill your listview structre with values as you have done
    3. Transfer the structure to allocated memory in remote process
    4. Send the message but this time with address to allocated memory i remote process
    5. Transfer the item text from allocated memory in remote process to allocated memory in your process
    6. Free allocated memory

    Now you can show messagebox with item text.
    Last edited by minor28; Jan 17th, 2009 at 08:45 AM.

  5. #5

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    Re: howto get text from listview with api?

    Quote Originally Posted by minor28
    Processes are running i virtual memory, i.e. all starts at address &H400000. You har requesting information from a remote process which will retrieve the data from a non existing listview structure. As I understand you have got the remote window handle already. This is how you do it.

    1. Allocate memory in remote process
    2. Fill your listview structre with values as you have done
    3. Transfer the structure to allocated memory in remote process
    4. Send the message but this time with address to allocated memory i remote process
    5. Transfer the item text from allocated memory in remote process to allocated memory in your process
    6. Free allocated memory

    Now you can show messagebox with item text.
    hey men help me

    this is another,i find this but when get item only empty added to listbox?
    why?
    Code:
    Option Explicit
    
    Private Const LVIF_TEXT As Long = &H1
    Private Const LVM_FIRST As Long = &H1000
    Private Const LVM_GETITEM As Long = (LVM_FIRST + 5)
    Private Const LVM_SETITEM As Long = (LVM_FIRST + 6)
    Private Const LVM_GETITEMCOUNT As Long = (LVM_FIRST + 4)
    Private Const MEM_COMMIT As Long = &H1000
    Private Const PAGE_READWRITE As Long = &H4
    Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000
    Private Const SYNCHRONIZE As Long = &H100000
    Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)
    Private Const MEM_RELEASE As Long = &H8000
    
    Private Type LVITEM
        mask As Long
        iItem As Long
        iSubItem As Long
        state As Long
        stateMask As Long
        pszText As Long 'Notice not string but long
        cchTextMax As Long
        iImage As Long
        lParam As Long
        iIndent As Long
    End Type
    
    Private Declare Function OpenProcess Lib "kernel32.dll" ( _
         ByVal dwDesiredAccess As Long, _
         ByVal bInheritHandle As Long, _
         ByVal dwProcessId As Long) As Long
         
    Private Declare Function WriteProcessMemory Lib "kernel32.dll" ( _
         ByVal hProcess As Long, _
         ByRef lpBaseAddress As Any, _
         ByRef lpBuffer As Any, _
         ByVal nSize As Long, _
         ByRef lpNumberOfBytesWritten As Long) As Long
         
    Private Declare Function ReadProcessMemory Lib "kernel32.dll" ( _
         ByVal hProcess As Long, _
         ByRef lpBaseAddress As Any, _
         ByRef lpBuffer As Any, _
         ByVal nSize As Long, _
         ByRef lpNumberOfBytesWritten As Long) As Long
         
    Private Declare Function GetWindowThreadProcessId Lib "user32.dll" ( _
         ByVal hwnd As Long, _
         ByRef lpdwProcessId As Long) As Long
         
    Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
         ByVal lpClassName As Long, _
         ByVal lpWindowName As String) As Long
         
    Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" ( _
         ByVal hwndParent As Long, _
         ByVal hwndChildAfter As Long, _
         ByVal lpszClass As String, _
         ByVal lpszWindow As Long) As Long
         
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" ( _
         ByVal hwnd As Long, _
         ByVal wMsg As Long, _
         ByVal wParam As Long, _
         ByVal lParam As Long) As Long
    
    Private Declare Function VirtualAllocEx Lib "kernel32.dll" ( _
         ByVal hProcess As Long, _
         ByVal lpAddress As Long, _
         ByVal dwSize As Long, _
         ByVal flAllocationType As Long, _
         ByVal flProtect As Long) As Long
    
    Private Declare Function VirtualFreeEx Lib "kernel32.dll" ( _
         ByVal hProcess As Long, _
         ByVal lpAddress As Long, _
         ByVal dwSize As Long, _
         ByVal dwFreeType As Long) As Long
    
    Private Declare Function CloseHandle Lib "kernel32.dll" ( _
         ByVal hObject As Long) As Long
         
    Private Declare Function TerminateProcess Lib "kernel32.dll" ( _
         ByVal hProcess As Long, _
         ByVal uExitCode As Long) As Long
         
    Dim hProcess As Long
    
    Private Sub Command1_Click()
        Dim hndl As Long
        Dim hListView As Long
        Dim lpdwProcessId As Long
        Dim pMem As Long
        Dim lvi As LVITEM
        Dim lpNumberOfBytesWritten As Long
        Dim i As Long
        Dim cItems As Long
        Dim txt As String
        Dim pTxt As Long
        
        'Get the handle of listview control
        hndl = FindWindow(0, "WindowName")
        hListView = FindWindowEx(hndl, 0, "SysListView32", 0)
        
        'Retrieve a handle of the listview control process
        GetWindowThreadProcessId hListView, lpdwProcessId
        hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, lpdwProcessId)
        
        'Allocate memory in listview process memory space for the LVITEM structure and listitem text
        pMem = VirtualAllocEx(hProcess, 0, Len(lvi), MEM_COMMIT, PAGE_READWRITE)
        pTxt = VirtualAllocEx(hProcess, 0, 256, MEM_COMMIT, PAGE_READWRITE)
        
        'Retrieve number of listview items
        cItems = SendMessage(hListView, LVM_GETITEMCOUNT, 0, 0)
        
        'Fill a LVITEM structure with values
        lvi.mask = LVIF_TEXT
        lvi.cchTextMax = 256
        lvi.pszText = pTxt 'This is a pointer to the address where item text will be hold
        
        'Allocate space for a string
        txt = Space(256)
        
        For i = 0 To cItems - 1
            'Add item index to structure
            lvi.iItem = i
            
            'Transfer the structure to allocated memory in listview memory space
            WriteProcessMemory hProcess, ByVal pMem, lvi, Len(lvi), lpNumberOfBytesWritten
            
            'Send message to get listview item [i]. Result hold in LVITEM strucktur at address pMem
            SendMessage hListView, LVM_GETITEM, 0, ByVal pMem
            
            'Transfer the item text from allocated memory at pTxt to txt space in this app process memory
            ReadProcessMemory hProcess, ByVal pTxt, ByVal txt, 256, lpNumberOfBytesWritten
            List1.AddItem txt
        Next i
        'Free allocated memory
        VirtualFreeEx hProcess, pMem, Len(lvi), MEM_RELEASE
        VirtualFreeEx hProcess, pTxt, 256, MEM_RELEASE
        
    End Sub
    
    Private Sub Form_Load()
        Shell "fullpath to listview.exe"
    End Sub
    
    Private Sub Form_Terminate()
        TerminateProcess hProcess, 0
        CloseHandle hProcess
    End Sub
    Last edited by Y.P.Y; Jan 18th, 2009 at 02:05 AM.

  6. #6

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    Re: howto get text from listview with api?

    please answer my ques!

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: howto get text from listview with api?

    I think the main problem is with this line of code
    Code:
    hndl = FindWindow(0, "WindowName")
    You have to supply the window's titlebar text of the window that contains the listview.

    Ensure hndl1 and hListView are not zero. If they are, you are not finding what you are looking for.
    Last edited by LaVolpe; Jan 18th, 2009 at 02:21 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    Arrow Re: howto get text from listview with api?

    Quote Originally Posted by LaVolpe
    I think the main problem is with this line of code
    Code:
    hndl = FindWindow(0, "WindowName")
    You have to supply the window's titlebar text of the window that contains the listview.

    Ensure hndl1 and hListView are not zero. If they are, you are not finding what you are looking for.
    iknow, but its for example!

    this attached file is my vb codes its work for taskmgr.exe and i SUCCESSFUL to get text from taskmgr.exe but not work for my remote program(RSDLite)
    this link is my remote program >> http://www.4shared.com/file/23878331...te_39.html?s=1

    when i get text from listview of rsdlite only empty give to me?

    why?
    help please
    Attached Files Attached Files

  9. #9
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: howto get text from listview with api?

    Have a look at this thread if it helps.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  10. #10

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    Re: howto get text from listview with api?

    Quote Originally Posted by dee-u
    Have a look at this thread if it helps.

    i get text from taskmmgr.exe.its ok no problem but when get text from RSDlite listview, send error to me? (http://www.4shared.com/file/23878331...te_39.html?s=1)

    help please
    many thanks

  11. #11
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: howto get text from listview with api?

    I recognize the code. It looks like you have come across some of my code. This code is complete and should work. Of your answer to LaVolpe's suggestion I can't conclude that hnd1 or hListView are zero or not. I guess you haven't found the window.

  12. #12

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    Arrow Re: howto get text from listview with api?

    Quote Originally Posted by minor28
    I recognize the code. It looks like you have come across some of my code. This code is complete and should work. Of your answer to LaVolpe's suggestion I can't conclude that hnd1 or hListView are zero or not. I guess you haven't found the window.

    thanks much
    yes its work fine but woth some change

    how to select with left mouse click on listview frist item?

  13. #13
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: howto get text from listview with api?

    Quote Originally Posted by Y.P.Y
    thanks much
    yes its work fine but woth some change

    how to select with left mouse click on listview frist item?
    What do you mean? Have you got the text from the listview or not. Is it a new question?

  14. #14

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    Question Re: howto get text from listview with api?

    Quote Originally Posted by minor28
    What do you mean? Have you got the text from the listview or not. Is it a new question?
    yes i have got text from listview,

    this is new question:
    How to send left click mouse button(WM_LBUTTON) message to items of listview?

  15. #15

    Thread Starter
    Lively Member Y.P.Y's Avatar
    Join Date
    Sep 2008
    Location
    Tehran - Iran
    Posts
    88

    Re: howto get text from listview with api?

    i think must be create another Thread for my 2nd questions!!

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