Page 1 sur 1

[..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : mar. 05 mai 2020 17:31
par Anthony
Bonjour à tous,

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 :idea:
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

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : mar. 05 mai 2020 19:01
par mikell
La checkbox est un controle, pas du texte, alors elle n'est pas retracée par le _WinAPI_DrawText
Le plus simple est de carrément ne pas la prendre dans la coloration en l'excluant du rectangle à traiter

   ; 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))

         ; tu décales le bord gauche du rectangle ici
         DllStructSetData($tRect, "Left", 23)  ;<<<<<<<<<<<<<<<<<
           _WinAPI_FillRect($hDC, DllStructGetPtr($tRect), _WinAPI_GetStockObject($LTGRAY_BRUSH)) ; Change the bush here. You can use GDI+ to make your own.
        EndIf

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : mar. 05 mai 2020 23:06
par Anthony
Si c'était si facile, çà suffit pas sous Win X, j'ai pas XP moi :P
CheckBox.jpg

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", 23)
							  _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

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : mer. 06 mai 2020 21:29
par mikell
Comme c'est bête... Image
J'aurais bien d'autres idées mais comme je ne peux pas les tester (vu que chez moi la solution précédente fonctionne), impossible d'en parler de crainte d'écrire une sottise
Image

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : jeu. 07 mai 2020 18:15
par walkson
Bonjour,
Je viens de tester sous Win 7, même problème qu'Anthony, et sous Xp le checkbox de la ligne sélectionnée est inaccessible.
Je propose une solution peu orthodoxe mais qui marche que sous W7 et W10. Sous Xp, ChrW(0x2611) et ChrW(0x2610) ne sont pas reconnu et renvoie toujours une box vide. A noter que ma solution permet de cocher ou décocher la ligne sélectionnée :P
Sous W10, ce n'est pas très esthétique mais j'ai lancé le script compilé car Autoit n'est pas installé sur la VM, à voir en attendant la soluce de Michel...
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <StructureConstants.au3>

$GUI = GUICreate("Listview Custom Draw", 400, 300)

