Sign in to follow this  
Followers 0
nhardel

Listview with clickable cells?

7 posts in this topic

Okay, who is ready to point me to the quickest answer ever on this forum?  I am attempting to make a listview type control and cant get my head around how to pull this off.

Requirements

DYNAMIC number of rows and columns

Autoscroll capabilities for a set ctrl size

Ability to click individual cells

Issues with listviews

I can select an item but that really just selects the whole row - perhaps I am missing a style or exstyle setting?

meets all other requirements

Issues with table.au3  even modified to use input boxes

Don't know how I would stick entire table into some type of ctrl box that would do the autoscroll capabilities when the table starts to get large

Groupbox?

Issues with Embeded excel

No way to know for sure that computer that is being used will have excel

Don't want to go down the road of making sure installed if I don't have to.

Another possible answer is Gridviews

but there isnt much info on these in the forum other than how to interact with one already in another application.  Not sure how I might go about creating one for myself in autoit

So there we go, I have scoured the forums and I can post some code if that helps.  Not sure how it will as the code I have works as expected from an Autoit standpoint, just not what I need.    Let the 'Ah Ha' moments begin! :thumbsup:

Share this post


Link to post
Share on other sites



nhardel,

I have been looking for a way to hightlight individual cells in a ListView for a long time and never found anything really satisfactory. This is the best I have ever managed myself based on my GUIListViewEx UDF:

GLVEx_HiLite.zip

Let me know what you think. :)

M23

1 person likes this

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

Wow, my skills must be improving.  I have stumped one of the AutoIT sorcerers. :sorcerer:   

Melba,

Looking thru the sample script, I see your point.  It works but man, ouch.  I don't need to really edit the cell, just recognize what cell it is and maybe change the background color so the user knows that they selected that cell.  I think I can adapt what you have to pull this off, still looking thru it and at work so tons of interuptions.  It really seems like such a simple request for individual selectable cells.  :think:  Thanks for the input.

To all others

Keep the ideas coming.  As you can see there is a demand for a good way to do this. 

Share this post


Link to post
Share on other sites

nhardel,

 

It works but man, ouch

I could not have put it better myself! :D

But seriously, if all you are looking for is to highlight a single cell then it should be possible to reduce the code significantly. We are forecast a wet weekend here - so if you think there is some merit in the line I have taken I could see what I could develop. ;)

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)

May be a custom drawn listview:

 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Opt( "MustDeclareVars", 1 )

Global $hGui, $hLV, $aHit[2] = [ -1, -1 ] ; $aHit contains row & col of marked cell

MainFunc()

Func MainFunc()

  $hGui = GUICreate( "Mark Cell in Listview", 300, 222 )

  Local $idLV = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 2, 2, 300-4, 222-4 )
  $hLV = ControlGetHandle( $hGui, "", $idLV )
  For $i = 0 To 49
    GUICtrlCreateListViewItem( "Cell " & $i & ".0" & "|Cell " & $i & ".1" & "|Cell " & $i & ".2", $idLV )
  Next

  GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" )

  GUISetState()

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
  WEnd

