Hi Leute,
habe meine alte viel zu überladene Version nochmal überarbeitet und was echt cooles erstellt. Sieht dann so aus:
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#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)
; 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
Global $ids = 0
Global $aProgress[1][4] ; stores handles of edit controls
Global $aBox[1][4]
$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)
;~ _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
;~ ConsoleWrite(_GUICtrlListView_GetTopIndex($hListView))
[/autoit][autoit][/autoit][autoit]$top = _SendMessage($hListView, $LVM_GETTOPINDEX)
_GUICtrlListView_SetItemSelected($hListView, $top)
_GUICtrlListView_SetItemFocused($hListView, $top) ; set focus
;~ _Arraydisplay($aBox)
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; place after GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func MoveIt()
Local $curitem = _GUICtrlListView_GetSelectedIndices($hListView)
ConsoleWrite($curitem)
_GUICtrlEdit_Destroy($aProgress[$curitem+1][0])
EndFunc
Func Beenden()
Exit
EndFunc
Func SetHot()
$top = _SendMessage($hListView, $LVM_GETTOPINDEX)
_GUICtrlListView_SetItemSelected($hListView, $top)
_GUICtrlListView_SetItemFocused($hListView, $top)
EndFunc
[/autoit][autoit][/autoit][autoit]Func GetLastRect()
GetRecItem($hListView, 29, 1)
EndFunc
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
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
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
$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)
$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
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
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
Func _MoveControl($hListView, $hCtrl, $sItemIndex, $sSubItemIndex)
Local $ClassName = _WinAPI_GetClassName($hCtrl)
Local $aRect
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
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
$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)
$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
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)
; 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
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)
Local $EditList = ObjCreate("System.Collections.ArrayList")
Local $BoxList = ObjCreate("System.Collections.ArrayList")
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
$top = _SendMessage($hListView, $LVM_GETTOPINDEX) ; get top item
_GUICtrlListView_SetItemSelected($hListView, $top) ; select top item
_GUICtrlListView_SetItemFocused($hListView, $top) ; focus top item
;~ _Arraydisplay($aBox)
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM")
GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; place after GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Func MoveIt()
Local $curitem = _GUICtrlListView_GetSelectedIndices($hListView)
ConsoleWrite($curitem)
_GUICtrlEdit_Destroy($aProgress[$curitem+1][0])
EndFunc
Func Beenden()
Exit
EndFunc
Func SetHot()
$top = _SendMessage($hListView, $LVM_GETTOPINDEX)
_GUICtrlListView_SetItemSelected($hListView, $top)
_GUICtrlListView_SetItemFocused($hListView, $top)
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
Func GetLastRect()
GetRecItem($hListView, 29, 1)
EndFunc
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)
;~ 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
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
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_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)
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)
Return $oDict
EndFunc ;==>_ListView_InsertEdit
Func _Ex_CreateCtrl($hWnd, $iText, $CtlType, $iX, $iY, $iWidth = -1, $iHeight = -1, $iStyle = 0, $iExStyle = 0)
Local $hCtrl
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
Func _MoveControl($hListView, $hCtrl, $sItemIndex, $sSubItemIndex)
Local $ClassName = _WinAPI_GetClassName($hCtrl)
Local $aRect
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
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