Jump to content

mLipok

MVPs
  • Posts

    11,931
  • Joined

  • Last visited

  • Days Won

    68

mLipok last won the day on May 11

mLipok had the most liked content!

About mLipok

  • Birthday 07/19/1978

Profile Information

  • Member Title
    Sometimes... even usually I'm nitpicky.
  • Location
    Europe, Poland, Upper Silesia, Zabrze
  • Interests
    ¯\_(ツ)_/¯

Recent Profile Visitors

30,549 profile views

mLipok's Achievements

  1. Thanks for findings. Here is the corrected, cleaned and refactored code: ;~ https://www.autoitscript.com/forum/topic/213681-listview-with-groups-inserting-new-rows-issue-with-_guictrllistview_insertitem/ #AutoIt3Wrapper_UseX64=n ; From Nine #include <WindowsConstants.au3> #include <ColorConstants.au3> #include <GUIConstants.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WinAPIDiag.au3> #include <WinAPITheme.au3> Global Enum $__g_eLVColumn_Name, $__g_eLVColumn_ItemIndex, $__g_eLVColumn_ItemID, $__g_eLVColumn_GroupIndex, $__g_eLVColumn_GroupID Opt("MustDeclareVars", True) Global $__g_hListView, $__g_hHeader Example() Func Example() GUICreate("Example", 900, 700) Local $idListview = GUICtrlCreateListView("", 10, 10, 880, 550, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_INFOTIP)) $__g_hListView = GUICtrlGetHandle($idListview) $__g_hHeader = GUICtrlSendMsg($idListview, $LVM_GETHEADER, 0, 0) _WinAPI_SetWindowTheme($__g_hHeader, "", "") ;Turn off theme for header Local $iStyle = _WinAPI_GetWindowLong($__g_hHeader, $GWL_STYLE) _WinAPI_SetWindowLong($__g_hHeader, $GWL_STYLE, BitOR($iStyle, $HDS_FLAT)) ; remove header 3D button effect Local $idButton = GUICtrlCreateButton("Enable/Disable GroupView", 10, 620, 200, 20) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) _GUICtrlListView_AddColumn($idListview, "Item (row name given by user)", 100) ; $__g_eLVColumn_Name _GUICtrlListView_AddColumn($idListview, "ItemIndex (current row index)", 100) ; $__g_eLVColumn_ItemIndex _GUICtrlListView_AddColumn($idListview, "ItemID (creation order index)", 100) ; $__g_eLVColumn_ItemID _GUICtrlListView_AddColumn($idListview, "GroupIndex (current group index)", 100) ; $__g_eLVColumn_GroupIndex _GUICtrlListView_AddColumn($idListview, "GroupID (ID mark given by user)", 100) ; $__g_eLVColumn_GroupID _GUICtrlListView_SetColumnWidth($idListview, $__g_eLVColumn_Name, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, $__g_eLVColumn_ItemIndex, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, $__g_eLVColumn_ItemID, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, $__g_eLVColumn_GroupIndex, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, $__g_eLVColumn_GroupID, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0) _GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 0) _GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 0) _GUICtrlListView_AddItem($idListview, "Row 4: Col 1", 0) _GUICtrlListView_InsertGroup($idListview, -1, 101, '"First Group"') _GUICtrlListView_InsertGroup($idListview, -1, 202, '"Second Group"') _GUICtrlListView_InsertGroup($idListview, -1, 303, '"Third Group"') _GUICtrlListView_SetItemGroupID($idListview, 0, 101) _GUICtrlListView_SetItemGroupID($idListview, 1, 202) _GUICtrlListView_SetItemGroupID($idListview, 2, 202) _GUICtrlListView_SetItemGroupID($idListview, 3, 303) MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'Before InsertItem') _GUICtrlListView_InsertItem($idListview, "NEW ITEM 1", 2) ; insert as 2 ID .... before "Row 3: Col 1" _GUICtrlListView_SetItemGroupID($idListview, 2, 202) MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'After InsertItem NEW ITEM 1 .. before EnableGroupView') _GUICtrlListView_InsertItem($idListview, "NEW ITEM 2", 3) ; insert as 2 ID .... before "Row 3: Col 1" _GUICtrlListView_SetItemGroupID($idListview, 3, 202) MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'After InsertItem NEW ITEM 2 .. before EnableGroupView' & @CRLF & @CRLF & 'Take a note that NEW ITEM 1 and 2 are before ROW 3: Col 1') _GUICtrlListView_EnableGroupView($idListview, True) MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'After EnableGroupView' & @CRLF & @CRLF & 'Take a note that NEW ITEM 1 and 2 are after ROW 3: Col 1' & @CRLF & 'but they were put before ROW 3: Col 1') MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'before RE-setting for each Item from "Second Group"') _GUICtrlListView_ReSetItemGroupID($idListview, 202) _GUICtrlListView_AddItem($idListview, "Row 5: Col 1", 0) _GUICtrlListView_SetItemGroupID($idListview, 6, 303) _GUICtrlListView_ReSetItemGroupID($idListview, 303) #NO_DOC_FUNCTION# => _GUICtrlListView_SetInfoTip() ; testing _GUICtrlListView_SetInfoTip($__g_hListView, 0, "set some Info TIP", 0) ; Redraw entire ListView control _WinAPI_RedrawWindow($__g_hListView, True, 0) _GUICtrlListView_InsertGroup($idListview, 1, 404, '"4th Group"') _GUICtrlListView_SetItemGroupID($idListview, 1, 101) _GUICtrlListView_SetItemGroupID($idListview, 0, 404) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton _GUICtrlListView_EnableGroupView($idListview, Not _GUICtrlListView_GetGroupViewEnabled($idListview)) ConsoleWrite('"Enable/Disable GroupView" button clicked' & @CRLF) EndSwitch WEnd EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tItem = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) If $tItem.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG Local Static $clrHighlight = _WinAPI_GetSysColor($COLOR_HIGHLIGHT) Local Static $clrBack = _WinAPI_SwitchColor($COLOR_LIGHTBLUE) Local Static $clrText = _WinAPI_SwitchColor($COLOR_DARKBLUE) Local Static $hPenGroup_GuideLine = _WinAPI_CreatePen($PS_DASH, 1, $clrBack) Local Static $hPenItem_Borders = _WinAPI_CreatePen($PS_SOLID, 1, _WinAPI_SwitchColor($COLOR_GRAY)) Local Static $hPenHeader_Borders = _WinAPI_CreatePen($PS_SOLID, 1, _WinAPI_SwitchColor($COLOR_RED)) Local Static $hBrushGroup = _WinAPI_CreateSolidBrush($COLOR_BLACK) Local Static $hBrushItem_Selected = _WinAPI_CreateSolidBrush($clrHighlight) Local Static $hBrushItem_Unselected = _WinAPI_CreateSolidBrush(0xFFFFFF) Local Static $hBrushHeader = _WinAPI_CreateSolidBrush(0xFFCCDD) ;~ Local Static $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tItem, "left")) Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tItem, "left")) ; $tRect for each Cell is different Local $hDC = $tItem.hDC ; the same $hDC for each Cell is different If $tItem.hWndFrom = $__g_hHeader Then If $tItem.dwDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW ;~ If Not $tItem.dwItemSpec Then $tRect.left += 5 $tRect.bottom -= 1 _WinAPI_SelectObject($tItem.hDC, $hPenHeader_Borders) _WinAPI_SelectObject($tItem.hDC, $hBrushHeader) _WinAPI_Rectangle($tItem.hDC, $tRect) $tRect.Left += 5 $tRect.Top += 3 _WinAPI_SetTextColor($tItem.hDC, 0) _WinAPI_SetBkMode($tItem.hDC, $TRANSPARENT) _WinAPI_DrawText($tItem.hDC, _GUICtrlHeader_GetItemText($tItem.hWndFrom, $tItem.dwItemSpec), $tRect, $DT_LEFT) Return $CDRF_SKIPDEFAULT ElseIf $tItem.hWndFrom = $__g_hListView And $tItem.Code = $NM_CUSTOMDRAW And $tItem.dwItemSpec > -1 Then Local $iGroupIndex_0based = -1 Local $iGroupId = -2 If $tItem.dwItemType = $LVCDI_GROUP Then If $tItem.dwDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $tItem.dwDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW $iGroupId = $tItem.dwItemSpec $iGroupIndex_0based = _GUICtrlListView_GetGroupIndexByGroupID($tItem.hWndFrom, $iGroupId) $tRect.bottom = $tRect.top + 15 _WinAPI_FillRect($hDC, $tRect, $hBrushGroup) _WinAPI_SelectObject($hDC, $hPenGroup_GuideLine) _WinAPI_DrawLine($hDC, $tRect.left + 5, $tRect.top + 8, $tRect.right - 5, $tRect.top + 8) _WinAPI_SetBkColor($hDC, $clrBack) _WinAPI_SetBkMode($hDC, $OPAQUE) _WinAPI_SetTextColor($hDC, $clrText) _WinAPI_SetTextCharacterExtra($hDC, 1) $tRect.left += 20 ; move INDENT the Group Text #NO_DOC_FUNCTION# => _GUICtrlListView_GetGroupState() ; Testing Local $s_FOCUSED = _GUICtrlListView_GetGroupState($tItem.hWndFrom, $iGroupId, $LVGS_FOCUSED) Local $s_SUBSETED = _GUICtrlListView_GetGroupState($tItem.hWndFrom, $iGroupId, $LVGS_SUBSETED) Local $s_SUBSETLINKFOCUSED = _GUICtrlListView_GetGroupState($tItem.hWndFrom, $iGroupId, $LVGS_SUBSETLINKFOCUSED) Local $s_GroupText = _GUICtrlListView_GetGroupInfo($tItem.hWndFrom, $iGroupId)[0] Local $s_INFO = $s_GroupText & " [ IDX=" & $iGroupIndex_0based & " ID=" & $iGroupId & " :: FOCUSED=" & $s_FOCUSED & " :: SUBSETED=" & $s_SUBSETED & " :: SUBSETLINKFOCUSED=" & $s_SUBSETLINKFOCUSED & " ] " _WinAPI_DrawText($hDC, $s_INFO, $tRect, BitOR($DT_LEFT, $DT_WORDBREAK, $DT_WORD_ELLIPSIS)) Return $CDRF_SKIPDEFAULT Else If $tItem.dwDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $tItem.dwDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iItemIndex = $tItem.dwItemSpec Local $iItemID = _GUICtrlListView_MapIndexToID($tItem.hWndFrom, $iItemIndex) $iGroupId = _GUICtrlListView_GetItemGroupID($tItem.hWndFrom, $iItemIndex) $iGroupIndex_0based = _GUICtrlListView_GetGroupIndexByGroupID($tItem.hWndFrom, $iGroupId) Local $bIsSelected = _GUICtrlListView_GetItemState($tItem.hWndFrom, $tItem.dwItemSpec, $LVIS_SELECTED) If $bIsSelected Then _WinAPI_SelectObject($hDC, $hBrushItem_Selected) Else _WinAPI_SelectObject($hDC, $hBrushItem_Unselected) EndIf _WinAPI_SelectObject($hDC, $hPenItem_Borders) If $tItem.iSubitem = $__g_eLVColumn_Name Then $tRect.left -= 3 If $tItem.dwItemSpec >= 0 Then $tRect.top -= 1 $tRect.bottom += 1 _WinAPI_Rectangle($hDC, $tRect) _WinAPI_SetTextColor($hDC, $bIsSelected ? 0xFFFFFF : $clrHighlight) _WinAPI_SetBkMode($hDC, $TRANSPARENT) If $tItem.iSubitem = $__g_eLVColumn_Name Then $tRect.left += 3 $tRect.Top += 2 Local $s_Text3 = _GUICtrlListView_GetItemText($tItem.hWndFrom, $tItem.dwItemSpec, $tItem.iSubitem) _WinAPI_DrawText($hDC, $s_Text3, $tRect, BitOR($DT_LEFT, $DT_INTERNAL, $DT_WORDBREAK)) Return $CDRF_SKIPDEFAULT ElseIf $tItem.iSubitem = $__g_eLVColumn_ItemIndex Then _WinAPI_SetTextColor($hDC, $CLR_RED) _WinAPI_DrawText($hDC, $iItemIndex, $tRect, $DT_CENTER) Return $CDRF_SKIPDEFAULT ElseIf $tItem.iSubitem = $__g_eLVColumn_ItemID Then _WinAPI_SetTextColor($hDC, $CLR_BLUE) _WinAPI_DrawText($hDC, $iItemID, $tRect, $DT_CENTER) Return $CDRF_SKIPDEFAULT ElseIf $tItem.iSubitem = $__g_eLVColumn_GroupIndex Then _WinAPI_SetTextColor($hDC, $CLR_RED) _WinAPI_DrawText($hDC, $iGroupIndex_0based, $tRect, $DT_CENTER) Return $CDRF_SKIPDEFAULT ElseIf $tItem.iSubitem = $__g_eLVColumn_GroupID Then _WinAPI_SetTextColor($hDC, $CLR_BLUE) _WinAPI_DrawText($hDC, $iGroupId, $tRect, $DT_CENTER) Return $CDRF_SKIPDEFAULT EndIf EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _GUICtrlListView_ReSetItemGroupID($idListview, $iGroupId) For $iItemIndex = 0 To _GUICtrlListView_GetItemCount($idListview) - 1 If _GUICtrlListView_GetItemGroupID($idListview, $iItemIndex) = $iGroupId Then _GUICtrlListView_SetItemGroupID($idListview, $iItemIndex, -2) _GUICtrlListView_SetItemGroupID($idListview, $iItemIndex, $iGroupId) EndIf Next EndFunc ;==>_GUICtrlListView_ReSetItemGroupID Func _GUICtrlListView_GetGroupIndexByGroupID($hWnd, $iGroupId) ;https://www.autoitscript.com/forum/topic/213679-listview-get-igroupid-and-igroup-for-listviewitem/#findComment-1552392 Local $iMaxIndex = _GUICtrlListView_GetGroupCount($hWnd) - 1 Local $aInfo For $i = 0 To $iMaxIndex $aInfo = _GUICtrlListView_GetGroupInfoByIndex($hWnd, $i) If $aInfo[2] = $iGroupId Then Return $i Next Return SetError(1, 0, -1) EndFunc ;==>_GUICtrlListView_GetGroupIndexByGroupID
  2. Here's an example, but it doesn't work well #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> Global Const $LVNI_SAMEGROUPONLY = 0x0080 Example() Func Example() GUICreate("ListView Enable Group View", 400, 300) Local $idListview = GUICtrlCreateListView("", 2, 2, 394, 268) Local $hLV = GUICtrlGetHandle($idListview) GUISetState(@SW_SHOW) ; Add columns _GUICtrlListView_InsertColumn($idListview, 0, "Column 1", 150) _GUICtrlListView_InsertColumn($idListview, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($idListview, 2, "Column 3", 100) ; Add items _GUICtrlListView_AddItem($idListview, "Item 0 Row 1: Col 1") _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem($idListview, "Item 1 Row 2: Col 1") _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem($idListview, "Item 2 Row 3: Col 1") _GUICtrlListView_AddItem($idListview, "Item 3 Row 4: Col 1") _GUICtrlListView_AddItem($idListview, "Item 4 Row 5: Col 1") _GUICtrlListView_AddItem($idListview, "Item 5 Row 6: Col 1") ; Build groups _GUICtrlListView_EnableGroupView($idListview) _GUICtrlListView_InsertGroup($idListview, -1, 101, "Group 101") _GUICtrlListView_InsertGroup($idListview, -1, 202, "Group 202") _GUICtrlListView_SetItemGroupID($idListview, 0, 101) _GUICtrlListView_SetItemGroupID($idListview, 1, 101) _GUICtrlListView_SetItemGroupID($idListview, 2, 202) _GUICtrlListView_SetItemGroupID($idListview, 3, 202) _GUICtrlListView_SetItemGroupID($idListview, 4, 202) _GUICtrlListView_SetItemGroupID($idListview, 5, 202) _GetGroupAllItems($hLV, 101) _GetGroupAllItems($hLV, 202) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func _GetGroupAllItems($hLV, $iGroupID) Local $iFirstItem = _GetGroupFirstItem($hLV, $iGroupID) Local $iNextItem = $iFirstItem ConsoleWrite("> iGroupID = " & $iGroupID & " $iFirstItem = " & $iFirstItem & @CRLF) Do $iNextItem = _GetGroupNextItem($hLV, $iNextItem) ConsoleWrite("- $iNextItem = " & $iNextItem & @CRLF) Until $iNextItem = -1 EndFunc ;==>_GetGroupAllItems Func _GetGroupNextItem($hLV, $iItemIndex) Local $iFound = _SendMessage( _ $hLV, _ $LVM_GETNEXTITEM, _ $iItemIndex, _ $LVNI_SAMEGROUPONLY) Return $iFound EndFunc ;==>_GetGroupNextItem Func _GetGroupFirstItem($hLV, $iGroupID) Local $tag = _ "dword cbSize;" & _ "dword mask;" & _ "ptr pszHeader;" & _ "int cchHeader;" & _ "int iGroupId;" & _ "dword stateMask;" & _ "dword state;" & _ "uint uAlign;" & _ "int cItems;" & _ "int iFirstItem" Local $t = DllStructCreate($tag) DllStructSetData($t, "cbSize", DllStructGetSize($t)) ; IMPORTANT: request iFirstItem DllStructSetData($t, "mask", $LVGF_ITEMS) _SendMessage($hLV, $LVM_GETGROUPINFO, $iGroupID, DllStructGetPtr($t)) Return DllStructGetData($t, "iFirstItem") EndFunc ;==>_GetGroupFirstItem I get: but it should gives: any concept why _GetGroupFirstItem() nad _GetGroupNextItem() both doesn't work well ?
  3. Another not working example #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WinAPIGdi.au3> _Example() Func _Example() Local $hGUI = GUICreate("GroupHeaderImageList", 500, 300) #forceref $hGUI Local $idListView = GUICtrlCreateListView("Name|Value", 10, 10, 480, 250) Local $hListView = GUICtrlGetHandle($idListView) ; Enable group view _SendMessage($hListView, $LVM_ENABLEGROUPVIEW, True, 0) ; ===================================================== ; Create ImageList ; ===================================================== Local $hImageList = _GUIImageList_Create(16, 16) Local $hIcon = _WinAPI_LoadIcon(0, $IDI_INFORMATION) ; Add icon to ImageList _GUIImageList_AddIcon($hImageList, $hIcon) ; ===================================================== ; Set Group Header ImageList ; ===================================================== ListView_SetGroupHeaderImageList($hListView, $hImageList) ; ===================================================== ; Get Group Header ImageList ; ===================================================== Local $hReturned = ListView_GetGroupHeaderImageList($hListView) ConsoleWrite("Original : " & $hImageList & @CRLF) ConsoleWrite("Returned : " & "0x" & Hex($hReturned) & @CRLF) ; ===================================================== ; Create group ; ===================================================== Local $tagLVGROUP = _ "uint cbSize;" & _ "uint mask;" & _ "ptr pszHeader;" & _ "int cchHeader;" & _ "ptr pszFooter;" & _ "int cchFooter;" & _ "int iGroupId;" & _ "uint stateMask;" & _ "uint state;" & _ "uint uAlign;" & _ "int iTitleImage" Local $sHeader = "Group A" Local $tText = DllStructCreate("wchar[" & StringLen($sHeader) + 1 & "]") DllStructSetData($tText, 1, $sHeader) Local $tGroup = DllStructCreate($tagLVGROUP) DllStructSetData($tGroup, "cbSize", DllStructGetSize($tGroup)) DllStructSetData($tGroup, "mask", _ BitOR($LVGF_HEADER, $LVGF_GROUPID, $LVGF_TITLEIMAGE)) DllStructSetData($tGroup, "pszHeader", DllStructGetPtr($tText)) DllStructSetData($tGroup, "cchHeader", StringLen($sHeader)) DllStructSetData($tGroup, "iGroupId", 1) ; Use image index 0 DllStructSetData($tGroup, "iTitleImage", 0) ; Insert group _SendMessage($hListView, $LVM_INSERTGROUP, -1, DllStructGetPtr($tGroup)) ; ===================================================== ; Add item into group ; ===================================================== Local $iItem = _GUICtrlListView_AddItem($hListView, "Item 1") _GUICtrlListView_AddSubItem($hListView, $iItem, "123", 1) _GUICtrlListView_SetItemGroupID($hListView, $iItem, 1) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd EndFunc ; #FUNCTION# =================================================================== ; Name...........: ListView_SetGroupHeaderImageList ; Description ...: Sets the ImageList used by group headers. ; ============================================================================== Func ListView_SetGroupHeaderImageList($hListView, $hImageList) Return _SendMessage( _ $hListView, _ $LVM_SETIMAGELIST, _ $LVSIL_GROUPHEADER, _ $hImageList) EndFunc ; #FUNCTION# =================================================================== ; Name...........: ListView_GetGroupHeaderImageList ; Description ...: Gets the ImageList used by group headers. ; ============================================================================== Func ListView_GetGroupHeaderImageList($hListView) Return _SendMessage( _ $hListView, _ $LVM_GETIMAGELIST, _ $LVSIL_GROUPHEADER, _ 0) EndFunc
  4. My research led me to: #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WinAPIGdi.au3> _Example() Func _Example() Local $hGUI = GUICreate("LVSIL_GROUPHEADER Example", 500, 300) #forceref $hGUI Local $idListView = GUICtrlCreateListView("Name|Value", 10, 10, 480, 250) Local $hListView = GUICtrlGetHandle($idListView) ; Enable group view _SendMessage($hListView, $LVM_ENABLEGROUPVIEW, True, 0) ; Create ImageList for LVSIL_GROUPHEADER Local $hImageList = _GUIImageList_Create(16, 16) Local $hIcon = _WinAPI_LoadIcon(0, $IDI_INFORMATION) ; Image index = 0 _GUIImageList_AddIcon($hImageList, $hIcon) ; Assign ImageList to GROUP HEADER slot _SendMessage($hListView, $LVM_SETIMAGELIST, $LVSIL_GROUPHEADER, $hImageList) ; Create group using iTitleImage Local $tagLVGROUP = _ "uint cbSize;" & _ "uint mask;" & _ "ptr pszHeader;" & _ "int cchHeader;" & _ "ptr pszFooter;" & _ "int cchFooter;" & _ "int iGroupId;" & _ "uint stateMask;" & _ "uint state;" & _ "uint uAlign;" & _ "int iTitleImage" Local $sHeader = "Group A" Local $tText = DllStructCreate("wchar[" & StringLen($sHeader) + 1 & "]") DllStructSetData($tText, 1, $sHeader) Local $tGroup = DllStructCreate($tagLVGROUP) DllStructSetData($tGroup, "cbSize", DllStructGetSize($tGroup)) ; Use HEADER + GROUPID + TITLEIMAGE DllStructSetData($tGroup, "mask", _ BitOR($LVGF_HEADER, $LVGF_GROUPID, $LVGF_TITLEIMAGE)) DllStructSetData($tGroup, "pszHeader", DllStructGetPtr($tText)) DllStructSetData($tGroup, "cchHeader", StringLen($sHeader)) DllStructSetData($tGroup, "iGroupId", 1) ; Use image index 0 from LVSIL_GROUPHEADER DllStructSetData($tGroup, "iTitleImage", 0) ; Insert group _SendMessage($hListView, $LVM_INSERTGROUP, -1, DllStructGetPtr($tGroup)) ; Add item into group Local $iItem = _GUICtrlListView_AddItem($hListView, "Item 1") _GUICtrlListView_AddSubItem($hListView, $iItem, "123", 1) _GUICtrlListView_SetItemGroupID($hListView, $iItem, 1) GUISetState() While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd EndFunc But I has no positive effect. Here I saw some positive results: https://www.vbforums.com/showthread.php?804969-PARTIALLY-RESOLVED-Listview-Grouping-in-Virtual-Mode I mean I looking for such result (image in Headers and image in Groups): http://vbrichclient.com/Downloads/OwnerDrawnGroupList.png
  5. Can anyone find a solution to this flickering in the _GUICtrlListView_CreateDragImage.au3 example ?
  6. In the last example script Cell [0][0] in list view has no border/gridline. I think I mess something in WM_NOTIFY
  7. @Nine could you take a look and say to me what I'm doing wrong here ?
  8. Awesome code. Sorry to butt in here a bit .... but I just couldn't resist and checked if this code could do something I've always wanted to do. Through the color of the red frame and the highlighting of the active element (its background and text color) it clearly indicates which tab is active. #include <ColorConstants.au3> #include <GUIConstantsEx.au3> #include <GuiTab.au3> #include <TabConstants.au3> #include <WindowsNotifsConstants.au3> #include <WindowsSysColorConstants.au3> #include <WinAPIGdi.au3> #include <WinAPISysWin.au3> #include <WinAPITheme.au3> ; Initialize System DPI awareness DllCall("user32.dll", "bool", "SetProcessDpiAwarenessContext", @AutoItX64 ? "int64" : "int", -2) Global $g_hTab_CB, $g_pTab_CB, $g_hProc, $g_hTab Global Const $COLOR_BUTTON_BG = 0x383838, $COLOR_BG_DARK = 0x202020, $COLOR_GUI_BG = 0x101010, $COLOR_BORDER = 0x606060, $COLOR_BORDER_DARK = 0x303030 Example() Func Example() Local $hGUI = GUICreate("DarkTheme TabControl (24H2/25H2)", 500, 300) GUISetBkColor($COLOR_GUI_BG) GUISetFont(10) Local $idTab = GUICtrlCreateTab(20, 20, 460, 260) $g_hTab = GUICtrlGetHandle($idTab) GUICtrlCreateTabItem("tab0") GUICtrlCreateTabItem("tab1") GUICtrlCreateTabItem("tab2") GUICtrlSetState(-1, $GUI_SHOW) GUICtrlCreateTabItem("tab3") GUICtrlCreateTabItem("tab4") ; Remove focus rectangle from tab control GUICtrlSendMsg($idTab, $WM_CHANGEUISTATE, 65537, 0) ; Set dark titlebar _WinAPI_DwmSetWindowAttribute($hGUI, $DWMWA_USE_IMMERSIVE_DARK_MODE, True) ; Set theme if OS supports it If _is24H2Plus() Then _WinAPI_SetWindowTheme(GUICtrlGetHandle($idTab), 'DarkMode_DarkTheme') ; Register Subclassing / Window Procedure $g_hTab_CB = DllCallbackRegister(_WinProc, "ptr", "hwnd;uint;wparam;lparam") $g_pTab_CB = DllCallbackGetPtr($g_hTab_CB) $g_hProc = _WinAPI_SetWindowLong($g_hTab, $GWL_WNDPROC, $g_pTab_CB) GUISetState(@SW_SHOW) Local $idMsg While 1 $idMsg = GUIGetMsg() If $idMsg = $GUI_EVENT_CLOSE Then ExitLoop WEnd ; Cleanup: Restore original Window Procedure _WinAPI_SetWindowLong($g_hTab, $GWL_WNDPROC, $g_hProc) DllCallbackFree($g_hTab_CB) EndFunc ;==>Example Func _is24H2Plus() ; Check if this OS build is Windows 11 24H2/25H2 to support the newer DarkMode_DarkTheme Local $iRevision = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "UBR") Local $b24H2Plus = False If @OSBuild >= 26100 And $iRevision >= 6899 Then $b24H2Plus = True Else ConsoleWrite("Windows 11 24H2/25H2 (build 26100.6899 or higher) is required to use DarkMode_DarkTheme." & @CRLF) EndIf Return $b24H2Plus EndFunc ;==>_is24H2Plus Func _WinProc($hWnd, $iMsg, $wParam, $lParam) ;coded by UEZ Switch $iMsg Case $WM_ERASEBKGND Return 1 ; Prevent background erasing to avoid flickering Case $WM_PAINT Local $tPaint = DllStructCreate($tagPAINTSTRUCT) Local $hDC = _WinAPI_BeginPaint($hWnd, $tPaint) If @error Or Not $hDC Then Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam) Local $tClient = _WinAPI_GetClientRect($hWnd) Local $iWidth = $tClient.Right Local $iHeight = $tClient.Bottom ; Prepare Double Buffering Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC) Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight) Local $hOldBmp = _WinAPI_SelectObject($hMemDC, $hBitmap) ; --- 1. Clipping (Exclude child controls from drawing) --- Local $hParent = _WinAPI_GetParent($hWnd) Local $hChild = _WinAPI_GetWindow($hParent, $GW_CHILD) Local $tCR, $tPR = _WinAPI_GetWindowRect($hWnd) Local $left, $top, $right, $bottom While $hChild If $hChild <> $hWnd And _WinAPI_IsWindowVisible($hChild) Then $tCR = _WinAPI_GetWindowRect($hChild) If Not ($tCR.right < $tPR.left Or $tCR.left > $tPR.right Or $tCR.bottom < $tPR.top Or $tCR.top > $tPR.bottom) Then $left = Max($tCR.left, $tPR.left) - $tPR.left $top = Max($tCR.top, $tPR.top) - $tPR.top $right = Min($tCR.right, $tPR.right) - $tPR.left $bottom = Min($tCR.bottom, $tPR.bottom) - $tPR.top DllCall("gdi32.dll", "int", "ExcludeClipRect", "handle", $hMemDC, "int", $left, "int", $top, "int", $right, "int", $bottom) EndIf EndIf $hChild = _WinAPI_GetWindow($hChild, $GW_HWNDNEXT) WEnd Local $hTabUpDown = _WinAPI_FindWindowEx($hWnd, "msctls_updown32") If $hTabUpDown And _WinAPI_IsWindowVisible($hTabUpDown) Then $tCR = _WinAPI_GetWindowRect($hTabUpDown) If Not ($tCR.right < $tPR.left Or $tCR.left > $tPR.right Or $tCR.bottom < $tPR.top Or $tCR.top > $tPR.bottom) Then $left = Max($tCR.left, $tPR.left) - $tPR.left $top = Max($tCR.top, $tPR.top) - $tPR.top $right = Min($tCR.right, $tPR.right) - $tPR.left $bottom = Min($tCR.bottom, $tPR.bottom) - $tPR.top DllCall("gdi32.dll", "int", "ExcludeClipRect", "handle", $hMemDC, "int", $left, "int", $top, "int", $right, "int", $bottom) EndIf EndIf ; 2. Draw main background (Dark color) Local $hBrushBg = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BG_DARK)) ; _WinAPI_FillRect($hMemDC, $tClient, $hBrushBg) Local $iTabCount = _SendMessage($hWnd, $TCM_GETITEMCOUNT, 0, 0) Local $iCurSel = _SendMessage($hWnd, $TCM_GETCURSEL, 0, 0) ; 3. Prepare the Body Frame (The area beneath the tabs) Local $tFirstTabRect = DllStructCreate($tagRECT) _SendMessage($hWnd, $TCM_GETITEMRECT, 0, DllStructGetPtr($tFirstTabRect)) Local $tBodyRect = DllStructCreate($tagRECT) $tBodyRect.Left = 0 $tBodyRect.Top = $tFirstTabRect.Bottom ; Starts at the bottom edge of the tabs $tBodyRect.Right = $iWidth $tBodyRect.Bottom = $iHeight Local $hBrushBorder = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_RED)) _WinAPI_FrameRect($hMemDC, $tBodyRect, $hBrushBorder) ; 4. Draw the "Gap" to the right of the tabs in GUI background color If $iTabCount > 0 Then Local $tLastTabRect = DllStructCreate($tagRECT) _SendMessage($hWnd, $TCM_GETITEMRECT, $iTabCount - 1, DllStructGetPtr($tLastTabRect)) Local $tGapRect = DllStructCreate($tagRECT) $tGapRect.Left = $tLastTabRect.Right + 2 $tGapRect.Top = 0 $tGapRect.Right = $iWidth $tGapRect.Bottom = $tLastTabRect.Bottom Local $hBrushGui = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_GUI_BG)) _WinAPI_FillRect($hMemDC, $tGapRect, $hBrushGui) _WinAPI_DeleteObject($hBrushGui) EndIf _WinAPI_SetBkMode($hMemDC, 1) ; Transparent background for text ;~ _WinAPI_SetTextColor($hMemDC, _ColorToCOLORREF(0xF0F0F0)) ; 5. Draw individual tabs For $i = 0 To $iTabCount - 1 Local $tRECT = DllStructCreate($tagRECT) _SendMessage($hWnd, $TCM_GETITEMRECT, $i, DllStructGetPtr($tRECT)) If $tRECT.Right < 0 Or $tRECT.Left > $iWidth Then ContinueLoop $tRECT.top -= 2 Local $bSelected = ($i = $iCurSel) Local $iTabColor = $bSelected ? $COLOR_DARKSLATEGRAY : $COLOR_BG_DARK Local $hTabBrush = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($iTabColor)) ; Fill tab background _WinAPI_FillRect($hMemDC, $tRECT, $hTabBrush) If $bSelected Then _WinAPI_SetTextColor($hMemDC, _WinAPI_SwitchColor($COLOR_VIOLET)) ; Draw border ONLY for the active tab (Top, Left, Right) _WinAPI_FrameRect($hMemDC, $tRECT, $hBrushBorder) ; OPEN BOTTOM: Draw a line in tab-color over the body-border to merge them Local $tOpenLine = DllStructCreate($tagRECT) $tOpenLine.Left = $tRECT.Left + 1 $tOpenLine.Top = $tRECT.Bottom - 1 ; Exactly on the border line of the body $tOpenLine.Right = $tRECT.Right - 1 $tOpenLine.Bottom = $tRECT.Bottom + 1 _WinAPI_FillRect($hMemDC, $tOpenLine, $hTabBrush) Else _WinAPI_SetTextColor($hMemDC, _WinAPI_SwitchColor($COLOR_RED)) ; Draw rectangle around non active tabs Local $hBrushTabRecDark = _WinAPI_CreateSolidBrush(_ColorToCOLORREF($COLOR_BORDER_DARK)) _WinAPI_FrameRect($hMemDC, $tRECT, $hBrushTabRecDark) _WinAPI_DeleteObject($hBrushTabRecDark) EndIf _WinAPI_DeleteObject($hTabBrush) ; Draw text centered Local $sText = _GUICtrlTab_GetItemText($hWnd, $i) Local $tTextRect = DllStructCreate($tagRECT) With $tTextRect .Left = $tRECT.Left + 6 .Top = $tRECT.Top + ($bSelected ? 1 : 3) .Right = $tRECT.Right - 6 .Bottom = $tRECT.Bottom - 3 EndWith DllCall("user32.dll", "int", "DrawTextW", "handle", $hMemDC, "wstr", $sText, "int", -1, "struct*", $tTextRect, "uint", BitOR($DT_CENTER, $DT_VCENTER, $DT_SINGLELINE, $DT_NOPREFIX)) Next ; 6. Copy memory DC to screen DC (BitBlt) _WinAPI_BitBlt($hDC, 0, 0, $iWidth, $iHeight, $hMemDC, 0, 0, $SRCCOPY) ; Cleanup _WinAPI_SelectObject($hMemDC, $hOldBmp) _WinAPI_DeleteObject($hBitmap) _WinAPI_DeleteObject($hBrushBg) _WinAPI_DeleteObject($hBrushBorder) _WinAPI_DeleteDC($hMemDC) _WinAPI_EndPaint($hWnd, $tPaint) Return 0 EndSwitch Return _WinAPI_CallWindowProc($g_hProc, $hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_WinProc Func _ColorToCOLORREF($iColor) ; Convert RGB to BGR Local $iR = BitAND(BitShift($iColor, 16), 0xFF) Local $iG = BitAND(BitShift($iColor, 8), 0xFF) Local $iB = BitAND($iColor, 0xFF) Return BitOR(BitShift($iB, -16), BitShift($iG, -8), $iR) EndFunc ;==>_ColorToCOLORREF Func Min($a, $b) Return ($a < $b ? $a : $b) EndFunc ;==>Min Func Max($a, $b) Return ($a > $b ? $a : $b) EndFunc ;==>Max Func _WinAPI_FindWindowEx($hParent, $sClass, $sTitle = "", $hAfter = 0) Local $ret = DllCall("user32.dll", "hwnd", "FindWindowExW", "hwnd", $hParent, "hwnd", $hAfter, "wstr", $sClass, "wstr", $sTitle) If @error Or Not IsArray($ret) Then Return 0 Return $ret[0] EndFunc ;==>_WinAPI_FindWindowEx
  9. I just wana try to use: https://learn.microsoft.com/en-us/windows/win32/api/commctrl/ns-commctrl-lvgroupmetrics As so far I got: #AutoIt3Wrapper_UseX64=N #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <WinAPISys.au3> ; https://learn.microsoft.com/en-us/windows/win32/api/commctrl/ns-commctrl-lvgroupmetrics Global Const $tagLVGROUPMETRICS = _ "uint cbSize;" & _ "uint mask;" & _ "uint Left;" & _ "uint Top;" & _ "uint Right;" & _ "uint Bottom;" & _ "COLORREF crLeft;" & _ "COLORREF crTop;" & _ "COLORREF crRight;" & _ "COLORREF crBottom;" & _ "COLORREF crHeader;" & _ "COLORREF crFooter;" Global Const $LVGMF_BORDERSIZE = 0x00000001 Global Const $LVGMF_BORDERCOLOR = 0x00000002 Global Const $LVGMF_TEXTCOLOR = 0x00000004 _Example() Func _Example() ; GUI Local $hGUI = GUICreate("Windows 11 LVGROUPMETRICS", 900, 500) #forceref $hGUI Local $idLV = GUICtrlCreateListView( _ "Name|Description|State", _ 10, 10, 880, 440, _ BitOR($LVS_REPORT, $LVS_SHOWSELALWAYS)) Local $hLV = GUICtrlGetHandle($idLV) ; Explorer theme (Win11) DllCall("uxtheme.dll", "none", "SetWindowTheme", _ "hwnd", $hLV, _ "wstr", "Explorer", _ "ptr", 0) ; Extended styles _GUICtrlListView_SetExtendedListViewStyle($hLV, _ BitOR($LVS_EX_FULLROWSELECT, _ $LVS_EX_DOUBLEBUFFER, _ $LVS_EX_BORDERSELECT)) ; Group view _GUICtrlListView_EnableGroupView($hLV, True) ; Groups _GUICtrlListView_InsertGroup($hLV, 0, 100, "Applications") _GUICtrlListView_InsertGroup($hLV, 1, 200, "Services") ; Items Local $i $i = _GUICtrlListView_AddItem($hLV, "Explorer.exe") _GUICtrlListView_AddSubItem($hLV, $i, "Windows Shell", 1) _GUICtrlListView_AddSubItem($hLV, $i, "Running", 2) _GUICtrlListView_SetItemGroupID($hLV, $i, 100) $i = _GUICtrlListView_AddItem($hLV, "Notepad.exe") _GUICtrlListView_AddSubItem($hLV, $i, "Text Editor", 1) _GUICtrlListView_AddSubItem($hLV, $i, "Idle", 2) _GUICtrlListView_SetItemGroupID($hLV, $i, 100) $i = _GUICtrlListView_AddItem($hLV, "AudioSrv") _GUICtrlListView_AddSubItem($hLV, $i, "Windows Audio", 1) _GUICtrlListView_AddSubItem($hLV, $i, "Active", 2) _GUICtrlListView_SetItemGroupID($hLV, $i, 200) #Region ; LVGROUPMETRICS Local $tMetrics = DllStructCreate($tagLVGROUPMETRICS) DllStructSetData($tMetrics, "cbSize", DllStructGetSize($tMetrics)) DllStructSetData($tMetrics, "mask", _ BitOR($LVGMF_BORDERSIZE, _ $LVGMF_BORDERCOLOR, _ $LVGMF_TEXTCOLOR)) ; Margins DllStructSetData($tMetrics, "Left", 12) DllStructSetData($tMetrics, "Top", 8) DllStructSetData($tMetrics, "Right", 12) DllStructSetData($tMetrics, "Bottom", 8) ; Border colors DllStructSetData($tMetrics, "crLeft", 0xFFD0D0) DllStructSetData($tMetrics, "crTop", 0xD0FFD0) DllStructSetData($tMetrics, "crRight", 0xD0D0FF) DllStructSetData($tMetrics, "crBottom", 0xD0D0D0) ; Header text color (BGR) DllStructSetData($tMetrics, "crHeader", 0xFF0000) ; Footer text color (BGR) ; RGB(0,128,0) DllStructSetData($tMetrics, "crFooter", 0x00FF00) #EndRegion ; LVGROUPMETRICS ; ---------------------------- ; Apply metrics ; ---------------------------- Local $bRet = _GUICtrlListView_SetGroupMetrics($hLV, $tMetrics) ConsoleWrite("SetGroupMetrics: " & $bRet & @CRLF) ; ---------------------------- ; Column widths ; ---------------------------- _GUICtrlListView_SetColumnWidth($hLV, 0, 220) _GUICtrlListView_SetColumnWidth($hLV, 1, 350) _GUICtrlListView_SetColumnWidth($hLV, 2, 120) GUISetState(@SW_SHOW) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd EndFunc ;==>_Example Func _GUICtrlListView_SetGroupMetrics($hWnd, $pMetrics) If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd) EndIf If $hWnd = 0 Then Return SetError(1, 0, False) EndIf If Not IsDllStruct($pMetrics) Then Return SetError(2, 0, False) EndIf Return _SendMessage( _ $hWnd, _ $LVM_SETGROUPMETRICS, _ 0, _ DllStructGetPtr($pMetrics), _ 0, _ "ptr") EndFunc ;==>_GUICtrlListView_SetGroupMetrics of course most features are: Not implemented by MS
  10. Take a look also for: #NO_DOC_FUNCTION# => _GUICtrlListView_SetInfoTip() ; testing _GUICtrlListView_SetInfoTip($__g_hListView, 0, "set some Info TIP", 0) and: #NO_DOC_FUNCTION# => _GUICtrlListView_GetGroupState() ; Testing
  11. Fixed button issue, but still have problem with GridLines in [0][0] cell ;~ https://www.autoitscript.com/forum/topic/213681-listview-with-groups-inserting-new-rows-issue-with-_guictrllistview_insertitem/ #AutoIt3Wrapper_UseX64=n ; From Nine #include <WindowsConstants.au3> #include <ColorConstants.au3> #include <GUIConstants.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WinAPIDiag.au3> #include <WinAPITheme.au3> Global Enum $__Example_LVColumn_Name, $__Example_LVColumn_ItemIndex, $__Example_LVColumn_ItemID, $__Example_LVColumn_GroupIndex, $__Example_LVColumn_GroupID Opt("MustDeclareVars", True) Global $__g_hListView, $__g_hHeader Example() Func Example() GUICreate("Example", 900, 700) Local $idListview = GUICtrlCreateListView("", 10, 10, 880, 550, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_INFOTIP)) $__g_hListView = GUICtrlGetHandle($idListview) $__g_hHeader = GUICtrlSendMsg($idListview, $LVM_GETHEADER, 0, 0) _WinAPI_SetWindowTheme($__g_hHeader, "", "") ;Turn off theme for header Local $iStyle = _WinAPI_GetWindowLong($__g_hHeader, $GWL_STYLE) _WinAPI_SetWindowLong($__g_hHeader, $GWL_STYLE, BitOR($iStyle, $HDS_FLAT)) ; remove header 3D button effect Local $idButton = GUICtrlCreateButton("Enable/Disable GroupView", 10, 620, 200, 20) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) _GUICtrlListView_AddColumn($idListview, "Item (row name given by user)", 100) ; $__Example_LVColumn_Name _GUICtrlListView_AddColumn($idListview, "ItemIndex (current row index)", 100) ; $__Example_LVColumn_ItemIndex _GUICtrlListView_AddColumn($idListview, "ItemID (creation order index)", 100) ; $__Example_LVColumn_ItemID _GUICtrlListView_AddColumn($idListview, "GroupIndex (current group index)", 100) ; $__Example_LVColumn_GroupIndex _GUICtrlListView_AddColumn($idListview, "GroupID (ID mark given by user)", 100) ; $__Example_LVColumn_GroupID _GUICtrlListView_SetColumnWidth($idListview, $__Example_LVColumn_Name, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, $__Example_LVColumn_ItemIndex, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, $__Example_LVColumn_ItemID, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, $__Example_LVColumn_GroupIndex, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, $__Example_LVColumn_GroupID, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0) _GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 0) _GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 0) _GUICtrlListView_AddItem($idListview, "Row 4: Col 1", 0) _GUICtrlListView_InsertGroup($idListview, -1, 101, '"First Group"') _GUICtrlListView_InsertGroup($idListview, -1, 202, '"Second Group"') _GUICtrlListView_InsertGroup($idListview, -1, 303, '"Third Group"') _GUICtrlListView_SetItemGroupID($idListview, 0, 101) _GUICtrlListView_SetItemGroupID($idListview, 1, 202) _GUICtrlListView_SetItemGroupID($idListview, 2, 202) _GUICtrlListView_SetItemGroupID($idListview, 3, 303) MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'Before InsertItem') _GUICtrlListView_InsertItem($idListview, "NEW ITEM 1", 2) ; insert as 2 ID .... before "Row 3: Col 1" _GUICtrlListView_SetItemGroupID($idListview, 2, 202) MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'After InsertItem NEW ITEM 1 .. before EnableGroupView') _GUICtrlListView_InsertItem($idListview, "NEW ITEM 2", 3) ; insert as 2 ID .... before "Row 3: Col 1" _GUICtrlListView_SetItemGroupID($idListview, 3, 202) MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'After InsertItem NEW ITEM 2 .. before EnableGroupView' & @CRLF & @CRLF & 'Take a note that NEW ITEM 1 and 2 are before ROW 3: Col 1') _GUICtrlListView_EnableGroupView($idListview, True) MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'After EnableGroupView' & @CRLF & @CRLF & 'Take a note that NEW ITEM 1 and 2 are after ROW 3: Col 1' & @CRLF & 'but they were put before ROW 3: Col 1') MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'before RE-setting for each Item from "Second Group"') _GUICtrlListView_ReSetItemGroupID($idListview, 202) _GUICtrlListView_AddItem($idListview, "Row 5: Col 1", 0) _GUICtrlListView_SetItemGroupID($idListview, 6, 303) _GUICtrlListView_ReSetItemGroupID($idListview, 303) #NO_DOC_FUNCTION# => _GUICtrlListView_SetInfoTip() ; testing _GUICtrlListView_SetInfoTip($__g_hListView, 0, "set some Info TIP", 0) ; Redraw entire ListView control _WinAPI_RedrawWindow($__g_hListView, True, 0) _GUICtrlListView_InsertGroup($idListview, 1, 404, '"4th Group"') _GUICtrlListView_SetItemGroupID($idListview, 1, 101) _GUICtrlListView_SetItemGroupID($idListview, 0, 404) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton _GUICtrlListView_EnableGroupView($idListview, Not _GUICtrlListView_GetGroupViewEnabled($idListview)) ConsoleWrite('"Enable/Disable GroupView" button clicked' & @CRLF) EndSwitch WEnd EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tItem = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) If $tItem.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG Local Static $clrHighlight = _WinAPI_GetSysColor($COLOR_HIGHLIGHT) Local Static $clrBack = _WinAPI_SwitchColor($COLOR_LIGHTBLUE) Local Static $clrText = _WinAPI_SwitchColor($COLOR_BLUE) Local Static $hPenGroup_GuideLine = _WinAPI_CreatePen($PS_DASH, 1, $clrBack) Local Static $hPenItem_Borders = _WinAPI_CreatePen($PS_SOLID, 1, _WinAPI_SwitchColor($COLOR_GRAY)) Local Static $hPenHeader_Borders = _WinAPI_CreatePen($PS_SOLID, 1, _WinAPI_SwitchColor($COLOR_RED)) Local Static $hBrushGroup = _WinAPI_CreateSolidBrush($COLOR_BLACK) Local Static $hBrushItem_Selected = _WinAPI_CreateSolidBrush($clrHighlight) Local Static $hBrushItem_Unselected = _WinAPI_CreateSolidBrush(0xFFFFFF) Local Static $hBrushHeader = _WinAPI_CreateSolidBrush(0xFFCCDD) ;~ Local Static $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tItem, "left")) Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tItem, "left")) ; $tRect for each Cell is different Local $hDC = $tItem.hDC ; the same $hDC for each Cell is different If $tItem.hWndFrom = $__g_hHeader Then If $tItem.dwDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If Not $tItem.dwItemSpec Then $tRect.left += 5 $tRect.bottom -= 1 _WinAPI_SelectObject($tItem.hDC, $hPenHeader_Borders) _WinAPI_SelectObject($tItem.hDC, $hBrushHeader) _WinAPI_Rectangle($tItem.hDC, $tRect) $tRect.Left += 5 $tRect.Top += 3 _WinAPI_SetTextColor($tItem.hDC, 0) _WinAPI_SetBkMode($tItem.hDC, $TRANSPARENT) _WinAPI_DrawText($tItem.hDC, _GUICtrlHeader_GetItemText($tItem.hWndFrom, $tItem.dwItemSpec), $tRect, $DT_LEFT) Return $CDRF_SKIPDEFAULT ElseIf $tItem.hWndFrom = $__g_hListView And $tItem.Code = $NM_CUSTOMDRAW And $tItem.dwItemSpec > -1 Then Local $iGroupIndex_0based = -1 Local $iGroupId = -2 If $tItem.dwItemType = $LVCDI_GROUP Then If $tItem.dwDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $tItem.dwDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW $iGroupId = $tItem.dwItemSpec $iGroupIndex_0based = _GUICtrlListView_GetGroupIndexByGroupID($tItem.hWndFrom, $iGroupId) $tRect.bottom = $tRect.top + 15 _WinAPI_FillRect($hDC, $tRect, $hBrushGroup) _WinAPI_SelectObject($hDC, $hPenGroup_GuideLine) _WinAPI_DrawLine($hDC, $tRect.left + 5, $tRect.top + 8, $tRect.right - 5, $tRect.top + 8) _WinAPI_SetBkColor($hDC, $clrBack) _WinAPI_SetBkMode($hDC, $OPAQUE) _WinAPI_SetTextColor($hDC, $clrText) $tRect.left += 20 #NO_DOC_FUNCTION# => _GUICtrlListView_GetGroupState() ; Testing Local $s_FOCUSED = _GUICtrlListView_GetGroupState($tItem.hWndFrom, $iGroupId, $LVGS_FOCUSED) Local $s_SUBSETED = _GUICtrlListView_GetGroupState($tItem.hWndFrom, $iGroupId, $LVGS_SUBSETED) Local $s_SUBSETLINKFOCUSED = _GUICtrlListView_GetGroupState($tItem.hWndFrom, $iGroupId, $LVGS_SUBSETLINKFOCUSED) Local $s_GroupText = _GUICtrlListView_GetGroupInfo($tItem.hWndFrom, $iGroupId)[0] Local $s_INFO = $s_GroupText & " [ IDX=" & $iGroupIndex_0based & " ID=" & $iGroupId & " :: FOCUSED=" & $s_FOCUSED & " :: SUBSETED=" & $s_SUBSETED & " :: SUBSETLINKFOCUSED=" & $s_SUBSETLINKFOCUSED & " ] " _WinAPI_DrawText($hDC, $s_INFO, $tRect, BitOR($DT_LEFT, $DT_WORDBREAK, $DT_WORD_ELLIPSIS)) Return $CDRF_SKIPDEFAULT Else If $tItem.dwDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $tItem.dwDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iItemIndex = $tItem.dwItemSpec Local $iItemID = _GUICtrlListView_MapIndexToID($tItem.hWndFrom, $iItemIndex) $iGroupId = _GUICtrlListView_GetItemGroupID($tItem.hWndFrom, $iItemIndex) $iGroupIndex_0based = _GUICtrlListView_GetGroupIndexByGroupID($tItem.hWndFrom, $iGroupId) Local $bIsSelected = _GUICtrlListView_GetItemState($tItem.hWndFrom, $tItem.dwItemSpec, $LVIS_SELECTED) If $bIsSelected Then _WinAPI_SelectObject($hDC, $hBrushItem_Selected) Else _WinAPI_SelectObject($hDC, $hBrushItem_Unselected) EndIf _WinAPI_SelectObject($hDC, $hPenItem_Borders) If $tItem.dwItemSpec > 0 Then $tRect.top -= 1 $tRect.bottom += 1 _WinAPI_Rectangle($hDC, $tRect) _WinAPI_SetTextColor($hDC, $bIsSelected ? 0xFFFFFF : $clrHighlight) _WinAPI_SetBkMode($hDC, $TRANSPARENT) $tRect.Left += 5 $tRect.Top += 2 Local $s_Text3 = _GUICtrlListView_GetItemText($tItem.hWndFrom, $tItem.dwItemSpec, $tItem.iSubitem) _WinAPI_DrawText($hDC, $s_Text3, $tRect, BitOR($DT_LEFT, $DT_INTERNAL, $DT_WORDBREAK)) If $tItem.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG Local $dwDrawStage = $tItem.dwDrawStage If $dwDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $dwDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW If $tItem.iSubitem = $__Example_LVColumn_ItemIndex Then _WinAPI_SetTextColor($hDC, $CLR_RED) _WinAPI_DrawText($hDC, $iItemIndex, $tRect, $DT_CENTER) Return $CDRF_SKIPDEFAULT ElseIf $tItem.iSubitem = $__Example_LVColumn_ItemID Then _WinAPI_SetTextColor($hDC, $CLR_BLUE) _WinAPI_DrawText($hDC, $iItemID, $tRect, $DT_CENTER) Return $CDRF_SKIPDEFAULT ElseIf $tItem.iSubitem = $__Example_LVColumn_GroupIndex Then _WinAPI_SetTextColor($hDC, $CLR_RED) _WinAPI_DrawText($hDC, $iGroupIndex_0based, $tRect, $DT_CENTER) Return $CDRF_SKIPDEFAULT ElseIf $tItem.iSubitem = $__Example_LVColumn_GroupID Then _WinAPI_SetTextColor($hDC, $CLR_BLUE) _WinAPI_DrawText($hDC, $iGroupId, $tRect, $DT_CENTER) Return $CDRF_SKIPDEFAULT EndIf EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _GUICtrlListView_ReSetItemGroupID($idListview, $iGroupId) For $iItemIndex = 0 To _GUICtrlListView_GetItemCount($idListview) - 1 If _GUICtrlListView_GetItemGroupID($idListview, $iItemIndex) = $iGroupId Then _GUICtrlListView_SetItemGroupID($idListview, $iItemIndex, -2) _GUICtrlListView_SetItemGroupID($idListview, $iItemIndex, $iGroupId) EndIf Next EndFunc ;==>_GUICtrlListView_ReSetItemGroupID Func _GUICtrlListView_GetGroupIndexByGroupID($hWnd, $iGroupId) ;https://www.autoitscript.com/forum/topic/213679-listview-get-igroupid-and-igroup-for-listviewitem/#findComment-1552392 Local $iMaxIndex = _GUICtrlListView_GetGroupCount($hWnd) - 1 Local $aInfo For $i = 0 To $iMaxIndex $aInfo = _GUICtrlListView_GetGroupInfoByIndex($hWnd, $i) If $aInfo[2] = $iGroupId Then Return $i Next Return SetError(1, 0, -1) EndFunc ;==>_GUICtrlListView_GetGroupIndexByGroupID
  12. Got it. #include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Example() Func Example() Local $hImage, $idListview GUICreate("ListView Set Group Info", 400, 300) $idListview = GUICtrlCreateListView("", 2, 2, 394, 268) GUISetState(@SW_SHOW) ; Load images $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0x0000FF, 16, 16)) _GUICtrlListView_SetImageList($idListview, $hImage, 1) ; Add columns _GUICtrlListView_AddColumn($idListview, "Column 1", 100) _GUICtrlListView_AddColumn($idListview, "Column 2", 100) _GUICtrlListView_AddColumn($idListview, "Column 3", 100) ; Add items _GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 2) ; Build groups _GUICtrlListView_EnableGroupView($idListview) _GUICtrlListView_InsertGroup($idListview, -1, 1, "Group 1", 1) _GUICtrlListView_InsertGroup($idListview, -1, 2, "Group 2", 0) _GUICtrlListView_SetItemGroupID($idListview, 0, 1) _GUICtrlListView_SetItemGroupID($idListview, 1, 2) _GUICtrlListView_SetItemGroupID($idListview, 2, 2) MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, "Before focusing on the group 1", 2) Sleep(1000) _GUICtrlListView_SetGroupInfo($idListview, 1, "New Group 1", 1, $LVGS_FOCUSED) MsgBox($MB_SYSTEMMODAL, "Information", "Group has focus at Index: " & _GUICtrlListView_GetFocusedGroup($idListview)) MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, "Before focusing on the group 2", 2) Sleep(1000) _GUICtrlListView_SetGroupInfo($idListview, 2, "New Group 2", 1, $LVGS_FOCUSED) MsgBox($MB_SYSTEMMODAL, "Information", "Group has focus at Index: " & _GUICtrlListView_GetFocusedGroup($idListview)) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example
  13. Updated example: ;~ https://www.autoitscript.com/forum/topic/213681-listview-with-groups-inserting-new-rows-issue-with-_guictrllistview_insertitem/ #AutoIt3Wrapper_UseX64=n ; From Nine #include <WindowsConstants.au3> #include <ColorConstants.au3> #include <GUIConstants.au3> #include <GuiListView.au3> #include <WinAPI.au3> #include <WinAPIDiag.au3> #include <WinAPITheme.au3> Global Enum $__Example_LVColumn_Name, $__Example_LVColumn_ItemIndex, $__Example_LVColumn_ItemID, $__Example_LVColumn_GroupIndex, $__Example_LVColumn_GroupID Opt("MustDeclareVars", True) Global $__g_hListView, $__g_hHeader Example() Func Example() GUICreate("Example", 900, 700) Local $idListview = GUICtrlCreateListView("", 10, 10, 880, 650, -1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER, $LVS_EX_INFOTIP)) $__g_hListView = GUICtrlGetHandle($idListview) $__g_hHeader = GUICtrlSendMsg($idListview, $LVM_GETHEADER, 0, 0) _WinAPI_SetWindowTheme($__g_hHeader, "", "") ;Turn off theme for header Local $iStyle = _WinAPI_GetWindowLong($__g_hHeader, $GWL_STYLE) _WinAPI_SetWindowLong($__g_hHeader, $GWL_STYLE, BitOR($iStyle, $HDS_FLAT)) ; remove header 3D button effect Local $idButton = GUICtrlCreateButton("Enable/Disable GroupView", 10, 320, 200, 20) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, WM_NOTIFY) _GUICtrlListView_AddColumn($idListview, "Item (row name given by user)", 100) ; $__Example_LVColumn_Name _GUICtrlListView_AddColumn($idListview, "ItemIndex (current row index)", 100) ; $__Example_LVColumn_ItemIndex _GUICtrlListView_AddColumn($idListview, "ItemID (creation order index)", 100) ; $__Example_LVColumn_ItemID _GUICtrlListView_AddColumn($idListview, "GroupIndex (current group index)", 100) ; $__Example_LVColumn_GroupIndex _GUICtrlListView_AddColumn($idListview, "GroupID (ID mark given by user)", 100) ; $__Example_LVColumn_GroupID _GUICtrlListView_SetColumnWidth($idListview, $__Example_LVColumn_Name, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, $__Example_LVColumn_ItemIndex, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, $__Example_LVColumn_ItemID, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, $__Example_LVColumn_GroupIndex, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_SetColumnWidth($idListview, $__Example_LVColumn_GroupID, $LVSCW_AUTOSIZE_USEHEADER) _GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0) _GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 0) _GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 0) _GUICtrlListView_AddItem($idListview, "Row 4: Col 1", 0) _GUICtrlListView_InsertGroup($idListview, -1, 101, '"First Group"') _GUICtrlListView_InsertGroup($idListview, -1, 202, '"Second Group"') _GUICtrlListView_InsertGroup($idListview, -1, 303, '"Third Group"') _GUICtrlListView_SetItemGroupID($idListview, 0, 101) _GUICtrlListView_SetItemGroupID($idListview, 1, 202) _GUICtrlListView_SetItemGroupID($idListview, 2, 202) _GUICtrlListView_SetItemGroupID($idListview, 3, 303) MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'Before InsertItem') _GUICtrlListView_InsertItem($idListview, "NEW ITEM 1", 2) ; insert as 2 ID .... before "Row 3: Col 1" _GUICtrlListView_SetItemGroupID($idListview, 2, 202) MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'After InsertItem NEW ITEM 1 .. before EnableGroupView') _GUICtrlListView_InsertItem($idListview, "NEW ITEM 2", 3) ; insert as 2 ID .... before "Row 3: Col 1" _GUICtrlListView_SetItemGroupID($idListview, 3, 202) MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'After InsertItem NEW ITEM 2 .. before EnableGroupView' & @CRLF & @CRLF & 'Take a note that NEW ITEM 1 and 2 are before ROW 3: Col 1') _GUICtrlListView_EnableGroupView($idListview, True) MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'After EnableGroupView' & @CRLF & @CRLF & 'Take a note that NEW ITEM 1 and 2 are after ROW 3: Col 1' & @CRLF & 'but they were put before ROW 3: Col 1') MsgBox($MB_TOPMOST, 'TEST #' & @ScriptLineNumber, 'before RE-setting for each Item from "Second Group"') _GUICtrlListView_ReSetItemGroupID($idListview, 202) _GUICtrlListView_AddItem($idListview, "Row 5: Col 1", 0) _GUICtrlListView_SetItemGroupID($idListview, 6, 303) _GUICtrlListView_ReSetItemGroupID($idListview, 303) #NO_DOC_FUNCTION# => _GUICtrlListView_SetInfoTip() ; testing _GUICtrlListView_SetInfoTip($__g_hListView, 0, "set some Info TIP", 0) ; Redraw entire ListView control _WinAPI_RedrawWindow($__g_hListView, True, 0) _GUICtrlListView_InsertGroup($idListview, 1, 404, '"4th Group"') _GUICtrlListView_SetItemGroupID($idListview, 1, 101) _GUICtrlListView_SetItemGroupID($idListview, 0, 404) While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idButton _GUICtrlListView_EnableGroupView($idListview, Not _GUICtrlListView_GetGroupViewEnabled($idListview)) ConsoleWrite('"Enable/Disable GroupView" button clicked' & @CRLF) EndSwitch WEnd EndFunc ;==>Example Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tItem = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) If $tItem.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG Local Static $clrHighlight = _WinAPI_GetSysColor($COLOR_HIGHLIGHT) Local Static $clrBack = _WinAPI_SwitchColor($COLOR_LIGHTBLUE) Local Static $clrText = _WinAPI_SwitchColor($COLOR_BLUE) Local Static $hPenGroup_GuideLine = _WinAPI_CreatePen($PS_DASH, 1, $clrBack) Local Static $hPenItem_Borders = _WinAPI_CreatePen($PS_SOLID, 1, _WinAPI_SwitchColor($COLOR_GRAY)) Local Static $hPenHeader_Borders = _WinAPI_CreatePen($PS_SOLID, 1, _WinAPI_SwitchColor($COLOR_RED)) Local Static $hBrushGroup = _WinAPI_CreateSolidBrush($COLOR_BLACK) Local Static $hBrushItem_Selected = _WinAPI_CreateSolidBrush($clrHighlight) Local Static $hBrushItem_Unselected = _WinAPI_CreateSolidBrush(0xFFFFFF) Local Static $hBrushHeader = _WinAPI_CreateSolidBrush(0xFFCCDD) ;~ Local Static $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tItem, "left")) Local $tRect = DllStructCreate($tagRECT, DllStructGetPtr($tItem, "left")) Local $hDC = $tItem.hDC If $tItem.hWndFrom = $__g_hHeader Then If $tItem.dwDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If Not $tItem.dwItemSpec Then $tRect.left += 5 $tRect.bottom -= 1 _WinAPI_SelectObject($tItem.hDC, $hPenHeader_Borders) _WinAPI_SelectObject($tItem.hDC, $hBrushHeader) _WinAPI_Rectangle($tItem.hDC, $tRect) $tRect.Left += 5 $tRect.Top += 3 _WinAPI_SetTextColor($tItem.hDC, 0) _WinAPI_SetBkMode($tItem.hDC, $TRANSPARENT) _WinAPI_DrawText($tItem.hDC, _GUICtrlHeader_GetItemText($tItem.hWndFrom, $tItem.dwItemSpec), $tRect, $DT_LEFT) Return $CDRF_SKIPDEFAULT ElseIf $tItem.hWndFrom = $__g_hListView And $tItem.Code = $NM_CUSTOMDRAW And $tItem.dwItemSpec > -1 Then Local $iGroupId = 2 Local $iGroupIndex_0based = -1 If $tItem.dwItemType = $LVCDI_GROUP Then If $tItem.dwDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $tItem.dwDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW $iGroupId = $tItem.dwItemSpec $iGroupIndex_0based = _GUICtrlListView_GetGroupIndexByGroupID($tItem.hWndFrom, $iGroupId) $tRect.bottom = $tRect.top + 15 _WinAPI_FillRect($hDC, $tRect, $hBrushGroup) _WinAPI_SelectObject($hDC, $hPenGroup_GuideLine) _WinAPI_DrawLine($hDC, $tRect.left + 5, $tRect.top + 8, $tRect.right - 5, $tRect.top + 8) _WinAPI_SetBkColor($hDC, $clrBack) _WinAPI_SetBkMode($hDC, $OPAQUE) _WinAPI_SetTextColor($hDC, $clrText) $tRect.left += 20 #NO_DOC_FUNCTION# => _GUICtrlListView_GetGroupState() ; Testing Local $s_FOCUSED = _GUICtrlListView_GetGroupState($tItem.hWndFrom, $iGroupId, $LVGS_FOCUSED) Local $s_SUBSETED = _GUICtrlListView_GetGroupState($tItem.hWndFrom, $iGroupId, $LVGS_SUBSETED) Local $s_SUBSETLINKFOCUSED = _GUICtrlListView_GetGroupState($tItem.hWndFrom, $iGroupId, $LVGS_SUBSETLINKFOCUSED) Local $s_GroupText = _GUICtrlListView_GetGroupInfo($tItem.hWndFrom, $iGroupId)[0] Local $s_INFO = $s_GroupText & " [ IDX=" & $iGroupIndex_0based & " ID=" & $iGroupId & " :: FOCUSED=" & $s_FOCUSED & " :: SUBSETED=" & $s_SUBSETED & " :: SUBSETLINKFOCUSED=" & $s_SUBSETLINKFOCUSED & " ] " _WinAPI_DrawText($hDC, $s_INFO, $tRect, BitOR($DT_LEFT, $DT_WORDBREAK, $DT_WORD_ELLIPSIS)) Return $CDRF_SKIPDEFAULT Else If $tItem.dwDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $tItem.dwDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iItemIndex = $tItem.dwItemSpec Local $iItemID = _GUICtrlListView_MapIndexToID($tItem.hWndFrom, $iItemIndex) $iGroupId = _GUICtrlListView_GetItemGroupID($tItem.hWndFrom, $iItemIndex) $iGroupIndex_0based = _GUICtrlListView_GetGroupIndexByGroupID($tItem.hWndFrom, $iGroupId) Local $bIsSelected = _GUICtrlListView_GetItemState($tItem.hWndFrom, $tItem.dwItemSpec, $LVIS_SELECTED) If $bIsSelected Then _WinAPI_SelectObject($hDC, $hBrushItem_Selected) Else _WinAPI_SelectObject($hDC, $hBrushItem_Unselected) EndIf _WinAPI_SelectObject($hDC, $hPenItem_Borders) If $tItem.dwItemSpec > 0 Then $tRect.top -= 1 $tRect.bottom += 1 _WinAPI_Rectangle($hDC, $tRect) _WinAPI_SetTextColor($hDC, $bIsSelected ? 0xFFFFFF : $clrHighlight) _WinAPI_SetBkMode($hDC, $TRANSPARENT) $tRect.Left += 5 $tRect.Top += 2 Local $s_Text3 = _GUICtrlListView_GetItemText($tItem.hWndFrom, $tItem.dwItemSpec, $tItem.iSubitem) _WinAPI_DrawText($hDC, $s_Text3, $tRect, BitOR($DT_LEFT, $DT_INTERNAL, $DT_WORDBREAK)) If $tItem.Code <> $NM_CUSTOMDRAW Then Return $GUI_RUNDEFMSG Local $dwDrawStage = $tItem.dwDrawStage If $dwDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $dwDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW If $tItem.iSubitem = $__Example_LVColumn_ItemIndex Then _WinAPI_SetTextColor($hDC, $CLR_RED) _WinAPI_DrawText($hDC, $iItemIndex, $tRect, $DT_CENTER) Return $CDRF_SKIPDEFAULT ElseIf $tItem.iSubitem = $__Example_LVColumn_ItemID Then _WinAPI_SetTextColor($hDC, $CLR_BLUE) _WinAPI_DrawText($hDC, $iItemID, $tRect, $DT_CENTER) Return $CDRF_SKIPDEFAULT ElseIf $tItem.iSubitem = $__Example_LVColumn_GroupIndex Then _WinAPI_SetTextColor($hDC, $CLR_RED) _WinAPI_DrawText($hDC, $iGroupIndex_0based, $tRect, $DT_CENTER) Return $CDRF_SKIPDEFAULT ElseIf $tItem.iSubitem = $__Example_LVColumn_GroupID Then _WinAPI_SetTextColor($hDC, $CLR_BLUE) _WinAPI_DrawText($hDC, $iGroupId, $tRect, $DT_CENTER) Return $CDRF_SKIPDEFAULT EndIf EndIf EndIf Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _GUICtrlListView_ReSetItemGroupID($idListview, $iGroupId) For $iItemIndex = 0 To _GUICtrlListView_GetItemCount($idListview) - 1 If _GUICtrlListView_GetItemGroupID($idListview, $iItemIndex) = $iGroupId Then _GUICtrlListView_SetItemGroupID($idListview, $iItemIndex, -2) _GUICtrlListView_SetItemGroupID($idListview, $iItemIndex, $iGroupId) EndIf Next EndFunc ;==>_GUICtrlListView_ReSetItemGroupID Func _GUICtrlListView_GetGroupIndexByGroupID($hWnd, $iGroupId) ;https://www.autoitscript.com/forum/topic/213679-listview-get-igroupid-and-igroup-for-listviewitem/#findComment-1552392 Local $iMaxIndex = _GUICtrlListView_GetGroupCount($hWnd) - 1 Local $aInfo For $i = 0 To $iMaxIndex $aInfo = _GUICtrlListView_GetGroupInfoByIndex($hWnd, $i) If $aInfo[2] = $iGroupId Then Return $i Next Return SetError(1, 0, -1) EndFunc ;==>_GUICtrlListView_GetGroupIndexByGroupID
  14. #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <WinAPISys.au3> _Example() Func _Example() ; Create GUI window Local $hGUI = GUICreate("LVM_UPDATE Example", 500, 300) ; Create ListView control Local $idListView = GUICtrlCreateListView("Name|Value", 10, 10, 480, 240) ; Add items to ListView For $i = 0 To 9 GUICtrlCreateListViewItem("Item " & $i & "|Data " & $i, $idListView) Next GUISetState(@SW_SHOW) ; Get ListView handle Local $hListView = GUICtrlGetHandle($idListView) Sleep(1000) ; Change text in item index 3 _GUICtrlListView_SetItemText($hListView, 3, "UPDATED ITEM", 0) ; Redraw entire window _WinAPI_RedrawWindow($hGUI, True, 0) ; Redraw entire ListView control _WinAPI_RedrawWindow($hListView, True, 0) ; Redraw all ListView items _GUICtrlListView_RedrawItems($hListView, 0, _GUICtrlListView_GetItemCount($hListView)) ; Redraw only item index 3 _SendMessage($hListView, $LVM_UPDATE, 3, 0) ; GUI message loop While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd EndFunc ;==>_Example
×
×
  • Create New...