$cListView = GUICtrlCreateListView("Column 1|Column 2|Column 3", 2, 2, 394, 268, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
GUICtrlSetFont(-1,10)
$hListView = GUICtrlGetHandle($cListView)
_GUICtrlListView_SetColumnWidth($hListView, 0, 120)
; Add items
For $i = 1 To 30
    GUICtrlCreateListViewItem("Row" & $i & ": Col 1|Row" & $i & ": Col 2|Row" & $i & ": Col 3", $cListView)
Next

GUICtrlCreateInput("Click here to test 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)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hWndFrom
        Case $hListView
            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", 0)
                                    _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", 0)
                                DllStructSetData($tRect, "Top", $iSubitem)
                                _SendMessage($hWndFrom, $LVM_GETSUBITEMRECT, $iItem, DllStructGetPtr($tRect))

                                Local $sText =  _GUICtrlListView_GetItemText($hWndFrom, $iItem, $iSubitem)
                        If _GUICtrlListView_GetItemChecked ( $hWndFrom, $iItem ) = True Then
                           $ChrW = ChrW(0x2611)
                        Else
                           $ChrW = ChrW(0x2610)
                        EndIf

                        If $iSubitem = 0 Then $sText = $ChrW & " " & $sText
                                _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") + 3)
                                Else
                                    DllStructSetData($tRect, "Left", DllStructGetData($tRect, "Left") + 5)
                                EndIf
                               _WinAPI_SetTextColor($hDC, 0xFF0000)
                        _WinAPI_DrawText($hDC,$sText, $tRect, BitOR($DT_VCENTER, $DT_INTERNAL, $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
A noter aussi que le trie n'est pas terrible et mériterait d’être améliorer

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : jeu. 07 mai 2020 21:50
par mikell
C'est à dire que plutôt que d'essayer de bricoler un code existant (ce qui je l'avoue ne m'emballe pas des masses), je préférerais connaître le but recherché des fois qu'on puisse s'y prendre autrement
Par exemple comme Anthony a rajouté des checkbox au code initial, du coup je me dis que peut-être ce qui l'intéresse ébin ça serait de colorer les items cochés, ce qu'on peut faire beaucoup plus simplement - surtout que sélectionner un item sans cocher sa chb ça n'aurait pas grand sens AMHA

Code : Tout sélectionner

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

$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_CHECKBOXES))

; Add items
Local $items[30]
For $i = 1 To 30
    $items[$i-1] = GUICtrlCreateListViewItem( "Ligne " & $i & " : Col 1|Ligne " & $i & " : Col 2|Ligne " & $i & " : Col 3", $ListBox_1)
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE



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
         Switch $iCode
		 
	   Case $NM_CLICK
		$hit = _GUICtrlListView_SubItemHitTest($hWndListView)
		If $hit[0] <> -1 Then
			_GUICtrlListView_SetItemSelected($ListBox_1, $hit[0], false, false)
			$item = $items[$hit[0]]
			$ischecked = _GUICtrlListView_GetItemChecked($ListBox_1, $hit[0])
			GUICtrlSetBkColor($item, ($ischecked = false) ? 0xffddbb : 0xffffff)
			GUICtrlSetColor($item, ($ischecked = false) ? 0xaa0000 : 0x000000)
			If $hit[1] > 0 Then _GUICtrlListView_SetItemChecked($ListBox_1, $hit[0], not $ischecked)
		EndIf

		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

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : sam. 09 mai 2020 13:54
par Anthony
Bonjour à tous,

Merci d'être présent...
J'ai testé le code de walkson, c'est presque çà :wink:
j'étais tombé sur ce code.. c'est une histoire de 13 pixels et de texte "Check 1" > "" à ce que je pense comprendre :shock:

Code : Tout sélectionner

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <SendMessage.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

_GUICtrlTransCheckbox_Init()

;~ https://www.autoitscript.com/forum/topic/123936-transparent-checkbox/

$hGUI = GUICreate("Test transparent checkbox replacement", 400, 200)
$nPic = GUICtrlCreatePic(@AutoItExe & "\..\Examples\GUI\msoobe.jpg", 0, 0, 400, 200, 0)

$nCB1 = _GUICtrlTransCheckbox_Create($hGUI, $nPic, "Check 1", 100, 70)
$nCB2 = _GUICtrlTransCheckbox_Create($hGUI, $nPic, "", 100, 120)

GUISetState(@SW_SHOW, $hGUI)

While 1
   $nGUIMsg = GUIGetMsg()

   Switch $nGUIMsg
	  Case $GUI_EVENT_CLOSE
		 Exit
	  Case $nCB1, $nCB2
		 ConsoleWrite("CheckBox [" & GUICtrlRead($nGUIMsg, 1) & "] checked = " & (GUICtrlRead($nGUIMsg) = $GUI_CHECKED) & @LF)
   EndSwitch
WEnd

Func _GUICtrlTransCheckbox_Init()
   Global Enum $i_Start_Row = -1, $i_hGUI_Row, $i_hPic_Row, $i_hCB_Row, $i_Total_Rows
   Global $aTrnsChckBxs_DATA[1][$i_Total_Rows]
EndFunc
Func _GUICtrlTransCheckbox_Create($hGUI, $nBackPic, $sText, $iLeft, $iAbove, $iWidth = -1, $iHeight = -1, $iStyle = -1, $iExStyle = 0)

   Local $nCB = GUICtrlCreateCheckbox($sText, $iLeft, $iAbove, $iWidth, $iHeight, $iStyle, $iExStyle)
   Local $hCB = GUICtrlGetHandle($nCB)
   Local $hPic = GUICtrlGetHandle($nBackPic)

   If $aTrnsChckBxs_DATA[0][0] = 0 Then
	  GUIRegisterMsg($WM_NOTIFY, '_TrnsChckBx_WM_NOTIFY')
   EndIf

   $aTrnsChckBxs_DATA[0][0] += 1
   ReDim $aTrnsChckBxs_DATA[$aTrnsChckBxs_DATA[0][0] + 1][$i_Total_Rows]

   $aTrnsChckBxs_DATA[$aTrnsChckBxs_DATA[0][0]][$i_hGUI_Row] = $hGUI
   $aTrnsChckBxs_DATA[$aTrnsChckBxs_DATA[0][0]][$i_hPic_Row] = $hPic
   $aTrnsChckBxs_DATA[$aTrnsChckBxs_DATA[0][0]][$i_hCB_Row] = $hCB

   Return $nCB
EndFunc   ;==>_GUICtrlTransCheckbox_Create
Func _GUICtrlTransCheckbox_Delete($nChckBx)
   Local $hCB = GUICtrlGetHandle($nChckBx)
   Local $aTmp[$aTrnsChckBxs_DATA[0][0]][$i_Total_Rows]

   GUICtrlDelete($nChckBx)

   For $i = 1 To $aTrnsChckBxs_DATA[0][0]
	  If $aTrnsChckBxs_DATA[$i][$i_hCB_Row] <> $hCB Then
		 $aTmp[0][0] += 1

		 $aTmp[$aTmp[0][0]][$i_hGUI_Row] = $aTrnsChckBxs_DATA[$i][$i_hGUI_Row]
		 $aTmp[$aTmp[0][0]][$i_hPic_Row] = $aTrnsChckBxs_DATA[$i][$i_hPic_Row]
		 $aTmp[$aTmp[0][0]][$i_hCB_Row] = $aTrnsChckBxs_DATA[$i][$i_hCB_Row]
	  EndIf
   Next

   ReDim $aTmp[$aTmp[0][0] + 1][$i_Total_Rows]
   $aTrnsChckBxs_DATA = $aTmp

   Return $aTmp[0][0]
EndFunc   ;==>_GUICtrlTransCheckbox_Delete
Func _TrnsChckBx_WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
   Local $hWndFrom, $iIDFrom, $tNMHDR
   Local Const $tagNMCUSTOMDRAW = 'hwnd hWndFrom;uint_ptr IDFrom;int Code;dword DrawStage;hwnd hDC;' & $tagRECT & ';dword_ptr ItemSpec;uint ItemState;lparam ItemlParam'
   Local Const $STM_GETIMAGE = 0x0173

   Local $tNMCD = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
   Local $hWndFrom = DllStructGetData($tNMCD, 'hWndFrom')
   Local $iCode = DllStructGetData($tNMCD, 'Code')
   Local $DrawStage = DllStructGetData($tNMCD, 'DrawStage')
   Local $ItemSpec = DllStructGetData($tNMCD, 'ItemSpec')
   Local $hDC = DllStructGetData($tNMCD, 'hDC')
   Local $hPic, $aPos, $hMemDC, $hBitmap, $hPrev
   Local $iAbove, $iBeneath, $iBoxSize = 13
   For $i = 1 To $aTrnsChckBxs_DATA[0][0]
	  If $hWndFrom = $aTrnsChckBxs_DATA[$i][$i_hCB_Row] Then
		 Switch $iCode
			Case $NM_CUSTOMDRAW
			   Switch $DrawStage
				  Case $CDDS_PREPAINT
					 $hPic = $aTrnsChckBxs_DATA[$i][$i_hPic_Row]
					 $aPos = ControlGetPos($hWnd, '', $hWndFrom)

					 If @error Then
						ExitLoop
					 EndIf

					 If $aPos[3] < $iBoxSize Then $iBoxSize = $aPos[3]
						$iAbove = Floor(($aPos[3] - $iBoxSize) / 2)
						$iBeneath = $iAbove + $iBoxSize

						$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
						$hBitmap = _SendMessage($hPic, $STM_GETIMAGE, $IMAGE_BITMAP, 0)
						$hPrev = _WinAPI_SelectObject($hMemDC, $hBitmap)
						_WinAPI_BitBlt($hDC, 0, 0, $iBoxSize, $iAbove, $hMemDC, $aPos[0], $aPos[1], $SRCCOPY) ;field above checkbox
						_WinAPI_BitBlt($hDC, 0, $iBeneath, $iBoxSize, $iBeneath - $iAbove, $hMemDC, $aPos[0], $aPos[1] + $iBeneath, $SRCCOPY) ;field beneath checkbox
						_WinAPI_BitBlt($hDC, $iBoxSize, 0, $aPos[2] - $iBoxSize, $aPos[3], $hMemDC, $aPos[0] + $iBoxSize, $aPos[1], $SRCCOPY) ;checkbox text field
						_WinAPI_SelectObject($hMemDC, $hPrev)
						_WinAPI_DeleteDC($hMemDC)
						Return $CDRF_DODEFAULT
			   EndSwitch
		 EndSwitch

		 ExitLoop
	  EndIf
   Next

   Return $GUI_RUNDEFMSG
EndFunc   ;==>_TrnsChckBx_WM_NOTIFY
La solution de mikell, je n'y avais pas pensé :oops: mais il y à un petit bug (voir capture) :mrgreen:
TMP.jpg


Voici mon projet et ce que je cherche à faire, oui on peut voir la StatusBar :P
MMBV.jpg

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : sam. 09 mai 2020 14:10
par mikell
Anthony a écrit : sam. 09 mai 2020 13:54 il y à un petit bug (voir capture)
Là, limite je pense que tu y mets de la mauvaise volonté... Image
J'avais fait très vite, bon... mais le remède est vraiment simple

Code : Tout sélectionner

Case $NM_CLICK
	$hit = _GUICtrlListView_SubItemHitTest($hWndListView)
	If $hit[0] <> -1 Then
		_GUICtrlListView_SetItemSelected($ListBox_1, $hit[0], false, false)
		_GUICtrlListView_SetItemFocused($ListBox_1, $hit[0], false)  ;<<<<<<<<<<<<<<<<<<<<<<<
		$item = $items[$hit[0]]
		$ischecked = _GUICtrlListView_GetItemChecked($ListBox_1, $hit[0])
		GUICtrlSetBkColor($item, ($ischecked = false) ? 0xffddbb : 0xffffff)
		GUICtrlSetColor($item, ($ischecked = false) ? 0xaa0000 : 0x000000)
		If $hit[1] > 0 Then _GUICtrlListView_SetItemChecked($ListBox_1, $hit[0], not $ischecked)
	EndIf

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : dim. 10 mai 2020 03:21
par Anthony
Je souhaite sélectionner n'importe où sur la ligne et que çà coche, çà c'est bon mais si je coche c'est plus bon :roll: sans changement de couleur de fond :P (Sélection ou désélection de playlist).


En $NM_DBLCLK je souhaite garder la séléction (coché ou pas coché) et lancer l'apperçu avec changement de couleur de fond.
PS: En rouge, c'est une simulation d'erreur :wink:
Je suis à 12 heures d'AutoIt / jour, çà doit être la saturation :lol:

Code : Tout sélectionner

#include <Array.au3>	; _ArrayDisplay($aArray, "Infos")

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

#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>
#include <StructureConstants.au3>

Global $TrackNotSelected=0xDDDDAA, $TrackSelected=0x00F0FF ,$TrackBad = 0xFF3F3F

$GUI = GUICreate("Listview Custom Draw", 400, 300)
GUISetStyle(BitOR($WS_MINIMIZEBOX,  $WS_SIZEBOX, $WS_CAPTION, $WS_SYSMENU))

$nPic = GUICtrlCreatePic(@AutoItExe & "\..\Examples\GUI\msoobe.jpg", 0, 0, 400, 300, 0)
GUICtrlSetResizing( -1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT)

$ListBox_1 = GUICtrlCreateListView("Colonne 1_____.|Colonne 2_____.|Colonne 3_____.", 10, 10, 380, 280, $WS_BORDER, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))	; $LVS_EX_FULLROWSELECT
GUICtrlSetResizing( -1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT)
GUICtrlSetBkColor($ListBox_1, $TrackSelected)

; Add items
Local $items[30]

For $i = 1 To 30
   If Not StringInStr( $i, 2) Then
	  $items[$i-1] = GUICtrlCreateListViewItem( "Ligne " & $i & " : Col 1|Ligne " & $i & " : Col 2|Ligne " & $i & " : Col 3", $ListBox_1)
	  _GUICtrlListView_SetItemChecked($ListBox_1, $i-1, True)
	  GUICtrlSetBkColor(-1, $TrackSelected)
   Else
	  $items[$i-1] = GUICtrlCreateListViewItem( "Ligne " & $i & " : Col 1||", $ListBox_1)
	  GUICtrlSetBkColor(-1, $TrackBad)
   EndIf
Next

;~ _GUICtrlListView_HideColumn($ListBox_1, 1)
;~ _ArrayDisplay($items, "Infos")

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE



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
		 Switch $iCode

			Case $NM_DBLCLK
			   $hit = _GUICtrlListView_SubItemHitTest($hWndListView)	; $hit[0]=Line	; $hit[1]=Column
			   If $hit[0] <> -1 And _GUICtrlListView_GetItemText($hWndListView, $hit[0],1) <> '' Then
				  _GUICtrlListView_SetItemSelected($ListBox_1, $hit[0], false, false)
				  _GUICtrlListView_SetItemFocused($ListBox_1, $hit[0], false)  ;<<<<<<<<<<<<<<<<<<<<<<<
				  $item = $items[$hit[0]]
				  $ischecked = _GUICtrlListView_GetItemChecked($ListBox_1, $hit[0])
				  GUICtrlSetBkColor($item, ($ischecked = false) ? $TrackSelected : $TrackNotSelected)
				  GUICtrlSetColor($item, ($ischecked = false) ? 0xaa0000 : 0x000000)
			   EndIf

			Case $NM_CLICK
; ===============================================================================================================================
			   $hit = _GUICtrlListView_SubItemHitTest($hWndListView)	; $hit[0]=Line	; $hit[1]=Column
			   If $hit[0] <> -1 And _GUICtrlListView_GetItemText($hWndListView, $hit[0],1) <> '' Then
				  _GUICtrlListView_SetItemSelected($ListBox_1, $hit[0], false, false)
				  _GUICtrlListView_SetItemFocused($ListBox_1, $hit[0], false)  ;<<<<<<<<<<<<<<<<<<<<<<<
				  $ischecked = _GUICtrlListView_GetItemChecked($ListBox_1, $hit[0])
				  If $ischecked Then
					 _GUICtrlListView_SetItemChecked($ListBox_1, $hit[0], False)
				  Else
					 _GUICtrlListView_SetItemChecked($ListBox_1, $hit[0], True)
				  EndIf
			   Else
				  _GUICtrlListView_SetItemSelected($ListBox_1, $hit[0], false, false)
				  _GUICtrlListView_SetItemFocused($ListBox_1, $hit[0], false)  ;<<<<<<<<<<<<<<<<<<<<<<<
			   EndIf
;~ 			   ConsoleWrite('$hit[0]='&$hit[0]&', $hit[1]='&$hit[1]&', $ischecked='&$ischecked &@CRLF)
; ===============================================================================================================================
;~ 			   $hit = _GUICtrlListView_SubItemHitTest($hWndListView)	; $hit[0]=Line	; $hit[1]=Column
;~ 			   ConsoleWrite('$hit[0]Y='&$hit[0]&', $hit[1]X='&$hit[1]&', $hit[2]='&$hit[2]&', $hit[3]='&$hit[3] &@CRLF)
;~ 			   If $hit[0] <> -1 Then
;~ 				  _GUICtrlListView_SetItemSelected($ListBox_1, $hit[0], false, false)
;~ 				  _GUICtrlListView_SetItemFocused($ListBox_1, $hit[0], false)  ;<<<<<<<<<<<<<<<<<<<<<<<
;~ 				  $item = $items[$hit[0]]
;~ 				  $ischecked = _GUICtrlListView_GetItemChecked($ListBox_1, $hit[0])
;~ 				  If $hit[0] > 0 Then
;~ 					 _GUICtrlListView_SetItemChecked($ListBox_1, $hit[0], not $ischecked)
;~ 				  Else
;~ 					 _GUICtrlListView_SetItemChecked($ListBox_1, $hit[0], $ischecked)
;~ 				  EndIf
;~ 				  $ischecked = _GUICtrlListView_GetItemChecked($ListBox_1, $hit[0])
;~ 				  ConsoleWrite('$hit[0]='&$hit[0]&', $hit[1]='&$hit[1]&', $ischecked='&$ischecked &@CRLF)
;~ 				  ConsoleWrite('$hit[0]='&$hit[0]&', $hit[1]='&$hit[1]&', $item='&$item&', $ischecked='&$ischecked &@CRLF)
;~ 			   EndIf
; ===============================================================================================================================
;~ 				  If _GUICtrlListView_GetItemText($hWndListView, $hit[0],1) <> '' Then
;~ 					 _GUICtrlListView_SetItemSelected($ListBox_1, $hit[0], False, False)
;~ 					 _GUICtrlListView_SetItemFocused($ListBox_1, $hit[0], False)  ;<<<<<<<<<<<<<<<<<<<<<<<
;~ 					 $item = $items[$hit[0]]
;~ 					 $ischecked = _GUICtrlListView_GetItemChecked($ListBox_1, $hit[0])
;~ 					 If $ischecked = True Then
;~ 						_GUICtrlListView_SetItemChecked($ListBox_1, $hit[0], $ischecked)
;~ 					 Else
;~ 						_GUICtrlListView_SetItemChecked($ListBox_1, $hit[0], $ischecked)
;~ 					 EndIf
;~ 					 GUICtrlSetBkColor($item, ($ischecked = False) ? $TrackSelected : $TrackNotSelected)
;~ 					 GUICtrlSetColor($item, ($ischecked = False) ? 0xFF0000 : 0x000000)
;					 If $hit[1] > 0 Then _GUICtrlListView_SetItemChecked($ListBox_1, $hit[0], $ischecked)
;~ 					 ConsoleWrite('$hit[0]='&$hit[0]&', $hit[1]='&$hit[1]&', $item='&$item&', $ischecked='&$ischecked& ' > '&_GUICtrlListView_GetItemText($hWndListView, $hit[0],1) &@CRLF)
;~ 				  EndIf
; == Original ===================================================================================================================
;~ 			   $hit = _GUICtrlListView_SubItemHitTest($hWndListView)	; $hit[0]=Line	; $hit[1]=Column
;~ 			   ConsoleWrite('$hit[0]='&$hit[0]&', $hit[1]='&$hit[1]&', $hit[2]='&$hit[2]&', $hit[3]='&$hit[3] &@CRLF)
;~ 			   If $hit[0] <> -1 Then
;~ 				  _GUICtrlListView_SetItemSelected($ListBox_1, $hit[0], false, false)
;~ 				  _GUICtrlListView_SetItemFocused($ListBox_1, $hit[0], false)  ;<<<<<<<<<<<<<<<<<<<<<<<
;~ 				  $item = $items[$hit[0]]
;~ 				  $ischecked = _GUICtrlListView_GetItemChecked($ListBox_1, $hit[0])
;~ 				  GUICtrlSetBkColor($item, ($ischecked = false) ? $TrackSelected : $TrackNotSelected)
;~ 				  GUICtrlSetColor($item, ($ischecked = false) ? 0xaa0000 : 0x000000)
;~ 				  If $hit[1] > 0 Then _GUICtrlListView_SetItemChecked($ListBox_1, $hit[0], not $ischecked)
;~ 			   EndIf
;~ 			   ConsoleWrite('$hit[0]='&$hit[0]&', $hit[1]='&$hit[1]&', $item='&$item&', $ischecked='&$ischecked& ' > '&_GUICtrlListView_GetItemText($hWndListView, $hit[0],1) &@CRLF)
; ===============================================================================================================================
		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

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : dim. 10 mai 2020 19:15
par mikell
Sur mon PC il se passe un truc marrant, et apparemment je ne suis pas le seul à avoir la blague loin de là
Quand on fait un double clic, _WM_NOTIFY enregistre d'abord le 1er clic (comme un clic "normal"), et ensuite le double clic. C'est très facile à vérifier avec des consolewrite
Et ça devient particulièrement fun quand tu as des instructions complémentaires/contradictoires dans $NM_CLICK et $NM_DBLCLK :mrgreen:

On pourrait mettre dans le $NM_DBLCLK des instructions préalables pour annuler celles du $NM_CLICK , OK mais personnellement j'applique souvent une autre solution :
-) si je veux garder le double click, j'utilise $LVN_ITEMCHANGED (qui déclenche au check de la checkbox) à la place de $NM_CLICK
-) si je veux garder le $NM_CLICK, alors j'utilise le clic droit à la place du double clic

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : lun. 11 mai 2020 14:36
par TommyDDR
Je suis peut être un peu fatigué mais est ce que j'ai bien compris votre demande ?
Vous voulez cocher la ligne où l'on a cliqué (qu'importe le subitem) ?

