ListView mit Checkboxen und Edit Controls V2

  • Hi Leute,
    habe meine alte viel zu überladene Version nochmal überarbeitet und was echt cooles erstellt. Sieht dann so aus:

    [autoit]

    #include <GuiConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GuiListView.au3>
    #include <WinAPI.au3>

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    #include <Array.au3>
    #include <GDIPlus.au3>
    #include <GuiConstantsEx.au3>
    #include <GuiListView.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    #include <EditConstants.au3>
    #include <StaticConstants.au3>
    #include <GuiEdit.au3>
    #include <Constants.au3>
    #include <WinAPIEx.au3> ; from <a href='http://www.autoitscript.com/forum/topic/98712-winapiex-udf/' class='bbc_url' title=''>http://www.autoitscript.com/forum/topic/98712-winapiex-udf/</a>
    #include <GuiButton.au3>
    #include "ExListViewConstants.au3"
    Opt("GUIOnEventMode", 1)

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    ; WM_MEASUREITEM allows setting the row height
    Global $lListView_row_height = 25
    GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ; place before listview creation - message sent once for each ownerdrawn control created

    [/autoit][autoit][/autoit][autoit]

    Global $ids = 0
    Global $aProgress[1][4] ; stores handles of edit controls
    Global $aBox[1][4]

    [/autoit][autoit][/autoit][autoit]

    $hGUI = GUICreate("ListView Set Item State", 700, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Beenden")
    $btn = GUICtrlCreateButton("Move", 420, 2, 50, 25)
    GUICtrlSetOnEvent(-1, "MoveIt")
    $btn1 = GUICtrlCreateButton("SetHot", 480, 2, 50, 25)
    GUICtrlSetOnEvent(-1, "SetHot")
    $btn2 = GUICtrlCreateButton("GetLastRect", 530, 2, 50, 25)
    GUICtrlSetOnEvent(-1, "GetLastRect")
    $input = GUICtrlCreateEdit("sdaasd", 420, 100, 100, 50)
    $iStyle = BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS, $LVS_SINGLESEL) ; style
    $iExStyle = $LVS_EX_FULLROWSELECT ; extended style
    $hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems|SubItems", 2, 2, 394, 252, $iStyle, $iExStyle)

    [/autoit][autoit][/autoit][autoit]

    ;~ _GUICtrlListView_SetExtendedListViewStyle($hListView, $LVS_EX_FULLROWSELECT)

    [/autoit][autoit][/autoit][autoit]

    For $i = 1 To 30
    _GUICtrlListView_AddItem($hListView, "") ; text of first column
    _GUICtrlListView_AddSubItem($hListView, $i-1, "SubItem " & $i-1, 1)
    _GUICtrlListView_AddSubItem($hListView, $i-1, "", 2)
    _ListView_InsertEdit($hListView, $i-1, 2)
    _ListView_InsertCheckbox($hListView, $i-1, 0)
    Next

    [/autoit][autoit][/autoit][autoit]

    ;~ ConsoleWrite(_GUICtrlListView_GetTopIndex($hListView))

    [/autoit][autoit][/autoit][autoit]

    $top = _SendMessage($hListView, $LVM_GETTOPINDEX)
    _GUICtrlListView_SetItemSelected($hListView, $top)
    _GUICtrlListView_SetItemFocused($hListView, $top) ; set focus

    [/autoit][autoit][/autoit][autoit]

    ;~ _Arraydisplay($aBox)
    GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; place after GUISetState()

    [/autoit][autoit][/autoit][autoit]

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func MoveIt()
    Local $curitem = _GUICtrlListView_GetSelectedIndices($hListView)
    ConsoleWrite($curitem)
    _GUICtrlEdit_Destroy($aProgress[$curitem+1][0])
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func Beenden()
    Exit
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func SetHot()
    $top = _SendMessage($hListView, $LVM_GETTOPINDEX)
    _GUICtrlListView_SetItemSelected($hListView, $top)
    _GUICtrlListView_SetItemFocused($hListView, $top)

    [/autoit][autoit][/autoit][autoit]

    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func GetLastRect()
    GetRecItem($hListView, 29, 1)
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Global $prevItem ; have to be global
    Local $firstItem, $lastItem
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    Local $nNotifyCode = DllStructGetData($tNMHDR, "Code")
    Local $hHeader = _GUICtrlListView_GetHeader($hListView)
    Switch $hWndFrom
    Case $hListView
    Switch $nNotifyCode
    Case $LVN_BEGINSCROLL
    ; Notifies a list-view control's parent window when a scrolling operation starts
    Case $LVN_ENDSCROLL
    ; Notifies a list-view control's parent window when a scrolling operation ends
    Local $items = _GUICtrlListView_GetCounterPage($hListView)
    ; change top and last item on scroll up
    If $prevItem > _SendMessage($hListView, $LVM_GETTOPINDEX) Then
    $firstItem = _SendMessage($hListView, $LVM_GETTOPINDEX)
    ; change top and last item on scroll down
    Else
    $firstItem = _SendMessage($hListView, $LVM_GETTOPINDEX) ; get index of top item
    $lastItem = $firstItem+$items
    EndIf
    $prevItem = $firstItem ; get previous top item
    ConsoleWrite("first: " & $firstItem &" last: " & $lastItem)
    For $i = $firstItem To $lastItem
    ConsoleWrite(" i: " &$i & @CRLF)
    _MoveControl($hListView, $aProgress[$i][0], $aProgress[$i][1], $aProgress[$i][2])
    _MoveControl($hListView, $aBox[$i][0], $aBox[$i][1], $aBox[$i][2])
    ;~ ConsoleWrite("itemmmm10: " & $aProgress[10][1])
    ; redraw text
    $sText = _GUICtrlEdit_GetText($aProgress[$i][0])
    _GUICtrlEdit_SetText($aProgress[$i][0], $sText)
    ;~ If Not $firstItem Then Return ConsoleWrite("hier")
    Next
    _GUICtrlListView_SetItemSelected($hListView, $firstItem) ; set selection
    _GUICtrlListView_SetItemFocused($hListView, $firstItem) ; set focus
    EndSwitch
    Case $hHeader
    Switch $nNotifyCode
    Case $HDN_ITEMCHANGEDW
    ; Notifies a header control's parent window that the attributes of a header item have changed
    Local $items = _GUICtrlListView_GetCounterPage($hListView)
    Local $firstItem = _SendMessage($hListView, $LVM_GETTOPINDEX) ; get index of top item
    Local $lastItem = $firstItem+$items
    For $i = $firstItem To $lastItem
    _MoveControl($hListView, $aProgress[$i][0], $aProgress[$i][1], $aProgress[$i][2])
    Next
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tMEASUREITEMS = DllStructCreate("uint cType;uint cID;uint itmID;uint itmW;uint itmH;ulong_ptr itmData", $lParam)
    If DllStructGetData($tMEASUREITEMS, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    DllStructSetData($tMEASUREITEMS, "itmH", $lListView_row_height) ; row height
    Return 1
    EndFunc ;==>WM_MEASUREITEM

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView)
    Local $aTextFormatting = BitOR($DT_VCENTER, $DT_SINGLELINE, $DT_CENTER, $DT_END_ELLIPSIS)
    Local $aRectMargins[4] = [6, -1, -4, 0]
    Local $tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $bSelected
    $timer = TimerInit()
    $tagDRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _
    "hwnd hItm;hwnd hDC;int itmRect[4];dword itmData", $lParam)
    If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    $cID = DllStructGetData($tagDRAWITEMSTRUCT, "cID")
    $itmID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID")
    $itmAction = DllStructGetData($tagDRAWITEMSTRUCT, "itmAction")
    $itmState = DllStructGetData($tagDRAWITEMSTRUCT, "itmState")
    $hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm")
    $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC")
    $bSelected = BitAND($itmState, $ODS_SELECTED)
    $bfocusSelected = BitOR($ODS_FOCUS, $ODS_SELECTED)
    Switch $itmAction
    Case $ODA_DRAWENTIRE
    ; change color of selected items
    Switch $itmState
    Case $ODS_SELECTED
    ; The menu item's status is selected
    Case $ODS_GRAYED
    ; The item is to be grayed. This bit is used only in a menu
    Case $ODS_DISABLED
    ; The item is to be drawn as disabled
    Case $ODS_CHECKED
    ; The menu item is to be checked. This bit is used only in a menu
    Case $ODS_FOCUS, $bSelected
    ; The item has the keyboard focus
    $iBrushColor = 0xFFFFFF
    Case $ODS_DEFAULT
    ; The item is the default item
    Case $ODS_COMBOBOXEDIT
    ; The drawing takes place in the selection field (edit control) of an owner-drawn combo box
    Case $bfocusSelected
    ; The menu item's status is selected and has keyboard focus
    $iBrushColor = 0xEEDDBB
    EndSwitch
    ; create a brush with the desired color
    Local $aBrush = DLLCall("gdi32.dll","hwnd","CreateSolidBrush", "int", $iBrushColor)
    ; get the rectangle for the whole row and fill it
    Local $iLeft = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1)
    DllStructSetData($tagDRAWITEMSTRUCT, "itmRect", $iLeft + 5, 1)
    _WinAPI_FillRect($hDC, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), $aBrush[0])
    For $i = 0 To $iColumnCount-1
    ; get subitem text
    Local $iSubItmText = _GUICtrlListView_GetItemText($hListView, $itmID, $i)
    ; get subitem coordinates for drawing its respective text:
    Local $aSubItmRect = _GUICtrlListView_GetSubItemRect($hListView, $itmID, $i)
    ; the function above accepts not only subitems (one-based index), but also main item (index=0)
    ; pass the coordinates to a DLL struct
    Local $iSubItmRect = DllStructCreate("int Left;int Top;int Right;int Bottom")
    DllStructSetData($iSubItmRect, 1, $aSubItmRect[0] + $aRectMargins[0]) ; left margin
    DllStructSetData($iSubItmRect, 2, $aSubItmRect[1] + $aRectMargins[1]) ; upper margin
    DllStructSetData($iSubItmRect, 3, $aSubItmRect[2] + $aRectMargins[2]) ; right margin
    DllStructSetData($iSubItmRect, 4, $aSubItmRect[3] + $aRectMargins[3]) ; bottom margin
    Local $tRect = DllStructGetPtr($iSubItmRect)
    ; draw text
    DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $iSubItmText, "int", StringLen($iSubItmText), _
    "ptr", $tRect, "int", $aTextFormatting)
    Next
    Case $ODA_FOCUS
    ; The control has lost or gained the keyboard focus. The itemState member should be checked to determine whether the control has the focus.
    Case $ODA_SELECT
    ; The selection status has changed. The itemState member should be checked to determine the new selection state.
    EndSwitch
    ;~ ConsoleWrite(Round(TimerDiff($timer),2) & @TAB & "WM_DRAWITEM" & @CRLF)
    Return $GUI_RUNDEFMSG
    EndFunc





    Func _ListView_InsertEdit($sHwnd, $sItemIndex, $sSubItemIndex = 0)
    If Not IsHWnd($sHwnd) Then $sHwnd = GUICtrlGetHandle($sHwnd)
    ;~ Local $iStyle = _WinAPI_GetWindowLong($sHwnd, $GWL_STYLE)
    ;~ If BitAND($iStyle, $WS_CLIPCHILDREN) <> $WS_CLIPCHILDREN Then
    ;~ _WinAPI_SetWindowLong($sHwnd, $GWL_STYLE, BitOR($iStyle, $WS_CLIPCHILDREN))
    ;~ EndIf
    Local $aRect
    If $sSubItemIndex = 0 Then
    $aRect = _GUICtrlListView_GetItemRect($sHwnd, $sItemIndex, 2)
    Else
    $aRect = _GUICtrlListView_GetSubItemRect($sHwnd, $sItemIndex, $sSubItemIndex)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    $aProgress[0][0] += 1
    ReDim $aProgress[$aProgress[0][0]+1][4]
    $aProgress[$aProgress[0][0]][0] = _Edit_Create($sHwnd, $aRect[0] + 6, $aRect[1] + 2, ($aRect[2] - $aRect[0]) - 12, ($aRect[3] - $aRect[1]) - 4)

    [/autoit][autoit][/autoit][autoit]

    $aProgress[$aProgress[0][0]][1] = $sItemIndex
    $aProgress[$aProgress[0][0]][2] = $sSubItemIndex
    $aProgress[$aProgress[0][0]][3] = $sHwnd

    Return $aProgress[$aProgress[0][0]][0]
    EndFunc ;==>_ListView_InsertEdit

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func _Edit_Create($hWnd, $iX, $iY, $iWidth = -1, $iHeight = -1, $iStyle = 0, $iExStyle = 0x00000200)

    [/autoit][autoit][/autoit][autoit]

    $iStyle = BitOR($iStyle, $WS_TABSTOP, $WS_CHILD, $WS_VISIBLE, $ES_LEFT, $ES_AUTOHSCROLL, $ES_NOHIDESEL)
    ;~ Local $hEdit = _WinAPI_CreateWindowEx($iExStyle, "EDIT", "", $iStyle, $iX, $iY, $iWidth, $iHeight, $hWnd, $ids)
    ;~ _SendMessage($hEdit, $__EDITCONSTANT_WM_SETFONT, _WinAPI_GetStockObject($__EDITCONSTANT_DEFAULT_GUI_FONT), True) ; set font style
    Local $hEdit = _GUICtrlEdit_Create($hWnd, "", $iX, $iY, $iWidth, $iHeight, $iStyle, $iExStyle)
    ; testen
    ;~ _GUICtrlEdit_SetLimitText($hEdit, 0)

    _GUICtrlEdit_SetText($hEdit, "test"&$ids)
    ;~ _GUICtrlEdit_SetReadOnly($hEdit, True)
    $ids += 1
    ;~ _WinAPI_ShowWindow($hEdit, $SW_HIDE)
    Return $hEdit
    EndFunc ;==>_Edit_Create

    [/autoit][autoit][/autoit][autoit]

    Func GetRecItem($hListView, $sItemIndex, $sSubItemIndex)
    ConsoleWrite("Item: " & $sItemIndex & " SubItem: " & $sSubItemIndex & @CRLF)
    $aRect = _GUICtrlListView_GetSubItemRect($hListView, $sItemIndex, $sSubItemIndex)
    ConsoleWrite("xleft: " & $aRect[0] & " yleft: " & $aRect[1] & "xright: " & $aRect[2] & " yright: " & $aRect[3] & @CRLF)
    ;~ $label = GUICtrlCreateLabel("Hier", $aRect[0], $aRect[1], 20, 18)
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func _MoveControl($hListView, $hCtrl, $sItemIndex, $sSubItemIndex)
    Local $ClassName = _WinAPI_GetClassName($hCtrl)
    Local $aRect

    [/autoit][autoit][/autoit][autoit]

    If $sSubItemIndex = 0 Then
    $aRect = _GUICtrlListView_GetItemRect($hListView, $sItemIndex, 2)
    Else
    $aRect = _GUICtrlListView_GetSubItemRect($hListView, $sItemIndex, $sSubItemIndex)
    EndIf
    ConsoleWrite("item: " & $sItemIndex & " xleft: " & $aRect[0] & " yleft: " & $aRect[1] & "xright: " & $aRect[2] & " yright: " & $aRect[3] & @CRLF)
    If $aRect[1] < 10 Then
    _WinAPI_ShowWindow($hCtrl, $SW_HIDE)
    ElseIf $aRect[1] >= 10 Then
    _WinAPI_ShowWindow($hCtrl, $SW_SHOW)
    EndIf

    If $ClassName = "Edit" Then _WinAPI_MoveWindow($hCtrl, $aRect[0] + 6, $aRect[1] + 2, ($aRect[2] - $aRect[0]) - 12, ($aRect[3] - $aRect[1]) - 4, True)
    If $ClassName = "Button" Then _WinAPI_MoveWindow($hCtrl, $aRect[0] + 6, $aRect[1] + 6, 14, 14, True)
    EndFunc ;==>_MoveControl

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func _CheckBox_Create($hWnd, $iX, $iY, $iWidth = -1, $iHeight = -1, $iStyle = 0, $iExStyle = -1)
    $iStyle = BitOR($iStyle, $BS_AUTOCHECKBOX)
    Local $hBtn = _GUICtrlButton_Create($hWnd, "", $iX, $iY, $iWidth, $iHeight, $iStyle, $iExStyle)
    Return $hBtn
    EndFunc ;==>_CheckBox_Create

    Func _ListView_InsertCheckbox($sHwnd, $sItemIndex, $sSubItemIndex = 0)
    If Not IsHWnd($sHwnd) Then $sHwnd = GUICtrlGetHandle($sHwnd)
    ;~ Local $iStyle = _WinAPI_GetWindowLong($sHwnd, $GWL_STYLE)
    ;~ If BitAND($iStyle, $WS_CLIPCHILDREN) <> $WS_CLIPCHILDREN Then
    ;~ _WinAPI_SetWindowLong($sHwnd, $GWL_STYLE, BitOR($iStyle, $WS_CLIPCHILDREN))
    ;~ EndIf
    Local $aRect
    If $sSubItemIndex = 0 Then
    $aRect = _GUICtrlListView_GetItemRect($sHwnd, $sItemIndex, 2)
    Else
    $aRect = _GUICtrlListView_GetSubItemRect($sHwnd, $sItemIndex, $sSubItemIndex)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    $aBox[0][0] += 1
    ReDim $aBox[$aBox[0][0]+1][4]
    $aBox[$aBox[0][0]][0] = _CheckBox_Create($sHwnd, $aRect[0] + 6, $aRect[1] + 6, 14, 14)

    [/autoit][autoit][/autoit][autoit]

    $aBox[$aBox[0][0]][1] = $sItemIndex
    $aBox[$aBox[0][0]][2] = $sSubItemIndex
    $aBox[$aBox[0][0]][3] = $sHwnd

    Return $aBox[$aBox[0][0]][0]
    EndFunc

    [/autoit]


    Sooo das obere läuft allerdings noch mit Arrays, was zwar super funktioniert, mir persönlich aber nicht gefällt, das geht noch besser. Habe das Ganze jetzt nochmal mit Listen von Dictionarys umgebaut:

    [autoit]

    #include <GuiConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GuiListView.au3>
    #include <WinAPI.au3>
    #include <Array.au3>
    #include <GuiConstantsEx.au3>
    #include <GuiListView.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    #include <EditConstants.au3>
    #include <StaticConstants.au3>
    #include <GuiEdit.au3>
    #include <Constants.au3>
    #include <WinAPIEx.au3> ; from <a href='http://www.autoitscript.com/forum/topic/98712-winapiex-udf/' class='bbc_url' title=''>http://www.autoitscript.com/forum/topic/98712-winapiex-udf/</a>
    #include "ExListViewConstants.au3"
    #include <GuiButton.au3>
    Opt("GUIOnEventMode", 1)

    [/autoit][autoit][/autoit][autoit][/autoit][autoit][/autoit][autoit]

    ; WM_MEASUREITEM allows setting the row height
    Global $lListView_row_height = 25
    GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ; place before listview creation - message sent once for each ownerdrawn control created

    [/autoit][autoit][/autoit][autoit]

    Global $ids = 0

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    $hGUI = GUICreate("ListView Set Item State", 700, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Beenden")
    $btn = GUICtrlCreateButton("Move", 420, 2, 50, 25)
    GUICtrlSetOnEvent(-1, "MoveIt")
    $btn1 = GUICtrlCreateButton("SetHot", 480, 2, 50, 25)
    GUICtrlSetOnEvent(-1, "SetHot")
    $btn2 = GUICtrlCreateButton("GetLastRect", 530, 2, 50, 25)
    GUICtrlSetOnEvent(-1, "GetLastRect")
    $input = GUICtrlCreateEdit("sdaasd", 420, 100, 100, 50)
    $iStyle = BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS, $LVS_SINGLESEL) ; style
    $iExStyle = $LVS_EX_FULLROWSELECT ; extended style
    $hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems|SubItems", 2, 2, 394, 252, $iStyle, $iExStyle)
    Global $items = _GUICtrlListView_GetCounterPage($hListView)

    [/autoit][autoit][/autoit][autoit]

    Local $EditList = ObjCreate("System.Collections.ArrayList")
    Local $BoxList = ObjCreate("System.Collections.ArrayList")

    [/autoit][autoit][/autoit][autoit]

    For $i = 1 To 30
    _GUICtrlListView_AddItem($hListView, "") ; text of first column
    _GUICtrlListView_AddSubItem($hListView, $i-1, "SubItem " & $i-1, 1)
    _GUICtrlListView_AddSubItem($hListView, $i-1, "", 2)
    $EditList.add(_ListView_InsertControl($hListView, "", $i-1, 2, "Edit"))
    $BoxList.add(_ListView_InsertControl($hListView, "", $i-1, 0, "CheckBox"))
    Next

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    $top = _SendMessage($hListView, $LVM_GETTOPINDEX) ; get top item
    _GUICtrlListView_SetItemSelected($hListView, $top) ; select top item
    _GUICtrlListView_SetItemFocused($hListView, $top) ; focus top item

    [/autoit][autoit][/autoit][autoit]

    ;~ _Arraydisplay($aBox)
    GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; place after GUISetState()

    [/autoit][autoit][/autoit][autoit]

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func MoveIt()
    Local $curitem = _GUICtrlListView_GetSelectedIndices($hListView)
    ConsoleWrite($curitem)
    _GUICtrlEdit_Destroy($aProgress[$curitem+1][0])
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func Beenden()
    Exit
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func SetHot()
    $top = _SendMessage($hListView, $LVM_GETTOPINDEX)
    _GUICtrlListView_SetItemSelected($hListView, $top)
    _GUICtrlListView_SetItemFocused($hListView, $top)

    [/autoit][autoit][/autoit][autoit]

    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func GetRecItem($hListView, $sItemIndex, $sSubItemIndex)
    ConsoleWrite("Item: " & $sItemIndex & " SubItem: " & $sSubItemIndex & @CRLF)
    $aRect = _GUICtrlListView_GetSubItemRect($hListView, $sItemIndex, $sSubItemIndex)
    ConsoleWrite("xleft: " & $aRect[0] & " yleft: " & $aRect[1] & "xright: " & $aRect[2] & " yright: " & $aRect[3] & @CRLF)
    ;~ $label = GUICtrlCreateLabel("Hier", $aRect[0], $aRect[1], 20, 18)
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func GetLastRect()
    GetRecItem($hListView, 29, 1)
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Global $prevItem ; have to be global
    Global $firstItem, $lastItem ; have to be global
    Global $lEdit, $lBox
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    Local $nNotifyCode = DllStructGetData($tNMHDR, "Code")
    Local $hHeader = _GUICtrlListView_GetHeader($hListView)
    Switch $hWndFrom
    Case $hListView
    Switch $nNotifyCode
    Case $LVN_BEGINSCROLL
    ; Notifies a list-view control's parent window when a scrolling operation starts
    Case $LVN_ENDSCROLL
    ; Notifies a list-view control's parent window when a scrolling operation ends
    ; change top and last item on scroll up
    If $prevItem > _SendMessage($hListView, $LVM_GETTOPINDEX) Then
    $firstItem = _SendMessage($hListView, $LVM_GETTOPINDEX)
    ; change top and last item on scroll down
    Else
    $firstItem = _SendMessage($hListView, $LVM_GETTOPINDEX) ; get index of top item
    $lastItem = $firstItem+$items
    EndIf
    $prevItem = $firstItem ; get previous top item
    ConsoleWrite("first: " & $firstItem &" last: " & $lastItem)
    For $i = $firstItem To $lastItem
    ConsoleWrite(" i: " &$i & @CRLF)
    If $i = 0 Then ContinueLoop
    $lEdit = $EditList.Item($i-1)
    $lBox = $BoxList.Item($i-1)

    [/autoit][autoit][/autoit][autoit]

    ;~ ConsoleWrite("sItemIndex: " & $lEdit.Item("sItemIndex") &" last: " & $lastItem & @CRLF)
    _MoveControl($hListView, $lEdit.Item("hCtrl"), $lEdit.Item("sItemIndex"), $lEdit.Item("sSubItemIndex"))
    _MoveControl($hListView, $lBox.Item("hCtrl"), $lBox.Item("sItemIndex"), $lBox.Item("sSubItemIndex"))
    ; redraw text
    $sText = _GUICtrlEdit_GetText($lEdit.Item("hCtrl"))
    _GUICtrlEdit_SetText($lEdit.Item("hCtrl"), $sText)
    Next
    _GUICtrlListView_SetItemSelected($hListView, $firstItem) ; set selection
    _GUICtrlListView_SetItemFocused($hListView, $firstItem) ; set focus
    EndSwitch
    Case $hHeader
    Switch $nNotifyCode
    Case $HDN_ITEMCHANGEDW
    ; Notifies a header control's parent window that the attributes of a header item have changed
    Local $fItem = _SendMessage($hListView, $LVM_GETTOPINDEX) ; get index of top item
    Local $lItem = $firstItem+$items
    For $i = $fItem To $lItem
    $lEdit = $EditList.Item($i)
    _MoveControl($hListView, $lEdit.Item("hCtrl"), $lEdit.Item("sItemIndex"), $lEdit.Item("sSubItemIndex"))
    Next
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tMEASUREITEMS = DllStructCreate("uint cType;uint cID;uint itmID;uint itmW;uint itmH;ulong_ptr itmData", $lParam)
    If DllStructGetData($tMEASUREITEMS, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    DllStructSetData($tMEASUREITEMS, "itmH", $lListView_row_height) ; row height
    Return 1
    EndFunc ;==>WM_MEASUREITEM

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView)
    Local $aTextFormatting = BitOR($DT_VCENTER, $DT_SINGLELINE, $DT_CENTER, $DT_END_ELLIPSIS)
    Local $aRectMargins[4] = [6, -1, -4, 0]
    Local $tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $bSelected
    $timer = TimerInit()
    $tagDRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _
    "hwnd hItm;hwnd hDC;int itmRect[4];dword itmData", $lParam)
    If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    $cID = DllStructGetData($tagDRAWITEMSTRUCT, "cID")
    $itmID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID")
    $itmAction = DllStructGetData($tagDRAWITEMSTRUCT, "itmAction")
    $itmState = DllStructGetData($tagDRAWITEMSTRUCT, "itmState")
    $hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm")
    $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC")
    $bSelected = BitAND($itmState, $ODS_SELECTED)
    $bfocusSelected = BitOR($ODS_FOCUS, $ODS_SELECTED)
    Switch $itmAction
    Case $ODA_DRAWENTIRE
    ; change color of selected items
    Switch $itmState
    Case $ODS_SELECTED
    ; The menu item's status is selected
    Case $ODS_GRAYED
    ; The item is to be grayed. This bit is used only in a menu
    Case $ODS_DISABLED
    ; The item is to be drawn as disabled
    Case $ODS_CHECKED
    ; The menu item is to be checked. This bit is used only in a menu
    Case $ODS_FOCUS, $bSelected
    ; The item has the keyboard focus
    $iBrushColor = 0xFFFFFF
    Case $ODS_DEFAULT
    ; The item is the default item
    Case $ODS_COMBOBOXEDIT
    ; The drawing takes place in the selection field (edit control) of an owner-drawn combo box
    Case $bfocusSelected
    ; The menu item's status is selected and has keyboard focus
    $iBrushColor = 0xEEDDBB
    EndSwitch
    ; create a brush with the desired color
    Local $aBrush = DLLCall("gdi32.dll","hwnd","CreateSolidBrush", "int", $iBrushColor)
    ; get the rectangle for the whole row and fill it
    Local $iLeft = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1)
    DllStructSetData($tagDRAWITEMSTRUCT, "itmRect", $iLeft + 5, 1)
    _WinAPI_FillRect($hDC, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), $aBrush[0])
    For $i = 0 To $iColumnCount-1
    ; get subitem text
    Local $iSubItmText = _GUICtrlListView_GetItemText($hListView, $itmID, $i)
    ; get subitem coordinates for drawing its respective text:
    Local $aSubItmRect = _GUICtrlListView_GetSubItemRect($hListView, $itmID, $i)
    ; the function above accepts not only subitems (one-based index), but also main item (index=0)
    ; pass the coordinates to a DLL struct
    Local $iSubItmRect = DllStructCreate("int Left;int Top;int Right;int Bottom")
    DllStructSetData($iSubItmRect, 1, $aSubItmRect[0] + $aRectMargins[0]) ; left margin
    DllStructSetData($iSubItmRect, 2, $aSubItmRect[1] + $aRectMargins[1]) ; upper margin
    DllStructSetData($iSubItmRect, 3, $aSubItmRect[2] + $aRectMargins[2]) ; right margin
    DllStructSetData($iSubItmRect, 4, $aSubItmRect[3] + $aRectMargins[3]) ; bottom margin
    Local $tRect = DllStructGetPtr($iSubItmRect)
    ; draw text
    DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $iSubItmText, "int", StringLen($iSubItmText), _
    "ptr", $tRect, "int", $aTextFormatting)
    Next
    Case $ODA_FOCUS
    ; The control has lost or gained the keyboard focus. The itemState member should be checked to determine whether the control has the focus.
    Case $ODA_SELECT
    ; The selection status has changed. The itemState member should be checked to determine the new selection state.
    EndSwitch
    ;~ ConsoleWrite(Round(TimerDiff($timer),2) & @TAB & "WM_DRAWITEM" & @CRLF)
    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func _ListView_InsertControl($sHwnd, $iText, $sItemIndex, $sSubItemIndex = 0, $CtlType = Default)
    Local $oDict = ObjCreate("Scripting.Dictionary")
    Local $iX, $iY, $iWidth, $iHeight, $aRect
    If Not IsHWnd($sHwnd) Then $sHwnd = GUICtrlGetHandle($sHwnd)

    [/autoit][autoit][/autoit][autoit]

    If $sSubItemIndex = 0 Then
    $aRect = _GUICtrlListView_GetItemRect($sHwnd, $sItemIndex, 2)
    Else
    $aRect = _GUICtrlListView_GetSubItemRect($sHwnd, $sItemIndex, $sSubItemIndex)
    EndIf

    Local $iX = $aRect[0] + 6, $iY = $aRect[1] + 2, $iWidth = ($aRect[2] - $aRect[0]) - 12, $iHeight = ($aRect[3] - $aRect[1]) - 4
    If $CtlType = "CheckBox" Then Local $iY = $aRect[1] + 6, $iWidth = 14, $iHeight = 14

    Local $hCtrl = _Ex_CreateCtrl($sHwnd, $iText, $CtlType, $iX, $iY, $iWidth, $iHeight)

    $oDict.add("hCtrl", $hCtrl)
    $oDict.add("sItemIndex", $sItemIndex)
    $oDict.add("sSubItemIndex", $sSubItemIndex)

    [/autoit][autoit][/autoit][autoit]

    Return $oDict
    EndFunc ;==>_ListView_InsertEdit

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func _Ex_CreateCtrl($hWnd, $iText, $CtlType, $iX, $iY, $iWidth = -1, $iHeight = -1, $iStyle = 0, $iExStyle = 0)
    Local $hCtrl

    [/autoit][autoit][/autoit][autoit]

    Switch $CtlType
    Case Default, "Edit"
    ;~ ConsoleWrite("xleft: " & $iX & " yleft: " & $iY & "xright: " & $iWidth & " yright: " & $iHeight & @CRLF)
    ;~ ConsoleWrite(
    $hCtrl = _GUICtrlEdit_Create($hWnd, $iText & $ids, $iX, $iY, $iWidth, $iHeight, BitOR($iStyle, $WS_TABSTOP, $WS_CHILD, $WS_VISIBLE, $ES_LEFT, $ES_AUTOHSCROLL, $ES_NOHIDESEL), BitOR($iExStyle, $WS_EX_CLIENTEDGE))
    $ids += 1
    Case "CheckBox"
    ;~ ConsoleWrite("hier")
    ;~ ConsoleWrite("xleft: " & $iX & " yleft: " & $iY & "xright: " & $iWidth & " yright: " & $iHeight & @CRLF)
    $hCtrl = _GUICtrlButton_Create($hWnd, $iText, $iX, $iY, $iWidth, $iHeight, BitOR($iStyle, $BS_AUTOCHECKBOX), $iExStyle)
    EndSwitch

    Return $hCtrl
    EndFunc ;==>_Edit_Create

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func _MoveControl($hListView, $hCtrl, $sItemIndex, $sSubItemIndex)
    Local $ClassName = _WinAPI_GetClassName($hCtrl)
    Local $aRect

    [/autoit][autoit][/autoit][autoit]

    If $sSubItemIndex = 0 Then
    $aRect = _GUICtrlListView_GetItemRect($hListView, $sItemIndex, 2)
    Else
    $aRect = _GUICtrlListView_GetSubItemRect($hListView, $sItemIndex, $sSubItemIndex)
    EndIf
    ConsoleWrite("item: " & $sItemIndex & " xleft: " & $aRect[0] & " yleft: " & $aRect[1] & "xright: " & $aRect[2] & " yright: " & $aRect[3] & @CRLF)
    If $aRect[1] < 10 Then
    _WinAPI_ShowWindow($hCtrl, $SW_HIDE)
    ElseIf $aRect[1] >= 10 Then
    _WinAPI_ShowWindow($hCtrl, $SW_SHOW)
    EndIf

    If $ClassName = "Edit" Then _WinAPI_MoveWindow($hCtrl, $aRect[0] + 6, $aRect[1] + 2, ($aRect[2] - $aRect[0]) - 12, ($aRect[3] - $aRect[1]) - 4, True)
    If $ClassName = "Button" Then _WinAPI_MoveWindow($hCtrl, $aRect[0] + 6, $aRect[1] + 6, 14, 14, True)
    EndFunc ;==>_MoveControl

    [/autoit]


    Da ist irgendwas nicht richtig, kann aber das Problem nicht ausfindig machen. Die Darstellung ist total daneben und die Checkboxen werden zum Teil gar nicht mehr angezeigt, wenn gescrollt wird. Die Header width vergrößern funktioniert nun gar nicht mehr ?(

    Habe das ganze Projekt mal angehangen, so kann man es sofort benutzen

    Kann da jemand mal bitte mit drüber schauen?

    Gruß Andi

  • Ganz komisch, wenn ich im 2ten Beispiel in Zeile 248 mir $hCtrl ausgeben lasse ist ein hex Wert so wie es sein soll und wenn ich es nach $oDict.add("hCtrl", $hCtrl) nochmal ausgeben lasse ist es dezimal Wert. Jemand eine Idee was das soll? ?(

  • So wie es aussieht kann das Dictionary keine handles speichern? Ich bekomme von der Funktion _Ex_CreateCtrl beispielsweise folgendes handle zurück: 0x007604AE.
    Wenn ich mir dann das Dictionary Item anschaue steht folgendes drin: 6424530

    Hat jemand ne Idee?

  • Danke BugFix habs schon gelöst! Ja stimmt, sieht aber so übersichtlicher aus, ein Grund komplett auf Arrays zu verzichten...

    Bin gerade dabei das Ganze so umzuschreiben, dass es in eine Funktion eingesetzt werden kann, für mich ist es nur ein UnterProjekt welches ich in eine Main Funktionen packen will, d.h. manche Variablen werden dann nicht mehr erkannt, weil sie nicht mehr global sind.

    Ist es möglich das Handle vom ListViewControl im WM_DRAWITEM abzufragen?

  • So jetzt läufts prima und das alles unter 2s :thumbup:

    Das Einzige was mich stört ist Zeile 81: Wenn die Variablen nicht global definiert sind, kommt der scroll up nicht mehr mit. Also einmal komplett nach unten und danach wieder komplett nach oben scrollen, anstelle der 8 im Edit steht die 29. Vllt. hat jemand eine Idee dazu?


    [autoit]

    #include <GuiConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GuiListView.au3>
    #include <WinAPI.au3>
    #include <Array.au3>
    #include <GuiConstantsEx.au3>
    #include <GuiListView.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    #include <EditConstants.au3>
    #include <StaticConstants.au3>
    #include <GuiEdit.au3>
    #include <Constants.au3>
    #include <WinAPIEx.au3> ; from <a href='http://www.autoitscript.com/forum/topic/98712-winapiex-udf/' class='bbc_url' title=''>http://www.autoitscript.com/forum/topic/98712-winapiex-udf/</a>
    #include "ExListViewConstants.au3"
    #include <GuiButton.au3>
    Opt("GUIOnEventMode", 1)

    [/autoit][autoit][/autoit][autoit][/autoit][autoit][/autoit][autoit]

    ; WM_MEASUREITEM allows setting the row height
    Global $lListView_row_height = 25
    GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ; place before listview creation - message sent once for each ownerdrawn control created

    [/autoit][autoit][/autoit][autoit]

    Global $ids = 0

    [/autoit][autoit][/autoit][autoit]

    Main()

    [/autoit][autoit][/autoit][autoit]

    Func Main()
    Global $hListView
    Global $EditList = ObjCreate("System.Collections.ArrayList"), $BoxList = ObjCreate("System.Collections.ArrayList")

    $hGUI = GUICreate("ListView Set Item State", 700, 300)
    GUISetOnEvent($GUI_EVENT_CLOSE, "Beenden")

    [/autoit][autoit][/autoit][autoit]

    $iStyle = BitOR($LVS_REPORT, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS, $LVS_SINGLESEL) ; style
    $iExStyle = $LVS_EX_FULLROWSELECT ; extended style
    $hListView = _GUICtrlListView_Create($hGUI, "Items|SubItems|SubItems", 2, 2, 394, 252, $iStyle, $iExStyle)

    For $i = 1 To 30
    _GUICtrlListView_AddItem($hListView, "") ; text of first column
    $BoxList.add(_ListView_InsertControl($hListView, "", $i-1, 0, "CheckBox")) ; add sub item to column 1
    _GUICtrlListView_AddSubItem($hListView, $i-1, "SubItem " & $i-1, 1) ; add sub item to column 2
    $EditList.add(_ListView_InsertControl($hListView, "", $i-1, 2, "Edit")) ; add sub item to column 3
    Next

    [/autoit][autoit][/autoit][autoit]

    ; first start
    $top = _SendMessage($hListView, $LVM_GETTOPINDEX) ; get top item
    _GUICtrlListView_SetItemSelected($hListView, $top) ; select top item
    _GUICtrlListView_SetItemFocused($hListView, $top) ; focus top item

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; place after GUISetState()
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    [/autoit][autoit][/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func Beenden()
    Exit
    EndFunc

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    Local $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    Local $nNotifyCode = DllStructGetData($tNMHDR, "Code")
    Local $hHeader = _GUICtrlListView_GetHeader($hListView) ; get header of listview control
    Local $items = _GUICtrlListView_GetCounterPage($hListView) ; get visible items
    Switch $hWndFrom
    Case $hListView
    Switch $nNotifyCode
    Case $LVN_BEGINSCROLL
    ; Notifies a list-view control's parent window when a scrolling operation starts
    Case $LVN_ENDSCROLL
    ; Notifies a list-view control's parent window when a scrolling operation ends
    Global $prevItem, $firstItem, $lastItem ; have to be global
    ; change top and last item on scroll up
    If $prevItem > _SendMessage($hListView, $LVM_GETTOPINDEX) Then
    $firstItem = _SendMessage($hListView, $LVM_GETTOPINDEX)
    ; change top and last item on scroll down
    Else
    $firstItem = _SendMessage($hListView, $LVM_GETTOPINDEX) ; get index of top item
    $lastItem = $firstItem+$items
    EndIf
    $prevItem = $firstItem ; get previous top item
    Local $lEdit, $lBox ; stores control data
    For $i = $firstItem To $lastItem
    If $i = 0 Then ContinueLoop
    $lEdit = $EditList.Item($i-1)
    $lBox = $BoxList.Item($i-1)
    _MoveControl($hListView, $lEdit.Item("hCtrl"), $lEdit.Item("sItemIndex"), $lEdit.Item("sSubItemIndex"))
    _MoveControl($hListView, $lBox.Item("hCtrl"), $lBox.Item("sItemIndex"), $lBox.Item("sSubItemIndex"))
    ; redraw text
    $sText = _GUICtrlEdit_GetText($lEdit.Item("hCtrl"))
    _GUICtrlEdit_SetText($lEdit.Item("hCtrl"), $sText)
    Next
    _GUICtrlListView_SetItemSelected($hListView, $firstItem) ; set selection
    _GUICtrlListView_SetItemFocused($hListView, $firstItem) ; set focus
    EndSwitch
    Case $hHeader
    Switch $nNotifyCode
    Case $HDN_ITEMCHANGEDW
    ; Notifies a header control's parent window that the attributes of a header item have changed
    Local $fItem = _SendMessage($hListView, $LVM_GETTOPINDEX) ; get index of top item
    Local $lItem = $fItem+$items
    For $i = $fItem To $lItem
    $lEdit = $EditList.Item($i)
    _MoveControl($hListView, $lEdit.Item("hCtrl"), $lEdit.Item("sItemIndex"), $lEdit.Item("sSubItemIndex"))
    _GUICtrlListView_SetItemState($hListView, $i, $LVIS_FOCUSED, $LVIS_FOCUSED)
    Next
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tMEASUREITEMS = DllStructCreate("uint cType;uint cID;uint itmID;uint itmW;uint itmH;ulong_ptr itmData", $lParam)
    If DllStructGetData($tMEASUREITEMS, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    DllStructSetData($tMEASUREITEMS, "itmH", $lListView_row_height) ; row height
    Return 1
    EndFunc ;==>WM_MEASUREITEM

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $iColumnCount = _GUICtrlListView_GetColumnCount($hListView) ; get column count
    Local $aTextFormatting = BitOR($DT_VCENTER, $DT_SINGLELINE, $DT_CENTER, $DT_END_ELLIPSIS)
    Local $aRectMargins[4] = [6, -1, -4, 0]
    Local $tagDRAWITEMSTRUCT, $iBrushColor, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC, $bSelected
    $timer = TimerInit()
    $tagDRAWITEMSTRUCT = DllStructCreate("uint cType;uint cID;uint itmID;uint itmAction;uint itmState;" & _
    "hwnd hItm;hwnd hDC;int itmRect[4];dword itmData", $lParam)
    If DllStructGetData($tagDRAWITEMSTRUCT, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    $cID = DllStructGetData($tagDRAWITEMSTRUCT, "cID")
    $itmID = DllStructGetData($tagDRAWITEMSTRUCT, "itmID")
    $itmAction = DllStructGetData($tagDRAWITEMSTRUCT, "itmAction")
    $itmState = DllStructGetData($tagDRAWITEMSTRUCT, "itmState")
    $hItm = DllStructGetData($tagDRAWITEMSTRUCT, "hItm")
    $hDC = DllStructGetData($tagDRAWITEMSTRUCT, "hDC")
    $bSelected = BitAND($itmState, $ODS_SELECTED)
    $bFocus = BitAND($itmState, $ODS_FOCUS) ; value: 16
    $bFocusSelected = BitOR($ODS_FOCUS, $ODS_SELECTED) ; item has focus and is selected. value: 17
    ;Local $hListView = ControlGetHandle($hWnd, "", $cID) ; get handle of listview control local
    Switch $itmAction
    Case $ODA_DRAWENTIRE
    ; change color of selected items
    Switch $itmState
    Case $ODS_SELECTED, $bfocusSelected
    ; The menu item's status is selected or is selected and has keyboard focus
    $iBrushColor = 0xEEDDBB
    Case $ODS_GRAYED
    ; The item is to be grayed. This bit is used only in a menu
    Case $ODS_DISABLED
    ; The item is to be drawn as disabled
    Case $ODS_CHECKED
    ; The menu item is to be checked. This bit is used only in a menu
    Case $ODS_FOCUS, $bSelected
    ; The item has the keyboard focus
    $iBrushColor = 0xFFFFFF
    Case $ODS_DEFAULT
    ; The item is the default item
    Case $ODS_COMBOBOXEDIT
    ; The drawing takes place in the selection field (edit control) of an owner-drawn combo box
    EndSwitch
    ; create a brush with the desired color
    Local $aBrush = DLLCall("gdi32.dll","hwnd","CreateSolidBrush", "int", $iBrushColor)
    ; get the rectangle for the whole row and fill it
    Local $iLeft = DllStructGetData($tagDRAWITEMSTRUCT, "itmRect", 1)
    DllStructSetData($tagDRAWITEMSTRUCT, "itmRect", $iLeft + 5, 1)
    _WinAPI_FillRect($hDC, DllStructGetPtr($tagDRAWITEMSTRUCT, "itmRect"), $aBrush[0])
    For $i = 0 To $iColumnCount-1
    ; get subitem text
    Local $iSubItmText = _GUICtrlListView_GetItemText($hListView, $itmID, $i)
    ; get subitem coordinates for drawing its respective text:
    Local $aSubItmRect = _GUICtrlListView_GetSubItemRect($hListView, $itmID, $i)
    ; the function above accepts not only subitems (one-based index), but also main item (index=0)
    ; pass the coordinates to a DLL struct
    Local $iSubItmRect = DllStructCreate("int Left;int Top;int Right;int Bottom")
    DllStructSetData($iSubItmRect, 1, $aSubItmRect[0] + $aRectMargins[0]) ; left margin
    DllStructSetData($iSubItmRect, 2, $aSubItmRect[1] + $aRectMargins[1]) ; upper margin
    DllStructSetData($iSubItmRect, 3, $aSubItmRect[2] + $aRectMargins[2]) ; right margin
    DllStructSetData($iSubItmRect, 4, $aSubItmRect[3] + $aRectMargins[3]) ; bottom margin
    Local $tRect = DllStructGetPtr($iSubItmRect)
    ; draw text
    DllCall("user32.dll", "int", "DrawText", "hwnd", $hDC, "str", $iSubItmText, "int", StringLen($iSubItmText), _
    "ptr", $tRect, "int", $aTextFormatting)
    Next
    Case $ODA_FOCUS
    ; The control has lost or gained the keyboard focus. The itemState member should be checked to determine whether the control has the focus.
    Case $ODA_SELECT
    ; The selection status has changed. The itemState member should be checked to determine the new selection state.
    EndSwitch
    ConsoleWrite(Round(TimerDiff($timer),2) & @TAB & "WM_DRAWITEM" & @CRLF)
    Return $GUI_RUNDEFMSG
    EndFunc

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func _ListView_InsertControl($sHwnd, $iText, $sItemIndex, $sSubItemIndex = 0, $CtlType = Default)
    Local $oDict = ObjCreate("Scripting.Dictionary")
    Local $iX, $iY, $iWidth, $iHeight, $aRect
    If Not IsHWnd($sHwnd) Then $sHwnd = GUICtrlGetHandle($sHwnd)

    [/autoit][autoit][/autoit][autoit]

    If $sSubItemIndex = 0 Then
    $aRect = _GUICtrlListView_GetItemRect($sHwnd, $sItemIndex, 2)
    Else
    $aRect = _GUICtrlListView_GetSubItemRect($sHwnd, $sItemIndex, $sSubItemIndex)
    EndIf

    Local $iX = $aRect[0] + 6, $iY = $aRect[1] + 2, $iWidth = ($aRect[2] - $aRect[0]) - 12, $iHeight = ($aRect[3] - $aRect[1]) - 4
    Switch $CtlType
    Case Default, "Edit"
    _GUICtrlListView_AddSubItem($sHwnd, $sItemIndex, "", $sSubItemIndex) ; place empty items behind the Edit controls
    Case "CheckBox"
    Local $iY = $aRect[1] + 6, $iWidth = 14, $iHeight = 14
    EndSwitch
    Local $hCtrl = _Ex_CreateCtrl($sHwnd, $iText, $CtlType, $iX, $iY, $iWidth, $iHeight)

    $oDict.add("hCtrl", $hCtrl)
    $oDict.add("sItemIndex", $sItemIndex)
    $oDict.add("sSubItemIndex", $sSubItemIndex)

    [/autoit][autoit][/autoit][autoit]

    Return $oDict
    EndFunc ;==>_ListView_InsertEdit

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func _Ex_CreateCtrl($hWnd, $iText, $CtlType, $iX, $iY, $iWidth = -1, $iHeight = -1, $iStyle = 0, $iExStyle = 0)
    Local $hCtrl
    Switch $CtlType
    Case Default, "Edit"
    $hCtrl = _GUICtrlEdit_Create($hWnd, $iText & $ids, $iX, $iY, $iWidth, $iHeight, BitOR($iStyle, $WS_TABSTOP, $WS_CHILD, $WS_VISIBLE, $ES_LEFT, $ES_AUTOHSCROLL, $ES_NOHIDESEL), BitOR($iExStyle, $WS_EX_CLIENTEDGE))
    $ids += 1
    Case "CheckBox"
    $hCtrl = _GUICtrlButton_Create($hWnd, $iText, $iX, $iY, $iWidth, $iHeight, BitOR($iStyle, $BS_AUTOCHECKBOX), $iExStyle)
    EndSwitch
    Return $hCtrl
    EndFunc ;==>_Edit_Create

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    Func _MoveControl($hListView, $hCtrl, $sItemIndex, $sSubItemIndex)
    $hCtrl = HWnd($hCtrl) ; storing handles in dictionaries or lists fails, so this converts the expression into handles
    Local $ClassName = _WinAPI_GetClassName($hCtrl)
    Local $aRect
    ; if first colum have to be moved
    If $sSubItemIndex = 0 Then
    $aRect = _GUICtrlListView_GetItemRect($hListView, $sItemIndex, 2)
    Else
    $aRect = _GUICtrlListView_GetSubItemRect($hListView, $sItemIndex, $sSubItemIndex)
    EndIf

    [/autoit][autoit][/autoit][autoit]

    If $aRect[1] < 10 Then
    _WinAPI_ShowWindow($hCtrl, $SW_HIDE) ; hide items out of view
    ElseIf $aRect[1] >= 10 Then
    _WinAPI_ShowWindow($hCtrl, $SW_SHOW) ; show items in view
    EndIf

    If $ClassName = "Edit" Then _WinAPI_MoveWindow($hCtrl, $aRect[0] + 6, $aRect[1] + 2, ($aRect[2] - $aRect[0]) - 12, ($aRect[3] - $aRect[1]) - 4, True)
    If $ClassName = "Button" Then _WinAPI_MoveWindow($hCtrl, $aRect[0] + 6, $aRect[1] + 6, 14, 14, True)
    EndFunc ;==>_MoveControl

    [/autoit]