Sign in to follow this  
Followers 0
Champak

External _GUICtrlListView_GetItemText issue

14 posts in this topic

I'm trying to get the text of an external listview, and nothing is being returned. I can get the count, but I can't get the text.

$Var1 = ControlGetHandle( "Find", "", 59535 )
$Var2 = _GUICtrlListView_GetItemCount($Var1)
If $Var2 > 1 Then
    For $i = 0 To $Var2 - 1
        ConsoleWrite("+++++++ " & _GUICtrlListView_GetItemText($Var1, $i))
    Next
EndIf

Any help?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This problem comes over and over and I think that it might be either improper function call by you or that the function actually doesn't success with allocation of the string in the callee process's address space because the _GUICtrlListView_GetItemCount function just send message with wparam and lparam both 0 so nothing can get wrong but if you're trying to get pointer to strings either via improper function call or definition, then this is the result and can be even worse if you're trying to send message with pointers to external control which will receive null pointers and crash it's own program ^^. If you can allocate and send message yourself it'll save you a lot of headache like whether it's your mistake or it's actually the function doesn't handle it properly. Cheers

Edited by Authenticity

Share this post


Link to post
Share on other sites

You say I may have used it incorrectly...do you see what is wrong with it? Because I don't. So if you see specifically what is wrong...in saying that I may have used it wrong...can you point it out to me? This is exactly how I used it. Can you suggest/show another way specifically, because I don't understand anything else that you said with allocations, addresses, pointers and so on. So if I have used this correctly, and others have had the same issue, I would venture to say that there IS a problem with the function...unless it just doesn't read some lists for whatever reason. Any other suggestions, Thanks.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Forgive me about my hazy explanation but in this case I can just assume that you successfully got a valid handle, if $Val1 does contain the handle and _GUICtrlListView_GetItemText is making troubles I cannot help you with this but I've recommended a way which this function does in it's own way.

I can say, for example I did some test once with the system's task manager with the help of sources on the network and I've got also this annoying problem but after I've understand what is the problem and that it's not just a theory then it's exactly what I told you earlier.

If you can give me an example of this window and it's ListView control then maybe I'll get around this, right now I'm talking about empty spaces -_'

Edited by Authenticity

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The name/title of the window is "Find".

Below is the screen shot of the Window Info. Thanks.

EDIT: I've just tried _GUICtrlListView_GetItemTextString, _GUICtrlListView_GetItemTextArray, and _GUICtrlListView_GetItem, and none of them are returning the text of the external listview....but they are returning my internal listviews texts.

post-12133-1232841260_thumb.gif

Edited by Champak

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Func _GUICtrlListView_GetItemText($hWnd, $iIndex, $iSubItem = 0)
    If $Debug_LV Then _GUICtrlListView_ValidateClassName($hWnd)
    Local $pBuffer, $tBuffer, $iItem, $pItem, $tItem, $pMemory, $tMemMap, $pText
    Local $fUnicode = _GUICtrlListView_GetUnicodeFormat($hWnd)

    If $fUnicode Then
        $tBuffer = DllStructCreate("wchar Text[4096]")
    Else
        $tBuffer = DllStructCreate("char Text[4096]")
    EndIf
    $pBuffer = DllStructGetPtr($tBuffer)
    $tItem = DllStructCreate($tagLVITEM)
    $pItem = DllStructGetPtr($tItem)
    DllStructSetData($tItem, "SubItem", $iSubItem)
    DllStructSetData($tItem, "TextMax", 4096)
    If IsHWnd($hWnd) Then
        If _WinAPI_InProcess($hWnd, $_lv_ghLastWnd) Then
            DllStructSetData($tItem, "Text", $pBuffer)
            If $fUnicode Then
                _SendMessage($hWnd, $LVM_GETITEMTEXTW, $iIndex, $pItem, 0, "wparam", "ptr")
            Else
                _SendMessage($hWnd, $LVM_GETITEMTEXTA, $iIndex, $pItem, 0, "wparam", "ptr")
            EndIf
        Else
            $iItem = DllStructGetSize($tItem)
            $pMemory = _MemInit($hWnd, $iItem + 4096, $tMemMap)
            $pText = $pMemory + $iItem
            DllStructSetData($tItem, "Text", $pText)
            _MemWrite($tMemMap, $pItem, $pMemory, $iItem)
            If $fUnicode Then
                _SendMessage($hWnd, $LVM_GETITEMTEXTW, $iIndex, $pMemory, 0, "wparam", "ptr")
            Else
                _SendMessage($hWnd, $LVM_GETITEMTEXTA, $iIndex, $pMemory, 0, "wparam", "ptr")
            EndIf
            _MemRead($tMemMap, $pText, $pBuffer, 4096)
            _MemFree($tMemMap)
        EndIf
    Else
        DllStructSetData($tItem, "Text", $pBuffer)
        If $fUnicode Then
            GUICtrlSendMsg($hWnd, $LVM_GETITEMTEXTW, $iIndex, $pItem)
        Else
            GUICtrlSendMsg($hWnd, $LVM_GETITEMTEXTA, $iIndex, $pItem)
        EndIf
    EndIf
    Return DllStructGetData($tBuffer, "Text")