EndFunc

Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam )
  #forceref $hWnd, $iMsg, $wParam
  Local $tNMHDR, $hWndFrom, $iCode
  Local Static $bItemChanged
  $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
  $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) )
  $iCode = DllStructGetData( $tNMHDR, "Code" )

  Switch $hWndFrom

    Case $hLV

      Switch $iCode

        Case $LVN_ITEMCHANGED
          $bItemChanged = True
          Local $aInfo = GUIGetCursorInfo( $hGui )
          If $aInfo[2] Then
            $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0], $aInfo[1] )
            If $aInfo[0] > -1 And $aInfo[1] > -1 Then
              If $aHit[0] > -1 Then _
                _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] )
              $aHit[0] = $aInfo[0] ; Row
              $aHit[1] = $aInfo[1] ; Col
              _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] )
              _GUICtrlListView_SetItemSelected( $hLV, $aHit[0], False )
            EndIf
          Else
            Local $tNMLISTVIEW = DllStructCreate( $tagNMLISTVIEW, $lParam )
            _GUICtrlListView_SetItemSelected( $hLV, DllStructGetData( $tNMLISTVIEW, "Item" ), False )
          EndIf

        Case $NM_CLICK
          If Not $bItemChanged Then
            Local $aInfo = GUIGetCursorInfo( $hGui )
            $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0], $aInfo[1] )
            If $aInfo[0] > -1 And $aInfo[1] > -1 Then
              If $aHit[0] > -1 Then _
                _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] )
              $aHit[0] = $aInfo[0] ; Row
              $aHit[1] = $aInfo[1] ; Col
              _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] )
              _GUICtrlListView_SetItemSelected( $hLV, $aHit[0], False )
            EndIf
          EndIf
          $bItemChanged = False

        Case $NM_RCLICK
          Local $aInfo = GUIGetCursorInfo( $hGui )
          $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0], $aInfo[1] )
          If $aInfo[0] = $aHit[0] And $aInfo[1] = $aHit[1] Then
            _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] )
            _GUICtrlListView_SetItemSelected( $hLV, $aHit[0], False )
            $aHit[0] = -1 ; Row
            $aHit[1] = -1 ; Col
          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 $dwItemSpec = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ) ; Item index
              Local $iSubItem   = DllStructGetData( $tNMLVCUSTOMDRAW, "iSubItem"   ) ; Subitem index
              Local $uItemState = DllStructGetData( $tNMLVCUSTOMDRAW, "uItemState" ) ; Item state
              If $dwItemSpec = $aHit[0] Then ; Marked row
                Switch $iSubItem
                  Case $aHit[1] ; Marked column
                    DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )      ; Forecolor black
                    DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xFFFF00 )      ; Backcolor cyan, BGR
                  Case Else ; Other columns
                    If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                      DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF )    ; Forecolor white
                      DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 )    ; Backcolor dark blue, BGR
                    Else
                      DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )    ; Forecolor black
                      DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )    ; Backcolor white
                    EndIf
                EndSwitch
              Else ; Other rows
                If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF )
                  DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 )
                Else
                  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

  EndSwitch

  Return $GUI_RUNDEFMSG
EndFunc

Edit: Added code for NM_CLICK-event.

Edit 2: Right click to unmark.

Edit 3: Don't use this code. Use the code in post 6 or 7.

Edited by LarsJ
1 person likes this

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Click to mark. Click once more to unmark.

 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Opt( "MustDeclareVars", 1 )

Global $hGui, $hLV, $aHit[2] = [ -1, -1 ] ; $aHit contains row & col of marked cell

MainFunc()

Func MainFunc()

  $hGui = GUICreate( "Mark Cell in Listview", 250, 222 )

  Local $idLV = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 2, 2, 250-4, 222-4 )
  $hLV = ControlGetHandle( $hGui, "", $idLV )
  For $i = 0 To 49
    GUICtrlCreateListViewItem( "Cell " & $i & ".0" & "|Cell " & $i & ".1" & "|Cell " & $i & ".2", $idLV )
  Next

  GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" )

  GUISetState()

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
  WEnd

EndFunc

Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam )
  #forceref $hWnd, $iMsg, $wParam
  Local $tNMHDR, $hWndFrom, $iCode
  $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
  $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) )
  $iCode = DllStructGetData( $tNMHDR, "Code" )

  Switch $hWndFrom

    Case $hLV

      Switch $iCode

        Case $LVN_ITEMCHANGED
          Local $tNMLISTVIEW, $iItem, $aInfo
          $tNMLISTVIEW = DllStructCreate( $tagNMLISTVIEW, $lParam )
          $iItem = DllStructGetData( $tNMLISTVIEW, "Item" )
          _GUICtrlListView_SetItemSelected( $hLV, $iItem, False )

          Local $aInfo = GUIGetCursorInfo( $hGui )
          If $aInfo[2] Then
            $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0]-2, $aInfo[1]-2 ) ; Upper left = ( 2, 2 )
            If $aInfo[0] > -1 And $aInfo[1] > -1 And $aInfo[0] = $iItem Then
              If $aHit[0] > -1 Then _
                _GUICtrlListView_RedrawItems( $hLV, $aHit[0], $aHit[0] )
              If $aHit[0] <> $aInfo[0] Or $aHit[1] <> $aInfo[1] Then
                $aHit[0] = $aInfo[0] ; Row
                $aHit[1] = $aInfo[1] ; Col
              Else
                $aHit[0] = -1 ; Row
                $aHit[1] = -1 ; Col
              EndIf
              _GUICtrlListView_RedrawItems( $hLV, $iItem, $iItem )
            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 $dwItemSpec = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ) ; Item index
              Local $iSubItem   = DllStructGetData( $tNMLVCUSTOMDRAW, "iSubItem"   ) ; Subitem index
              Local $uItemState = DllStructGetData( $tNMLVCUSTOMDRAW, "uItemState" ) ; Item state
              If $dwItemSpec = $aHit[0] Then ; Marked row
                Switch $iSubItem
                  Case $aHit[1] ; Marked column
                    DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )      ; Forecolor black
                    DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xFFFF00 )      ; Backcolor cyan, BGR
                  Case Else ; Other columns
                    If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                      DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF )    ; Forecolor white
                      DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 )    ; Backcolor dark blue, BGR
                    Else
                      DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )    ; Forecolor black
                      DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )    ; Backcolor white
                    EndIf
                EndSwitch
              Else ; Other rows
                If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF )
                  DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 )
                Else
                  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

  EndSwitch

  Return $GUI_RUNDEFMSG
