J'ai upgradé un peu ce code mais je ne comprend pas pourquoi la CheckBox disparait sous le brush de la ListView
Y a-t'il une solution
Es-ce un bogue
J'ai aussi éssayé "GuiCtrlSetOrderZ" viewtopic.php?f=4&t=15389
Code : Tout sélectionner
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <StructureConstants.au3>
; Source > https://www.autoitscript.com/forum/topic/170634-_guictrllistview_simplesort-and-nm_customdraw/?tab=comments#comment-1247689
$GUI = GUICreate("Listview Custom Draw", 400, 300)
$ListBox_1 = GUICtrlCreateListView("Colonne 1_____.|Colonne 2_____.|Colonne 3_____.", 2, 2, 394, 268, $WS_BORDER, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
; Add items
For $i = 1 To 30
    GUICtrlCreateListViewItem("Ligne " & $i & " : Col 1|Ligne " & $i & " : Col 2|Ligne " & $i & " : Col 3", $ListBox_1)
Next
GUICtrlCreateInput("Cliquer ici pour tester le focus", 50, 275, 200, 18)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
Exit
Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
   #forceref $hWnd, $Msg, $wParam
   Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
   $hWndListView = $ListBox_1	; $ListBox_1
   If Not IsHWnd($hWndListView) Then $hWndListView = GUICtrlGetHandle($hWndListView)
   $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
   $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
   $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
   $iCode = DllStructGetData($tNMHDR, "Code")
   Switch $hWndFrom
	  Case $hWndListView
		 If $iCode = $NM_CLICK Then				; Sent by a list-view control when the user clicks an item with the left mouse button
			ConsoleWrite("_Click("&$iCode&")"&@CRLF)		; _Click()
		 EndIf
		 If $iCode = $NM_DBLCLK Then			; Sent by a list-view control when the user double-clicks an item with the left mouse button
			ConsoleWrite("_DblClick"&$iCode&")"&@CRLF)		; _DblClick()
		 EndIf
		 If $iCode = $NM_RCLICK Then			; Sent by a list-view control when the user clicks an item with the right mouse button
			ConsoleWrite("_RClick"&$iCode&")"&@CRLF)		; _RClick()
		 EndIf
		 If $iCode = $NM_RDBLCLK Then			; Sent by a list-view control when the user double-clicks an item with the right mouse button
			ConsoleWrite("_DblRClick"&$iCode&")"&@CRLF)		; _DblRClick()
		 EndIf
		 Switch $iCode
			Case $NM_CUSTOMDRAW
			   If _GUICtrlListView_GetView($hWndFrom) <> 1 Then Return $GUI_RUNDEFMSG ; Not in details mode
				  Local $tCustDraw, $iDrawStage, $iItem, $iSubitem, $hDC, $tRect, $iColor1, $iColor2, $iColor3
				  $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
				  $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage')
				  Switch $iDrawStage
					 Case $CDDS_PREPAINT
						Return $CDRF_NOTIFYITEMDRAW
					 Case $CDDS_ITEMPREPAINT
						Return $CDRF_NOTIFYSUBITEMDRAW
					 Case $CDDS_ITEMPOSTPAINT
						; Not handled
					 Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
						$iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
						$iSubitem = DllStructGetData($tCustDraw, 'iSubItem')
						If _GUICtrlListView_GetItemSelected($hWndFrom, $iItem) Then ; Item to draw is selected
						   $hDC = _WinAPI_GetDC($hWndFrom)
						   $tRect = DllStructCreate($tagRECT)
						   ; We draw the background when we draw the first item.
						   If $iSubitem = 0 Then
							  ; We must send the message as we want to use the struct. _GUICtrlListView_GetSubItemRect returns an array.
							  _SendMessage($hWndFrom, $LVM_GETSUBITEMRECT, $iItem, DllStructGetPtr($tRect))
							  DllStructSetData($tRect, "Left", 2)
							  _WinAPI_FillRect($hDC, DllStructGetPtr($tRect), _WinAPI_GetStockObject($LTGRAY_BRUSH)) ; Change the bush here. You can use GDI+ to make your own.
						   EndIf
						   DllStructSetData($tRect, "Left", 2)
						   DllStructSetData($tRect, "Top", $iSubitem)
						   _SendMessage($hWndFrom, $LVM_GETSUBITEMRECT, $iItem, DllStructGetPtr($tRect))
						   Local $sText = _GUICtrlListView_GetItemText($hWndFrom, $iItem, $iSubitem)
						   _WinAPI_SetBkMode($hDC, $TRANSPARENT) ; It uses the background drawn for the first item.
						   ; Select the font we want to use
						   _WinAPI_SelectObject($hDC, _SendMessage($hWndFrom, $WM_GETFONT))
						   If $iSubitem = 0 Then
							  DllStructSetData($tRect, "Left", DllStructGetData($tRect, "Left") + 2)
						   Else
							  DllStructSetData($tRect, "Left", DllStructGetData($tRect, "Left") + 6)
						   EndIf
						   _WinAPI_DrawText($hDC, $sText, $tRect, BitOR($DT_VCENTER, $DT_END_ELLIPSIS, $DT_SINGLELINE))
						   _WinAPI_ReleaseDC($hWndFrom, $hDC)
						   Return $CDRF_SKIPDEFAULT ; Don't do default processing
						EndIf
						Return $CDRF_NEWFONT ; Let the system do the drawing for non-selected items
					 Case BitOR($CDDS_ITEMPOSTPAINT, $CDDS_SUBITEM)
						; Not handled
				  EndSwitch
			Case $LVN_COLUMNCLICK
			   $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
			   $iCol = DllStructGetData($tInfo, "SubItem")
			   $hHdr = _GUICtrlListView_GetHeader($hWndFrom)
			   ; Work out sort from arrows in header, and clear other arrows
			   $fSort = True
			   For $i = 0 To _GUICtrlHeader_GetItemCount($hHdr)
				  $iFmt = _GUICtrlHeader_GetItemFormat($hHdr, $i)
				  If $i = $iCol Then
					 If BitAND($iFmt, $HDF_SORTUP) Then
						$fSort = True
						$iFmt = BitOR(BitAND($iFmt, BitNOT($HDF_SORTUP)), $HDF_SORTDOWN)
					 ElseIf BitAND($iFmt, $HDF_SORTDOWN) Then
						$fSort = False
						$iFmt = BitOR(BitAND($iFmt, BitNOT($HDF_SORTDOWN)), $HDF_SORTUP)
					 Else
						; Default
						$iFmt = BitOR(BitAND($iFmt, BitNOT($HDF_SORTUP)), $HDF_SORTDOWN)
						$fSort = True
					 EndIf
					 _GUICtrlHeader_SetItemFormat($hHdr, $i, $iFmt)
				  Else
					 $iFmt = BitAND($iFmt, BitNOT(BitOR($HDF_SORTUP, $HDF_SORTDOWN)))
					 _GUICtrlHeader_SetItemFormat($hHdr, $i, $iFmt)
				  EndIf
			   Next
			   $tInfo = DllStructCreate("HWND;int;int")
			   DllStructSetData($tInfo, 1, $hWndFrom)
			   DllStructSetData($tInfo, 2, $fSort)
			   DllStructSetData($tInfo, 3, $iCol)
			   $cb = DllCallbackRegister(__Compare, "int", "LPARAM;LPARAM;LPARAM")
			   _SendMessage($hWndFrom, $LVM_SORTITEMSEX, DllStructGetPtr($tInfo), DllCallbackGetPtr($cb))
			   DllCallbackFree($cb)
			   Return True
		 EndSwitch
   EndSwitch
   Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
; int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
Func __Compare($nItem1, $nItem2, $lParamSort)
   Local $tInfo = DllStructCreate("HWND;int;int", $lParamSort)
   Local $hWndFrom = DllStructGetData($tInfo, 1)
   Local $fSort = DllStructGetData($tInfo, 2)
   Local $iCol = DllStructGetData($tInfo, 3)
   Local $s1 = _GUICtrlListView_GetItemText($hWndFrom, $nItem1, $iCol)
   Local $s2 = _GUICtrlListView_GetItemText($hWndFrom, $nItem2, $iCol)
   Return StringCompare($s1, $s2) * ($fSort ? -1 : 1)
EndFunc   ;==>__Compare