EndFunc   ;==>_GUICtrlListView_GetItemText

Test by your-self to see if the handle is valid using IsHwnd, because if it's not as you can see you'll get back an empty string, also this function seems to be just fine but I can't say that it's so if you actually have a valid handle of the SysListView32 class and nothing else is wrong.

Just to clarify my point, I've did this sort of process using pure WinAPI C application on the system's "Windows Task Manager" and it actually worked but I still haven't tried it using AutoIt script but I do believe it's working but maybe calling this API functions directly from the dll is better for testing purpose. It's just my opinion.

Edited by Authenticity

Share this post


Link to post
Share on other sites

I'm unable to run this, getting a bunch of errors.

Where are these functions:

_GUICtrlListView_ValidateClassName

_MemInit

_MemWrite

_MemRead

_MemFree

What should the starting value of '$Debug_LV' be?

And what do you mean by "see if the handle is valid"? I do get a handle if I consolwrite the "$Var1"?

Share this post


Link to post
Share on other sites

I should have noted this, it's the function you're calling from the gui file header... What I intended to show is that if the hWnd is not an handle you'll drop by directly to the Else section which returns nothing but an empty string.

Share this post


Link to post
Share on other sites

Why the hell did you create ticket #788 for this? Let me explain why you're wasting my time right now:

  • You don't even know if this is a bug. You say so yourself in the ticket. If you have to ask "is this a bug" then you shouldn't be posting on the issue tracker.
  • You didn't give any useful information. You didn't mention your OS or the application. If you did mention it, I missed it because...
  • Rather than writing a proper bug report you just linked to a thread. I'm not going to read through a thread to find the few details that are relevant. If you can't be bothered to summarize the issue and provide all relevant information in the ticket itself then don't bother posting. We stopped using the forum for bug tracking for a reason.
  • There's no script. How are we supposed to reproduce the issue without the information you aren't giving us?

Maybe you found a bug, maybe you didn't. A good start to figuring things out would be to try ControListView() and see if it works. And if it does write an example that proves _GUICtrlListView_GetItemText() doesn't and that ControlListView() does. And then tell us what OS you use as well. Because without a script or any information about what you're working with or your environment then there's nothing we can do.

You've been around long enough to know better than to waste time like this. Very disappointing. I want the 10 minutes of my life back I've spent dealing with this.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

  • I paraphrased "is this a bug" in my ticket because I've noticed that it works on some apps and not all...my mistake that I didn't bring that to light; but I said it like that because maybe it was known to be like the ObjGet() not working with all COM object, and therefor not a bug. But since you didn't seem to know that, I guess it is a bug.
  • I didn't "give any useful info" there because I pointed to this thread thinking it would be more useful to see what was discussed, and I showed the way I tried to utilize the function here, and to not be redundant. I didn't mention the app I was using because I felt a high probability that you/someone did not have the app so you wouldn't be able to test it anyway....BUT I wouldn't have posted the ticket unless I tried it on multiple apps. I didn't mention the OS because nowhere in the tracker (that I saw) is it mentioned that it is of significant importance or required, so it wasn't on my mind to mention. I guess it would be a good idea for that requirement to be on the ticket request by making a drop down selection like the other drop down selections that are there so it is known.
  • OK, now I know. But I will venture to say, if you don't want certain behavior, to state it in some type of faq/rules like you do on this forum, and on the "Requesting New Features" in the trac so you don't get behaviors/postings that waste minutes out of your life, and I don't get responses like this.
  • I'll just be repeating my second point here.
It wasn't my intention to waste minutes of your life. Learned and wont happen again.