EndFunc

Edit: Forgot to take into account that the upper left corner of the listview is ( 2, 2 ) and not ( 0, 0 ). Cleaned up the code.

Edited by LarsJ

Share this post


Link to post
Share on other sites

Multiple cells.

 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
;#include <Array.au3>

Opt( "MustDeclareVars", 1 )

Global $hGui, $hLV

; $aMarkedCells is used to store columns with marked cells. Line (index) in $aMarkedCells is stored in ItemParam. When all
; marks in a row are cleared the line in question in $aMarkedCells can be reused. Line (index) is stored in $aNotUsedLines.
Global $iMarkedCells = 0, $aMarkedCells[10][4] ; Col 3 = number of marked cells per row
Global $iNotUsedLines = 0, $aNotUsedLines[10]

MainFunc()

Func MainFunc()

  $hGui = GUICreate( "Mark Cells in Listview", 250, 222, 300, 300 )

  Local $idLV = GUICtrlCreateListView( "Column 0|Column 1|Column 2", 2, 2, 250-4, 222-4 ), $idx
  $hLV = ControlGetHandle( $hGui, "", $idLV )
  ; ItemParam will be used to keep track of marked cells
  ; Create rows with _GUICtrlListView_AddItem and _GUICtrlListView_AddSubItem
  ; (For rows created with GUICtrlCreateListViewItem ControlID is stored in ItemParam)
  For $i = 0 To 49
    $idx = _GUICtrlListView_AddItem( $hLV, "Cell " & $i & ".0" )
    _GUICtrlListView_AddSubItem( $hLV, $idx, "Cell " & $i & ".1", 1 )
    _GUICtrlListView_AddSubItem( $hLV, $idx, "Cell " & $i & ".2", 2 )
    ;GUICtrlCreateListViewItem( "Cell " & $i & ".0" & "|Cell " & $i & ".1" & "|Cell " & $i & ".2", $idLV )
  Next

  GUIRegisterMsg( $WM_NOTIFY, "WM_NOTIFY" )

  GUISetState()

  While 1
    Switch GUIGetMsg()
      ;Case $GUI_EVENT_SECONDARYDOWN
      ;  _ArrayDisplay( $aMarkedCells, "$aMarkedCells" )
      ;  _ArrayDisplay( $aNotUsedLines, "$aNotUsedLines" )
      Case $GUI_EVENT_CLOSE
        Exit
    EndSwitch
  WEnd

