UEZ Posted September 22, 2014 Posted September 22, 2014 (edited) I want that the Listview acts as CTRL key was pressed by default to avoid any deletion when the listview was clicked. Here an example code: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> $hGUI = GUICreate("ListView Test", 400, 550) $iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_AddColumn($iLV, "Date", 100, 1) _GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1) _GUICtrlListView_AddColumn($iLV, "File Name", 100, 1) For $i = 0 to 150 _GUICtrlListView_AddItem($iLV, "Row " & $i) _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1) _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2) Next $cButton = GUICtrlCreateButton("Reset", 10, 510, 80, 30) GUISetState() _GUICtrlListView_SetItemChecked($iLV, 0) _GUICtrlListView_SetItemSelected($iLV, 0) _GUICtrlListView_SetItemChecked($iLV, 1) _GUICtrlListView_SetItemSelected($iLV, 1) _GUICtrlListView_SetItemChecked($iLV, 2) _GUICtrlListView_SetItemSelected($iLV, 2) ControlFocus($hGUI, "", $iLV) ; Create array to hold selection state Global $aSelected[_GUICtrlListView_GetItemCount($iLV)] GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton ; Clear all selections _GUICtrlListView_SetItemSelected($iLV, -1, False) ; Clear selected array Global $aSelected[_GUICtrlListView_GetItemCount($iLV)] EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam) If @error Then Return Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $hWndFrom = HWnd($tNMHDR.hWndFrom) Local $iIDFrom = $tNMHDR.IDFrom Local $iCode = $tNMHDR.Code Local Static $iCount = 0 Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Switch $iCode Case $LVN_ITEMCHANGED If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then Switch $tInfo.NewState Case 8192 ;item checked _GUICtrlListView_SetItemSelected($iLV, $tInfo.Item, True) Case 4096 ;item unchecked _GUICtrlListView_SetItemSelected($iLV, $tInfo.Item, False) EndSwitch EndIf Case $NM_CLICK $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) ;~ _DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _ ;~ "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _ ;~ "-->Code:" & @TAB & $iCode & @CRLF & _ ;~ "-->Index:" & @TAB & $tInfo.Index & @CRLF & _ ;~ "-->SubItem:" & @TAB & $tInfo.SubItem & @CRLF & _ ;~ "-->NewState:" & @TAB & $tInfo.NewState & @CRLF & _ ;~ "-->OldState:" & @TAB & $tInfo.OldState & @CRLF & _ ;~ "-->Changed:" & @TAB & $tInfo.Changed & @CRLF & _ ;~ "-->ActionX:" & @TAB & $tInfo.ActionX & @CRLF & _ ;~ "-->ActionY:" & @TAB & $tInfo.ActionY & @CRLF & _ ;~ "-->lParam:" & @TAB & $tInfo.lParam & @CRLF & _ ;~ "-->KeyFlags:" & @TAB & $tInfo.KeyFlags) _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, _GUICtrlListView_GetItemState($iLV, $tInfo.Index, $LVIS_SELECTED)) EndSwitch Return $__LISTVIEWCONSTANT_GUI_RUNDEFMSG EndFunc Func _DebugPrint($s_Text , $sLine = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @CRLF & _ "+======================================================" & @CRLF & _ "-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _ "+======================================================" & @CRLF) EndFunc ;==>_DebugPrint Just cklick the listview and you will see that the selection is deleted. Repeat it and hold the CTRL key pressed. Any ideas? I don't want to read the listview and check whether the checkbox is checked and mark the row appropriately! It's lagging... Thanks, UEZ Edited September 22, 2014 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Solution LarsJ Posted September 23, 2014 Solution Posted September 23, 2014 UEZ, May be you can use something like this:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> $hGUI = GUICreate("ListView Test", 400, 550) $iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_AddColumn($iLV, "Date", 100, 1) _GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1) _GUICtrlListView_AddColumn($iLV, "File Name", 100, 1) For $i = 0 to 150 _GUICtrlListView_AddItem($iLV, "Row " & $i) _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1) _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2) Next _GUICtrlListView_SetItemChecked($iLV, 0) _GUICtrlListView_SetItemParam($iLV, 0, True) _GUICtrlListView_SetItemChecked($iLV, 1) _GUICtrlListView_SetItemParam($iLV, 1, True) _GUICtrlListView_SetItemChecked($iLV, 2) _GUICtrlListView_SetItemParam($iLV, 2, True) ControlFocus($hGUI, "", $iLV) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $iCode $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) $iCode = $tNMHDR.Code Switch $iCode Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then Switch $tInfo.NewState Case 8192 ;item checked _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, True) Case 4096 ;item unchecked _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, False) EndSwitch EndIf Case $NM_CLICK Local $aInfo = GUIGetCursorInfo() Local $aTest = _GUICtrlListView_SubItemHitTest( $iLV, $aInfo[0], $aInfo[1] ) If Not ( Not $aTest[4] And $aTest[6] ) Then $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $fChecked = Not _GUICtrlListView_GetItemParam($iLV, $tInfo.Index) _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, $fChecked) _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, $fChecked) EndIf Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" ) Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations Case BitOR( $CDDS_ITEMPREPAINT, $CDDS_SUBITEM ) ; Before painting a subitem Local $lItemlParam = $tNMLVCUSTOMDRAW.lItemlParam ; Item param Local $iSubItem = $tNMLVCUSTOMDRAW.iSubItem ; Subitem index Local $uItemState = $tNMLVCUSTOMDRAW.uItemState ; Item state If $lItemlParam Then ; Checked rows If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF ) ; Forecolor white DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 ) ; Backcolor dark blue, BGR EndIf Else ; Other rows If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0x000000 ) DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF ) EndIf EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFuncChecked state (and selection) in ItemParam. UEZ 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
UEZ Posted September 23, 2014 Author Posted September 23, 2014 (edited) LarsJ, interesting idea to simulate the CTRL key behavior which didn't came to my mind although I used $NM_CUSTOMDRAW to draw the grid in different color. Just for my curiosity: is there a way without simulating? How is windows handling the lv when ctrl is pressed? Thanks! Br, UEZ Edited September 23, 2014 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Moderators Melba23 Posted September 23, 2014 Moderators Posted September 23, 2014 LarsJ,Another nice script. But could I make 2 suggested changes?- 1. When adding extended styles to a ListView it is always advisable to use _GUICtrlListView_SetExtendedListViewStyle as some of these values are also used by $WS_Ex_* styles and can be confused with them. That is why the function exists. - 2. In ListViews created with the native function, AutoIt uses the item parameter to store the internal ControlID of the row. As explained in the Help file, it is best to use parameter values well above any possible existing ControlIDs (we recommend 1000+) as experience has shown that there can be "ghost" effects on the real control if this is not done. In this case you are only using True/False (1/0) and so there is no real possibility of this happening, but I raise it a useful hint for anyone reading. Making those changes does not affect the script as you can see here (I use 1000/1001 as checked/unchecked):expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> $hGUI = GUICreate("ListView Test", 400, 550) $iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetExtendedListViewStyle($iLV, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_AddColumn($iLV, "Date", 100, 1) _GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1) _GUICtrlListView_AddColumn($iLV, "File Name", 100, 1) For $i = 0 To 150 _GUICtrlListView_AddItem($iLV, "Row " & $i) _GUICtrlListView_SetItemParam($iLV, $i, 1000) _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1) _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2) Next _GUICtrlListView_SetItemChecked($iLV, 0) _GUICtrlListView_SetItemParam($iLV, 0, 1001) _GUICtrlListView_SetItemChecked($iLV, 1) _GUICtrlListView_SetItemParam($iLV, 1, 1001) _GUICtrlListView_SetItemChecked($iLV, 2) _GUICtrlListView_SetItemParam($iLV, 2, 1001) ControlFocus($hGUI, "", $iLV) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $iCode = $tNMHDR.Code Switch $iCode Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then Switch $tInfo.NewState Case 8192 ;item checked _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1001) Case 4096 ;item unchecked _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1000) EndSwitch EndIf Case $NM_CLICK Local $aInfo = GUIGetCursorInfo() Local $aTest = _GUICtrlListView_SubItemHitTest($iLV, $aInfo[0], $aInfo[1]) If Not (Not $aTest[4] And $aTest[6]) Then $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $iChecked = _GUICtrlListView_GetItemParam($iLV, $tInfo.Index) ConsoleWrite($iChecked & @CRLF) If $iChecked = 1000 Then _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, 1001) _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, True) Else _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, 1000) _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, False) EndIf EndIf Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage") Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Return $CDRF_NOTIFYSUBITEMDRAW ; Notify the parent window of any SUBITEM-related drawing operations Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM) ; Before painting a subitem Local $lItemlParam = $tNMLVCUSTOMDRAW.lItemlParam ; Item param Local $iSubItem = $tNMLVCUSTOMDRAW.iSubItem ; Subitem index Local $uItemState = $tNMLVCUSTOMDRAW.uItemState ; Item state If $lItemlParam = 1001 Then ; Checked rows If Not BitAND($uItemState, $CDIS_FOCUS) Then DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF) ; Forecolor white DllStructSetData($tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600) ; Backcolor dark blue, BGR EndIf Else ; Other rows If Not BitAND($uItemState, $CDIS_FOCUS) Then DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", 0x000000) DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF) EndIf EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFYM23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
UEZ Posted October 15, 2014 Author Posted October 15, 2014 (edited) At first glance it looks like what I want BUT it doesn't work when you have checkboxes and mark checked and unmark unchecked rows in the list view. Only rows with checked checkboxes should be selected using _GUICtrlListView_SetItemSelected(). Is it possible in this section ... If $wParam = $iListView_Web Then Local $lItemlParam = $tNMLVCUSTOMDRAW.lItemlParam ; Item param Local $iSubItem = $tNMLVCUSTOMDRAW.iSubItem ; Subitem index Local $uItemState = $tNMLVCUSTOMDRAW.uItemState ; Item state If $lItemlParam Then ; Checked rows If Not BitAND($uItemState, $CDIS_FOCUS) Then DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", $iColor_Text) ; Forecolor white DllStructSetData($tNMLVCUSTOMDRAW, "clrTextBk", 0x00FF00) ;0xFF9933) ; Backcolor blue, BGR EndIf Else ; Other rows If Not BitAND($uItemState, $CDIS_FOCUS) Then DllStructSetData($tNMLVCUSTOMDRAW, "ClrText", $iColor_Text) DllStructSetData($tNMLVCUSTOMDRAW, "ClrTextBk", 0x0000FF) ;$iColor_LV) EndIf EndIf EndIf ... to set the background color only for checked rows? Edit: seems that $CDIS_CHECKED, $CDIS_SELECTED, $CDIS_MARKED are doing partly the job. Continuing to test and search for a solution...Btw, is there a way to get the color which the system uses to mark a row in LV? -> _WinAPI_GetSysColor($COLOR_HIGHLIGHT)Forget it, it was my wrong implementation which caused the problems. Br, UEZ Edited October 16, 2014 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
LarsJ Posted October 16, 2014 Posted October 16, 2014 One important thing. Because a row is drawn only in one color, the row should be drawn in the item part of the drawing stage, where the entire row is drawn at once. To draw such a row column by column in the subitem part is wrong, and leads to bad performance.Here the rows are drawn in the item part of the drawing stage. The subitem part is deleted. A controlID offset with a value of 1000 is added to ItemParam.expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> $hGUI = GUICreate("ListView Test", 400, 550) $iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_AddColumn($iLV, "Date", 100, 1) _GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1) _GUICtrlListView_AddColumn($iLV, "File Name", 100, 1) For $i = 0 to 150 _GUICtrlListView_AddItem($iLV, "Row " & $i) _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1) _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2) _GUICtrlListView_SetItemParam($iLV, $i, 1000) Next _GUICtrlListView_SetItemChecked($iLV, 0) _GUICtrlListView_SetItemParam($iLV, 0, 1001) _GUICtrlListView_SetItemChecked($iLV, 1) _GUICtrlListView_SetItemParam($iLV, 1, 1001) _GUICtrlListView_SetItemChecked($iLV, 2) _GUICtrlListView_SetItemParam($iLV, 2, 1001) ControlFocus($hGUI, "", $iLV) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $iCode $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) $iCode = $tNMHDR.Code Switch $iCode Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then Switch $tInfo.NewState Case 8192 ;item checked _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1001) Case 4096 ;item unchecked _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1000) EndSwitch EndIf Case $NM_CLICK Local $aInfo = GUIGetCursorInfo() Local $aTest = _GUICtrlListView_SubItemHitTest( $iLV, $aInfo[0], $aInfo[1] ) If Not ( Not $aTest[4] And $aTest[6] ) Then $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $fChecked = Not ( _GUICtrlListView_GetItemParam($iLV, $tInfo.Index) = 1001 ) _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, $fChecked + 1000) _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, $fChecked) EndIf Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" ) Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Local $lItemlParam = $tNMLVCUSTOMDRAW.lItemlParam - 1000 ; Item param Local $uItemState = $tNMLVCUSTOMDRAW.uItemState ; Item state If $lItemlParam Then ; Checked rows If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF ) ; Forecolor white DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 ) ; Backcolor dark blue, BGR EndIf Else ; Other rows If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0x000000 ) DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF ) EndIf EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
UEZ Posted October 16, 2014 Author Posted October 16, 2014 (edited) Thanks LarsJ. One question how would you implement multi selection? I mean if you change $NM_CLICK to $NM_DBLCLK and select some rows by holding down the shift key. These lines should be marked and the checkbox should be set. The same when unselecting some lines. This is what I did: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> Global Const $iColor_TextBk = _WinAPI_GetSysColor($COLOR_HIGHLIGHT) #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> $hGUI = GUICreate("ListView Test", 400, 550) $iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS) _GUICtrlListView_SetExtendedListViewStyle($iLV, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_AddColumn($iLV, "Date", 100, 1) _GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1) _GUICtrlListView_AddColumn($iLV, "File Name", 100, 1) For $i = 0 To 150 _GUICtrlListView_AddItem($iLV, "Row " & $i) _GUICtrlListView_SetItemParam($iLV, $i, 1000) _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1) _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2) Next _GUICtrlListView_SetItemChecked($iLV, 0) _GUICtrlListView_SetItemParam($iLV, 0, 1001) _GUICtrlListView_SetItemChecked($iLV, 1) _GUICtrlListView_SetItemParam($iLV, 1, 1001) _GUICtrlListView_SetItemChecked($iLV, 2) _GUICtrlListView_SetItemParam($iLV, 2, 1001) ControlFocus($hGUI, "", $iLV) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $iCode, $aIndices, $n $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $iCode = $tNMHDR.Code Switch $iCode Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then Switch $tInfo.NewState Case 8192 ;item checked _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1001) Case 4096 ;item unchecked _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1000) EndSwitch EndIf Case $NM_CLICK $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) If $tInfo.KeyFlags = 4 Then Local $aIndices = _GUICtrlListView_GetSelectedIndices($iLV, True), $n For $n = 1 To $aIndices[0] Switch Not _GUICtrlListView_GetItemChecked($iLV, $aIndices[$n]) Case False _GUICtrlListView_SetItemParam($iLV, $aIndices[$n], 1000) _GUICtrlListView_SetItemChecked($iLV, $aIndices[$n], False) Case True _GUICtrlListView_SetItemParam($iLV, $aIndices[$n], 1001) _GUICtrlListView_SetItemChecked($iLV, $aIndices[$n], True) EndSwitch Next EndIf Case $NM_DBLCLK Local $aInfo = GUIGetCursorInfo() Local $aTest = _GUICtrlListView_SubItemHitTest($iLV, $aInfo[0], $aInfo[1]) If Not (Not $aTest[4] And $aTest[6]) Then $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $iChecked = _GUICtrlListView_GetItemParam($iLV, $tInfo.Index) If $iChecked = 1000 Then _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, 1001) _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, True) Else _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, 1000) _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, False) EndIf EndIf Case $NM_CLICK $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) If $tInfo.KeyFlags = 4 Then $aIndices = _GUICtrlListView_GetSelectedIndices($iLV, True) ConsoleWrite(UBound($aIndices) - 1 & @CRLF) For $n = 1 To $aIndices[0] Switch Not _GUICtrlListView_GetItemChecked($iLV, $aIndices[$n]) Case False _GUICtrlListView_SetItemParam($iLV, $aIndices[$n], 1000) _GUICtrlListView_SetItemChecked($iLV, $aIndices[$n], False) Case True _GUICtrlListView_SetItemParam($iLV, $aIndices[$n], 1001) _GUICtrlListView_SetItemChecked($iLV, $aIndices[$n], True) EndSwitch Next EndIf Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" ) Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Local $lItemlParam = $tNMLVCUSTOMDRAW.lItemlParam - 1000 ; Item param Local $uItemState = $tNMLVCUSTOMDRAW.uItemState ; Item state If $lItemlParam Then ; Checked rows If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF ) ; Forecolor white DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", $iColor_TextBk ) ; Backcolor dark blue, BGR EndIf Else ; Other rows If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0x000000 ) DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF ) EndIf EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Br, UEZ Edited October 16, 2014 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
LarsJ Posted October 17, 2014 Posted October 17, 2014 I would separate checked and selected rows to make things easier: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> $hGUI = GUICreate("ListView Test", 400, 550) $iLV = GUICtrlCreateListView("", 0, 10, 400, 480, $LVS_SHOWSELALWAYS, BitOR($LVS_EX_FLATSB, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER)) _GUICtrlListView_AddColumn($iLV, "Date", 100, 1) _GUICtrlListView_AddColumn($iLV, "Size (bytes)", 100, 1) _GUICtrlListView_AddColumn($iLV, "File Name", 100, 1) For $i = 0 to 150 _GUICtrlListView_AddItem($iLV, "Row " & $i) _GUICtrlListView_AddSubItem($iLV, $i, $i * 2, 1) _GUICtrlListView_AddSubItem($iLV, $i, $i * 4, 2) _GUICtrlListView_SetItemParam($iLV, $i, 1000) Next _GUICtrlListView_SetItemChecked($iLV, 0) _GUICtrlListView_SetItemParam($iLV, 0, 1001) _GUICtrlListView_SetItemChecked($iLV, 1) _GUICtrlListView_SetItemParam($iLV, 1, 1001) _GUICtrlListView_SetItemChecked($iLV, 2) _GUICtrlListView_SetItemParam($iLV, 2, 1001) ControlFocus($hGUI, "", $iLV) GUICtrlCreateLabel( "Space to invert checked state of selected items", 10, 500, 380, 20 ) GUICtrlSetFont( -1, 10, 700 ) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $iCode $tNMHDR = DllStructCreate( $tagNMHDR, $lParam ) $iCode = $tNMHDR.Code Switch $iCode Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) If BitAND($tInfo.Changed, $LVIF_STATE) = $LVIF_STATE Then Switch $tInfo.NewState Case 8192 ;item checked _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1001) Case 4096 ;item unchecked _GUICtrlListView_SetItemParam($iLV, $tInfo.Item, 1000) EndSwitch EndIf Case $LVN_KEYDOWN Local $tKey = DllStructCreate($tagNMLVKEYDOWN, $lParam) If $tKey.VKey = 0x20 Then ; $VK_SPACE = 0x20 Local $aSelected = _GUICtrlListView_GetSelectedIndices($iLV, True) If $aSelected[0] > 1 Then ; $aSelected[0] = 1 is handled by default code For $i = 1 To $aSelected[0] If _GUICtrlListView_GetItemState($iLV, $aSelected[$i], $LVIS_FOCUSED ) Then ContinueLoop ; Handled by default code Local $fChecked = Not ( _GUICtrlListView_GetItemParam($iLV, $aSelected[$i]) = 1001 ) _GUICtrlListView_SetItemParam($iLV, $aSelected[$i], $fChecked + 1000) _GUICtrlListView_SetItemChecked($iLV, $aSelected[$i], $fChecked) _GUICtrlListView_SetItemSelected($iLV, $aSelected[$i], False) Next EndIf EndIf Case $NM_DBLCLK Local $aInfo = GUIGetCursorInfo() Local $aTest = _GUICtrlListView_SubItemHitTest( $iLV, $aInfo[0], $aInfo[1] ) If Not ( Not $aTest[4] And $aTest[6] ) Then $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam) Local $fChecked = Not ( _GUICtrlListView_GetItemParam($iLV, $tInfo.Index) = 1001 ) _GUICtrlListView_SetItemParam($iLV, $tInfo.Index, $fChecked + 1000) _GUICtrlListView_SetItemChecked($iLV, $tInfo.Index, $fChecked) EndIf Case $NM_CUSTOMDRAW Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam ) Local $dwDrawStage = DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" ) Switch $dwDrawStage ; Holds a value that specifies the drawing stage Case $CDDS_PREPAINT ; Before the paint cycle begins Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any ITEM-related drawing operations Case $CDDS_ITEMPREPAINT ; Before painting an item Local $lItemlParam = $tNMLVCUSTOMDRAW.lItemlParam - 1000 ; Item param Local $uItemState = $tNMLVCUSTOMDRAW.uItemState ; Item state If $lItemlParam Then ; Checked rows If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then ;DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0xFFFFFF ) ; Forecolor white ;DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 ) ; Backcolor dark blue, BGR DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xFFFF00 ) ; Backcolor cyan, BGR EndIf Else ; Other rows If Not BitAnd( $uItemState, $CDIS_FOCUS ) Then ;DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText", 0x000000 ) ;DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF ) DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF ) EndIf EndIf Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
UEZ Posted October 17, 2014 Author Posted October 17, 2014 Thanks LarsJ, Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now