OS: XP SP2

Apps tested on: MS Streets & Trips, Vuze, Encompass, Genesis, Sequoia, Nero Express....Nero did work.

Getting/finding text in Nero works on both ControlListView() and _GUICtrlListView text finding/retrieving functions. And both functions don't work on the other apps. The infowindow on all the apps pretty much look the same as the image in the post 5.

EDIT: Easiest app to see the issue with is Vuze(free). Although in the first post, here is one with controllistview:

#include <GuiListView.au3>
;#include <ListViewConstants.au3>

;Sleep(2000)

;The control numbers seem to change in Vuze everytime the app is restarted
;$Var1 = ControlGetHandle( "Vuze", "", 2819666 );Downloading listview
$Var1 = ControlGetHandle( "Vuze", "", 591410 );Uploading listview

;========================================================================
;$Var1 = ControlGetHandle( "Nero Express", "", 3591 )
;========================================================================

$Var2 = _GUICtrlListView_GetItemCount($Var1)
ConsoleWrite("!Count " & $Var2 & @CRLF)
If $Var2 > 1 Then
    For $i = 0 To $Var2 - 1
        ;------------------------------------------------------------------------------------
        $44 = ControlListView ( "Vuze", "", $Var1, "GetText", $i, 9)
        ConsoleWrite("-C-ListView " & $44 & @CRLF)
        ;-------------------------------------------------------------------------------------
        ConsoleWrite(">GC-ListView " & _GUICtrlListView_GetItemTextString($Var1, $i) & @CRLF)
        ;-------------------------------------------------------------------------------------
    Next
EndIf

;ControlListView ( "Vuze", "", $Var1, "SelectAll")
Edited by Champak

Share this post


Link to post
Share on other sites

I paraphrased "is this a bug" in my ticket because I've noticed that it works on some apps and not all...my mistake that I didn't bring that to light; but I said it like that because maybe it was known to be like the ObjGet() not working with all COM object, and therefor not a bug. But since you didn't seem to know that, I guess it is a bug.

It is known not to work all the time and it is not a bug. Owner-drawn list-views may or may not return information.

I didn't "give any useful info" there because I pointed to this thread thinking it would be more useful to see what was discussed, and I showed the way I tried to utilize the function here, and to not be redundant.

Why would you think it's useful to read through an entire thread instead of a single post on the issue tracker? This makes no sense.

I didn't mention the app I was using because I felt a high probability that you/someone did not have the app so you wouldn't be able to test it anyway....BUT I wouldn't have posted the ticket unless I tried it on multiple apps.

Where have we ever stated we wouldn't try to reproduce a bug if you couldn't give us a script that used something we already had? And how are we supposed to know you tried multiple applications?

I didn't mention the OS because nowhere in the tracker (that I saw) is it mentioned that it is of significant importance or required, so it wasn't on my mind to mention. I guess it would be a good idea for that requirement to be on the ticket request by making a drop down selection like the other drop down selections that are there so it is known.

Or people could use some common sense but that's a lot to ask.

OK, now I know. But I will venture to say, if you don't want certain behavior, to state it in some type of faq/rules like you do on this forum, and on the "Requesting New Features" in the trac so you don't get behaviors/postings that waste minutes out of your life, and I don't get responses like this.

I agree that it needs done but it's not fun to write things like that and it's also not very clear how to ensure people will actually see it.

Just so it's clear, this is not a bug. Chances are that if you see a ListView with non-text items in it, its probably not going to respond to requests for text. It means the ListView is probably owner-drawn or uses the alternate way of handling the text strings. Just a look at the Vuze UI in the screenshots on their site tell me that is very likely the case.

Share this post


Link to post
Share on other sites

well, maybe i have a hint to this:

i don't understand how and why, but apparently on some dialog windows, the handles of the external controls are not constant.

i found this strange phenomenom in the system filesave/fileopen dialogs. the listviewhandle is no more valid when you change the path in the combobox.

the solution was to always get a new handle by ControlGetHandle instead of using the one found at first.

i hope this is of any help.

j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

problem is still not resolved? I have the same problem,  Autoit seems cannot handle  owner-drawn listview?

Any solutions?

Share this post


Link to post
Share on other sites

Open a new thread, this one is 5 years old, and you're posting worthless information without a script showing what you've tried, at least give us the name of the program you're trying to read from and the Au3Info information showing the listview control.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0