Jump to content

ControlListView vs. "The one who would not read, at first"


Go to solution Solved by argumentum,

Recommended Posts

So am reading a ControlListView() and is not working so I code a troubleshooter to figure it out.

#AutoIt3Wrapper_UseX64=n
#include <Array.au3>

;       Remarks:  ( from the help file )
;       ------------------------------------------------------------------------------------------------
;       Some commands may fail when using a 32-bit AutoIt process to read from a 64-bit process.
;           Likewise commands may fail when using a 64-bit AutoIt process to read from a 32-bit process.


Global $g_sAutoIt3Path = StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1))
If StringInStr($CmdLineRaw, "/GuiListviewToReadFrom") Then Exit GuiListviewToReadFrom()

ShellExecute($g_sAutoIt3Path & "AutoIt3.exe", '"' & @ScriptFullPath & '" /GuiListviewToReadFrom')
;~ ShellExecute($g_sAutoIt3Path & "AutoIt3_x64.exe", '"' & @ScriptFullPath & '" /GuiListviewToReadFrom')

Test()
Func Test()
    Local $vRet = ReadTheListViewFromSomewhere()
    If @error And @error < 5 Then
        MsgBox(262144, @ScriptName, "Fail #:" & @error & @CR & $vRet, 10)
    Else
        _ArrayDisplay($vRet, 'Error: ' & @error & " - " & _
                (@AutoItX64 ? "64-bit" : "32-bit") & " - " & _
                @ScriptName, "", 0, Default, "Row A|Row B|Row C")
    EndIf
    WinClose("GuiListviewToReadFrom - ")
EndFunc   ;==>Test

Func GuiListviewToReadFrom()
    Opt("TrayIconHide", 1)
    Local $iW = 400, $iH = 100, $sXbit = (@AutoItX64 ? "64-bit" : "32-bit")
    Local $hGui = GUICreate("GuiListviewToReadFrom - " & $sXbit, $iW, $iH)
    Local $idListview = GUICtrlCreateListView("Row A|Row B|Row C", 0, 0, $iW, $iH)
    GUICtrlCreateListViewItem("0-A|0-B|0-C", $idListview)
    GUICtrlCreateListViewItem("1-A|1-B|1-C", $idListview)
    GUICtrlCreateListViewItem("2-A|2-B|2-C", $idListview)
    GUISetState()
    While GUIGetMsg() <> -3
    WEnd
    GUIDelete()
EndFunc   ;==>GuiListviewToReadFrom

Func ReadTheListViewFromSomewhere($sTitle = "GuiListviewToReadFrom - ", $sLvCtrl = "SysListView321")
    If Not WinWait($sTitle, "", 3) Then Return SetError(1, 0, "Window not found")
    Local $hWin = WinGetHandle($sTitle)
    If @error Then Return SetError(2, 0, "No WinHandle")
    Local $n, $iItemCount = ControlListView($hWin, "", $sLvCtrl, "GetItemCount")
    If @error Then Return SetError(3, 0, "No ItemCount")
    Local $m, $iSubItemCount = ControlListView($hWin, "", $sLvCtrl, "GetSubItemCount")
    If @error Then Return SetError(4, 0, "No SubItemCount")
    Local $aArray[$iItemCount][$iSubItemCount]
    For $n = 0 To $iItemCount - 1
        For $m = 0 To $iSubItemCount - 1
            $aArray[$n][$m] = ControlListView($hWin, "", $sLvCtrl, "GetText", $n, $m)
            If @error Then Return SetError(5, 0, $aArray) ; "No ItemText")
        Next
    Next
    Return $aArray
EndFunc   ;==>ReadTheListViewFromSomewhere

Did not need to do this. :imwithstupid:

Edited by argumentum
better code ?

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
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
 Share

×
×
  • Create New...