Jump to content

How I read all data in List control


 Share

Recommended Posts

Hi everyone,

I use List control to store data (GUICtrlCreateList). When program run, it add some data to this control. I use GUICtrlRead to read data in this control, but this function only read selected value. I wanna read all data in List control. How I do it?

Thanks for your help,

Edited by konani
Link to comment
Share on other sites

You will need to use a For Next statement and check out the _GUICtrlListBox from the help file.

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

Are you trying to return the list as an array or as a string?

To Return an array Call the following function with no second parameter, To return it as a delimited string call it with the second parameter being anything except Default, True or -1.

The first parameter is always the List control.

As an array >> _GUIList_GetAllItems($mylist) or _GUIList_GetAllItems($mylist, Default) or _GUIList_GetAllItems($mylist, -1)

As a string >> _GUIList_GetAllItems($mylist, 0) or _GUIList_GetAllItems($mylist, False)

Func _GUIList_GetAllItems($hWnd, $Array = True)
    If StringRegExp($Array, "(?i)-?1|default|True") Then
        $Array = True
    Else
        $Array = False
    EndIf
    If NOT IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $sRtn = "", $iLen, $tHold, $aResult, $sSep = Opt("GUIDataSeparatorChar")
    $aResult = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", 0x018B, "wparam", 0, "lparam", 0)
    If @Error Then Return SetError(@Error, @Extended, "")
    Local $iCount = $aResult[0]
    For $i = 0 To $iCount - 1
        $aResult = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", 0x018A, "wparam", 0, "lparam", 0)
        If @Error Then Return SetError(@Error, @Extended, "")
        $iLen = $aResult[0] + 1
        $tHold = DllStructCreate("wchar Text[" & $iLen & "]")
        DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", 0x0189, "wparam", $i, "lparam", DllStructGetPtr($tHold))
        If @Error Then Return SetError(@Error, @Extended, "")
        $sRtn &= DllStructGetData($tHold, "Text") & $sSep
    Next
    $sRtn = StringTrimRight($sRtn, StringLen($sSep))
    If $Array Then Return StringSplit($sRtn, $sSep, 2)
    Return $sRtn
EndFunc   ;==>_GUIList_GetAllItems

EDIT: Fixed a potential error in the code and added error checking

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Are you trying to return the list as an array or as a string?

To Return an array Call the following function with no second parameter, To return it as a delimited string call it with the second parameter being anything except Default, True or -1.

The first parameter is always the List control.

As an array >> _GUIList_GetAllItems($mylist) or _GUIList_GetAllItems($mylist, Default) or _GUIList_GetAllItems($mylist, -1)

As a string >> _GUIList_GetAllItems($mylist, 0) or _GUIList_GetAllItems($mylist, False)

Func _GUIList_GetAllItems($hWnd, $Array = True)
    If StringRegExp($Array, "(?i)-?1|default|True") Then
        $Array = True
    Else
        $Array = False
    EndIf
    If NOT IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
    Local $sRtn = "", $iLen, $tHold, $aResult, $sSep = Opt("GUIDataSeparatorChar")
    $aResult = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", 0x018B, "wparam", 0, "lparam", 0)
    If @Error Then Return SetError(@Error, @Extended, "")
    Local $iCount = $aResult[0]
    For $i = 0 To $iCount - 1
        $aResult = DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", 0x018A, "wparam", 0, "lparam", 0)
        If @Error Then Return SetError(@Error, @Extended, "")
        $iLen = $aResult[0] + 1
        $tHold = DllStructCreate("wchar Text[" & $iLen & "]")
        DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", $hWnd, "uint", 0x0189, "wparam", $i, "lparam", DllStructGetPtr($tHold))
        If @Error Then Return SetError(@Error, @Extended, "")
        $sRtn &= DllStructGetData($tHold, "Text") & $sSep
    Next
    $sRtn = StringTrimRight($sRtn, StringLen($sSep))
    If $Array Then Return StringSplit($sRtn, $sSep, 2)
    Return $sRtn
EndFunc   ;==>_GUIList_GetAllItems

EDIT: Fixed a potential error in the code and added error checking

Thanks in advance, I solved.
Link to comment
Share on other sites

  • 2 years later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...