EndFunc

Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam )
  #forceref $hWnd, $iMsg, $wParam
  Local $tNMHDR, $hWndFrom, $iCode
  $tNMHDR = DllStructCreate( $tagNMHDR, $lParam )
  $hWndFrom = HWnd( DllStructGetData( $tNMHDR, "hWndFrom" ) )
  $iCode = DllStructGetData( $tNMHDR, "Code" )

  Switch $hWndFrom

    Case $hLV

      Switch $iCode

        Case $LVN_ITEMCHANGED
          Local $tNMLISTVIEW, $iItem, $iParam, $aInfo
          $tNMLISTVIEW = DllStructCreate( $tagNMLISTVIEW, $lParam )
          $iItem = DllStructGetData( $tNMLISTVIEW, "Item" )
          $iParam = DllStructGetData( $tNMLISTVIEW, "Param" )
          _GUICtrlListView_SetItemSelected( $hLV, $iItem, False )

          $aInfo = GUIGetCursorInfo( $hGui )
          If $aInfo[2] Then
            $aInfo = _GUICtrlListView_SubItemHitTest( $hLV, $aInfo[0]-2, $aInfo[1]-2 ) ; Upper left = ( 2, 2 )
            If $aInfo[0] > -1 And $aInfo[1] > -1 And $aInfo[0] = $iItem Then
              If Not $iParam Then
                ; First mark in row
                Local $idxMarkedCells
                If $iNotUsedLines Then ; Unused lines in $aMarkedCells?
                  $idxMarkedCells = $aNotUsedLines[$iNotUsedLines-1]
                  $iNotUsedLines -= 1
                Else ; Allocate a new line in $aMarkedCells?
                  $idxMarkedCells = $iMarkedCells
                  $iMarkedCells += 1
                  If Mod( $iMarkedCells, 10 ) = 0 Then _
                    ReDim $aMarkedCells[$iMarkedCells+10][4]
                EndIf
                $aMarkedCells[$idxMarkedCells][3] = 1
                $aMarkedCells[$idxMarkedCells][$aInfo[1]] = 1
                _GUICtrlListView_SetItemParam( $hLV, $iItem, $idxMarkedCells + 1 )
              Else
                $iParam -= 1
                If Not $aMarkedCells[$iParam][$aInfo[1]] Then
                  ; Add mark in row
                  $aMarkedCells[$iParam][$aInfo[1]] = 1
                  $aMarkedCells[$iParam][3] += 1
                Else
                  ; Del mark in row
                  $aMarkedCells[$iParam][$aInfo[1]] = 0
                  $aMarkedCells[$iParam][3] -= 1
                  If Not $aMarkedCells[$iParam][3] Then
                    _GUICtrlListView_SetItemParam( $hLV, $iItem, 0 )
                    ; When all marks in a row are cleared store the line (index) from $aMarkedCells in
                    ; $aNotUsedLines. This line can be reused to store marks in another row in the LV.
                    $aNotUsedLines[$iNotUsedLines] = $iParam
                    $iNotUsedLines += 1
                    If Mod( $iNotUsedLines, 10 ) = 0 Then _
                      ReDim $aNotUsedLines[$iNotUsedLines+10]
                  EndIf
                EndIf
              EndIf
              _GUICtrlListView_RedrawItems( $hLV, $iItem, $iItem )
            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 = DllStructGetData( $tNMLVCUSTOMDRAW, "lItemlParam" ) ; Item param
              Local $iSubItem    = DllStructGetData( $tNMLVCUSTOMDRAW, "iSubItem"   )  ; Subitem index
              Local $uItemState  = DllStructGetData( $tNMLVCUSTOMDRAW, "uItemState" )  ; Item state
              If $lItemlParam Then ; Marked row
                If $aMarkedCells[$lItemlParam-1][$iSubItem] Then ; Marked column
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )          ; Forecolor black
                  If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                    DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0x00FFFF )        ; Backcolor yellow, BGR
                  Else
                    DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xFFFF00 )        ; Backcolor cyan, BGR
                  EndIf
                Else ; Other columns
                  If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                    DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF )        ; Forecolor white
                    DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 )        ; Backcolor dark blue, BGR
                  Else
                    DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0x000000 )        ; Forecolor black
                    DllStructSetData( $tNMLVCUSTOMDRAW, "ClrTextBk", 0xFFFFFF )        ; Backcolor white
                  EndIf
                EndIf
              Else ; Other rows
                If BitAnd( $uItemState, $CDIS_FOCUS ) Then ; Selected row
                  DllStructSetData( $tNMLVCUSTOMDRAW, "ClrText",   0xFFFFFF )
                  DllStructSetData( $tNMLVCUSTOMDRAW, "clrTextBk", 0xCC6600 )
                Else
                  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

  EndSwitch

  Return $GUI_RUNDEFMSG
EndFunc

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?
    • OtenMoten
      By OtenMoten
      Hello dear community,
       
      definitely I need external help now. I've did all 'ControlClick() - Tutorials' and read a lot of topics about interaction betweend AutoIT and external programs.
      The most of them are about "Clicking a button ...". In my case it's different because I need to click a specific element within the program.
       
      The 'program' what I am talking about is called Mendeley. It's library software for documents administration.
       
      In the attachements in picture '1.jpg' you can see the red marked Help element. 
      In the picture '2.jpg' you see the context menu of the Help element. This is what I'm trying to do with the ControlClick() function.
       
      Following I represent my code which not worked for me:
      #include <MsgBoxConstants.au3> Opt("WinTitleMatchMode", 2) $hWnd = WinGetHandle("Mendeley Desktop", "") MsgBox($MB_SYSTEMMODAL, "handle check", $hWnd) ControlClick($hWnd, "Mendeley Desktop", "Help") The MsgBox tells me the number of the handle of the Mendeley window. It's not 0 so for me it means the window is recognized correctly.
       
      When I'm execute the script the Help element is not clicked.
      Any suggestions for me?
       
      Kind regards
      OtenMoten


    • 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  
    • boy233
      By boy233
      I need to click on the text "Batch submission" but I can not!
      <div class="batchmenu2" onclick="Go('/lot/')" style="background-color: rgb(255, 255, 255);"> <span class="iconep">l</span> <div class="menu"> <b>Batch submission</b> <br> Bulk messages via file </div> </div> How could I do it?
      How can I click the specific OnClick?
       
    • 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