Sign in to follow this  
Followers 0
UEZ

How a ListView acts as CTRL was pressed by default?

9 posts in this topic

#1 ·  Posted (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:

#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 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites



UEZ, May be you can use something like this:

#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
EndFunc
Checked state (and selection) in ItemParam.
1 person likes this

Share this post


Link to post
Share on other sites

#3 ·  Posted (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.  :thumbsup:

Just for my curiosity: is there a way without simulating? How is windows handling the lv when ctrl is pressed?

Thanks!

Br,

UEZ

Edited 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

LarsJ,

Another nice script. :thumbsup:

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

#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_NOTIFY
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (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 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

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.

#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

Share this post


Link to post
Share on other sites

#7 ·  Posted (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:

#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 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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

I would separate checked and selected rows to make things easier:

 

#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

Share this post


Link to post
Share on other sites

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • Daka
      By Daka
      I know there are listbox and listview, but now I have?
      here is the video of infowindow 
      I tried to read mouse selection like for listbox:
      $listWindow = "[CLASS:TFormResearchGR]" $topicsList = "[CLASS:TMWrapper; INSTANCE:255]" WinWait($listWindow, "", 60) $hdlWindow = WinGetHandle($listWindow) $hdlList = ControlGetHandle($hdlWindow, "", $topicsList) _GUICtrlListBox_ClickItem($hdlList, 0, "left") $countOfList = _GUICtrlListBox_GetCount($hdlList) ConsoleWrite("Count of list: " & $countOfList & @LF) count of list is not working.
      I realiezed that there are difference between listbox and listview, but this is something different.
      and till now I never saw that you can go inside with infotool and also get instances.
       
      so Im confused how to get the list number and the names of selection?
    • AndyS19
      By AndyS19
      I have a listview with 3 columns and I want to set the 3rd column's color based on the item's 'Param' value, but even though I set up for the 3rd column, the entire row always gets the color.
      My test code is below, but here is the pertinent code:
      Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg
      Here is the full test code:
      #include-once ;#cs #NoTrayIcon #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_UseX64=N Opt("GUICloseOnESC", 1) ; ESC closes GUI? (0 = no, 1 = yes) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Opt('MustDeclareVars', 1) OnAutoItExitRegister("_test_exit") Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase #include <GuiListBox.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> Global $__MCP_obj, $__MCP_GUI_hWnd, $idListView, $hListView Global $hMainWin test() Exit Func test() $hMainWin = GUICreate("Test window", 120, 100, @DesktopWidth / 2, -1) GUICtrlCreateButton("Hwnd", 10, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_1stTEST_btn") GUICtrlCreateButton("ID", 50, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_2ndTEST_btn") GUISetOnEvent($GUI_EVENT_CLOSE, "_test_exit") GUISetState(@SW_SHOW) While (1) Sleep(17) WEnd EndFunc ;==>test Func _myColorPicker($obj) logmsg("+++: $obj = 0x" & Hex($obj) & @CRLF) Local $flags = 0 Local $ww, $wh, $x, $y, $w, $h $__MCP_obj = $obj $ww = 350 $wh = 500 $x = 200 $y = 150 $__MCP_GUI_hWnd = GUICreate("myColorPicker", $ww, $wh, $x, $y, $flags) $x = 10 $y = 10 $w = 150 $h = 20 GUICtrlCreateButton("Set caller's color", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_SetColor_btn") $y += $h + 5 $w = $ww - 25 $h = $wh - 100 $idListView = GUICtrlCreateListView("", $x, $y, $w, $h, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $hListView = GUICtrlGetHandle($idListView) $x = $ww / 2 - 50 $y = $wh - 60 $w = 100 $h = 25 GUICtrlCreateButton("Quit Popup", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_QUIT_btn") GUICtrlSetFont($idListView, 8.5, -1, -1, "courier new") _GUICtrlListView_AddColumn($idListView, "Name", 100) _GUICtrlListView_AddColumn($idListView, "Value", 100) _GUICtrlListView_AddColumn($idListView, "Sample", 100) _GUICtrlListView_SetColumnWidth($idListView, 0, 100) _GUICtrlListView_SetColumnWidth($idListView, 1, 80) logmsg("+++: $idListView = " & $idListView) logmsg("+++: $hListView = 0x" & Hex($hListView)) __MCP_populateListView($hListView) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW, $__MCP_GUI_hWnd) EndFunc ;==>_myColorPicker Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg Func __MCP_exit() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_exit Func __MCP_handle_SetColor_btn() If (IsHWnd($__MCP_obj)) Then GUISetBkColor($COLOR_BLUE, $__MCP_obj) Else GUICtrlSetBkColor($__MCP_obj, $COLOR_BLUE) EndIf EndFunc ;==>__MCP_handle_SetColor_btn Func __MCP_populateListView($hWnd) Local $text, $parts, $iIndex Local Static $aItems[] = [ _ "BLACK | " & $CLR_BLACK & "|" & "", _ "BLUE | " & $CLR_BLUE & "|" & "", _ "RED | " & $CLR_RED & "|" & "", _ "WHITE | " & $CLR_WHITE & "|" & "", _ "YELLOW | " & $CLR_YELLOW & "|" & "" _ ] _GUICtrlListView_BeginUpdate($hWnd) _GUICtrlListView_DeleteAllItems($hWnd) For $ndx = 0 To UBound($aItems) - 1 $text = $aItems[$ndx] $parts = StringSplit($text, "|", 2) $parts[0] = StringStripWS($parts[0], 3) $parts[2] = StringStripWS($parts[2], 3) $iIndex = _GUICtrlListView_AddItem($hWnd, $parts[0], -1, $parts[1]) _GUICtrlListView_AddSubItem($hWnd, $iIndex, Hex($parts[1]), 1) _GUICtrlListView_AddSubItem($hWnd, $iIndex, $parts[0], 2) Next _GUICtrlListView_EndUpdate($hWnd) EndFunc ;==>__MCP_populateListView Func __MCP_handle_QUIT_btn() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_handle_QUIT_btn Func handle_1stTEST_btn() _myColorPicker($hMainWin) EndFunc ;==>handle_1stTEST_btn Func handle_2ndTEST_btn() _myColorPicker(@GUI_CtrlId) EndFunc ;==>handle_2ndTEST_btn Func _test_exit() Exit EndFunc ;==>_test_exit  
    • spuuunit
      By spuuunit
      This is what I'm trying to do: In Firefox, if you hold down CTRL + C for about 200ms, then press CTRL + T. This is my code:
      While WinActive(" - Mozilla Firefox") If _IsPressed("A2", $hDLL) And _IsPressed("43", $hDLL) Then $timer = TimerInit() While _IsPressed("A2", $hDLL) And _IsPressed("43", $hDLL) Sleep(10) $diff = TimerDiff($timer) If $diff > 200 Then Send("^{T}") While _IsPressed("A2", $hDLL) And _IsPressed("43", $hDLL) Sleep(10) WEnd EndIf WEnd EndIf WEnd The problem is that the CTRL key gets stuck down after Send("^{T}"). I found this, but what I understand that happens when I release, and that is not what I want. The "General unstuck method" did nothing.
    • nacerbaaziz
      By nacerbaaziz
      Hello guys
      Today I'll give you three functions to manage the list View items
      These functions will help you to do some works in your list view items
      1. list view Read
      To get the selected item text  
      2. listView_checke
      To checke an item
      3. isListViewChecked
      To see if the item is checked
      All of these functions will be illustrated by the following example
      You can download the include file from the link below
      Now with the example
      #include <easy_listView_functions.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Example() Func Example()  Local $idListview  GUICreate("ListView Get Item Checked State", 1000, 700)  $idListview = GUICtrlCreateListView("", 50, 30, 250, 120, 50)  _GUICtrlListView_SetExtendedListViewStyle($idListview, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES)) ; Add items $item1 = GUICtrlCreateListViewItem("item1", $idListview) $item2 = GUICtrlCreateListViewItem("item2", $idListview) _listview_Checke($idListview, "item1") $btn = GUICtrlCreateButton("&read", 100, 150, 50, 50) $btn2 = GUICtrlCreateButton("&if checked", 100, 200, 100, 50)  GUISetState(@SW_SHOW) while 1 switch GUIGetMSG() case $GUI_EVENT_CLOSE  GUIDelete() exit case $btn $read = _ListView_read($idListView) if $read then msgBox(0, "read listview", $read) else msgBox(0, "read listview", "no text ditected") endIf case $btn2 if _isListviewChecked($idListView, "item1") then msgBox(0, "get", "the item is checked") else msgBox(0, "get", "the item isn't checked") endIf endSwitch wend EndFunc   ;==>Example
       
      easy_listView_functions.au3
    • dascondor
      By dascondor
      So I having issues with this GUI/Listview. My main GUI works like it needs to but the ListView GUIs don't. The exit buttons do not work on them and om have a hard time getting them to work. And I'm trying to make the  listview GUI resizeable. But I'm not sure how to fix either of these issues any thoughts.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <ScreenCapture.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <ListviewConstants.au3> #include 'MultiPing.au3' Opt("GUIOnEventMode", 1) #Region ;Declares ; Reads text file for the base list of IP's Global $aBase_IPlist = _FileReadToArray_mod(".\IP_List.txt") Global $replace2 = "Second" Global $replace3 = "Thrid" ;Global $userdata1 = GUICtrlRead($data1) ;Global $userdata2 = GUICtrlRead($data2) Global $savefolder = "C:\Users\" Global $paths = "\Desktop\PingChecks" Global $1stpaths = "\~~~Store" Global $2ndpaths = "~~~" Global $results = FileExists($savefolder & @UserName & $paths) ;Global $foldercheck = FileExists($savefolder & @UserName & $paths & $1stpaths & $userdata1 & $userdata2 & $2ndpaths) ;Global $savefile = "C:\Users\" & @UserName & "\Desktop\PingChecks\~~~Store" & $userdata1 & $userdata2 & "~~~\" #EndRegion ;Declares #Region ### START Koda GUI section ### Form= $IPMonkey = GUICreate("IP Monkey", 573, 254, -1, -1) GUISetIcon("C:\Users\Dlex\Pictures\monkeyicon.ico", -1) GUISetFont(16, 800, 0, "Arial") GUISetBkColor(0xFFFFFF) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $data1 = GUICtrlCreateInput("1", 184, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $data2 = GUICtrlCreateInput("23", 280, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $GOButton = GUICtrlCreateButton("GO", 80, 192, 75, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlSetTip(-1, "Runs A Live Continuous Ping" & @CRLF & _ "Until Told Other Wise") GUICtrlSetOnEvent(-1, "GOButtonClick") $quickscan = GUICtrlCreateButton("Quick Scan", 224, 192, 107, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetOnEvent(-1, "quickscanClick") GUICtrlSetTip(-1, "Quickly Scans, Then Saves" & @CRLF & _ "Results In Your 'PingChecks' " & @CRLF & _ "Folder Under Your Store Number Folder") Global $exitbutton = GUICtrlCreateButton("Exit", 416, 192, 75, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetTip(-1, "What Do You Think This Button Does?") GUICtrlSetOnEvent(-1, "exitbuttonClick") $titlebar = GUICtrlCreateLabel("IP Monkey", 16, 120, 107, 28) GUICtrlSetColor(-1, 0x000000) $Pic1 = GUICtrlCreatePic("C:\Users\Dlex\Pictures\monkeyicon-0.jpg", 16, 16, 100, 100) GUICtrlSetOnEvent(-1, "Pic1Click") $infobutton = GUICtrlCreateButton("?", 536, 8, 27, 25) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF8000) GUICtrlSetTip(-1, "Unsure what to do?" & @CRLF & _ "This will get give you " & @CRLF & _ "the help for IP Monkey") GUICtrlSetOnEvent(-1, "infobuttonClick") $Whatstorelabel = GUICtrlCreateLabel("What Store?", 208, 56, 130, 28) GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ;ping gui ; ------ pinger GUI ------------------- Global $StopPing = 0 Local $Win_X = 1200, $Win_Y = 880 ; dimension of window Global $PingGui = GUICreate("IP Monkey", $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") Global $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) $button1 = GUICtrlCreateLabel("Hit Exit To Quit", 10, $Win_Y - 25, $Win_X - 20, 20, -1,$ES_CENTER) GUICtrlSetFont(-1, 10, 800) GUICtrlSetTip(-1, "exit") GUICtrlSetOnEvent(-1, 'SpecialEvents') GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) GUISetState(@SW_HIDE) ; hidden at startup ; --------- end of pinger gui ------------- #EndRegion ;ping gui ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) While 1 Sleep(100) WEnd Func exitbuttonClick() MsgBox(0,'0','0') Exit EndFunc ;==>exitbuttonClick Func GOButtonClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) ; pass the wanted new octet replace_And_Go($userdata1, $userdata2) ; generate a list of new IP and Go EndFunc ;==>GOButtonClick Func infobuttonClick() EndFunc ;==>infobuttonClick Func Pic1Click() EndFunc ;==>Pic1Click Func quickscanClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) replace_And_Go2($userdata1, $userdata2) EndFunc ;==>quickscanClick Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE _button1() Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE Case @GUI_CtrlId = $GUI_EVENT_MAXIMIZE EndSelect EndFunc ;==>SpecialEvents #Region ; Main_GO/Replace_and_GO #cs ############################## second script ############################################# ; this is to ping continuously a list of IP addresses, get and display ping result "live" ; it simulates the dos "ping -t" command but performed simultaneously on many IP ; presenting the results in a ListView highlighting not responding devices with a red box #ce Func replace_And_Go($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger Main_GO($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go Func Main_GO($IPlist) HotKeySet("{esc}", "exitbuttonClick") $StopPing = 0 ; $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's ; ; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt ; values in the file should be separated by a semicolon, something like in the following example: ; ; hostname1;192.168.0.1 ; hostname2;192.168.0.5 ; hostnameX;10.59.7.200 ; etc.... ; ; if values in the file are not separated by a semicolon, but another char is used, for example a comma, ; then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",") ; _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_DeleteAllItems($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) While Not $StopPing ; 1 ; continuously ping addresses of the previously loaded file (IP_List.txt) Sleep(10) ; ; $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case) ; | ; | 1 means the IP are in the second column of the $IPlist array (first colun is nr. 0) ; | | ; | | +--> 0 means return back an array loaded with results from all pinged addresses (responding and not responding) ; | | | if you use 1 then only responding addresses are loaded in the returned array [default] ; | | | if you use 2 then only NOT responding addresses are loaded in the returned array ; | | | In this case we do not need an array to be returned, we only need to perform all pings and pass results ; | | | directly (on the fly) to the "_refresh" callback function that will refresh the listview ; | | | ; | | | 0 means NO lookup name resolution must be performed ; | | | | ; | | | | +--> this is the callback function to be called for each pinged address each time the ping has finished ; | | | | | (see the MultiPing.au3 file for info on all passed params) ; | | | | | 6 parameters are passed to this function, but only 2 are used by the called function in this case: ; | | | | | [4] roundtrip of the responding ping or -1 if IP is down ; | | | | | [5] Index (position) of this IP within the caller's passed array ; | | | | | ; v v v v v _nPing($IPlist, 1, 0, 0, "_refresh") WEnd EndFunc ;==>Main_GO #EndRegion ; Main_GO/Replace_and_GO #Region ; QuickScan/Replace_and_GO2 Func replace_And_Go2($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger QuickRun($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go2 Func QuickRun($IPlist) $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) HotKeySet("{esc}", "_button1") Local $Win_X = 1200, $Win_Y = 880 ; dimension of window $PingGui = GUICreate("IP Monkey" & "~~~" & @UserName & "~~~" & "Store" & $userdata1 & $userdata2 & "~~~" & @MON & "." & @MDAY & "." & @YEAR & "~~~" & @HOUR & "." & @MIN, $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui) $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) $button1 = GUICtrlCreateButton("Exit", 10, $Win_Y - 25, $Win_X - 20, 20) GUICtrlSetTip(-1, "End of program") GUICtrlSetOnEvent(-1, "exitbuttonClick") GUISetState(@SW_SHOW) ;~ $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) ;While 1 ; perform Pings and update ListView by the "_refresh" callback function $aFinalResult = _nPing($IPlist, 1, 0, 0, "_refresh") ;~ _ArrayDisplay($aFinalResult) ;DirCheck() EndFunc ;==>QuickRun #EndRegion ; QuickScan/Replace_and_GO2 #Region ; Misc Funcs (network) Func _refresh($Params) ; this receive ping results and displays them in the ListView _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow Sleep(50) ; a little wait If $Params[4] = -1 Then ; Device not responding to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item Else ; Device responds to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN EndIf EndFunc ;==>_refresh Func _button1() ; Button 1 clicked ;~ $StopPing = 1 Exit EndFunc ;==>_button1 #EndRegion ; Misc Funcs (network)  
      MultiPing.au3
      IP_List.txt