Y a-t-il autre chose dans votre demande ?

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : lun. 11 mai 2020 16:39
par Anthony
@Mikell,
Les ConsoleWrite sont dans mon dernier code mais je m'emmêle de partout je regarde çà dès que j'ai un peu de temps.

@TommyDDR,
Oui, c'est exactement çà, la méthode de mikell serait parfaite, mais pas dans ce cas précis.

Et merci :wink:

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : mar. 12 mai 2020 13:33
par TommyDDR
Voilà comment je ferais :
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include "./include/_GUIXViewEx.au3"
; Source > https://www.autoitscript.com/forum/topic/170634-_guictrllistview_simplesort-and-nm_customdraw/?tab=comments#comment-1247689

Opt("GUIOnEventMode", 1)
Opt("MustDeclareVars", 1)

Global $gui
Global $listView
Global $input

$gui = GUICreate("Listview Custom Draw", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, quit, $gui)
$listView = GUICtrlCreateListView("Colonne 1_____.|Colonne 2_____.|Colonne 3_____.", 2, 2, 394, 268, $WS_BORDER, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
GUICtrlSetOnEvent($listView, columnClic)
_GUICtrlXView_SetExplorerTheme($listView)
_GUICtrlXView_SetOnEvent($listView, $NM_CLICK, itemClic)
; Add items
For $i = 1 To 30
    GUICtrlCreateListViewItem("Ligne " & $i & " : Col 1|Ligne " & $i & " : Col 2|Ligne " & $i & " : Col 3", $listView)
Next
$input = GUICtrlCreateInput("Cliquer ici pour tester le focus", 50, 275, 200, 18)
_GUICtrlListView_RegisterSortCallBack($listView)
GUISetState(@SW_SHOW, $gui)

While 1
   Sleep(10)
WEnd

Func columnClic()
   _GUICtrlListView_SortItems($listView, GUICtrlGetState($listView))
EndFunc

Func itemClic($hwnd, $event, $lparam)
   Local $item = _GUICtrlListView_HitTest(GUICtrlGetHandle($listView))
   Local $indice = $item[0]
   If($indice >= 0) Then
      Local $checked = _GUICtrlListView_GetItemChecked($listView, $indice)
      _GUICtrlListView_SetItemChecked($listView, $indice, Not($checked))
      _GUICtrlListView_RedrawItems($hwnd, $indice, $indice)
   EndIf
EndFunc

Func quit()
   Exit
EndFunc
Vous aurez besion de 3 UDF persos pour le faire fonctionner, je vous les mets en pièce jointe.
L'arborescence doit respecter ce shéma :

Code : Tout sélectionner

script.au3
include (dossier)
    _ArrayEx.au3
    _GUIRegisterMsg.au3
    _GUIXViewEx.au3

Re: [R] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : lun. 18 mai 2020 20:52
par Anthony
Merci à tous,

Une semaine+++ que je suis dessus et avec les enfants autour, une semaine sur deux :shock: ,bref j'AutoIt quand ils sont là, pas le choix :mrgreen:

J'ai peut-être eu du mal à me faire comprendre mais c'est vrais que mes demandes sont particulières :P mais pas sans raison.

Voici ce que je cherchais mikell :oops: et c'est chose faite :bisou: à tous les trois :wink:

Edit encore un beug voir post #16 :roll:
TMP.jpg

Code : Tout sélectionner

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         Anthony Baillou
 Modified:       mikell, walkson, TommyDDR

 Script Function:
	PlayList.au3

#ce ----------------------------------------------------------------------------

#include <FontConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Local $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

Global $ListBox_1

Global $TrackNotSelected=0xFFFFFF, $TrackSelected=0x00F0FF ,$TrackBad = 0xFF3F3F
Global $hImage_No, $hImage_Yes, $hImage_Bad, $hImage_Video, $hImage_Audio

Global $GUI = GUICreate("ListView Set Item State", 500, 400, -1, -1, $WS_MINIMIZEBOX+$WS_MAXIMIZEBOX+$WS_SIZEBOX, $WS_EX_ACCEPTFILES)
GUISetStyle(BitOR($WS_MINIMIZEBOX,  $WS_SIZEBOX, $WS_CAPTION, $WS_SYSMENU))

$nPic = GUICtrlCreatePic(@AutoItExe & "\..\Examples\GUI\msoobe.jpg", 0, 0, 500, 400, 0)
GUICtrlSetResizing( -1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT)

$ListBox_1 = GUICtrlCreateListView("Colonne 1_______________.|Colonne 2_______________.|Colonne 3_______________.", 10, 10, 480, 355)
_GUICtrlListView_SetExtendedListViewStyle($ListBox_1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUICtrlSetBkColor( -1, $TrackSelected)
GUICtrlSetResizing( -1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT)

    ; Load images
$hImage1			= _GUIImageList_Create(16, 16, 5, 3)
$hImage2			= _GUIImageList_Create(16, 16, 5, 3)

_GUIImageList_AddIcon($hImage1,	"shell32.dll", 131)			; $hImage	1 = No
_GUIImageList_AddIcon($hImage1,	"shell32.dll", 144)			; $hImage	2 = Yes
_GUIImageList_AddIcon($hImage1,	"shell32.dll", 109)			; $hImage	3 = Bad

_GUIImageList_AddIcon($hImage2,	"shell32.dll", 244)			; $hImage	1 =	!
_GUIImageList_AddIcon($hImage2,	"shell32.dll", 203)			; $hImage	2 = Video+Audio
_GUIImageList_AddIcon($hImage2,	"shell32.dll", 115)			; $hImage	3 = Video
_GUIImageList_AddIcon($hImage2,	"shell32.dll", 116)			; $hImage	4 = Audio
_GUIImageList_AddIcon($hImage2,	"shell32.dll", 117)			; $hImage	5 = Photo

_GUICtrlListView_SetImageList($ListBox_1, $hImage1	, 2)	; $hImage1
_GUICtrlListView_SetImageList($ListBox_1, $hImage2	, 1)	; $hImage2

; Add items
Local $items[30]
For $i = 1 To 30
   If Not StringInStr( $i, 3) Then	; Good Tracks
	  $items[$i-1] = GUICtrlCreateListViewItem( "Ligne " & $i & " : Col 1|Ligne " & $i & " : Col 2|Ligne " & $i & " : Col 3", $ListBox_1)
	  _GUICtrlListView_SetItemChecked($ListBox_1, $i-1, True)	; OK
	  GUICtrlSetBkColor(-1, $TrackSelected)						; OK
	  _GUICtrlListView_SetItemStateImage($ListBox_1, $i-1, 2)	; $hImage1		Yes
	  _GUICtrlListView_SetItemImage($ListBox_1, $i-1, 1)		; $hImage2		Video+Audio
   Else								; Bad Tracks
	  $items[$i-1] = GUICtrlCreateListViewItem( "Ligne " & $i & " : Col 1||", $ListBox_1)
	  _GUICtrlListView_SetItemChecked($ListBox_1, $i-1, False)	; OK
	  GUICtrlSetBkColor(-1, $TrackBad)							; OK
	  _GUICtrlListView_SetItemStateImage($ListBox_1, $i-1, 3)	; $hImage1		Bad
	  _GUICtrlListView_SetItemImage($ListBox_1, $i-1, 0)		; $hImage2		!
   EndIf
Next


GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")


; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
   GUIDelete()


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
   #forceref $hWnd, $iMsg, $iwParam
   Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
   $hWndListView = $ListBox_1
   If Not IsHWnd($ListBox_1) Then $hWndListView = GUICtrlGetHandle($ListBox_1)

   $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
   $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
   $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
   $iCode = DllStructGetData($tNMHDR, "Code")
   Switch $hWndFrom
	  Case $hWndListView
		 Switch $iCode
			Case $LVN_KEYDOWN ; A key has been pressed

			Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
			   ConsoleWrite("_Click("&$iCode&")"&@CRLF)			; _Click()
			   Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
			   Local $iIndex = DllStructGetData($tInfo, "Index")

			   If $iIndex <> -1 Then
				  Local $iX = DllStructGetData($tInfo, "X")
				  Local $iPart = 1
				  If _GUICtrlListView_GetView($ListBox_1) = 1 Then $iPart = 2 ;for large icons view

					 If _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 3 Then
						_GUICtrlListView_SetItemSelected($hWndListView, $iIndex, False, False)
						_GUICtrlListView_SetItemFocused($hWndListView, $iIndex, False)  ;<<<<<<<<<<<<<<<<<<<<<<<
					 EndIf

					 Local $aIconRect = _GUICtrlListView_GetItemRect($ListBox_1, $iIndex, $iPart)

					 If $iX < $aIconRect[0] And $iX >= 5 Then

						If Not _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 0 Then		; $hImage	1=No	2=Yes	3=Bad

						   If _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 2 Then
							  _GUICtrlListView_SetItemStateImage($hWndListView, $iIndex, 1)				; 1=No
							  GUICtrlSetBkColor($iIndex +5, $TrackNotSelected)							; +5 from $iIndex
							  GUICtrlSetColor($iIndex +5, 0XAAEEEE)										; +5 from $iIndex
						   ElseIf _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 1 Then
							  _GUICtrlListView_SetItemStateImage($hWndListView, $iIndex, 2)				; 2=Yes
							  GUICtrlSetBkColor($iIndex +5, $TrackSelected)								; +5 from $iIndex
							  GUICtrlSetColor($iIndex +5, 0x000000)										; +5 from $iIndex
						   EndIf
						   Return 0

						EndIf

					 EndIf

				  EndIf

				  ; No return value

			Case $NM_DBLCLK		; Sent by a list-view control when the user double-clicks an item with the left mouse button
			   ConsoleWrite("_DblClick"&$iCode&")"&@CRLF)		; _DblClick()

			Case $NM_RCLICK		; Sent by a list-view control when the user clicks an item with the right mouse button
			   ConsoleWrite("_RClick"&$iCode&")"&@CRLF)			; _RClick()

			Case $NM_RDBLCLK	; Sent by a list-view control when the user double-clicks an item with the right mouse button
			   ConsoleWrite("_DblRClick"&$iCode&")"&@CRLF)		; _DblRClick()

		 EndSwitch
   EndSwitch
   Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Re: [R] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : lun. 18 mai 2020 21:20
par mikell
Anthony a écrit : lun. 18 mai 2020 20:52J'ai peut-être eu du mal à me faire comprendre
Oh, oui :mrgreen: ... mais ça n'a rien à voir avec des "demandes particulières"
C'est surtout le manque d'une description précise du résultat recherché, qui complique vachement la tâche pour proposer des solutions et qui augmente terriblement le risque de répondre à côté de la plaque
Mais bon si tu es arrivé à un résultat qui te satisfait c'est l'essentiel :wink:

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : mar. 19 mai 2020 02:46
par Anthony
Bon en fait :cry: il y à un beug... Je rouvre le sujet :|
Intégré dans mon projet (Capture d'écran post # 7 viewtopic.php?f=4&t=15394&p=105239#p105201) çà change la couleur des bouton et le fond ne change pas de couleur quand je check ou uncheck :shock:
J'ai un début de réponse en désactivant l'image de fond... çà décale à une ligne en dessous :shock: un problème de bitmap :?:
Voici ce que çà donne à l'écran
TMP.jpg
Et sur mon projet
TMP2.jpg
Voici le code actuel

Code : Tout sélectionner

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         Anthony Baillou
 Modified:       mikell, walkson, TommyDDR

 Script Function:
	PlayList.au3

#ce ----------------------------------------------------------------------------

#include <FontConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Local $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work

Global $ListBox_1

Global $TrackNotSelected=0xFFFFFF, $TrackSelected=0x00F0FF ,$TrackBad = 0xFF3F3F
Global $hImage_No, $hImage_Yes, $hImage_Bad, $hImage_Video, $hImage_Audio

Global $GUI = GUICreate("ListView Set Item State", 500, 400, -1, -1, $WS_MINIMIZEBOX+$WS_MAXIMIZEBOX+$WS_SIZEBOX, $WS_EX_ACCEPTFILES)
GUISetStyle(BitOR($WS_MINIMIZEBOX,  $WS_SIZEBOX, $WS_CAPTION, $WS_SYSMENU))

;~ $nPic = GUICtrlCreatePic(@AutoItExe & "\..\Examples\GUI\msoobe.jpg", 0, 0, 500, 400, 0)
;~ GUICtrlSetResizing( -1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT)

$ListBox_1 = GUICtrlCreateListView("Colonne 1_______________.|Colonne 2_______________.|Colonne 3_______________.", 10, 10, 480, 355)
_GUICtrlListView_SetExtendedListViewStyle($ListBox_1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUICtrlSetBkColor( -1, $TrackSelected)
GUICtrlSetResizing( -1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT)

    ; Load images
$hImage1			= _GUIImageList_Create(16, 16, 5, 3)
$hImage2			= _GUIImageList_Create(16, 16, 5, 3)

_GUIImageList_AddIcon($hImage1,	"shell32.dll", 131)			; $hImage	1 = No
_GUIImageList_AddIcon($hImage1,	"shell32.dll", 144)			; $hImage	2 = Yes
_GUIImageList_AddIcon($hImage1,	"shell32.dll", 109)			; $hImage	3 = Bad

_GUIImageList_AddIcon($hImage2,	"shell32.dll", 244)			; $hImage	1 =	!
_GUIImageList_AddIcon($hImage2,	"shell32.dll", 203)			; $hImage	2 = Video+Audio
_GUIImageList_AddIcon($hImage2,	"shell32.dll", 115)			; $hImage	3 = Video
_GUIImageList_AddIcon($hImage2,	"shell32.dll", 116)			; $hImage	4 = Audio
_GUIImageList_AddIcon($hImage2,	"shell32.dll", 117)			; $hImage	5 = Photo

_GUICtrlListView_SetImageList($ListBox_1, $hImage1	, 2)			; $hImage1
_GUICtrlListView_SetImageList($ListBox_1, $hImage2	, 1)			; $hImage2

; Add items
Local $items[30]
For $i = 1 To 30
   If Not StringInStr( $i, 3) Then	; Good Tracks
	  $items[$i-1] = GUICtrlCreateListViewItem( "Ligne " & $i & " : Col 1|Ligne " & $i & " : Col 2|Ligne " & $i & " : Col 3", $ListBox_1)
	  _GUICtrlListView_SetItemChecked($ListBox_1, $i-1, True)	; OK
	  GUICtrlSetBkColor(-1, $TrackSelected)						; OK
	  _GUICtrlListView_SetItemStateImage($ListBox_1, $i-1, 2)	; $hImage1		Yes
	  _GUICtrlListView_SetItemImage($ListBox_1, $i-1, 1)		; $hImage2		Video+Audio
   Else								; Bad Tracks
	  $items[$i-1] = GUICtrlCreateListViewItem( "Ligne " & $i & " : Col 1||", $ListBox_1)
	  _GUICtrlListView_SetItemChecked($ListBox_1, $i-1, False)	; OK
	  GUICtrlSetBkColor(-1, $TrackBad)							; OK
	  _GUICtrlListView_SetItemStateImage($ListBox_1, $i-1, 3)	; $hImage1		Bad
	  _GUICtrlListView_SetItemImage($ListBox_1, $i-1, 0)		; $hImage2		!
   EndIf
Next


GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")


; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
   GUIDelete()


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
   #forceref $hWnd, $iMsg, $iwParam
   Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
   $hWndListView = $ListBox_1
   If Not IsHWnd($ListBox_1) Then $hWndListView = GUICtrlGetHandle($ListBox_1)

   $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
   $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
   $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
   $iCode = DllStructGetData($tNMHDR, "Code")
   Switch $hWndFrom
	  Case $hWndListView
		 Switch $iCode
			Case $LVN_KEYDOWN ; A key has been pressed

			Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
			   ConsoleWrite("_Click("&$iCode&")"&@CRLF)			; _Click()
			   Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
			   Local $iIndex = DllStructGetData($tInfo, "Index")

			   If $iIndex <> -1 Then
				  Local $iX = DllStructGetData($tInfo, "X")
				  Local $iPart = 1
				  If _GUICtrlListView_GetView($ListBox_1) = 1 Then $iPart = 2 ;for large icons view

					 If _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 3 Then
						_GUICtrlListView_SetItemSelected($hWndListView, $iIndex, False, False)
						_GUICtrlListView_SetItemFocused($hWndListView, $iIndex, False)  ;<<<<<<<<<<<<<<<<<<<<<<<
					 EndIf

					 Local $aIconRect = _GUICtrlListView_GetItemRect($ListBox_1, $iIndex, $iPart)

					 If $iX < $aIconRect[0] And $iX >= 5 Then

						If Not _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 0 Then		; $hImage	1=No	2=Yes	3=Bad

						   If _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 2 Then
							  _GUICtrlListView_SetItemStateImage($hWndListView, $iIndex, 1)				; 1=No
							  GUICtrlSetBkColor($iIndex +5, $TrackNotSelected)							; +5 from $iIndex
							  GUICtrlSetColor($iIndex +5, 0XAAEEEE)										; +5 from $iIndex
						   ElseIf _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 1 Then
							  _GUICtrlListView_SetItemStateImage($hWndListView, $iIndex, 2)				; 2=Yes
							  GUICtrlSetBkColor($iIndex +5, $TrackSelected)								; +5 from $iIndex
							  GUICtrlSetColor($iIndex +5, 0x000000)										; +5 from $iIndex
						   EndIf
						   Return 0

						EndIf

					 EndIf

				  EndIf

				  ; No return value

			Case $NM_DBLCLK		; Sent by a list-view control when the user double-clicks an item with the left mouse button
			   ConsoleWrite("_DblClick"&$iCode&")"&@CRLF)		; _DblClick()

			Case $NM_RCLICK		; Sent by a list-view control when the user clicks an item with the right mouse button
			   ConsoleWrite("_RClick"&$iCode&")"&@CRLF)			; _RClick()

			Case $NM_RDBLCLK	; Sent by a list-view control when the user double-clicks an item with the right mouse button
			   ConsoleWrite("_DblRClick"&$iCode&")"&@CRLF)		; _DblRClick()

		 EndSwitch
   EndSwitch
   Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Je suppose que le soucis vient d'ici mais j'ai beau changer de variables, çà change rien, je dois faire fausse route...

Code : Tout sélectionner

			   If $iIndex <> -1 Then
				  Local $iX = DllStructGetData($tInfo, "X")
				  Local $iPart = 1
				  If _GUICtrlListView_GetView($ListBox_1) = 1 Then $iPart = 2 ;for large icons view

					 If _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 3 Then
						_GUICtrlListView_SetItemSelected($hWndListView, $iIndex, False, False)
						_GUICtrlListView_SetItemFocused($hWndListView, $iIndex, False)  ;<<<<<<<<<<<<<<<<<<<<<<<
					 EndIf

					 Local $aIconRect = _GUICtrlListView_GetItemRect($ListBox_1, $iIndex, $iPart)

					 If $iX < $aIconRect[0] And $iX >= 5 Then

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : mar. 19 mai 2020 09:10
par mikell
Tu t'es mélangé les pinceaux entre les index et les ids
Remplace GUICtrlSetColor($iIndex +5, 0XAAEEEE) par GUICtrlSetColor($items[$iIndex], 0XAAEEEE)
et idem pour les autres GuiCtrlSet*

Re: [..] CheckBox qui disparait sous le brush de la ListView (Focus)

Posté : mer. 20 mai 2020 02:34
par Anthony
Oh oui :?
J'ai utilisé _GUICtrlListView_GetItemParam à la place, plus pratique, j'apprend, heureusement que la communauté est là, vous et Googole :lol:

Code : Tout sélectionner

						   If _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 2 Then								; 2=Yes
							  _GUICtrlListView_SetItemStateImage($hWndListView, $iIndex, 1)										; 1=No
							  GUICtrlSetBkColor( _GUICtrlListView_GetItemParam($hWndListView, $iIndex), $NotSelected_BkColor)	; SetBkColor
							  GUICtrlSetColor( _GUICtrlListView_GetItemParam($hWndListView, $iIndex), $NotSelected_SetColor)	; SetColorText
						   ElseIf _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 1 Then							; 1=No
							  _GUICtrlListView_SetItemStateImage($hWndListView, $iIndex, 2)										; 2=Yes
							  GUICtrlSetBkColor( _GUICtrlListView_GetItemParam($hWndListView, $iIndex), $Selected_BkColor)		; SetBkColor
							  GUICtrlSetColor( _GUICtrlListView_GetItemParam($hWndListView, $iIndex), $Selected_SetColor)		; SetColorText
						   EndIf
J'ai aussi pensé à terminer ce script et passer en résolu après cette fonction à ajouter dans WM_NOTIFY quand un CheckBox est déselectionné (comme dans la boucle For, Next)
Une piste, je ne trouve rien avec ce genre de recherche
https://www.google.com/search?biw=1705& ... CAw&uact=5

Code : Tout sélectionner

For $i = 0 To 30
   If _GUICtrlListView_GetItemStateImage($ListBox_1, $i) <> 3 Then	; $hImage1	1=No	2=Yes	> 3=Bad <
   Sleep(150)
   _GUICtrlListView_SetItemChecked( $ListBox_1, $i, False)
GUICtrlSetBkColor( _GUICtrlListView_GetItemParam($ListBox_1, $i), $NotSelected_BkColor)	; <<<<< Fonction à ajouter dans WM_NOTIFY quand un CheckBox est déselectionné
GUICtrlSetColor( _GUICtrlListView_GetItemParam($ListBox_1, $i), $NotSelected_SetColor)	; <<<<< Fonction à ajouter dans WM_NOTIFY quand un CheckBox est déselectionné

   Sleep(150)
   _GUICtrlListView_SetItemChecked( $ListBox_1, $i, True)
GUICtrlSetBkColor( _GUICtrlListView_GetItemParam($ListBox_1, $i), $Selected_BkColor)	; <<<<< Fonction à ajouter dans WM_NOTIFY quand un CheckBox est selectionné
GUICtrlSetColor( _GUICtrlListView_GetItemParam($ListBox_1, $i), $Selected_SetColor)		; <<<<< Fonction à ajouter dans WM_NOTIFY quand un CheckBox est selectionné

   EndIf
Next
Voici mon code actuel.....

Code : Tout sélectionner

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.14.5
 Author:         Anthony Baillou
 Modified:       mikell, walkson, TommyDDR

 Script Function:
	PlayList.au3

#ce ----------------------------------------------------------------------------

#include <FontConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <WindowsConstants.au3>

Global $NotSelected_SetColor	= 0XAAEEEE, $NotSelected_BkColor	= 0xFFFFFF
Global $Selected_SetColor		= 0x000000, $Selected_BkColor		= 0x00F0FF
Global $Bad_SetColor			= 0xDDDDDD, $Bad_BkColor			= 0xFF3F3F

; Create GUI
Global $GUI = GUICreate("ListView Set Item State", 480, 620, -1, -1, $WS_MINIMIZEBOX+$WS_MAXIMIZEBOX+$WS_SIZEBOX+$WS_CAPTION+$WS_SYSMENU, $WS_EX_ACCEPTFILES)	;

; Create Picture
$nPic = GUICtrlCreatePic(@AutoItExe & "\..\Examples\GUI\msoobe.jpg", 0, 0, 480, 620, 0)
GUICtrlSetResizing( -1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT)

; Create ListView
Global $ListBox_1 = GUICtrlCreateListView("Colonne 1_______________.|Colonne 2_______________.|Colonne 3_______________.", 10, 10, 460, 600)
_GUICtrlListView_SetExtendedListViewStyle( -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUICtrlSetBkColor( -1, $Selected_BkColor)
GUICtrlSetResizing( -1, $GUI_DOCKLEFT + $GUI_DOCKTOP + $GUI_DOCKBOTTOM + $GUI_DOCKRIGHT)

; Load images
$hImage1			= _GUIImageList_Create(16, 16, 5, 3)	; $hImage1 Create Image List 1
$hImage2			= _GUIImageList_Create(16, 16, 5, 3)	; $hImage2 Create Image List 2

_GUIImageList_AddIcon($hImage1,	"shell32.dll", 131)			; $hImage1	1 = No
_GUIImageList_AddIcon($hImage1,	"shell32.dll", 144)			; $hImage1	2 = Yes
_GUIImageList_AddIcon($hImage1,	"shell32.dll", 109)			; $hImage1	3 = Bad

_GUIImageList_AddIcon($hImage2,	"shell32.dll", 244)			; $hImage2	1 =	!
_GUIImageList_AddIcon($hImage2,	"shell32.dll", 203)			; $hImage2	2 = Video+Audio
_GUIImageList_AddIcon($hImage2,	"shell32.dll", 115)			; $hImage2	3 = Video
_GUIImageList_AddIcon($hImage2,	"shell32.dll", 116)			; $hImage2	4 = Audio
_GUIImageList_AddIcon($hImage2,	"shell32.dll", 117)			; $hImage2	5 = Photo

_GUICtrlListView_SetImageList($ListBox_1, $hImage1	, 2)	; $hImage1
_GUICtrlListView_SetImageList($ListBox_1, $hImage2	, 1)	; $hImage2

; Add items
Local $items[30]
For $i = 1 To 30
   If Not StringInStr( $i, 3) Then	; Good Tracks
	  $items[$i-1] = GUICtrlCreateListViewItem( "Ligne " & $i & " : Col 1|Ligne " & $i & " : Col 2|Ligne " & $i & " : Col 3", $ListBox_1)
	  _GUICtrlListView_SetItemChecked($ListBox_1, $i-1, True)	; OK
	  GUICtrlSetBkColor(-1, $Selected_BkColor)					; OK
	  _GUICtrlListView_SetItemStateImage($ListBox_1, $i-1, 2)	; $hImage1		Yes
	  _GUICtrlListView_SetItemImage($ListBox_1, $i-1, 1)		; $hImage2		Video+Audio
   Else								; Bad Tracks
	  $items[$i-1] = GUICtrlCreateListViewItem( "Ligne " & $i & " : Col 1||", $ListBox_1)
	  _GUICtrlListView_SetItemChecked($ListBox_1, $i-1, False)	; OK
	  GUICtrlSetBkColor(-1, $Bad_BkColor)						; OK
	  _GUICtrlListView_SetItemStateImage($ListBox_1, $i-1, 3)	; $hImage1		Bad
	  _GUICtrlListView_SetItemImage($ListBox_1, $i-1, 0)		; $hImage2		!
   EndIf
Next

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")


For $i = 0 To 30
   If _GUICtrlListView_GetItemStateImage($ListBox_1, $i) <> 3 Then	; $hImage1	1=No	2=Yes	> 3=Bad <
   Sleep(150)
   _GUICtrlListView_SetItemChecked( $ListBox_1, $i, False)
GUICtrlSetBkColor( _GUICtrlListView_GetItemParam($ListBox_1, $i), $NotSelected_BkColor)	; <<<<< Fonction à ajouter dans WM_NOTIFY quand un CheckBox est déselectionné
GUICtrlSetColor( _GUICtrlListView_GetItemParam($ListBox_1, $i), $NotSelected_SetColor)	; <<<<< Fonction à ajouter dans WM_NOTIFY quand un CheckBox est déselectionné

   Sleep(150)
   _GUICtrlListView_SetItemChecked( $ListBox_1, $i, True)
GUICtrlSetBkColor( _GUICtrlListView_GetItemParam($ListBox_1, $i), $Selected_BkColor)	; <<<<< Fonction à ajouter dans WM_NOTIFY quand un CheckBox est selectionné
GUICtrlSetColor( _GUICtrlListView_GetItemParam($ListBox_1, $i), $Selected_SetColor)		; <<<<< Fonction à ajouter dans WM_NOTIFY quand un CheckBox est selectionné

   EndIf
Next


; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
   GUIDelete()


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
   #forceref $hWnd, $iMsg, $iwParam
   Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $idListView, $tInfo
   $idListView = $ListBox_1
   If Not IsHWnd($idListView) Then $hWndListView = GUICtrlGetHandle($idListView)

   $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
   $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
   $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
   $iCode = DllStructGetData($tNMHDR, "Code")
   Switch $hWndFrom

	  Case $hWndListView

		 Switch $iCode

			Case $LVN_KEYDOWN ; A key has been pressed

			Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
			   ConsoleWrite("_Click("&$iCode&")"&@CRLF)			; _Click()

			   Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
			   Local $iIndex = DllStructGetData($tInfo, "Index")

			   If $iIndex <> -1 Then
				  Local $iX = DllStructGetData($tInfo, "X")
				  Local $iPart = 1
				  If _GUICtrlListView_GetView($ListBox_1) = 1 Then $iPart = 2 ;for large icons view

				  If _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 3 Then									; $hImage1	1=No	2=Yes	> 3=Bad <
					 _GUICtrlListView_SetItemSelected($hWndListView, $iIndex, False, False)									; Deselect track(s)
					 _GUICtrlListView_SetItemFocused($hWndListView, $iIndex, False)											; Remove focus for bad track(s)
				  EndIf

				  Local $aIconRect = _GUICtrlListView_GetItemRect($ListBox_1, $iIndex, $iPart)								; CheckBox Area

				  If $iX < $aIconRect[0] And $iX >= 5 Then

					 If Not _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 0 Then								; $hImage	1=No	2=Yes	3=Bad

						If _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 2 Then								; 2=Yes
						   _GUICtrlListView_SetItemStateImage($hWndListView, $iIndex, 1)									; 1=No
						   GUICtrlSetBkColor( _GUICtrlListView_GetItemParam($hWndListView, $iIndex), $NotSelected_BkColor)	; SetBkColor
						   GUICtrlSetColor( _GUICtrlListView_GetItemParam($hWndListView, $iIndex), $NotSelected_SetColor)	; SetColorText
						ElseIf _GUICtrlListView_GetItemStateImage($hWndListView, $iIndex) = 1 Then							; 1=No
						   _GUICtrlListView_SetItemStateImage($hWndListView, $iIndex, 2)									; 2=Yes
						   GUICtrlSetBkColor( _GUICtrlListView_GetItemParam($hWndListView, $iIndex), $Selected_BkColor)		; SetBkColor
						   GUICtrlSetColor( _GUICtrlListView_GetItemParam($hWndListView, $iIndex), $Selected_SetColor)		; SetColorText
						EndIf
						Return 0

					 EndIf

				  EndIf

			   EndIf

				  ; No return value

			Case $NM_DBLCLK		; Sent by a list-view control when the user double-clicks an item with the left mouse button
			   ConsoleWrite("_DblClick("&$iCode&")"&@CRLF)		; _DblClick()

			Case $NM_RCLICK		; Sent by a list-view control when the user clicks an item with the right mouse button
			   ConsoleWrite("_RClick("&$iCode&")"&@CRLF)			; _RClick()

			Case $NM_RDBLCLK	; Sent by a list-view control when the user double-clicks an item with the right mouse button
			   ConsoleWrite("_DblRClick("&$iCode&")"&@CRLF)		; _DblRClick()

		 EndSwitch
   EndSwitch
   Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY