Jump to content

GUIListViewEx - New Version 26 Feb 24


Melba23
 Share

Recommended Posts

  • Moderators

supersonic,

Glad it works for you, And this change will most certainly be included when I release a new version of the UDF - probably very soon.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple 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

 

Link to comment
Share on other sites

  • Moderators

[BUGFIX VERSION] - 26 Apr 19

Fixed:

The first attempt to edit an editable combo did not function correctly.

New UDF in zip in first post.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple 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

 

Link to comment
Share on other sites

  • 2 weeks later...

I'm starting with a tool for some collaborative planning between teams (scheduling script), hopefully a MRP (material resource planning) as exposed here.

First tab would be 5 multiline listviews to get a view of a week planning (data from a database).

The other tabs are listviews using the UDF, with data about resources and dates. Here the collaborative part is editing data from different users (teams).

The example code below is only a sketch of the idea, and there seems to be no conflicts between the basic 'blocks' i'd like to use: the GUIListViewEx UDF, some tabs and this "Ownerdrawn multiline ListView" by rover:

 

;https://www.autoitscript.com/forum/topic/139314-custom-listview-icons-checkboxes-multiline-edit-in-place/?do=findComment&comment=980443
;rover, April 19, 2012 (edited)
;coded by rover 2k12
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>

#include <GUIListViewEx.au3>

Opt("GUIDataSeparatorChar", "|")

Global Const $ODA_SELECT = 0x2
Global Const $ODA_FOCUS = 0x4
Global Const $ODS_SELECTED = 0x0001
Global Const $ODT_LISTVIEW = 102
Global Const $ODA_DRAWENTIRE = 0x1

Global $iDllGDI = DllOpen("gdi32.dll")
Global $iDllUSER32 = DllOpen("user32.dll")
Global $iDllUxtheme = DllOpen("uxtheme.dll")

;global resources for WM_DRAWITEM - optimize speed
Global $aFont[2]
$aFont[0] = _WinAPI_CreateFont(16, 0, 0, 0, $FW_HEAVY, False, False, False, _
        $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, $DEFAULT_PITCH, 'Calibri')
$aFont[1] = _WinAPI_CreateFont(16, 0, 0, 0, $FW_MEDIUM, False, False, False, _
        $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, $DEFAULT_PITCH, 'Calibri')

Global $hPen1 = _WinAPI_CreatePen($PS_SOLID, 1, 0xF3EAE7)
Global $hPen2 = _WinAPI_CreatePen($PS_SOLID, 1, 0xF4E8E6)
Global $hBrush = _WinAPI_CreateSolidBrush(0xEEDDBB)

;Theme Parts and States
;http://msdn.microsoft.com/en-us/library/windows/desktop/bb773210%28v=vs.85%29.aspx
;Part - vsstyle.h
Global Const $BP_PUSHBUTTON = 1
Global Const $LVP_GROUPHEADER = 6
;State - vsstyle.h
Global Enum $PBS_NORMAL=1,$PBS_HOT,$PBS_PRESSED,$PBS_DISABLED,$PBS_DEFAULTED
Global Enum $LVGH_CLOSEHOT=10,$LVGH_CLOSESELECTED,$LVGH_CLOSESELECTEDHOT,$LVGH_CLOSESELECTEDNOTFOCUSED

;this allows you to theme individual items for your own needs, not just if items are selected
;the same as customdrawing item and subitem colours
;XP+
Global $sTheme = 'Button'
Global $iThemePart = $BP_PUSHBUTTON
Global $iThemeState = $PBS_NORMAL

; Vista+
;Global $sTheme = 'Listview'
;Global $iThemePart = $LVP_GROUPHEADER
;Global $iThemeState = $LVGH_CLOSEMIXEDSELECTION

Global $hTheme = DllCall($iDllUxtheme, 'ptr', 'OpenThemeData', 'hwnd', 0, 'wstr', $sTheme)
$hTheme = $hTheme[0]

;global structs for WM_DRAWITEM - optimize speed
;rect, text buffer and LVITEM structures
Global $tLVRect = DllStructCreate($tagRECT)
Global $tLVText = DllStructCreate("wchar[4096]")
Global $tLVITEM = DllStructCreate($tagLVITEM)
Global $pLVITEM = DllStructGetPtr($tLVITEM)
DllStructSetData($tLVITEM, "TextMax", 4096)
DllStructSetData($tLVITEM, "SubItem", 0)
DllStructSetData($tLVITEM, "Text", DllStructGetPtr($tLVText))

; WM_MEASUREITEM allows setting the row height
Global $iListView_row_height = 130
Global $hListView_1, $hListView_2 ;must be declared before listview created
GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ; place before listview creation - message sent once for each ownerdrawn control created
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") ;placed here, WM_MEASUREITEM can now be unregistered in the handler (deleting or adding items after unregistering maintains row height setting this way)
; ---------------------------------------------------

Global $GuiWidth = @DesktopWidth-2, $GuiHight = @DesktopHeight-77

$hGUI = GUICreate("Ownerdrawn multiline ListView", $GuiWidth, $GuiHight)

$cTab = GUICtrlCreateTab(2, 2, $GuiWidth - 8, $GuiHight - 30)

$cTab_0 = GUICtrlCreateTabItem("Tab 0")

$cListView_1 = GUICtrlCreateListView("", 8, 32, 320, $GuiHight-112, BitOR($LVS_REPORT, $LVS_NOCOLUMNHEADER, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS))
$hListView_1 = GUICtrlGetHandle($cListView_1)
_GUICtrlListView_SetExtendedListViewStyle($hListView_1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT)) ;double buffer improves performance
_GUICtrlListView_AddColumn($hListView_1, "", 298)

GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ; place before listview creation - message sent once for each ownerdrawn control created

$cListView_2 = GUICtrlCreateListView("", 330, 32, 320, $GuiHight-112, BitOR($LVS_REPORT, $LVS_NOCOLUMNHEADER, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS))
$hListView_2 = GUICtrlGetHandle($cListView_2)
_GUICtrlListView_SetExtendedListViewStyle($hListView_2, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT)) ;double buffer improves performance
_GUICtrlListView_AddColumn($hListView_2, "", 298)

Global $aTextHdr[4] = ["From:", "Sent:", "To:", "Subject:"]
For $row = 1 To 10
    _GUICtrlListView_AddItem($hListView_1, "Rover - AutoIt Forums|Thursday, April 19, 2012 05:0" & $row - 1 & "AM|footswitch|Re: Multiline listview like Outlook|" & _
            "This is a rough mock-up of that Outlook listview" & @CRLF & "You will need to add code for the text metrics")

    _GUICtrlListView_AddItem($hListView_2, "Rover - AutoIt Forums|Thursday, April 19, 2012 05:0" & $row - 1 & "AM|footswitch|Re: Multiline listview like Outlook|" & _
            "This is a rough mock-up of that Outlook listview" & @CRLF & "You will need to add code for the text metrics")
Next

;~ ;adjust listview size for number of items shown - for efficient painting and to eliminate issue of a click on bottom item causing a jump to next item
;~ Local $iY = _GUICtrlListView_ApproximateViewHeight($hListView_1, _GUICtrlListView_GetCounterPage($hListView_1))
;~ GUICtrlSetPos($cListView_1, 2, 2, 328, $iY + 4)
;~ GUICtrlSetPos($cListView_2, 332, 2, 328, $iY + 4)

;~ Global $cSelect = GUICtrlCreateButton("Themed Select", 2, $iY + 8, 120, 23)
;~ Global $cTheme = GUICtrlCreateCombo("Button", 120+2, $iY + 9, 60)
;~ GUICtrlSetData(-1, "Listview", "Button")
;~ Global $cState = GUICtrlCreateCombo("1 NORMAL", 180+4, $iY + 9, 80)
;~ GUICtrlSetData(-1, "2 HOT|3 PRESSED|4 GREYED|5 DEFAULT", "1 NORMAL")
;~ Global $cLabel =  GUICtrlCreateLabel("Select Item"&@CRLF&"Style", 260+8, $iY + 8)

Global $Label = GUICtrlCreateLabel("Selected: ", 654, 32, 500, 300)
GUICtrlSetFont(-1, 11, Default, Default, "Segoe UI")

#cs
;Now trying to detect the index of highlighted item in the multiline ListView
;From 'A Beginner’s Guide To Melba23’s GUIListViewEx UDF':
The UDF registers these 4 messages automatically – if you already have handlers for these messages in your script,

do not register them again using the UDF function (set the relevant parameter of _GUIListViewEx_MsgRegister to False)
but call the relevant UDF handler function (_GUIListViewEx_WM_NOTIFY_Handler) from within your existing handler.
Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler
#ce
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
;~ ;prevent the UDF from initially registering the WM_NOTIFY
;~ _GUIListViewEx_MsgRegister(False)

$cTab_1 = GUICtrlCreateTabItem("Tab 1")

$cLV = GUICtrlCreateListView("Col 0|Col 1", 8, 32, 350, 300)

_GUICtrlListView_SetColumnWidth($cLV, 0, 250)
_GUICtrlListView_SetColumnWidth($cLV, 1, 550) ; Column wider than ListView <<<<<<<<<<<<<<<<<<<<<<<<<<<

Global $aContent[5]
For $i = 0 To 4
    $aContent[$i] = "Item " & $i & "-0|Item " & $i & "-1"
    GUICtrlCreateListViewItem($aContent[$i], $cLV)
Next

$iLV_Index = _GUIListViewEx_Init($cLV, $aContent)

_GUIListViewEx_SetEditStatus($iLV_Index, "1") ; Wide column editable <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$cTab_2 = GUICtrlCreateTabItem("Tab 2")

; Create ListView
Global $cListView_Left = GUICtrlCreateListView("Tom|Dick|Harry", 8, 32, 300, 300, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($cListView_Left, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_SetColumnWidth($cListView_Left, 0, 93)
_GUICtrlListView_SetColumnWidth($cListView_Left, 1, 93)
_GUICtrlListView_SetColumnWidth($cListView_Left, 2, 93)

; Create ListView
Global $cListView_Right = GUICtrlCreateListView("Tom|Dick|Harry", 320, 32, 300, 300, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($cListView_Right, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_SetColumnWidth($cListView_Right, 0, 93)
_GUICtrlListView_SetColumnWidth($cListView_Right, 1, 93)
_GUICtrlListView_SetColumnWidth($cListView_Right, 2, 93)

; Create array and fill Left listview
Global $aLV_List[10]
For $i = 0 To UBound($aLV_List) - 1
    $aLV_List[$i] = "Tom " & $i & "|Dick " & $i & "|Harry " & $i
    GUICtrlCreateListViewItem($aLV_List[$i], $cListView_Left)
    GUICtrlCreateListViewItem($aLV_List[$i], $cListView_Right)
Next

; Initiate LVEx
;Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting
Global $iLV_Index_Left = _GUIListViewEx_Init($cListView_Left, $aLV_List)
_GUIListViewEx_SetEditStatus($iLV_Index_Left, "*")
$iLV_Index_Right = _GUIListViewEx_Init($cListView_Right, $aLV_List)
_GUIListViewEx_SetEditStatus($iLV_Index_Right, "*")

GUICtrlCreateTabItem("")

_GUIListViewEx_SetActive($iLV_Index_Left)

; Register for sorting, dragging and editing
_GUIListViewEx_MsgRegister(False)


GUISetState()

;~ ;Select multiple items
;~ _GUICtrlListView_SetItemSelected($cListView_1, 1)
;~ _GUICtrlListView_SetItemSelected($cListView_1, 2)
;~ MsgBox(0, "Information", "Selected Indices: " & _GUICtrlListView_GetSelectedIndices($cListView_1))

;~ ;Show item 2 text
;~ $aItem = _GUICtrlListView_GetItem($cListView_1, 1)
;~ MsgBox(0, "Information", "Item 2 Text: " & $aItem[3])

; Loop until user exits
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
;~         Case $cTheme
;~             DllCall($iDllUxtheme, 'uint', 'CloseThemeData', 'ptr', $hTheme)
;~             Switch GUICtrlRead($cTheme)
;~                 Case "Button"
;~                     $sTheme = "Button"
;~                     $iThemePart = $BP_PUSHBUTTON
;~                     GUICtrlSetData($cState, "|1 NORMAL|2 HOT|3 PRESSED|4 GREYED|5 DEFAULT", "1 NORMAL")
;~                 Case "Listview"
;~                     $sTheme = "Listview"
;~                     $iThemePart = $LVP_GROUPHEADER
;~                     GUICtrlSetData($cState, "|10|11|12|13", "11")
;~             EndSwitch
;~             $hTheme = DllCall($iDllUxtheme, 'ptr', 'OpenThemeData', 'hwnd', 0, 'wstr', GUICtrlRead($cTheme))
;~             $hTheme = $hTheme[0]
;~             $iThemeState = Number(StringLeft(GUICtrlRead($cState), 2))
;~             _WinAPI_InvalidateRect($hListView_1)
;~         Case $cState
;~          $iThemeState = Number(StringLeft(GUICtrlRead($cState), 2))
;~             _WinAPI_InvalidateRect($hListView_1)
;~         Case $cSelect
;~             If Not $hTheme Then
;~                 GUICtrlSetData($cSelect, "Themed Select")
;~                 $hTheme = DllCall($iDllUxtheme, 'ptr', 'OpenThemeData', 'hwnd', 0, 'wstr', $sTheme)
;~                 $hTheme = $hTheme[0]
;~             Else
;~                 GUICtrlSetData($cSelect, "Unthemed Select")
;~                 DllCall($iDllUxtheme, 'uint', 'CloseThemeData', 'ptr', $hTheme)
;~                 $hTheme = 0
;~             EndIf
;~             _WinAPI_InvalidateRect($hListView_1)
    EndSwitch

    $vRet = _GUIListViewEx_EventMonitor()
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error)
    EndIf
    Switch @extended
        Case 1 ; This is returned after an edit attempt
            If $vRet = "" Then
                MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF)
            Else
                MsgBox($MB_SYSTEMMODAL, "Edit", "Successful edit" & @CRLF)
            EndIf
        Case 9 ; This is returned after a selection change
            MsgBox($MB_SYSTEMMODAL, "Selection changed", "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
    EndSwitch
WEnd
GUIDelete()
DllCall($iDllUxtheme, 'uint', 'CloseThemeData', 'ptr', $hTheme)
_WinAPI_DeleteObject($hPen1)
_WinAPI_DeleteObject($hPen2)
_WinAPI_DeleteObject($hBrush)
For $i = 0 To UBound($aFont) - 1
    If $aFont[$i] Then _WinAPI_DeleteObject($aFont[$i])
Next
Exit

;From: Melba23: Detect item checking
;https://www.autoitscript.com/forum/topic/182492-guilistviewex-new-version-27-may-16/?do=findComment&comment=1325933
;But you do not need to add this to the UDF code
;just create your own handler as below, do not register $WM_NOTIFY using the UDF function
;(set the relevant parameter of _GUIListViewEx_MsgRegister to False)
;and then call the UDF handler function (_GUIListViewEx_WM_NOTIFY_Handler) from within your own handler.
Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

   Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $hTemp, $nLV
   $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
   $hWndFrom = HWnd(DllStructGetData($tNMHDR, "HwndFrom"))
   $iCode = DllStructGetData($tNMHDR, "Code")

   $hTemp = Int(DllStructGetData($tNMHDR, 1))
   If $hTemp = $hListView_1 Then
      $hWndListView = $hListView_1
      $nLV = 1
   ElseIf $hTemp = $hListView_2 Then
      $hWndListView = $hListView_2
      $nLV = 2
   EndIf

   Switch $hWndFrom
     Case $hWndListView
         Switch $iCode
             Case $LVN_ITEMCHANGED
                 Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                 Local $iItem = DllStructGetData($tInfo, "Item")

                  ;From Zedna, in 'Highlighted item in the ListView?'
                  ;https://www.autoitscript.com/forum/topic/96234-highlighted-item-in-the-listview/?do=findComment&comment=691927
                 ;if state has changed
                 If BitAND(DllStructGetData($tInfo, "Changed"), $LVIF_STATE) = $LVIF_STATE And DllStructGetData($tInfo, "NewState") <> DllStructGetData($tInfo, "OldState") Then
                     ;take care of only newly selected items (not deselected ones)
                     If BitAND(DllStructGetData($tInfo, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED Then
                        ConsoleWrite(_GUICtrlListView_GetItemText($hWndListView, $iItem) & @CRLF)
                        ;Help File
                        ;Local $aItem = _GUICtrlListView_GetItem($hWndListView, $iItem)
                        ;MsgBox($MB_SYSTEMMODAL, "Information", $aItem[3])
                        GUICtrlSetData($Label, "Selected " & $nLV & ": " & _GUICtrlListView_GetItemText($hWndListView, $iItem))
                        ;Help File
                        ;Local $aItem = _GUICtrlListView_GetItem($hListView, $iItem)
                        ;MsgBox(0, "Information", $aItem[3])

                     EndIf
                 EndIf
             Case $NM_DBLCLK
               Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
               $Index = DllStructGetData($tInfo, "Index")
               If DllStructGetData($tInfo, "Index") = -1 Then
                  ConsoleWrite("no item" & @CRLF)
               Else
                  Local $iItemText = _GUICtrlListView_GetItemText($hWndListView, $Index)
                  ConsoleWrite("Dbclick item " & $iItemText & @CRLF)
                  GUICtrlSetData($Label, $nLV & " " & "Dbclick item " & $iItemText)
               EndIf
         EndSwitch
   EndSwitch

   ;Return $GUI_RUNDEFMSG
   ;From Melba23: pass the same parameters to the UDF handler as you received in your WM_NOTIFY handler:
   ;Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler
   _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $Msg, $wParam, $lParam)
EndFunc

Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tMEASUREITEMS = DllStructCreate("uint cType;uint cID;uint itmID;uint itmW;uint itmH;ulong_ptr itmData", $lParam)
    If DllStructGetData($tMEASUREITEMS, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    DllStructSetData($tMEASUREITEMS, "itmH", $iListView_row_height) ; row height
    GUIRegisterMsg($WM_MEASUREITEM, "") ; unregister message handler call this after last ownerdrawn listview created - message no longer sent
    Return 1
EndFunc   ;==>WM_MEASUREITEM

Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC
    $tDRAWITEMSTRUCT = DllStructCreate( _
            "uint cType;" & _
            "uint cID;" & _
            "uint itmID;" & _
            "uint itmAction;" & _
            "uint itmState;" & _
            "hwnd hItm;" & _
            "handle hDC;" & _
            "long itmRect[4];" & _
            "ulong_ptr itmData" _
            , $lParam)
    If DllStructGetData($tDRAWITEMSTRUCT, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    $cID = DllStructGetData($tDRAWITEMSTRUCT, "cID")
    $itmID = DllStructGetData($tDRAWITEMSTRUCT, "itmID")
    $itmAction = DllStructGetData($tDRAWITEMSTRUCT, "itmAction")
    $itmState = DllStructGetData($tDRAWITEMSTRUCT, "itmState")
    $hItm = DllStructGetData($tDRAWITEMSTRUCT, "hItm")
    $hDC = DllStructGetData($tDRAWITEMSTRUCT, "hDC")
    Switch $cID ; will look for ControlID, not window handle.
        Case $cListView_1, $cListView_2
            Switch $itmAction
            Case $ODA_DRAWENTIRE
                    __WM_DRAWITEM_ListView($hItm, $tDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hDC)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM

Func __WM_DRAWITEM_ListView(ByRef $hLV, ByRef $tDRAWITEMSTRUCT, ByRef $cID, ByRef $itmID, ByRef $itmAction, ByRef $itmState, ByRef $hDC)
    Local $iTxtCol, $bSelected = BitAND($itmState, $ODS_SELECTED), $iTextFormatting = BitOR($DT_LEFT, $DT_WORDBREAK)
    If Not $bSelected Then
        $iTxtCol = 0xB79588
    Else ;selected
        $iTxtCol = 0x494949
        ;Theme Parts and States
        ;http://msdn.microsoft.com/en-us/library/windows/desktop/bb773210%28v=vs.85%29.aspx
        Local $pItemRect = DllStructGetPtr($tDRAWITEMSTRUCT, "itmRect")
        If $hTheme Then
            If $sTheme = "Listview" Then
                Local $tItemRect = DllStructCreate($tagRect, $pItemRect)
                    DllStructSetData($tItemRect, 1, DllStructGetData($tItemRect, 1)+1)
                    DllStructSetData($tItemRect, 2, DllStructGetData($tItemRect, 2)+1)
                    DllStructSetData($tItemRect, 3, DllStructGetData($tItemRect, 3)-1)
                    DllStructSetData($tItemRect, 4, DllStructGetData($tItemRect, 4)-1)
                $pItemRect = DllStructGetPtr($tItemRect)
            EndIf
            DllCall($iDllUxtheme, 'uint', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hDC, 'int', $iThemePart, 'int', $iThemeState, 'ptr', $pItemRect, 'ptr', 0)
        Else
            DllCall($iDllUSER32, "int", "FillRect", "handle", $hDC, "ptr", DllStructGetPtr($tDRAWITEMSTRUCT, "itmRect"), "handle", $hBrush)
        EndIf
    EndIf
    GUICtrlSendMsg($cID, $LVM_GETITEMTEXTW, $itmID, $pLVITEM)
    Local $aSubItmText = StringSplit(DllStructGetData($tLVText, 1), "|", 2)
    DllStructSetData($tLVText, 1, "")
    DllStructSetData($tLVRect, "Top", 0)
    DllStructSetData($tLVRect, "Left", $LVIR_BOUNDS)
    GUICtrlSendMsg($cID, $LVM_GETSUBITEMRECT, $itmID, DllStructGetPtr($tLVRect))
    Local $iLeft = DllStructGetData($tLVRect, 1) + 6 ;Left
    Local $iTop = DllStructGetData($tLVRect, 2) ;Top
    DllStructSetData($tLVRect, 1, $iLeft) ;Left

    Switch $hLV
        Case $hListView_1, $hListView_2
            Local $iColPrev = __WinAPI_SetTextColor($hDC, 0x000000) ;save previous font and text colour
            Local $hFontOld = __WinAPI_SelectObject($hDC, $aFont[0]) ;Bold

            ;------------------------------------------------------------
            ;multiline, but no per line indentation or colour
            ;DllStructSetData($tLVRect, 2, $iTop+2)
            ;__WinAPI_DrawText($hDC, "From:"&@CRLF&"Sent:"&@CRLF&"To:"&@CRLF&"Subject:", $tLVRect, $iTextFormatting)
            ;------------------------------------------------------------

            DllStructSetData($tLVRect, 2, $iTop + 2)
            __WinAPI_DrawText($hDC, $aTextHdr[0], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 2, $iTop + 20)
            __WinAPI_DrawText($hDC, $aTextHdr[1], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 2, $iTop + 38)
            __WinAPI_DrawText($hDC, $aTextHdr[2], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 2, $iTop + 56)
            __WinAPI_DrawText($hDC, $aTextHdr[3], $tLVRect, $iTextFormatting)


            __WinAPI_SelectObject($hDC, $aFont[1]) ;Normal

            ;------------------------------------------------------------
            ;multiline, but no per line indentation or colour
            ;__WinAPI_SetTextColor($hDC, 0x494949)
            ;DllStructSetData($tLVRect, 1, $iLeft+50)
            ;DllStructSetData($tLVRect, 2, $iTop+2)
            ;__WinAPI_DrawText($hDC, $aSubItmText[0]&@CRLF&$aSubItmText[1]&@CRLF&$aSubItmText[2]&@CRLF&$aSubItmText[3], $tLVRect, $iTextFormatting)
            ;------------------------------------------------------------

            __WinAPI_SetTextColor($hDC, 0xFF0000)

            DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[0]) + 5)
            DllStructSetData($tLVRect, 2, $iTop + 2)
            __WinAPI_DrawText($hDC, $aSubItmText[0], $tLVRect, $iTextFormatting)

            __WinAPI_SetTextColor($hDC, 0x494949)

            DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[1]) + 5)
            DllStructSetData($tLVRect, 2, $iTop + 20)
            __WinAPI_DrawText($hDC, $aSubItmText[1], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[2]) + 5)
            DllStructSetData($tLVRect, 2, $iTop + 38)
            __WinAPI_DrawText($hDC, $aSubItmText[2], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[3]) + 5)
            DllStructSetData($tLVRect, 2, $iTop + 56)
            __WinAPI_DrawText($hDC, $aSubItmText[3], $tLVRect, $iTextFormatting)

            __WinAPI_SetTextColor($hDC, $iTxtCol)
            DllStructSetData($tLVRect, 1, $iLeft + 2)
            DllStructSetData($tLVRect, 2, $iTop + 80)
            __WinAPI_DrawText($hDC, $aSubItmText[4], $tLVRect, $iTextFormatting)

            If $bSelected And $hTheme Then Return ;optional - don't paint lines when item selected - in this example only for benefit of themed selected items

            Local $obj_orig = __WinAPI_SelectObject($hDC, $hPen1)
            __WinAPI_DrawLine($hDC, $iLeft, DllStructGetData($tLVRect, 4) - 2, 320 - ($iLeft * 2) - 16, DllStructGetData($tLVRect, 4) - 2)
            __WinAPI_SelectObject($hDC, $hPen2)
            __WinAPI_DrawLine($hDC, $iLeft, DllStructGetData($tLVRect, 4) - 3, 320 - ($iLeft * 2) - 16, DllStructGetData($tLVRect, 4) - 3)
            __WinAPI_SelectObject($hDC, $obj_orig)

            ;__WinAPI_SelectObject($hDC, $hFontOld)
            ;__WinAPI_SetTextColor($hDC, $iColPrev)
    EndSwitch
    Return
EndFunc   ;==>__WM_DRAWITEM_ListView

Func __WinAPI_DrawLine($hDC, $iX1, $iY1, $iX2, $iY2)
    DllCall($iDllGDI, "bool", "MoveToEx", "handle", $hDC, "int", $iX1, "int", $iY1, "ptr", 0)
    If @error Then Return SetError(@error, @extended, False)
    DllCall($iDllGDI, "bool", "LineTo", "handle", $hDC, "int", $iX2, "int", $iY2)
    If @error Then Return SetError(@error, @extended, False)
    Return True
EndFunc   ;==>__WinAPI_DrawLine

Func __WinAPI_DrawText(ByRef $hDC, $sText, ByRef $tRect, ByRef $iFlags)
    DllCall($iDllUSER32, "int", "DrawTextW", "hwnd", $hDC, "wstr", $sText, "int", StringLen($sText), "struct*", $tRect, "int", $iFlags)
EndFunc   ;==>__WinAPI_DrawText

Func __WinAPI_SetTextColor($hDC, $iColor)
    Local $aResult = DllCall($iDllGDI, "INT", "SetTextColor", "handle", $hDC, "dword", $iColor)
    If @error Then Return SetError(@error, @extended, -1)
    Return $aResult[0]
EndFunc   ;==>__WinAPI_SetTextColor

Func __WinAPI_SelectObject($hDC, $hGDIObj)
    Local $aResult = DllCall($iDllGDI, "handle", "SelectObject", "handle", $hDC, "handle", $hGDIObj)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc   ;==>__WinAPI_SelectObject

Func __GUICtrlListView_GetStringWidth($hWnd, $sString)
    Local $tBuffer = DllStructCreate("wchar Text[" & StringLen($sString) + 1 & "]")
    DllStructSetData($tBuffer, "Text", $sString)
    Local $iRet = GUICtrlSendMsg($hWnd, $LVM_GETSTRINGWIDTHW, 0, DllStructGetPtr($tBuffer))
    Return $iRet
EndFunc   ;==>__GUICtrlListView_GetStringWidth

 

Edited by robertocm
Link to comment
Share on other sites

  • Moderators

robertocm,

Is there an actual question in there?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple 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

 

Link to comment
Share on other sites

  • Moderators

ocm,

Fine - delighted it all works happily together.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple 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

 

Link to comment
Share on other sites

  • 1 month later...

Dear Melba23,

I'm having difficuties integrating these features:

- colours and single cell selection

- message handler for WM_NOTIFY

Below is what i'm trying. Please see this commented lines:

_GUIListViewEx_MsgRegister(False)  ;<<<< OK GET DATE ON TAB KEY, BUT NO COLORS, NO SINGLE CELL SELECTION
;_GUIListViewEx_MsgRegister()  ;<<<< OK COLORS, OK SINGLE CELL SELECTION, NO DATE ON TAB KEY
#include <GuiConstants.au3>
#include "GUIListViewEx.au3"

Opt( "MustDeclareVars", 1 )

;from Melba23 GUIListViewEx
Global $cLV, $iLV, $vRet, $Row, $Col, $EditMode = 22
Global $vRet, $Row, $Col, $EditMode = 22
;https://www.autoitscript.com/forum/topic/182492-guilistviewex-bugfix-version-25-sep-17/?do=findComment&comment=1370017
;Melba 23, Oct 2017
;... and a right-click menu to select the colour of another column (1) of the selected row.
Global  $iDarkSlateGray = "0x2F4F4F", _
        $iLtBlue = "0xCCCCFF", _
        $iGreen = "0x00FF00", _
        $iBlack = "0x000000", _
        $iWheat = "0xF5DEB3", _
        $iBlue = "0x0000FF", _
        $iLightBlue = "0xADD8E6"

Global $rstArray, $rstCount_1, $rstCount_2, $aColArBand[1][1]
Global $GuiWidth = @DesktopWidth-2, $GuiHight = @DesktopHeight-77

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

Global $hGui = GUICreate("Example", $GuiWidth, $GuiHight)

Global $iDate = GUICtrlCreateDate("", 8, 2, 120, 27, 0x00)
GUICtrlSetFont(-1, 10)

;argumentum, Nov 2017
;https://www.autoitscript.com/forum/topic/191058-datetime-pick-coloring/
Global $g_hDTP = GUICtrlGetHandle($iDate)
;Adapted: robertocm, May 2018
;https://www.autoitscript.com/forum/topic/159764-reading-gui-date-control-instantly/?do=findComment&comment=1428050

$cLV = GUICtrlCreateListView("F0|F1|F2|F3", 2, 35, $GuiWidth-4, $GuiHight-60) ;752
_GUICtrlListView_SetExtendedListViewStyle($cLV, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
GUICtrlSetFont($cLV, 9, Default, Default, "Segoe UI") ; Note edit control will use same font

_GUICtrlListView_SetColumnWidth($cLV, 0, 27)
_GUICtrlListView_SetColumnWidth($cLV, 1, 180)
_GUICtrlListView_SetColumnWidth($cLV, 2, 140)
_GUICtrlListView_SetColumnWidth($cLV, 3, 65)

; Create array and fill listview
Global $rstArray[10][4]
$rstCount_1 = Ubound($rstArray)
$rstCount_2 = Ubound($rstArray, 2)
For $i = 0 To $rstCount_1 - 1
   For $j = 0 To $rstCount_2 - 1
      $rstArray[$i][$j] =  "SubItem " & $i & "-" & $j
   Next
Next

;Load the ListView with data
_GUICtrlListView_AddArray($cLV, $rstArray)

;Melba23
;Set array to give alternate line colouring
ReDim $aColArBand[$rstCount_1][$rstCount_2]
For $i = 0 To $rstCount_1 - 1
   If Mod($i,2) = 0 Then
      For $j = 0 To $rstCount_2 - 1
         $aColArBand[$i][$j] = ";0xFFFFFF"
      Next
   Else
      For $j = 0 To $rstCount_2 - 1
         $aColArBand[$i][$j] = ";0xE6E6E6"
      Next
   EndIf
Next
;Initiate LVEx - using filling array - user colours
;Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting
$iLV = _GUIListViewEx_Init($cLV, $rstArray, 0, 0, False, 1 + 4 + 32 + 1024)

;Load the required ListView colour array
_GUIListViewEx_LoadColour($iLV, $aColArBand)
;Set editable columns
_GUIListViewEx_SetEditStatus($iLV, "1-3")

#cs
Melba 23
From 'A Beginner’s Guide To Melba23’s GUIListViewEx UDF':
The UDF registers these 4 messages automatically – if you already have handlers for these messages in your script,
do not register them again using the UDF function (set the relevant parameter of _GUIListViewEx_MsgRegister to False)
but call the relevant UDF handler function (_GUIListViewEx_WM_NOTIFY_Handler) from within your existing handler.
Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler
#ce
;prevent the UDF from initially registering the WM_NOTIFY
;Register for sorting, dragging and editing
;Register required message BEFORE any colour actions (register for sorting, dragging and editing)
;If colours used then this function must be run BEFORE GUISetState
;If message handlers already registered, then call the relevant handler function from within that handler

_GUIListViewEx_MsgRegister(False)  ;<<<< OK GET DATE ON TAB KEY, BUT NO COLORS, NO SINGLE CELL SELECTION
;_GUIListViewEx_MsgRegister()  ;<<<< OK COLORS, OK SINGLE CELL SELECTION, NO DATE ON TAB KEY

;Set deafult colours to use
Global $aDefCols[4] = ["0x000000", "0xFEFEFE", "0xFFFFFF", "0x778899"]
;Sets default colours for user colour/single cell select enabled ListViews
_GUIListViewEx_SetDefColours($iLV, $aDefCols)

GUISetState(@SW_SHOW)

Local $iMsg
While 1
   $iMsg = GUIGetMsg()
   Switch $iMsg
      Case $GUI_EVENT_CLOSE
         Exit
   EndSwitch

   $vRet = _GUIListViewEx_EventMonitor($EditMode)

   ;If @error Then
     ;MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error)
   ;EndIf
   Switch @extended
      Case 1 ; This is returned after an edit attempt started by user action
         ;Restore checked state (because using spacebar for starting the edit mode has the 'disadvantage' of also changing the checked state)
         ;_GUICtrlListView_SetItemChecked($cLV, $Row, $iCheckState)
         ;
      Case 9 ; This is returned after a selection change by the user, then listview is active
         ;MsgBox($MB_SYSTEMMODAL, "Selection changed", "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
         $Row = $vRet[1]
         $Col = $vRet[2]
         MsgBox(0, "LV: " & $vRet[0], "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
   EndSwitch
WEnd

;From: Melba23: Detect item checking
;https://www.autoitscript.com/forum/topic/182492-guilistviewex-new-version-27-may-16/?do=findComment&comment=1325933
;But you do not need to add this to the UDF code
;just create your own handler as below, do not register $WM_NOTIFY using the UDF function
;(set the relevant parameter of _GUIListViewEx_MsgRegister to False)
;and then call the UDF handler function (_GUIListViewEx_WM_NOTIFY_Handler) from within your own handler.
Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

   ;Melba23, March 2014
   ;https://www.autoitscript.com/forum/topic/159764-reading-gui-date-control-instantly/?do=findComment&comment=1161074
   ;Start by looking for the Date control
;~    Switch _WinAPI_LoWord($wParam) ; ControlID of the control
;~    Case $iDate
;~       Local $tStruct = DllStructCreate($tagNMHDR, $lParam)
;~       If DllStructGetData($tStruct, "Code") = $DTN_DATETIMECHANGE Then
;~          ConsoleWrite("1: " & GUICtrlRead($iDate) & @CRLF)
;~       EndIf
;~    EndSwitch

   ;And then see if the ListView needs attention
   Local $hWndFrom, $iCode, $tNMHDR, $iIDFrom
   $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
   $hWndFrom = HWnd(DllStructGetData($tNMHDR, "HwndFrom"))
   $iCode = DllStructGetData($tNMHDR, "Code")

   ;argumentum, Nov 2017
   ;https://www.autoitscript.com/forum/topic/191058-datetime-pick-coloring/
   $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")

   Switch $hWndFrom
      Case $g_hDTP
         Switch $iCode
            Case $NM_KILLFOCUS
               ConsoleWrite("$NM_KILLFOCUS" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
                  "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
                  "-->Code:" & @TAB & $iCode & @CRLF)
               Consolewrite("+-> GUICtrlRead:" & @TAB & GUICtrlRead($iDate) & @CRLF)
               MsgBox(0, "", GUICtrlRead($iDate))
         EndSwitch

   EndSwitch

   ;Return $GUI_RUNDEFMSG
   ;From Melba23: pass the same parameters to the UDF handler as you received in your WM_NOTIFY handler:
   ;Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler
   _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $Msg, $wParam, $lParam)
EndFunc

 

Many Thanks,

Edited by robertocm
Link to comment
Share on other sites

  • Moderators

robertocm,

Why are you using a handler to detect the TAB key? Why not use an Accelerator key like this:

#include <GuiConstants.au3>
#include "GUIListViewEx.au3"

Opt("MustDeclareVars", 1)

Global $cLV, $iLV, $vRet, $Row, $Col, $EditMode = 22
Global $vRet, $Row, $Col, $EditMode = 22
Global $iDarkSlateGray = "0x2F4F4F", _
        $iLtBlue = "0xCCCCFF", _
        $iGreen = "0x00FF00", _
        $iBlack = "0x000000", _
        $iWheat = "0xF5DEB3", _
        $iBlue = "0x0000FF", _
        $iLightBlue = "0xADD8E6"

Global $rstArray, $rstCount_1, $rstCount_2, $aColArBand[1][1]
Global $GuiWidth = 500, $GuiHight = 500

;GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

Global $hGui = GUICreate("Example", $GuiWidth, $GuiHight)

Global $iDate = GUICtrlCreateDate("", 8, 2, 120, 27, 0x00)
GUICtrlSetFont(-1, 10)

Global $cTabPressed = GUICtrlCreateDummy() ; Create a dummy to link with the acceleerator key <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

$cLV = GUICtrlCreateListView("F0|F1|F2|F3", 2, 35, $GuiWidth - 4, $GuiHight - 60) ;752
_GUICtrlListView_SetExtendedListViewStyle($cLV, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
GUICtrlSetFont($cLV, 9, Default, Default, "Segoe UI") ; Note edit control will use same font

_GUICtrlListView_SetColumnWidth($cLV, 0, 27)
_GUICtrlListView_SetColumnWidth($cLV, 1, 180)
_GUICtrlListView_SetColumnWidth($cLV, 2, 140)
_GUICtrlListView_SetColumnWidth($cLV, 3, 65)

; Create array and fill listview
Global $rstArray[10][4]
$rstCount_1 = UBound($rstArray)
$rstCount_2 = UBound($rstArray, 2)
For $i = 0 To $rstCount_1 - 1
    For $j = 0 To $rstCount_2 - 1
        $rstArray[$i][$j] = "SubItem " & $i & "-" & $j
    Next
Next

;Load the ListView with data
_GUICtrlListView_AddArray($cLV, $rstArray)

;Set array to give alternate line colouring
ReDim $aColArBand[$rstCount_1][$rstCount_2]
For $i = 0 To $rstCount_1 - 1
    If Mod($i, 2) = 0 Then
        For $j = 0 To $rstCount_2 - 1
            $aColArBand[$i][$j] = ";0xFFFFFF"
        Next
    Else
        For $j = 0 To $rstCount_2 - 1
            $aColArBand[$i][$j] = ";0xE6E6E6"
        Next
    EndIf
Next
;Initiate LVEx - using filling array - user colours
;Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting
$iLV = _GUIListViewEx_Init($cLV, $rstArray, 0, 0, False, 1 + 4 + 32 + 1024)

;Load the required ListView colour array
_GUIListViewEx_LoadColour($iLV, $aColArBand)
;Set editable columns
_GUIListViewEx_SetEditStatus($iLV, "1-3")

_GUIListViewEx_MsgRegister()

;Set deafult colours to use
Global $aDefCols[4] = ["0x000000", "0xFEFEFE", "0xFFFFFF", "0x778899"]
;Sets default colours for user colour/single cell select enabled ListViews
_GUIListViewEx_SetDefColours($iLV, $aDefCols)

GUISetState(@SW_SHOW)

; Set the accelerator key <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Local $aAccelKeys[1][2] = [["{TAB}", $cTabPressed]]
GUISetAccelerators($aAccelKeys)

Local $iMsg
While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cTabPressed ; When accelerator fired.... <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
            ConsoleWrite("+-> GUICtrlRead:" & @TAB & GUICtrlRead($iDate) & @CRLF) ; ...read the date <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    EndSwitch

    $vRet = _GUIListViewEx_EventMonitor($EditMode)

    Switch @extended
        Case 1 ; This is returned after an edit attempt started by user action
            ;Restore checked state (because using spacebar for starting the edit mode has the 'disadvantage' of also changing the checked state)
            ;_GUICtrlListView_SetItemChecked($cLV, $Row, $iCheckState)
            ;
        Case 9 ; This is returned after a selection change by the user, then listview is active
            ;MsgBox($MB_SYSTEMMODAL, "Selection changed", "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
            $Row = $vRet[1]
            $Col = $vRet[2]
            MsgBox(0, "LV: " & $vRet[0], "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
    EndSwitch
WEnd

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple 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

 

Link to comment
Share on other sites

I have several checkboxes, tabs, and other controls in the gui, also a second gui displayed from clicking in listviews 'external' to the udf (see below)

I'm using tab key to 'navigate' in the form controls

see this second example more similar to what i'm tryng

;https://www.autoitscript.com/forum/topic/139314-custom-listview-icons-checkboxes-multiline-edit-in-place/?do=findComment&comment=980443
;rover, April 19, 2012 (edited)
;This example is more relevant to your questions regarding the Outlook multiline listview.
;coded by rover 2k12
#include <GuiConstantsEx.au3>
;#include <GuiListView.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <ButtonConstants.au3>

#include "GUIListViewEx.au3"

Opt( "MustDeclareVars", 1 )

;from Melba23 GUIListViewEx
Global $cLV, $iLV, $vRet, $Row, $Col, $EditMode = 22
Global $vRet, $Row, $Col, $EditMode = 22
;https://www.autoitscript.com/forum/topic/182492-guilistviewex-bugfix-version-25-sep-17/?do=findComment&comment=1370017
;Melba 23, Oct 2017
;... and a right-click menu to select the colour of another column (1) of the selected row.
Global  $iDarkSlateGray = "0x2F4F4F", _
        $iLtBlue = "0xCCCCFF", _
        $iGreen = "0x00FF00", _
        $iBlack = "0x000000", _
        $iWheat = "0xF5DEB3", _
        $iBlue = "0x0000FF", _
        $iLightBlue = "0xADD8E6"

Global $rstArray, $rstCount_1, $rstCount_2, $aColArBand[1][1]
Global $GuiWidth = @DesktopWidth-2, $GuiHight = @DesktopHeight-77

;rover ---------------------------------------------------
Opt("GUIDataSeparatorChar", "|")

Global $hWndListView

Global Const $ODA_SELECT = 0x2
Global Const $ODA_FOCUS = 0x4
Global Const $ODS_SELECTED = 0x0001
Global Const $ODT_LISTVIEW = 102
Global Const $ODA_DRAWENTIRE = 0x1

Global $iDllGDI = DllOpen("gdi32.dll")
Global $iDllUSER32 = DllOpen("user32.dll")
Global $iDllUxtheme = DllOpen("uxtheme.dll")

;global resources for WM_DRAWITEM - optimize speed
Global $aFont[2]
$aFont[0] = _WinAPI_CreateFont(16, 0, 0, 0, $FW_HEAVY, False, False, False, _
        $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, $DEFAULT_PITCH, 'Segoe UI')
$aFont[1] = _WinAPI_CreateFont(16, 0, 0, 0, $FW_MEDIUM, False, False, False, _
        $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, $DEFAULT_PITCH, 'Segoe UI')

Global $hPen1 = _WinAPI_CreatePen($PS_SOLID, 1, 0xF3EAE7)
Global $hPen2 = _WinAPI_CreatePen($PS_SOLID, 1, 0xF4E8E6)
Global $hBrush = _WinAPI_CreateSolidBrush(0xEEDDBB)

;Theme Parts and States
;http://msdn.microsoft.com/en-us/library/windows/desktop/bb773210%28v=vs.85%29.aspx
;Part - vsstyle.h
Global Const $BP_PUSHBUTTON = 1
Global Const $LVP_GROUPHEADER = 6
;State - vsstyle.h
Global Enum $PBS_NORMAL=1,$PBS_HOT,$PBS_PRESSED,$PBS_DISABLED,$PBS_DEFAULTED
Global Enum $LVGH_CLOSEHOT=10,$LVGH_CLOSESELECTED,$LVGH_CLOSESELECTEDHOT,$LVGH_CLOSESELECTEDNOTFOCUSED

;this allows you to theme individual items for your own needs, not just if items are selected
;the same as customdrawing item and subitem colours
;XP+
;Global $sTheme = 'Button'
;Global $iThemePart = $BP_PUSHBUTTON
;Global $iThemeState = $PBS_NORMAL

;Vista+
Global $sTheme = 'Listview'
Global $iThemePart = $LVP_GROUPHEADER
Global $iThemeState = 10 ;tested: 2, 4, 8, 10, 11, 12, 13

Global $hTheme = DllCall($iDllUxtheme, 'ptr', 'OpenThemeData', 'hwnd', 0, 'wstr', $sTheme)
$hTheme = $hTheme[0]

;global structs for WM_DRAWITEM - optimize speed
;rect, text buffer and LVITEM structures
Global $tLVRect = DllStructCreate($tagRECT)
Global $tLVText = DllStructCreate("wchar[4096]")
Global $tLVITEM = DllStructCreate($tagLVITEM)
Global $pLVITEM = DllStructGetPtr($tLVITEM)
DllStructSetData($tLVITEM, "TextMax", 4096)
DllStructSetData($tLVITEM, "SubItem", 0)
DllStructSetData($tLVITEM, "Text", DllStructGetPtr($tLVText))

; WM_MEASUREITEM allows setting the row height
Global $iListView_row_height = 130
Global $hListView_1, $hListView_2 ;must be declared before listview created
GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ; place before listview creation - message sent once for each ownerdrawn control created
GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") ;placed here, WM_MEASUREITEM can now be unregistered in the handler (deleting or adding items after unregistering maintains row height setting this way)
; ---------------------------------------------------

;Now trying to detect the index of highlighted item in the multiline ListView
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

Global $hGui = GUICreate("Example", $GuiWidth, $GuiHight)
Global $Label = GUICtrlCreateLabel("Selected: ", 1000, 300, 300, 300)
GUICtrlSetFont(-1, 11, Default, Default, "Segoe UI")

$cLV = GUICtrlCreateListView("F0|F1|F2|F3", 2, 2, $GuiWidth-4, 200) ;752
_GUICtrlListView_SetExtendedListViewStyle($cLV, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
GUICtrlSetFont($cLV, 9, Default, Default, "Segoe UI") ; Note edit control will use same font

_GUICtrlListView_SetColumnWidth($cLV, 0, 27)
_GUICtrlListView_SetColumnWidth($cLV, 1, 180)
_GUICtrlListView_SetColumnWidth($cLV, 2, 140)
_GUICtrlListView_SetColumnWidth($cLV, 3, 65)

; Create array and fill listview
Global $rstArray[5][4]
$rstCount_1 = Ubound($rstArray)
$rstCount_2 = Ubound($rstArray, 2)
For $i = 0 To $rstCount_1 - 1
   For $j = 0 To $rstCount_2 - 1
      $rstArray[$i][$j] =  "SubItem " & $i & "-" & $j
   Next
Next

;Load the ListView with data
_GUICtrlListView_AddArray($cLV, $rstArray)

;Melba23
;Set array to give alternate line colouring
ReDim $aColArBand[$rstCount_1][$rstCount_2]
For $i = 0 To $rstCount_1 - 1
   If Mod($i,2) = 0 Then
      For $j = 0 To $rstCount_2 - 1
         $aColArBand[$i][$j] = ";0xFFFFFF"
      Next
   Else
      For $j = 0 To $rstCount_2 - 1
         $aColArBand[$i][$j] = ";0xE6E6E6"
      Next
   EndIf
Next
;Initiate LVEx - using filling array - user colours
;Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting
$iLV = _GUIListViewEx_Init($cLV, $rstArray, 0, 0, False, 1 + 4 + 32 + 1024)

;Load the required ListView colour array
_GUIListViewEx_LoadColour($iLV, $aColArBand)
;Set editable columns
_GUIListViewEx_SetEditStatus($iLV, "1-3")

#cs
Melba 23
From 'A Beginner’s Guide To Melba23’s GUIListViewEx UDF':
The UDF registers these 4 messages automatically – if you already have handlers for these messages in your script,
do not register them again using the UDF function (set the relevant parameter of _GUIListViewEx_MsgRegister to False)
but call the relevant UDF handler function (_GUIListViewEx_WM_NOTIFY_Handler) from within your existing handler.
Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler
#ce
;prevent the UDF from initially registering the WM_NOTIFY
;Register for sorting, dragging and editing
;Register required message BEFORE any colour actions (register for sorting, dragging and editing)
;If colours used then this function must be run BEFORE GUISetState
;If message handlers already registered, then call the relevant handler function from within that handler

_GUIListViewEx_MsgRegister(False)  ;<<<< OK GET DATE ON TAB KEY, BUT NO COLORS, NO SINGLE CELL SELECTION
;_GUIListViewEx_MsgRegister()  ;<<<< OK COLORS, OK SINGLE CELL SELECTION, NO DATE ON TAB KEY

;Set deafult colours to use
Global $aDefCols[4] = ["0x000000", "0xFEFEFE", "0xFFFFFF", "0x778899"]
;Sets default colours for user colour/single cell select enabled ListViews
_GUIListViewEx_SetDefColours($iLV, $aDefCols)


;rover ---------------------------------------------------

Global $cListView_1 = GUICtrlCreateListView("", 8, 304, 326, $GuiHight-112, BitOR($LVS_REPORT, $LVS_NOCOLUMNHEADER, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS))
$hListView_1 = GUICtrlGetHandle($cListView_1)
_GUICtrlListView_SetExtendedListViewStyle($hListView_1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT)) ;double buffer improves performance
_GUICtrlListView_AddColumn($hListView_1, "", 296) ;270

GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ; place before listview creation - message sent once for each ownerdrawn control created
Global $cListView_2 = GUICtrlCreateListView("", 334, 304, 326, $GuiHight-112, BitOR($LVS_REPORT, $LVS_NOCOLUMNHEADER, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS))
$hListView_2 = GUICtrlGetHandle($cListView_2)
_GUICtrlListView_SetExtendedListViewStyle($hListView_2, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT)) ;double buffer improves performance
_GUICtrlListView_AddColumn($hListView_2, "", 296)

Global $aTextHdr[4] = ["From:", "Sent:", "To:", "Subject:"]
For $row = 1 To 5
   _GUICtrlListView_BeginUpdate($hListView_1)
   _GUICtrlListView_AddItem($hListView_1, "Rover - AutoIt Forums|Thursday, April 19, 2012 05:0" & $row - 1 & "AM|footswitch|Re: Multiline listview like Outlook|" & _
         "This is a rough mock-up of that Outlook listview" & @CRLF & "You will need to add code for the text metrics")
   _GUICtrlListView_EndUpdate($hListView_1)

   _GUICtrlListView_BeginUpdate($hListView_2)
   _GUICtrlListView_AddItem($hListView_2, "Rover - AutoIt Forums|Thursday, April 19, 2012 05:0" & $row - 1 & "AM|footswitch|Re: Multiline listview like Outlook|" & _
         "This is a rough mock-up of that Outlook listview" & @CRLF & "You will need to add code for the text metrics")
   _GUICtrlListView_EndUpdate($hListView_2)
Next

;~ ;adjust listview size for number of items shown - for efficient painting and to eliminate issue of a click on bottom item causing a jump to next item
;~ Local $iY = _GUICtrlListView_ApproximateViewHeight($hListView_1, _GUICtrlListView_GetCounterPage($hListView_1))
;~ GUICtrlSetPos($cListView_1, 2, 2, 328, $iY + 4)
;~ GUICtrlSetPos($cListView_2, 332, 2, 328, $iY + 4)

;~ Global $cSelect = GUICtrlCreateButton("Themed Select", 2, $iY + 8, 120, 23)
;~ Global $cTheme = GUICtrlCreateCombo("Button", 120+2, $iY + 9, 60)
;~ GUICtrlSetData(-1, "Listview", "Button")
;~ Global $cState = GUICtrlCreateCombo("1 NORMAL", 180+4, $iY + 9, 80)
;~ GUICtrlSetData(-1, "2 HOT|3 PRESSED|4 GREYED|5 DEFAULT", "1 NORMAL")
;~ Global $cLabel =  GUICtrlCreateLabel("Select Item"&@CRLF&"Style", 260+8, $iY + 8)

; ---------------------------------------------------

GUISetState(@SW_SHOW)

Local $iMsg
While 1
   $iMsg = GUIGetMsg()
   Switch $iMsg
      Case $GUI_EVENT_CLOSE
         Exit
   EndSwitch

   $vRet = _GUIListViewEx_EventMonitor($EditMode)

   ;If @error Then
     ;MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error)
   ;EndIf
   Switch @extended
      Case 1 ; This is returned after an edit attempt started by user action
         ;Restore checked state (because using spacebar for starting the edit mode has the 'disadvantage' of also changing the checked state)
         ;_GUICtrlListView_SetItemChecked($cLV, $Row, $iCheckState)
         ;
      Case 9 ; This is returned after a selection change by the user, then listview is active
         ;MsgBox($MB_SYSTEMMODAL, "Selection changed", "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
         $Row = $vRet[1]
         $Col = $vRet[2]
         MsgBox(0, "LV: " & $vRet[0], "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
   EndSwitch
WEnd

;From: Melba23: Detect item checking
;https://www.autoitscript.com/forum/topic/182492-guilistviewex-new-version-27-may-16/?do=findComment&comment=1325933
;But you do not need to add this to the UDF code
;just create your own handler as below, do not register $WM_NOTIFY using the UDF function
;(set the relevant parameter of _GUIListViewEx_MsgRegister to False)
;and then call the UDF handler function (_GUIListViewEx_WM_NOTIFY_Handler) from within your own handler.
Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

   ;Melba23, March 2014
   ;https://www.autoitscript.com/forum/topic/159764-reading-gui-date-control-instantly/?do=findComment&comment=1161074
   ;Start by looking for the Date control
;~    Switch _WinAPI_LoWord($wParam) ; ControlID of the control
;~    Case $iDate
;~       Local $tStruct = DllStructCreate($tagNMHDR, $lParam)
;~       If DllStructGetData($tStruct, "Code") = $DTN_DATETIMECHANGE Then
;~          ConsoleWrite("1: " & GUICtrlRead($iDate) & @CRLF)
;~       EndIf
;~    EndSwitch

   ;And then see if the ListView needs attention
   Local $hWndFrom, $iCode, $tNMHDR, $iIDFrom
   $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
   $hWndFrom = HWnd(DllStructGetData($tNMHDR, "HwndFrom"))
   $iCode = DllStructGetData($tNMHDR, "Code")

   ;argumentum, Nov 2017
   ;https://www.autoitscript.com/forum/topic/191058-datetime-pick-coloring/
   $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")

   Switch $hWndFrom
;~    Case $g_hDTP
;~       Switch $iCode
;~          Case $NM_KILLFOCUS
;~             ConsoleWrite("$NM_KILLFOCUS" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
;~                "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
;~                "-->Code:" & @TAB & $iCode & @CRLF)
;~             Consolewrite("+-> GUICtrlRead:" & @TAB & GUICtrlRead($iDate) & @CRLF)
;~             $CurMonday = Monday(GUICtrlRead($iDate))
;~             GUISetState(@SW_LOCK, $hMainGUI)
;~             GUICtrlSetData($iDate, $CurMonday)
;~             Delete_Week()
;~             Load_Week()
;~             GUISetState(@SW_UNLOCK, $hMainGUI)
;~       EndSwitch

         Case $hListView_1, $hListView_2
            Switch $iCode
;~             Case $NM_CLICK
;~               Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
;~               ;Local $Index = DllStructGetData($tInfo, "Index")
;~               If DllStructGetData($tInfo, "Index") = -1 Then
;~                   ;ConsoleWrite("no item" & @CRLF)
;~               Else
;~                   ;ConsoleWrite(_GUICtrlListView_GetItemText($hWndListView, $Index) & @CRLF)
;~               EndIf
               Case $LVN_ITEMCHANGED
                  Global $hWndListView = DllStructGetData($tNMHDR, 1)
                  ;Global $hWndListView = $hWndFrom

                  If $hWndListView = $hListView_1 Then
                     Local $nLV = "Monday"
                  ElseIf $hWndListView = $hListView_2 Then
                     Local $nLV = "Tuesday"
                  EndIf

                  Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                  Global $Index = DllStructGetData($tInfo, "Item")

                  ;From Zedna, in 'Highlighted item in the ListView?'
                  ;https://www.autoitscript.com/forum/topic/96234-highlighted-item-in-the-listview/?do=findComment&comment=691927
                  ;if state has changed
                  If BitAND(DllStructGetData($tInfo, "Changed"), $LVIF_STATE) = $LVIF_STATE And DllStructGetData($tInfo, "NewState") <> DllStructGetData($tInfo, "OldState") Then
                     ;take care of only newly selected items (not deselected ones)
                     If BitAND(DllStructGetData($tInfo, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED Then
                        ;ConsoleWrite("Index: " & $Index & @TAB & _GUICtrlListView_GetItemText($hWndListView, $Index) & @CRLF)
                        ;Help File
                        ;Local $aItem = _GUICtrlListView_GetItem($hWndListView, $Index)
                        ;MsgBox($MB_SYSTEMMODAL, "Information", $aItem[3])

                        GUICtrlSetData($Label, "Selected " & $nLV & ": " & _GUICtrlListView_GetItemText($hWndListView, $Index))
                        Local $aArray = StringSplit(_GUICtrlListView_GetItemText($hWndListView, $Index), "|")
                        ;...

                     EndIf
                  EndIf
               Case $NM_DBLCLK
                  ;Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                  ;Global $Index = DllStructGetData($tInfo, "Index")

                  If $hWndListView = $hListView_1 Then
                     Local $nLV = "Monday"
                  ElseIf $hWndListView = $hListView_2 Then
                     Local $nLV = "Tuesday"
                  EndIf

                  If $Index = -1 Then
                     ;Local $iItemText = ''
                     ;ConsoleWrite("no item" & @CRLF)
                  Else
                     GUICtrlSetData($Label, $nLV & " " & "Dbclick item " & $Index)
                     ;_GUICtrlListView_SetItemText($hWndListView, $Index, "aaa|bbbb|cccc|ddd|eee")
                     ;_Show_GUI1()
                  EndIf
            EndSwitch
   EndSwitch

   ;Return $GUI_RUNDEFMSG
   ;From Melba23: pass the same parameters to the UDF handler as you received in your WM_NOTIFY handler:
   ;Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler
   _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $Msg, $wParam, $lParam)
EndFunc

;https://www.autoitscript.com/forum/topic/139314-custom-listview-icons-checkboxes-multiline-edit-in-place/?do=findComment&comment=980443
;rover, April 19, 2012 (edited)
Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tMEASUREITEMS = DllStructCreate("uint cType;uint cID;uint itmID;uint itmW;uint itmH;ulong_ptr itmData", $lParam)
    If DllStructGetData($tMEASUREITEMS, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    DllStructSetData($tMEASUREITEMS, "itmH", $iListView_row_height) ; row height
    GUIRegisterMsg($WM_MEASUREITEM, "") ; unregister message handler call this after last ownerdrawn listview created - message no longer sent
    Return 1
EndFunc   ;==>WM_MEASUREITEM

Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC
    $tDRAWITEMSTRUCT = DllStructCreate( _
            "uint cType;" & _
            "uint cID;" & _
            "uint itmID;" & _
            "uint itmAction;" & _
            "uint itmState;" & _
            "hwnd hItm;" & _
            "handle hDC;" & _
            "long itmRect[4];" & _
            "ulong_ptr itmData" _
            , $lParam)
    If DllStructGetData($tDRAWITEMSTRUCT, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    $cID = DllStructGetData($tDRAWITEMSTRUCT, "cID")
    $itmID = DllStructGetData($tDRAWITEMSTRUCT, "itmID")
    $itmAction = DllStructGetData($tDRAWITEMSTRUCT, "itmAction")
    $itmState = DllStructGetData($tDRAWITEMSTRUCT, "itmState")
    $hItm = DllStructGetData($tDRAWITEMSTRUCT, "hItm")
    $hDC = DllStructGetData($tDRAWITEMSTRUCT, "hDC")
    Switch $cID ; will look for ControlID, not window handle.
        Case $cListView_1, $cListView_2, $cListView_3, $cListView_4, $cListView_5
            Switch $itmAction
            Case $ODA_DRAWENTIRE
                    __WM_DRAWITEM_ListView($hItm, $tDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hDC)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM

Func __WM_DRAWITEM_ListView(ByRef $hLV, ByRef $tDRAWITEMSTRUCT, ByRef $cID, ByRef $itmID, ByRef $itmAction, ByRef $itmState, ByRef $hDC)
    Local $iTxtCol, $bSelected = BitAND($itmState, $ODS_SELECTED), $iTextFormatting = BitOR($DT_LEFT, $DT_WORDBREAK)
    If Not $bSelected Then
        $iTxtCol = 0xB79588
    Else ;selected
        $iTxtCol = 0x494949
        ;Theme Parts and States
        ;http://msdn.microsoft.com/en-us/library/windows/desktop/bb773210%28v=vs.85%29.aspx
        Local $pItemRect = DllStructGetPtr($tDRAWITEMSTRUCT, "itmRect")
        If $hTheme Then
            If $sTheme = "Listview" Then
                Local $tItemRect = DllStructCreate($tagRect, $pItemRect)
                    DllStructSetData($tItemRect, 1, DllStructGetData($tItemRect, 1)+1)
                    DllStructSetData($tItemRect, 2, DllStructGetData($tItemRect, 2)+1)
                    DllStructSetData($tItemRect, 3, DllStructGetData($tItemRect, 3)-1)
                    DllStructSetData($tItemRect, 4, DllStructGetData($tItemRect, 4)-1)
                $pItemRect = DllStructGetPtr($tItemRect)
            EndIf
            DllCall($iDllUxtheme, 'uint', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hDC, 'int', $iThemePart, 'int', $iThemeState, 'ptr', $pItemRect, 'ptr', 0)
        Else
            DllCall($iDllUSER32, "int", "FillRect", "handle", $hDC, "ptr", DllStructGetPtr($tDRAWITEMSTRUCT, "itmRect"), "handle", $hBrush)
        EndIf
    EndIf
    GUICtrlSendMsg($cID, $LVM_GETITEMTEXTW, $itmID, $pLVITEM)
    Local $aSubItmText = StringSplit(DllStructGetData($tLVText, 1), "|", 2)
    DllStructSetData($tLVText, 1, "")
    DllStructSetData($tLVRect, "Top", 0)
    DllStructSetData($tLVRect, "Left", $LVIR_BOUNDS)
    GUICtrlSendMsg($cID, $LVM_GETSUBITEMRECT, $itmID, DllStructGetPtr($tLVRect))
    Local $iLeft = DllStructGetData($tLVRect, 1) + 6 ;Left
    Local $iTop = DllStructGetData($tLVRect, 2) ;Top
    DllStructSetData($tLVRect, 1, $iLeft) ;Left

    Switch $hLV
        Case $hListView_1, $hListView_2, $hListView_3, $hListView_4, $hListView_5
            Local $iColPrev = __WinAPI_SetTextColor($hDC, 0x000000) ;save previous font and text colour
            Local $hFontOld = __WinAPI_SelectObject($hDC, $aFont[0]) ;Bold

            ;------------------------------------------------------------
            ;multiline, but no per line indentation or colour
            ;DllStructSetData($tLVRect, 2, $iTop+2)
            ;__WinAPI_DrawText($hDC, "From:"&@CRLF&"Sent:"&@CRLF&"To:"&@CRLF&"Subject:", $tLVRect, $iTextFormatting)
            ;------------------------------------------------------------

            DllStructSetData($tLVRect, 2, $iTop + 2)
            __WinAPI_DrawText($hDC, $aTextHdr[0], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 2, $iTop + 20)
            __WinAPI_DrawText($hDC, $aTextHdr[1], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 2, $iTop + 38)
            __WinAPI_DrawText($hDC, $aTextHdr[2], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 2, $iTop + 56)
            __WinAPI_DrawText($hDC, $aTextHdr[3], $tLVRect, $iTextFormatting)


            __WinAPI_SelectObject($hDC, $aFont[1]) ;Normal

            ;------------------------------------------------------------
            ;multiline, but no per line indentation or colour
            ;__WinAPI_SetTextColor($hDC, 0x494949)
            ;DllStructSetData($tLVRect, 1, $iLeft+50)
            ;DllStructSetData($tLVRect, 2, $iTop+2)
            ;__WinAPI_DrawText($hDC, $aSubItmText[0]&@CRLF&$aSubItmText[1]&@CRLF&$aSubItmText[2]&@CRLF&$aSubItmText[3], $tLVRect, $iTextFormatting)
            ;------------------------------------------------------------

            __WinAPI_SetTextColor($hDC, 0xFF0000)

            DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[0]) + 5)
            DllStructSetData($tLVRect, 2, $iTop + 2)
            __WinAPI_DrawText($hDC, $aSubItmText[0], $tLVRect, $iTextFormatting)

            __WinAPI_SetTextColor($hDC, 0x494949)

            DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[1]) + 5)
            DllStructSetData($tLVRect, 2, $iTop + 20)
            __WinAPI_DrawText($hDC, $aSubItmText[1], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[2]) + 5)
            DllStructSetData($tLVRect, 2, $iTop + 38)
            __WinAPI_DrawText($hDC, $aSubItmText[2], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[3]) + 5)
            DllStructSetData($tLVRect, 2, $iTop + 56)
            __WinAPI_DrawText($hDC, $aSubItmText[3], $tLVRect, $iTextFormatting)

            __WinAPI_SetTextColor($hDC, $iTxtCol)
            DllStructSetData($tLVRect, 1, $iLeft + 2)
            DllStructSetData($tLVRect, 2, $iTop + 80)
            __WinAPI_DrawText($hDC, $aSubItmText[4], $tLVRect, $iTextFormatting)

            If $bSelected And $hTheme Then Return ;optional - don't paint lines when item selected - in this example only for benefit of themed selected items

            Local $obj_orig = __WinAPI_SelectObject($hDC, $hPen1)
            __WinAPI_DrawLine($hDC, $iLeft, DllStructGetData($tLVRect, 4) - 2, 320 - ($iLeft * 2) - 16, DllStructGetData($tLVRect, 4) - 2)
            __WinAPI_SelectObject($hDC, $hPen2)
            __WinAPI_DrawLine($hDC, $iLeft, DllStructGetData($tLVRect, 4) - 3, 320 - ($iLeft * 2) - 16, DllStructGetData($tLVRect, 4) - 3)
            __WinAPI_SelectObject($hDC, $obj_orig)

            ;__WinAPI_SelectObject($hDC, $hFontOld)
            ;__WinAPI_SetTextColor($hDC, $iColPrev)
    EndSwitch
    Return
EndFunc   ;==>__WM_DRAWITEM_ListView

Func __WinAPI_DrawLine($hDC, $iX1, $iY1, $iX2, $iY2)
    DllCall($iDllGDI, "bool", "MoveToEx", "handle", $hDC, "int", $iX1, "int", $iY1, "ptr", 0)
    If @error Then Return SetError(@error, @extended, False)
    DllCall($iDllGDI, "bool", "LineTo", "handle", $hDC, "int", $iX2, "int", $iY2)
    If @error Then Return SetError(@error, @extended, False)
    Return True
EndFunc   ;==>__WinAPI_DrawLine

Func __WinAPI_DrawText(ByRef $hDC, $sText, ByRef $tRect, ByRef $iFlags)
    DllCall($iDllUSER32, "int", "DrawTextW", "hwnd", $hDC, "wstr", $sText, "int", StringLen($sText), "struct*", $tRect, "int", $iFlags)
EndFunc   ;==>__WinAPI_DrawText

Func __WinAPI_SetTextColor($hDC, $iColor)
    Local $aResult = DllCall($iDllGDI, "INT", "SetTextColor", "handle", $hDC, "dword", $iColor)
    If @error Then Return SetError(@error, @extended, -1)
    Return $aResult[0]
EndFunc   ;==>__WinAPI_SetTextColor

Func __WinAPI_SelectObject($hDC, $hGDIObj)
    Local $aResult = DllCall($iDllGDI, "handle", "SelectObject", "handle", $hDC, "handle", $hGDIObj)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc   ;==>__WinAPI_SelectObject

Func __GUICtrlListView_GetStringWidth($hWnd, $sString)
    Local $tBuffer = DllStructCreate("wchar Text[" & StringLen($sString) + 1 & "]")
    DllStructSetData($tBuffer, "Text", $sString)
    Local $iRet = GUICtrlSendMsg($hWnd, $LVM_GETSTRINGWIDTHW, 0, DllStructGetPtr($tBuffer))
    Return $iRet
 EndFunc   ;==>__GUICtrlListView_GetStringWidth

This is a screen capture to see the controls in main tab:

image.thumb.png.f1aec0873ced38321f9dae5af7188695.png

and with double click the second gui with the UDF Listview where i'm trying to incorporate band colors:

image.thumb.png.f4c8cc285636649ee705f0f6db174b20.png

 

Edited by robertocm
Link to comment
Share on other sites

  • Moderators

robertocm,

This script does not have a DateTimePicker to read when the TAB key is pressed - so what is the problem you have with it?

If you want help, please post a simple script with a detailed explanation of why it is not working as you want - I cannot read your mind to determine the problem.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple 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

 

Link to comment
Share on other sites

Dear Melba,

First MANY THANKS for your attention,

- i'm trying to get alternate colors in an udf listview placed on a second gui (or child)

- i need the second gui to be called from notify messages from clicking in items in a not udf listview in the main gui

- i need to use tab key in the main gui for several checkboxes and date/hour controls that function as filter criteria on the data displayed. Also needed tab for some inputboxes for filtering and commenting data.

I would rather prefer using colors, if possible, but is not essential

Here a very simplified example for the 'no colours' if Notify:

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

#include "GUIListViewEx.au3"

;From Melba23
;https://www.autoitscript.com/forum/topic/182492-guilistviewex-new-version-27-may-16/?do=findComment&comment=1325933
$hGUI = GUICreate("Test", 1200, 500)

$cLV = GUICtrlCreateListView("Item         ", 2, 2, 200, 300)
_GUICtrlListView_SetExtendedListViewStyle($cLV, $LVS_EX_CHECKBOXES)
$hLV = GUICtrlGetHandle($cLV)

For $i = 0 to 9
    GUICtrlCreateListViewItem("Item " & $i, $cLV)
Next

;from Melba23 GUIListViewEx
Global $cLV, $iLV, $vRet, $Row, $Col, $EditMode = 22
Global $vRet, $Row, $Col, $EditMode = 22
;https://www.autoitscript.com/forum/topic/182492-guilistviewex-bugfix-version-25-sep-17/?do=findComment&comment=1370017
;Melba 23, Oct 2017
;... and a right-click menu to select the colour of another column (1) of the selected row.
Global  $iDarkSlateGray = "0x2F4F4F", _
        $iLtBlue = "0xCCCCFF", _
        $iGreen = "0x00FF00", _
        $iBlack = "0x000000", _
        $iWheat = "0xF5DEB3", _
        $iBlue = "0x0000FF", _
        $iLightBlue = "0xADD8E6"

Global $rstArray, $rstCount_1, $rstCount_2, $aColArBand[1][1]
Global $GuiWidth = @DesktopWidth-2, $GuiHight = @DesktopHeight-77

;~ GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

$cLV = GUICtrlCreateListView("F0|F1|F2|F3", 210, 2, 400, 400)
_GUICtrlListView_SetExtendedListViewStyle($cLV, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
GUICtrlSetFont($cLV, 9, Default, Default, "Segoe UI") ; Note edit control will use same font

_GUICtrlListView_SetColumnWidth($cLV, 0, 27)
_GUICtrlListView_SetColumnWidth($cLV, 1, 100)
_GUICtrlListView_SetColumnWidth($cLV, 2, 100)
_GUICtrlListView_SetColumnWidth($cLV, 3, 100)

; Create array and fill listview
Global $rstArray[10][4]
$rstCount_1 = Ubound($rstArray)
$rstCount_2 = Ubound($rstArray, 2)
For $i = 0 To $rstCount_1 - 1
   For $j = 0 To $rstCount_2 - 1
      $rstArray[$i][$j] =  "SubItem " & $i & "-" & $j
   Next
Next

;Load the ListView with data
_GUICtrlListView_AddArray($cLV, $rstArray)

;Melba23
;Set array to give alternate line colouring
ReDim $aColArBand[$rstCount_1][$rstCount_2]
For $i = 0 To $rstCount_1 - 1
   If Mod($i,2) = 0 Then
      For $j = 0 To $rstCount_2 - 1
         $aColArBand[$i][$j] = ";0xFFFFFF"
      Next
   Else
      For $j = 0 To $rstCount_2 - 1
         $aColArBand[$i][$j] = ";0xE6E6E6"
      Next
   EndIf
Next
;Initiate LVEx - using filling array - user colours
;Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting
$iLV = _GUIListViewEx_Init($cLV, $rstArray, 0, 0, False, 1 + 4 + 32 + 1024)

;Load the required ListView colour array
_GUIListViewEx_LoadColour($iLV, $aColArBand)
;Set editable columns
_GUIListViewEx_SetEditStatus($iLV, "1-3")

#cs
Melba 23
From 'A Beginner’s Guide To Melba23’s GUIListViewEx UDF':
The UDF registers these 4 messages automatically – if you already have handlers for these messages in your script,
do not register them again using the UDF function (set the relevant parameter of _GUIListViewEx_MsgRegister to False)
but call the relevant UDF handler function (_GUIListViewEx_WM_NOTIFY_Handler) from within your existing handler.
Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler
#ce
;prevent the UDF from initially registering the WM_NOTIFY
;Register for sorting, dragging and editing
;Register required message BEFORE any colour actions (register for sorting, dragging and editing)
;If colours used then this function must be run BEFORE GUISetState
;If message handlers already registered, then call the relevant handler function from within that handler

_GUIListViewEx_MsgRegister(False)  ;<<<< NO COLORS, NO SINGLE CELL SELECTION

;Set deafult colours to use
Global $aDefCols[4] = ["0x000000", "0xFEFEFE", "0xFFFFFF", "0x778899"]
;Sets default colours for user colour/single cell select enabled ListViews
_GUIListViewEx_SetDefColours($iLV, $aDefCols)


GUISetState()

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

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

Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

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

    Switch $hWndFrom
        Case $hLV
            Switch $iCode
                Case $LVN_ITEMCHANGED
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    Local $iItem = DllStructGetData($tInfo, "Item")

                    If _GUICtrlListView_GetItemChecked($hLV, $iItem) Then
                        ConsoleWrite(_GUICtrlListView_GetItemText($hLV, $iItem) & " Checked" & @CRLF)
                        MsgBox(0, "", _GUICtrlListView_GetItemText($hLV, $iItem) & " Checked")
                    Else
                        Beep(50,50)
                        ConsoleWrite(_GUICtrlListView_GetItemText($hLV, $iItem) & " Unchecked" & @CRLF)
                        MsgBox(0, "", _GUICtrlListView_GetItemText($hLV, $iItem) & " Unchecked")
                    EndIf
            EndSwitch
    EndSwitch

   ;Return $GUI_RUNDEFMSG
   ;From Melba23: pass the same parameters to the UDF handler as you received in your WM_NOTIFY handler:
   ;Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler
   _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $Msg, $wParam, $lParam)
EndFunc

 

Edited by robertocm
Link to comment
Share on other sites

  • Moderators

robertocm,

The UDF does not work nicely with the standard alternate row colouring methods and I have not looked at how this might be implemented within the UDF. A quick look at the code suggests it might well be limited to native ListViews only.

If this is really important for you I could experiment over the weekend.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple 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

 

Link to comment
Share on other sites

Dear Melba,

Not really important, is ok, i only wanted to be sure and take some time to try before forget about colours in this particular application.

MANY THANKS

p.s: i remember to see some 'scientific article' about band list helping users to do less mistakes working with data, just for curiosity.

Edited by robertocm
Link to comment
Share on other sites

unregistering and registering for different Tabs or GUIs seems to solve

This works

(Edited: tab controls replaced by child GUIs because of 'second time' colors get lost second time a tab was selected after a the tab using notify handler)

;https://www.autoitscript.com/forum/topic/139314-custom-listview-icons-checkboxes-multiline-edit-in-place/?do=findComment&comment=980443
;rover, April 19, 2012 (edited)
;This example is more relevant to your questions regarding the Outlook multiline listview.
;coded by rover 2k12
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <StaticConstants.au3>
#include <WinAPISysWin.au3>
#include "GUIListViewEx.au3"

Opt('MustDeclareVars', 1)

;Managing Multiple GUIs - AutoIt Wiki.htm
;https://www.autoitscript.com/wiki/Main_Page
Global $hGUI1 = 9999, $idTab0 = 9999, $idTab1 = 9999 ;Predeclare the variables with dummy values to prevent firing the Case statements, only for GUI this time
Global $iTabPrev = -1

;from Melba23 GUIListViewEx
Global $cLV, $iLV, $vRet, $Row, $Col, $EditMode = 22
Global $iCheckState = True
Global $cLV_2, $iLV_2

Global $rstArray, $rstCount_1, $rstCount_2, $aColArBand[1][1]
Global $GuiWidth = @DesktopWidth-2, $GuiHight = @DesktopHeight-77

;https://www.autoitscript.com/forum/topic/182492-guilistviewex-bugfix-version-25-sep-17/?do=findComment&comment=1370017
;Melba 23, Oct 2017
;... and a right-click menu to select the colour of another column (1) of the selected row.
Global  $iDarkSlateGray = "0x2F4F4F", _
        $iLtBlue = "0xCCCCFF", _
        $iGreen = "0x00FF00", _
        $iBlack = "0x000000", _
        $iWheat = "0xF5DEB3", _
        $iBlue = "0x0000FF", _
        $iLightBlue = "0xADD8E6"

;rover ---------------------------------------------------
;https://www.autoitscript.com/forum/topic/139314-custom-listview-icons-checkboxes-multiline-edit-in-place/?do=findComment&comment=980443
;rover
Global $hListView_1, $hListView_2 ;must be declared before listview created
Global $hWndListView
Global $iListView_row_height = 130

Global Const $ODA_SELECT = 0x2
Global Const $ODA_FOCUS = 0x4
Global Const $ODS_SELECTED = 0x0001
Global Const $ODT_LISTVIEW = 102
Global Const $ODA_DRAWENTIRE = 0x1

Global $iDllGDI = DllOpen("gdi32.dll")
Global $iDllUSER32 = DllOpen("user32.dll")
Global $iDllUxtheme = DllOpen("uxtheme.dll")

;global resources for WM_DRAWITEM - optimize speed
Global $aFont[2]
$aFont[0] = _WinAPI_CreateFont(16, 0, 0, 0, $FW_HEAVY, False, False, False, _
        $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, $DEFAULT_PITCH, 'Segoe UI')
$aFont[1] = _WinAPI_CreateFont(16, 0, 0, 0, $FW_MEDIUM, False, False, False, _
        $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $PROOF_QUALITY, $DEFAULT_PITCH, 'Segoe UI')

Global $hPen1 = _WinAPI_CreatePen($PS_SOLID, 1, 0xF3EAE7)
Global $hPen2 = _WinAPI_CreatePen($PS_SOLID, 1, 0xF4E8E6)
Global $hBrush = _WinAPI_CreateSolidBrush(0xEEDDBB)

;Theme Parts and States
;http://msdn.microsoft.com/en-us/library/windows/desktop/bb773210%28v=vs.85%29.aspx
;Part - vsstyle.h
Global Const $BP_PUSHBUTTON = 1
Global Const $LVP_GROUPHEADER = 6
;State - vsstyle.h
Global Enum $PBS_NORMAL=1,$PBS_HOT,$PBS_PRESSED,$PBS_DISABLED,$PBS_DEFAULTED
Global Enum $LVGH_CLOSEHOT=10,$LVGH_CLOSESELECTED,$LVGH_CLOSESELECTEDHOT,$LVGH_CLOSESELECTEDNOTFOCUSED

;this allows you to theme individual items for your own needs, not just if items are selected
;the same as customdrawing item and subitem colours
;XP+
;Global $sTheme = 'Button'
;Global $iThemePart = $BP_PUSHBUTTON
;Global $iThemeState = $PBS_NORMAL

;Vista+
Global $sTheme = 'Listview'
Global $iThemePart = $LVP_GROUPHEADER
Global $iThemeState = 10 ;tested: 2, 4, 8, 10, 11, 12, 13

Global $hTheme = DllCall($iDllUxtheme, 'ptr', 'OpenThemeData', 'hwnd', 0, 'wstr', $sTheme)
$hTheme = $hTheme[0]

;global structs for WM_DRAWITEM - optimize speed
;rect, text buffer and LVITEM structures
Global $tLVRect = DllStructCreate($tagRECT)
Global $tLVText = DllStructCreate("wchar[4096]")
Global $tLVITEM = DllStructCreate($tagLVITEM)
Global $pLVITEM = DllStructGetPtr($tLVITEM)
DllStructSetData($tLVITEM, "TextMax", 4096)
DllStructSetData($tLVITEM, "SubItem", 0)
DllStructSetData($tLVITEM, "Text", DllStructGetPtr($tLVText))
; ---------------------------------------------------

Global $hMainGUI = GUICreate("Example", $GuiWidth, $GuiHight)

Global $iLblTab0 = GUICtrlCreateLabel("TAB 0", 2, 2, 100, 26, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 9, Default, Default, "Segoe UI")
GUICtrlSetBkColor(-1, 0xFFFFFF)
GUICtrlSetCursor(-1, 0)
;GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)

Global $iLblTab1 = GUICtrlCreateLabel("TAB 1", 102, 2, 100, 26, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 9, Default, Default, "Segoe UI")
GUICtrlSetBkColor(-1, 0xD3D3D3)
GUICtrlSetCursor(-1, 0)

_Show_Tab0()

;rover
;GUIRegisterMsg($WM_NCHITTEST, "_WM_NCHITTEST") ;comment this line, and child forms with WS_EX_CONTROLPARENT style are draggable
GUISetState(@SW_SHOW, $hMainGUI)

;Help: GUI Reference; Advanced GUIGetMsg and Multiple Windows
;When called with the 1 parameter instead of returning an event value an array will be returned,
;array contains the event (in $aArray[0]) and extra information such as the window handle (in $aArray[1])
;Initialize a Local variable.
Local $aMsg = 0

While 1
  ;Assign to $aMsg the advanced GUI messages.
  $aMsg = GUIGetMsg(1)

   ;Switch from GUIs
   Switch $aMsg[1]
      Case $hMainGUI
      ;The event comes from the $hMainGUI
         ;Switch from event ID
         Switch $aMsg[0]
            Case $GUI_EVENT_CLOSE
               ExitLoop
            Case $iLblTab0
               _Show_Tab0()
            Case $iLblTab1
               _Show_Tab1()
         EndSwitch
      Case $idTab0
      ;The event comes from the $idTab0
         ;Switch from event ID
         Switch $aMsg[0]
            Case $GUI_EVENT_CLOSE
               ExitLoop
            Case $iShowGui1a
               _Show_GUI1()
         EndSwitch
      Case $idTab1
      ;The event comes from the $idTab1
         ;Switch from event ID
         Switch $aMsg[0]
            Case $GUI_EVENT_CLOSE
               ExitLoop
            Case $iShowGui1b
               _Show_GUI1()
         EndSwitch
      Case $hGUI1
      ;The event comes from the $hGUI1
         ;Switch from event ID
         Switch $aMsg[0]
            Case $GUI_EVENT_CLOSE
               ;Re-enable the first GUI and active Tab GUI
               GUISetState(@SW_ENABLE, $hMainGUI)
               GUIDelete($hGUI1)
               GUIRegisterMsg($WM_COMMAND, "") ; unregister message handler
               If $iTabPrev = 0 Then
                  GUISetState(@SW_ENABLE, $idTab0)
               ElseIf $iTabPrev = 1 Then
                  GUISetState(@SW_ENABLE, $idTab1)
                  ;GUICtrlSetState($idFilt, $GUI_FOCUS)
                  GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
               EndIf
         EndSwitch
   EndSwitch

   $vRet = _GUIListViewEx_EventMonitor($EditMode)
   ;If @error Then
     ;MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error)
   ;EndIf
   Switch @extended
      Case 1 ; This is returned after an edit attempt started by user action
         If $vRet = "" Then
             MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF)
         Else
             MsgBox($MB_SYSTEMMODAL, "Edit", "Successful edit" & @CRLF)
         EndIf
      Case 9 ; This is returned after a selection change by the user, then listview is active
         If $vRet[0] = $iLV_2 Then
            MsgBox($MB_SYSTEMMODAL, "LV: " & $vRet[0], "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
            $Row = $vRet[1]
            $Col = $vRet[2]
            $iCheckState = _GUICtrlListView_GetItemChecked($cLV_2, $Row)
         Else
            MsgBox($MB_SYSTEMMODAL, "LV: " & $vRet[0], "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
            Local $Row_2 = $vRet[1]
            Local $Col_2 = $vRet[2]
         EndIf

         Switch $Col
            Case 0
               ;MsgBox(0, "", _GUICtrlListView_GetItemText($cLV, $Row, 0))
               If $iCheckState = True Then
                  ToolTip("Option 1")
                  Sleep(1000)
                  ToolTip("")
               Else
                  ToolTip("Option 2")
                  Sleep(1000)
                  ToolTip("")
               EndIf
         EndSwitch
   EndSwitch
WEnd

Func _Show_Tab0()
   #cs ----------------------------------------------------------------------------
   A good use for Static variables is when you need to maintain a record of a value within a function even though the function itself ends.
   An example might be that you want to do something the first time a function is called, but not subsequently:
   #ce ----------------------------------------------------------------------------
   ;Set the flag only on the first entry into the function
   ;This assignment will be ignored on subsequent entries
   Local Static $bTab0_First_Pass = True

   ;Check the flag
   If $bTab0_First_Pass Then
      ;Immediately clear the flag to prevent running on subsequent passes
      $bTab0_First_Pass = False
      ;Run on first pass because flag is set
      ;ConsoleWrite("First pass" & @CRLF)

      ;https://www.autoitscript.com/forum/topic/124882-problem-with-placing-child-forms-on-the-main-form/?do=findComment&comment=867692
      ;rover, Feb 2011
      ;WS_EX_CONTROLPARENT allows to tab through the controls on child windows. Without this style, the child dialog is tabbed as one control
      ;you can prevent a child dialog with WS_EX_CONTROLPARENT style from being dragged with a WM_NCHITTEST message handler.
      ;$idTab0 = GUICreate("TAB 0", $GuiWidth - 4, $GuiHight - 30, 1, 28, BitOR($WS_CHILD, $WS_TABSTOP), $WS_EX_CONTROLPARENT, $hMainGUI)
      ;https://www.autoitscript.com/forum/topic/133019-input-controls-in-child-windows/?do=findComment&comment=927084
      ;Melba 23, September 2011
      ;I have never really liked using $WS_CHILD - I find it gives too many problems, as you have discovered.
      ;So I tend to use _WinAPI_SetParent to get the correct parent/child relationship.
      ;$idTab0 = GUICreate("TAB 0", $GuiWidth - 4, $GuiHight - 30, 1, 28, $WS_POPUP)
      ;_WinAPI_SetParent($idTab0, $hMainGUI)
      ;https://www.autoitscript.com/forum/topic/170046-tabbing-between-parrent-control-and-child-controls/?do=findComment&comment=1242757
      ;$F = GuiCreate('', $FW, $FH, $FX, $FY, $WS_Popup, $WS_EX_MDICHILD, $gForm)
      ;OK trigger input on enter key, NO Tabbing between parent and child controls (non esencial), NO close main GUI on ESC where child active (fácil subsanar no idle loop)
      $idTab0 = GUICreate("TAB 0", $GuiWidth - 4, $GuiHight - 30, 1, 28, $WS_POPUP, $WS_EX_MDICHILD, $hMainGUI)
      ;GUISetBkColor(0xA9A9A9)

      Global $iShowGui1a = GUICtrlCreateButton("Show GUI", 800, 10, 100, 33)

      ;from Melba23 GUIListViewEx
      $cLV = GUICtrlCreateListView("F0|F1|F2|F3", 2, 2, 600, 400)
      _GUICtrlListView_SetExtendedListViewStyle($cLV, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
      GUICtrlSetFont($cLV, 10, Default, Default, "Segoe UI") ; Note edit control will use same font

      _GUICtrlListView_SetColumnWidth($cLV, 0, 27)
      _GUICtrlListView_SetColumnWidth($cLV, 1, 180)
      _GUICtrlListView_SetColumnWidth($cLV, 2, 140)
      _GUICtrlListView_SetColumnWidth($cLV, 3, 65)

      ; Create array and fill listview
      Global $rstArray[5][4]
      $rstCount_1 = Ubound($rstArray)
      $rstCount_2 = Ubound($rstArray, 2)
      For $i = 0 To $rstCount_1 - 1
         For $j = 0 To $rstCount_2 - 1
            $rstArray[$i][$j] =  "SubItem " & $i & "-" & $j
         Next
      Next

      ;Load the ListView with data
      _GUICtrlListView_AddArray($cLV, $rstArray)

      ;Melba23
      ;Set array to give alternate line colouring
      ReDim $aColArBand[$rstCount_1][$rstCount_2]
      For $i = 0 To $rstCount_1 - 1
         If Mod($i,2) = 0 Then
            For $j = 0 To $rstCount_2 - 1
               $aColArBand[$i][$j] = ";0xFFFFFF"
            Next
         Else
            For $j = 0 To $rstCount_2 - 1
               $aColArBand[$i][$j] = ";0xE6E6E6"
            Next
         EndIf
      Next
      ;Initiate LVEx - using filling array - user colours
      ;Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting
      $iLV = _GUIListViewEx_Init($cLV, $rstArray, 0, 0, False, 1 + 4 + 32 + 1024)

      ;Load the required ListView colour array
      _GUIListViewEx_LoadColour($iLV, $aColArBand)
      ;Set editable columns
      _GUIListViewEx_SetEditStatus($iLV, "1-3")

      ;Set deafult colours to use
      Global $aDefCols[4] = ["0x000000", "0xFEFEFE", "0xFFFFFF", "0x778899"]
      ;Sets default colours for user colour/single cell select enabled ListViews
      _GUIListViewEx_SetDefColours($iLV, $aDefCols)

      #cs
      Melba 23
      From 'A Beginner’s Guide To Melba23’s GUIListViewEx UDF':
      The UDF registers these 4 messages automatically – if you already have handlers for these messages in your script,
      do not register them again using the UDF function (set the relevant parameter of _GUIListViewEx_MsgRegister to False)
      but call the relevant UDF handler function (_GUIListViewEx_WM_NOTIFY_Handler) from within your existing handler.
      Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler
      #ce
      ;prevent the UDF from initially registering the WM_NOTIFY
      ;If colours used then this function must be run BEFORE GUISetState
      ;Register required message BEFORE any colour actions (register for sorting, dragging and editing)
      ;If message handlers already registered, then call the relevant handler function from within that handler
      ;https://www.autoitscript.com/forum/topic/182492-guilistviewex-bugfix-version-26-apr-19/?do=findComment&comment=1431227
      ;I'm having difficuties tryng to integrate two features:
      _GUIListViewEx_MsgRegister()

      GUISetState(@SW_SHOW, $idTab0)
   Else
      ;Flag remains cleared for subsequent passes
      ;ConsoleWrite("Not first pass" & @CRLF)

      If $iTabPrev = 1 Then
         GUISetState(@SW_HIDE, $idTab1)
         GUICtrlSetBkColor($iLblTab0, 0xFFFFFF)
         GUICtrlSetBkColor($iLblTab1, 0xD3D3D3)
      EndIf

      _GUIListViewEx_MsgRegister()
      GUISetState(@SW_SHOW, $idTab0)
   EndIf
   $iTabPrev = 0
EndFunc

Func _Show_Tab1()
   If $iTabPrev = 0 Then
      GUISetState(@SW_HIDE, $idTab0)
      GUICtrlSetBkColor($iLblTab0, 0xD3D3D3)
      GUICtrlSetBkColor($iLblTab1, 0xFFFFFF)
   EndIf
   $iTabPrev = 1

   ;Set the flag only on the first entry into the function
   ;This assignment will be ignored on subsequent entries
   Local Static $bTab1_First_Pass = True

   ;Check the flag
   If $bTab1_First_Pass Then
      ;Immediately clear the flag to prevent running on subsequent passes
      $bTab1_First_Pass = False
      ;Run on first pass because flag is set
      ;ConsoleWrite("First pass" & @CRLF)

      $idTab1 = GUICreate("TAB 1", $GuiWidth - 4, $GuiHight - 30, 1, 28, $WS_POPUP, $WS_EX_MDICHILD, $hMainGUI)
      ;GUISetBkColor(0x00E0FFFF)

      Global $iShowGui1b = GUICtrlCreateButton("Show GUI", 670, 2, 100, 33)

      Global $Label = GUICtrlCreateLabel("Selected: ", 670, 34, 300, 200)
      GUICtrlSetFont(-1, 11, Default, Default, "Segoe UI")

      ;Melba23
      $cLV = GUICtrlCreateListView("Col 0|Col 1", 670, 250, 350, 300)
      _GUICtrlListView_SetColumnWidth($cLV, 0, 250)
      _GUICtrlListView_SetColumnWidth($cLV, 1, 550) ; Column wider than ListView <<<<<<<<<<<<<<<<<<<<<<<<<<<

      Global $aContent[5]
      For $i = 0 To 4
          $aContent[$i] = "Item " & $i & "-0|Item " & $i & "-1"
          GUICtrlCreateListViewItem($aContent[$i], $cLV)
      Next

      Global $iLV_Index = _GUIListViewEx_Init($cLV, $aContent)

      _GUIListViewEx_SetEditStatus($iLV_Index, "1") ; Wide column editable <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

      ;https://www.autoitscript.com/forum/topic/139314-custom-listview-icons-checkboxes-multiline-edit-in-place/?do=findComment&comment=980443
      ;rover
      ; WM_MEASUREITEM allows setting the row height
      GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ; place before listview creation - message sent once for each ownerdrawn control created
      GUIRegisterMsg($WM_DRAWITEM, "WM_DRAWITEM") ;placed here, WM_MEASUREITEM can now be unregistered in the handler (deleting or adding items after unregistering maintains row height setting this way)

      Global $cListView_1 = GUICtrlCreateListView("", 8, 2, 326, $GuiHight-112, BitOR($LVS_REPORT, $LVS_NOCOLUMNHEADER, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS))
      $hListView_1 = GUICtrlGetHandle($cListView_1)
      _GUICtrlListView_SetExtendedListViewStyle($hListView_1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT)) ;double buffer improves performance
      _GUICtrlListView_AddColumn($hListView_1, "", 296) ;270

      GUIRegisterMsg($WM_MEASUREITEM, "WM_MEASUREITEM") ; place before listview creation - message sent once for each ownerdrawn control created
      Global $cListView_2 = GUICtrlCreateListView("", 334, 2, 326, $GuiHight-112, BitOR($LVS_REPORT, $LVS_NOCOLUMNHEADER, $LVS_OWNERDRAWFIXED, $LVS_SHOWSELALWAYS))
      $hListView_2 = GUICtrlGetHandle($cListView_2)
      _GUICtrlListView_SetExtendedListViewStyle($hListView_2, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FULLROWSELECT)) ;double buffer improves performance
      _GUICtrlListView_AddColumn($hListView_2, "", 296)

      Global $aTextHdr[4] = ["From:", "Sent:", "To:", "Subject:"]
      For $row = 1 To 5
         _GUICtrlListView_BeginUpdate($hListView_1)
         _GUICtrlListView_AddItem($hListView_1, "Rover - AutoIt Forums|Thursday, April 19, 2012 05:0" & $row - 1 & "AM|footswitch|Re: Multiline listview like Outlook|" & _
               "This is a rough mock-up of that Outlook listview" & @CRLF & "You will need to add code for the text metrics")
         _GUICtrlListView_EndUpdate($hListView_1)

         _GUICtrlListView_BeginUpdate($hListView_2)
         _GUICtrlListView_AddItem($hListView_2, "Rover - AutoIt Forums|Thursday, April 19, 2012 05:0" & $row - 1 & "AM|footswitch|Re: Multiline listview like Outlook|" & _
               "This is a rough mock-up of that Outlook listview" & @CRLF & "You will need to add code for the text metrics")
         _GUICtrlListView_EndUpdate($hListView_2)
      Next

      ;~ ;adjust listview size for number of items shown - for efficient painting and to eliminate issue of a click on bottom item causing a jump to next item
      ;~ Local $iY = _GUICtrlListView_ApproximateViewHeight($hListView_1, _GUICtrlListView_GetCounterPage($hListView_1))
      ;~ GUICtrlSetPos($cListView_1, 2, 2, 328, $iY + 4)
      ;~ GUICtrlSetPos($cListView_2, 332, 2, 328, $iY + 4)

      ;~ Global $cSelect = GUICtrlCreateButton("Themed Select", 2, $iY + 8, 120, 23)
      ;~ Global $cTheme = GUICtrlCreateCombo("Button", 120+2, $iY + 9, 60)
      ;~ GUICtrlSetData(-1, "Listview", "Button")
      ;~ Global $cState = GUICtrlCreateCombo("1 NORMAL", 180+4, $iY + 9, 80)
      ;~ GUICtrlSetData(-1, "2 HOT|3 PRESSED|4 GREYED|5 DEFAULT", "1 NORMAL")
      ;~ Global $cLabel =  GUICtrlCreateLabel("Select Item"&@CRLF&"Style", 260+8, $iY + 8)

      ;Now trying to detect the index of highlighted item in the multiline ListView
      GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

      ;Melba 23
      ;prevent the UDF from initially registering the WM_NOTIFY
      ;If message handlers already registered, then call the relevant handler function from within that handler
      _GUIListViewEx_MsgRegister(False)

      GUISetState(@SW_SHOW, $idTab1)
   Else
      ;Flag remains cleared for subsequent passes
      ;ConsoleWrite("Not first pass" & @CRLF)

      ;Now trying to detect the index of highlighted item in the multiline ListView
      GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

      ;Melba 23
      ;prevent the UDF from initially registering the WM_NOTIFY
      ;If message handlers already registered, then call the relevant handler function from within that handler
      _GUIListViewEx_MsgRegister(False)

      GUISetState(@SW_SHOW, $idTab1)
   EndIf
EndFunc

Func _WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $iMsg, $iwParam, $ilParam
    Switch Number($hWnd)
        Case Number($idTab0), Number($idTab1)
            ;Local $iCode = _WinAPI_DefWindowProc($hWnd, $iMsg, $iwParam, $ilParam)
            ;If $iCode = 2 Then Return 1
            ;Return $iCode
            Return 1
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

;From: Melba23: Detect item checking
;https://www.autoitscript.com/forum/topic/182492-guilistviewex-new-version-27-may-16/?do=findComment&comment=1325933
;But you do not need to add this to the UDF code
;just create your own handler as below, do not register $WM_NOTIFY using the UDF function
;(set the relevant parameter of _GUIListViewEx_MsgRegister to False)
;and then call the UDF handler function (_GUIListViewEx_WM_NOTIFY_Handler) from within your own handler.
Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)

   ;Melba23, March 2014
   ;https://www.autoitscript.com/forum/topic/159764-reading-gui-date-control-instantly/?do=findComment&comment=1161074
   ;Start by looking for the Date control
;~    Switch _WinAPI_LoWord($wParam) ; ControlID of the control
;~    Case $iDate
;~       Local $tStruct = DllStructCreate($tagNMHDR, $lParam)
;~       If DllStructGetData($tStruct, "Code") = $DTN_DATETIMECHANGE Then
;~          ConsoleWrite("1: " & GUICtrlRead($iDate) & @CRLF)
;~       EndIf
;~    EndSwitch

   ;And then see if the ListView needs attention
   Local $hWndFrom, $iCode, $tNMHDR, $iIDFrom
   $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
   $hWndFrom = HWnd(DllStructGetData($tNMHDR, "HwndFrom"))
   $iCode = DllStructGetData($tNMHDR, "Code")

   ;argumentum, Nov 2017
   ;https://www.autoitscript.com/forum/topic/191058-datetime-pick-coloring/
   $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")

   Switch $hWndFrom
;~    Case $g_hDTP
;~       Switch $iCode
;~          Case $NM_KILLFOCUS
;~             ConsoleWrite("$NM_KILLFOCUS" & @CRLF & "-->hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
;~                "-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
;~                "-->Code:" & @TAB & $iCode & @CRLF)
;~             Consolewrite("+-> GUICtrlRead:" & @TAB & GUICtrlRead($iDate) & @CRLF)
;~             $CurMonday = Monday(GUICtrlRead($iDate))
;~             GUISetState(@SW_LOCK, $hMainGUI)
;~             GUICtrlSetData($iDate, $CurMonday)
;~             Delete_Week()
;~             Load_Week()
;~             GUISetState(@SW_UNLOCK, $hMainGUI)
;~       EndSwitch

         Case $hListView_1, $hListView_2
            Switch $iCode
;~             Case $NM_CLICK
;~               Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
;~               ;Local $Index = DllStructGetData($tInfo, "Index")
;~               If DllStructGetData($tInfo, "Index") = -1 Then
;~                   ;ConsoleWrite("no item" & @CRLF)
;~               Else
;~                   ;ConsoleWrite(_GUICtrlListView_GetItemText($hWndListView, $Index) & @CRLF)
;~               EndIf
               Case $LVN_ITEMCHANGED
                  Global $hWndListView = DllStructGetData($tNMHDR, 1)
                  ;Global $hWndListView = $hWndFrom

                  If $hWndListView = $hListView_1 Then
                     Local $nLV = "Monday"
                  ElseIf $hWndListView = $hListView_2 Then
                     Local $nLV = "Tuesday"
                  EndIf

                  Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                  Global $Index = DllStructGetData($tInfo, "Item")

                  ;From Zedna, in 'Highlighted item in the ListView?'
                  ;https://www.autoitscript.com/forum/topic/96234-highlighted-item-in-the-listview/?do=findComment&comment=691927
                  ;if state has changed
                  If BitAND(DllStructGetData($tInfo, "Changed"), $LVIF_STATE) = $LVIF_STATE And DllStructGetData($tInfo, "NewState") <> DllStructGetData($tInfo, "OldState") Then
                     ;take care of only newly selected items (not deselected ones)
                     If BitAND(DllStructGetData($tInfo, "NewState"), $LVIS_SELECTED) = $LVIS_SELECTED Then
                        ;ConsoleWrite("Index: " & $Index & @TAB & _GUICtrlListView_GetItemText($hWndListView, $Index) & @CRLF)
                        ;Help File
                        ;Local $aItem = _GUICtrlListView_GetItem($hWndListView, $Index)
                        ;MsgBox($MB_SYSTEMMODAL, "Information", $aItem[3])

                        GUICtrlSetData($Label, "Selected " & $nLV & ": " & _GUICtrlListView_GetItemText($hWndListView, $Index))
                        Local $aArray = StringSplit(_GUICtrlListView_GetItemText($hWndListView, $Index), "|")
                        ;...

                     EndIf
                  EndIf
               Case $NM_DBLCLK
                  ;Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                  ;Global $Index = DllStructGetData($tInfo, "Index")

                  If $hWndListView = $hListView_1 Then
                     Local $nLV = "Monday"
                  ElseIf $hWndListView = $hListView_2 Then
                     Local $nLV = "Tuesday"
                  EndIf

                  If $Index = -1 Then
                     ;Local $iItemText = ''
                     ;ConsoleWrite("no item" & @CRLF)
                  Else
                     GUICtrlSetData($Label, $nLV & " " & "Dbclick item " & $Index)
                     ;_GUICtrlListView_SetItemText($hWndListView, $Index, "aaa|bbbb|cccc|ddd|eee")
                     _Show_GUI1()
                  EndIf
            EndSwitch
   EndSwitch

   ;Return $GUI_RUNDEFMSG
   ;From Melba23: pass the same parameters to the UDF handler as you received in your WM_NOTIFY handler:
   ;Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler
   _GUIListViewEx_WM_NOTIFY_Handler($hWnd, $Msg, $wParam, $lParam)
EndFunc

Func _Show_GUI1()
   GUISetState(@SW_DISABLE, $hMainGUI)
   If $iTabPrev = 0 Then
      GUISetState(@SW_DISABLE, $idTab0)
   ElseIf $iTabPrev = 1 Then
      GUISetState(@SW_DISABLE, $idTab1)
   EndIf

   ;GUIRegisterMsg($WM_NOTIFY, "")
   _GUIListViewEx_MsgRegister()

   ;mpower, June 2014
   ;https://www.autoitscript.com/forum/topic/162250-need-explanation-about-gui-parentchild-relationship/?do=findComment&comment=1179058
   ;Note how if you show the child GUI and then click anywhere on the parent GUI the Child GUI will *flash*. This is useful where you don't want a user to dismiss something important...
   $hGUI1 = GUICreate("Test2", 600, 600, -1, -1, -1, $WS_EX_MDICHILD, $hMainGUI)

   $cLV_2 = GUICtrlCreateListView("F0|F1|F2|F3", 2, 2, 600, 500)
   _GUICtrlListView_SetExtendedListViewStyle($cLV_2, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))

   ;Set font
   GUICtrlSetFont($cLV_2, 10, Default, Default, "Segoe UI") ; Note edit control will use same font

   _GUICtrlListView_SetColumnWidth($cLV_2, 0, 27)
   _GUICtrlListView_SetColumnWidth($cLV_2, 1, 100)
   _GUICtrlListView_SetColumnWidth($cLV_2, 2, 100)
   _GUICtrlListView_SetColumnWidth($cLV_2, 3, 100)

   ; Create array and fill listview
   Global $rstArray[10][4]
   $rstCount_1 = Ubound($rstArray)
   $rstCount_2 = Ubound($rstArray, 2)
   For $i = 0 To $rstCount_1 - 1
      For $j = 0 To $rstCount_2 - 1
         $rstArray[$i][$j] =  "SubItem " & $i & "-" & $j
      Next
   Next

   ;Load the ListView with data
   _GUICtrlListView_AddArray($cLV_2, $rstArray)

   ;Melba23
   ;Set array to give alternate line colouring
   Local $aColArBand2[$rstCount_1][$rstCount_2]
   For $i = 0 To $rstCount_1 - 1
      If Mod($i,2) = 0 Then
         For $j = 0 To $rstCount_2 - 1
            $aColArBand2[$i][$j] = ";0xFFFFFF"
         Next
      Else
         For $j = 0 To $rstCount_2 - 1
            $aColArBand2[$i][$j] = ";0xE6E6E6"
         Next
      EndIf
   ;~    ;Check all items, see examples:
   ;~    ;https://www.autoitscript.com/wiki/Snippets_(_Checkboxes_)
   ;~    If $rstArray[$i][10] = True Then
   ;~     _GUICtrlListView_SetItemChecked($cLV_2, $i, True)
   ;~    EndIf
   Next
   ;Initiate LVEx - using filling array - user colours
   ;Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting
   $iLV_2 = _GUIListViewEx_Init($cLV_2, $rstArray, 0, 0, False, 1 + 4 + 32 + 1024)

   ;Load the required ListView colour array
   _GUIListViewEx_LoadColour($iLV_2, $aColArBand2)
   ;Set editable columns
   _GUIListViewEx_SetEditStatus($iLV_2, "1-2")

   ;Initialise tooltip to display 0 column item content for 2 secs when clicked
   _GUIListViewEx_ToolTipInit($iLV_2, "1", 2000)

   ;SPACEBAR (but then we have to prevent to change the checbox state)
   ;_GUIListViewEx_SetEditKey("20")
   ;If @error Then Exit MsgBox(0, "", @error)

   ;~ ;Register required message BEFORE any colour actions (register for sorting, dragging and editing)
   ;~ ;If colours used then this function must be run BEFORE GUISetState
   ;~ _GUIListViewEx_MsgRegister()

   ;Sets default colours for user colour/single cell select enabled ListViews
   _GUIListViewEx_SetDefColours($iLV_2, $aDefCols)

   GUISetState()
EndFunc

;https://www.autoitscript.com/forum/topic/139314-custom-listview-icons-checkboxes-multiline-edit-in-place/?do=findComment&comment=980443
;rover, April 19, 2012 (edited)
Func WM_MEASUREITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tMEASUREITEMS = DllStructCreate("uint cType;uint cID;uint itmID;uint itmW;uint itmH;ulong_ptr itmData", $lParam)
    If DllStructGetData($tMEASUREITEMS, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    DllStructSetData($tMEASUREITEMS, "itmH", $iListView_row_height) ; row height
    GUIRegisterMsg($WM_MEASUREITEM, "") ; unregister message handler call this after last ownerdrawn listview created - message no longer sent
    Return 1
EndFunc   ;==>WM_MEASUREITEM

Func WM_DRAWITEM($hWnd, $Msg, $wParam, $lParam)
    Local $tDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hItm, $hDC
    $tDRAWITEMSTRUCT = DllStructCreate( _
            "uint cType;" & _
            "uint cID;" & _
            "uint itmID;" & _
            "uint itmAction;" & _
            "uint itmState;" & _
            "hwnd hItm;" & _
            "handle hDC;" & _
            "long itmRect[4];" & _
            "ulong_ptr itmData" _
            , $lParam)
    If DllStructGetData($tDRAWITEMSTRUCT, "cType") <> $ODT_LISTVIEW Then Return $GUI_RUNDEFMSG
    $cID = DllStructGetData($tDRAWITEMSTRUCT, "cID")
    $itmID = DllStructGetData($tDRAWITEMSTRUCT, "itmID")
    $itmAction = DllStructGetData($tDRAWITEMSTRUCT, "itmAction")
    $itmState = DllStructGetData($tDRAWITEMSTRUCT, "itmState")
    $hItm = DllStructGetData($tDRAWITEMSTRUCT, "hItm")
    $hDC = DllStructGetData($tDRAWITEMSTRUCT, "hDC")
    Switch $cID ; will look for ControlID, not window handle.
        Case $cListView_1, $cListView_2, $cListView_3, $cListView_4, $cListView_5
            Switch $itmAction
            Case $ODA_DRAWENTIRE
                    __WM_DRAWITEM_ListView($hItm, $tDRAWITEMSTRUCT, $cID, $itmID, $itmAction, $itmState, $hDC)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DRAWITEM

Func __WM_DRAWITEM_ListView(ByRef $hLV, ByRef $tDRAWITEMSTRUCT, ByRef $cID, ByRef $itmID, ByRef $itmAction, ByRef $itmState, ByRef $hDC)
    Local $iTxtCol, $bSelected = BitAND($itmState, $ODS_SELECTED), $iTextFormatting = BitOR($DT_LEFT, $DT_WORDBREAK)
    If Not $bSelected Then
        $iTxtCol = 0xB79588
    Else ;selected
        $iTxtCol = 0x494949
        ;Theme Parts and States
        ;http://msdn.microsoft.com/en-us/library/windows/desktop/bb773210%28v=vs.85%29.aspx
        Local $pItemRect = DllStructGetPtr($tDRAWITEMSTRUCT, "itmRect")
        If $hTheme Then
            If $sTheme = "Listview" Then
                Local $tItemRect = DllStructCreate($tagRect, $pItemRect)
                    DllStructSetData($tItemRect, 1, DllStructGetData($tItemRect, 1)+1)
                    DllStructSetData($tItemRect, 2, DllStructGetData($tItemRect, 2)+1)
                    DllStructSetData($tItemRect, 3, DllStructGetData($tItemRect, 3)-1)
                    DllStructSetData($tItemRect, 4, DllStructGetData($tItemRect, 4)-1)
                $pItemRect = DllStructGetPtr($tItemRect)
            EndIf
            DllCall($iDllUxtheme, 'uint', 'DrawThemeBackground', 'ptr', $hTheme, 'hwnd', $hDC, 'int', $iThemePart, 'int', $iThemeState, 'ptr', $pItemRect, 'ptr', 0)
        Else
            DllCall($iDllUSER32, "int", "FillRect", "handle", $hDC, "ptr", DllStructGetPtr($tDRAWITEMSTRUCT, "itmRect"), "handle", $hBrush)
        EndIf
    EndIf
    GUICtrlSendMsg($cID, $LVM_GETITEMTEXTW, $itmID, $pLVITEM)
    Local $aSubItmText = StringSplit(DllStructGetData($tLVText, 1), "|", 2)
    DllStructSetData($tLVText, 1, "")
    DllStructSetData($tLVRect, "Top", 0)
    DllStructSetData($tLVRect, "Left", $LVIR_BOUNDS)
    GUICtrlSendMsg($cID, $LVM_GETSUBITEMRECT, $itmID, DllStructGetPtr($tLVRect))
    Local $iLeft = DllStructGetData($tLVRect, 1) + 6 ;Left
    Local $iTop = DllStructGetData($tLVRect, 2) ;Top
    DllStructSetData($tLVRect, 1, $iLeft) ;Left

    Switch $hLV
        Case $hListView_1, $hListView_2, $hListView_3, $hListView_4, $hListView_5
            Local $iColPrev = __WinAPI_SetTextColor($hDC, 0x000000) ;save previous font and text colour
            Local $hFontOld = __WinAPI_SelectObject($hDC, $aFont[0]) ;Bold

            ;------------------------------------------------------------
            ;multiline, but no per line indentation or colour
            ;DllStructSetData($tLVRect, 2, $iTop+2)
            ;__WinAPI_DrawText($hDC, "From:"&@CRLF&"Sent:"&@CRLF&"To:"&@CRLF&"Subject:", $tLVRect, $iTextFormatting)
            ;------------------------------------------------------------

            DllStructSetData($tLVRect, 2, $iTop + 2)
            __WinAPI_DrawText($hDC, $aTextHdr[0], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 2, $iTop + 20)
            __WinAPI_DrawText($hDC, $aTextHdr[1], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 2, $iTop + 38)
            __WinAPI_DrawText($hDC, $aTextHdr[2], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 2, $iTop + 56)
            __WinAPI_DrawText($hDC, $aTextHdr[3], $tLVRect, $iTextFormatting)


            __WinAPI_SelectObject($hDC, $aFont[1]) ;Normal

            ;------------------------------------------------------------
            ;multiline, but no per line indentation or colour
            ;__WinAPI_SetTextColor($hDC, 0x494949)
            ;DllStructSetData($tLVRect, 1, $iLeft+50)
            ;DllStructSetData($tLVRect, 2, $iTop+2)
            ;__WinAPI_DrawText($hDC, $aSubItmText[0]&@CRLF&$aSubItmText[1]&@CRLF&$aSubItmText[2]&@CRLF&$aSubItmText[3], $tLVRect, $iTextFormatting)
            ;------------------------------------------------------------

            __WinAPI_SetTextColor($hDC, 0xFF0000)

            DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[0]) + 5)
            DllStructSetData($tLVRect, 2, $iTop + 2)
            __WinAPI_DrawText($hDC, $aSubItmText[0], $tLVRect, $iTextFormatting)

            __WinAPI_SetTextColor($hDC, 0x494949)

            DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[1]) + 5)
            DllStructSetData($tLVRect, 2, $iTop + 20)
            __WinAPI_DrawText($hDC, $aSubItmText[1], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[2]) + 5)
            DllStructSetData($tLVRect, 2, $iTop + 38)
            __WinAPI_DrawText($hDC, $aSubItmText[2], $tLVRect, $iTextFormatting)

            DllStructSetData($tLVRect, 1, $iLeft + __GUICtrlListView_GetStringWidth($cID, $aTextHdr[3]) + 5)
            DllStructSetData($tLVRect, 2, $iTop + 56)
            __WinAPI_DrawText($hDC, $aSubItmText[3], $tLVRect, $iTextFormatting)

            __WinAPI_SetTextColor($hDC, $iTxtCol)
            DllStructSetData($tLVRect, 1, $iLeft + 2)
            DllStructSetData($tLVRect, 2, $iTop + 80)
            __WinAPI_DrawText($hDC, $aSubItmText[4], $tLVRect, $iTextFormatting)

            If $bSelected And $hTheme Then Return ;optional - don't paint lines when item selected - in this example only for benefit of themed selected items

            Local $obj_orig = __WinAPI_SelectObject($hDC, $hPen1)
            __WinAPI_DrawLine($hDC, $iLeft, DllStructGetData($tLVRect, 4) - 2, 320 - ($iLeft * 2) - 16, DllStructGetData($tLVRect, 4) - 2)
            __WinAPI_SelectObject($hDC, $hPen2)
            __WinAPI_DrawLine($hDC, $iLeft, DllStructGetData($tLVRect, 4) - 3, 320 - ($iLeft * 2) - 16, DllStructGetData($tLVRect, 4) - 3)
            __WinAPI_SelectObject($hDC, $obj_orig)

            ;__WinAPI_SelectObject($hDC, $hFontOld)
            ;__WinAPI_SetTextColor($hDC, $iColPrev)
    EndSwitch
    Return
EndFunc   ;==>__WM_DRAWITEM_ListView

Func __WinAPI_DrawLine($hDC, $iX1, $iY1, $iX2, $iY2)
    DllCall($iDllGDI, "bool", "MoveToEx", "handle", $hDC, "int", $iX1, "int", $iY1, "ptr", 0)
    If @error Then Return SetError(@error, @extended, False)
    DllCall($iDllGDI, "bool", "LineTo", "handle", $hDC, "int", $iX2, "int", $iY2)
    If @error Then Return SetError(@error, @extended, False)
    Return True
EndFunc   ;==>__WinAPI_DrawLine

Func __WinAPI_DrawText(ByRef $hDC, $sText, ByRef $tRect, ByRef $iFlags)
    DllCall($iDllUSER32, "int", "DrawTextW", "hwnd", $hDC, "wstr", $sText, "int", StringLen($sText), "struct*", $tRect, "int", $iFlags)
EndFunc   ;==>__WinAPI_DrawText

Func __WinAPI_SetTextColor($hDC, $iColor)
    Local $aResult = DllCall($iDllGDI, "INT", "SetTextColor", "handle", $hDC, "dword", $iColor)
    If @error Then Return SetError(@error, @extended, -1)
    Return $aResult[0]
EndFunc   ;==>__WinAPI_SetTextColor

Func __WinAPI_SelectObject($hDC, $hGDIObj)
    Local $aResult = DllCall($iDllGDI, "handle", "SelectObject", "handle", $hDC, "handle", $hGDIObj)
    If @error Then Return SetError(@error, @extended, False)
    Return $aResult[0]
EndFunc   ;==>__WinAPI_SelectObject

Func __GUICtrlListView_GetStringWidth($hWnd, $sString)
    Local $tBuffer = DllStructCreate("wchar Text[" & StringLen($sString) + 1 & "]")
    DllStructSetData($tBuffer, "Text", $sString)
    Local $iRet = GUICtrlSendMsg($hWnd, $LVM_GETSTRINGWIDTHW, 0, DllStructGetPtr($tBuffer))
    Return $iRet
 EndFunc   ;==>__GUICtrlListView_GetStringWidth

 

Edited by robertocm
Tab controls replaced by Child GUIs
Link to comment
Share on other sites

  • Moderators

robertocm,

That sounds a very sensible solution - glad you got it working.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple 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

 

Link to comment
Share on other sites

On 7/22/2018 at 9:33 AM, Melba23 said:

It is not difficult to amend the UDF to indicate a selection change using _EventMonitor

Dear Melba23,

Now asking for a new feature for _GUIListViewEx_EventMonitor , if possible:

Indicating double click events in non-editable columns.

#cs ----------------------------------------------------------------------------
Melba23
https://www.autoitscript.com/forum/topic/182492-guilistviewex-new-version-22-feb-18/?do=findComment&comment=1397949
#ce ----------------------------------------------------------------------------

#include <GuiConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include "GUIListViewEx.au3"

;Create GUI
$hGUI = GUICreate("LVEx Example GetLastSel", 640, 510)

; Create ListView
Global $cListView_Left = GUICtrlCreateListView("Tom|Dick|Harry", 10, 40, 300, 300, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($cListView_Left, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_SetColumnWidth($cListView_Left, 0, 93)
_GUICtrlListView_SetColumnWidth($cListView_Left, 1, 93)
_GUICtrlListView_SetColumnWidth($cListView_Left, 2, 93)

; Create ListView
Global $cListView_Right = GUICtrlCreateListView("Tom|Dick|Harry", 310, 40, 300, 300, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($cListView_Right, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_SetColumnWidth($cListView_Right, 0, 93)
_GUICtrlListView_SetColumnWidth($cListView_Right, 1, 93)
_GUICtrlListView_SetColumnWidth($cListView_Right, 2, 93)

; Create array and fill Left listview
Global $aLV_List[10]
For $i = 0 To UBound($aLV_List) - 1
    $aLV_List[$i] = "Tom " & $i & "|Dick " & $i & "|Harry " & $i
    GUICtrlCreateListViewItem($aLV_List[$i], $cListView_Left)
    GUICtrlCreateListViewItem($aLV_List[$i], $cListView_Right)
Next

; Initiate LVEx
;Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting
Global $iLV_Index_Left = _GUIListViewEx_Init($cListView_Left, $aLV_List)
;~ _GUIListViewEx_SetEditStatus($iLV_Index_Left, "*")
$iLV_Index_Right = _GUIListViewEx_Init($cListView_Right, $aLV_List)
;~ _GUIListViewEx_SetEditStatus($iLV_Index_Right, "*")

$cExit_Button = GUICtrlCreateButton("Exit", 430, 390, 200, 110)

_GUIListViewEx_SetActive($iLV_Index_Left)

; Register for sorting, dragging and editing
_GUIListViewEx_MsgRegister()

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $cExit_Button
            Exit
    EndSwitch

    $vRet = _GUIListViewEx_EventMonitor()
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Error", "Event error: " & @error)
    EndIf
    Switch @extended
        Case 1 ; This is returned after an edit attempt
            If $vRet = "" Then
                MsgBox($MB_SYSTEMMODAL, "Edit", "Edit aborted" & @CRLF)
            Else
                MsgBox($MB_SYSTEMMODAL, "Edit", "Successful edit" & @CRLF)
            EndIf
        Case 9 ; This is returned after a selection change
            MsgBox($MB_SYSTEMMODAL, "Selection changed", "New selection:" & @CRLF & "Row: " & $vRet[1] & @CRLF & "Col: " & $vRet[2])
    EndSwitch

WEnd
Link to comment
Share on other sites

  • Moderators

robertocm ,

That functionality is already incorporated in the UDF - as explained in the header for _GUIListViewEx_EventMonitor:

; Return values .: Success:
[...]
;                  Failure: Sets @error as follows when editing:
[...]
;                      3 - Column not editable

So all you need to do is check for that @error return:

#include <GuiConstantsEx.au3>
#include "GUIListViewEx.au3"

;Create GUI
$hGUI = GUICreate("LVEx Example GetLastSel", 640, 510)

; Create ListView
Global $cListView_Left = GUICtrlCreateListView("Tom|Dick|Harry", 10, 40, 300, 300, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($cListView_Left, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_SetColumnWidth($cListView_Left, 0, 93)
_GUICtrlListView_SetColumnWidth($cListView_Left, 1, 93)
_GUICtrlListView_SetColumnWidth($cListView_Left, 2, 93)

; Create ListView
Global $cListView_Right = GUICtrlCreateListView("Tom|Dick|Harry", 310, 40, 300, 300, $LVS_SHOWSELALWAYS)
_GUICtrlListView_SetExtendedListViewStyle($cListView_Right, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES))
_GUICtrlListView_SetColumnWidth($cListView_Right, 0, 93)
_GUICtrlListView_SetColumnWidth($cListView_Right, 1, 93)
_GUICtrlListView_SetColumnWidth($cListView_Right, 2, 93)

; Create array and fill Left listview
Global $aLV_List[10]
For $i = 0 To UBound($aLV_List) - 1
    $aLV_List[$i] = "Tom " & $i & "|Dick " & $i & "|Harry " & $i
    GUICtrlCreateListViewItem($aLV_List[$i], $cListView_Left)
    GUICtrlCreateListViewItem($aLV_List[$i], $cListView_Right)
Next

; Initiate LVEx
;Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting
Global $iLV_Index_Left = _GUIListViewEx_Init($cListView_Left, $aLV_List)
;~ _GUIListViewEx_SetEditStatus($iLV_Index_Left, "*")
$iLV_Index_Right = _GUIListViewEx_Init($cListView_Right, $aLV_List)
;~ _GUIListViewEx_SetEditStatus($iLV_Index_Right, "*")

$cExit_Button = GUICtrlCreateButton("Exit", 430, 390, 200, 110)

_GUIListViewEx_SetActive($iLV_Index_Left)

; Register for sorting, dragging and editing
_GUIListViewEx_MsgRegister()

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $cExit_Button
            Exit
    EndSwitch
    $vRet = _GUIListViewEx_EventMonitor()
    If @error = 3 Then
        ConsoleWrite("Non-editable column" & @CRLF)
    EndIf
    Switch @extended
        Case 1 ; This is returned after an edit attempt
            If $vRet = "" Then
                ConsoleWrite("Edit aborted" & @CRLF)
            Else
                ConsoleWrite("Successful edit" & @CRLF)
            EndIf
        Case 9 ; This is returned after a selection change
            ConsoleWrite("New selection: " & $vRet[1] & "x" & $vRet[2] & @CRLF)
    EndSwitch
WEnd

All good?

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple 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

 

Link to comment
Share on other sites

Dear Melba23,

Let me explain better: return the row number of the double click item

would be something similar to this:

;                                5-7 (Not used at present)
;                                8 - User double click event  <<<<<<<<<<<<<<<<<<<<
;                                      Returns 3-element 1D array
;                                          - [ListView index, zero-based row, zero-based col]
;                                9 - User selection change event
;                                      Returns 3-element 1D array
;                                          - [ListView index, zero-based row, zero-based col]

 

And sorry, it seems that i'm finding an issue with _GUICtrlListView_GetSelectedIndices always returning no selection  (empty string) from an udf listview placed in a child gui.

For reproducing: in below example, click 'show gui' button, then in the second gui, selecting items seems to always return empty string from  _GUICtrlListView_GetSelectedIndices funcion

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include "GUIListViewEx.au3"

Opt('MustDeclareVars', 1)

;Managing Multiple GUIs - AutoIt Wiki.htm
;https://www.autoitscript.com/wiki/Main_Page
Global $hGUI1 = 9999 ;Predeclare the variables with dummy values to prevent firing the Case statements, only for GUI this time
Global $iTabPrev = -1

;from Melba23 GUIListViewEx
Global $cLV, $iLV, $vRet, $Row, $Col, $EditMode = 22
Global $iCheckState = True
Global $cLV_2, $iLV_2

Global $rstArray, $rstCount_1, $rstCount_2, $aColArBand[1][1]
Global $GuiWidth = @DesktopWidth-2, $GuiHight = @DesktopHeight-77

;https://www.autoitscript.com/forum/topic/182492-guilistviewex-bugfix-version-25-sep-17/?do=findComment&comment=1370017
;Melba 23, Oct 2017
;... and a right-click menu to select the colour of another column (1) of the selected row.
Global  $iDarkSlateGray = "0x2F4F4F", _
        $iLtBlue = "0xCCCCFF", _
        $iGreen = "0x00FF00", _
        $iBlack = "0x000000", _
        $iWheat = "0xF5DEB3", _
        $iBlue = "0x0000FF", _
        $iLightBlue = "0xADD8E6"

Global $hMainGUI = GUICreate("Example", $GuiWidth, $GuiHight)

Global $iShowGui1a = GUICtrlCreateButton("Show GUI", 800, 10, 100, 33)

;from Melba23 GUIListViewEx
$cLV = GUICtrlCreateListView("F0|F1|F2|F3", 2, 2, 600, 400)
_GUICtrlListView_SetExtendedListViewStyle($cLV, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))
GUICtrlSetFont($cLV, 10, Default, Default, "Segoe UI") ; Note edit control will use same font

_GUICtrlListView_SetColumnWidth($cLV, 0, 27)
_GUICtrlListView_SetColumnWidth($cLV, 1, 180)
_GUICtrlListView_SetColumnWidth($cLV, 2, 140)
_GUICtrlListView_SetColumnWidth($cLV, 3, 65)

; Create array and fill listview
Global $rstArray[5][4]
$rstCount_1 = Ubound($rstArray)
$rstCount_2 = Ubound($rstArray, 2)
For $i = 0 To $rstCount_1 - 1
   For $j = 0 To $rstCount_2 - 1
      $rstArray[$i][$j] =  "SubItem " & $i & "-" & $j
   Next
Next

;Load the ListView with data
_GUICtrlListView_AddArray($cLV, $rstArray)

;Melba23
;Set array to give alternate line colouring
ReDim $aColArBand[$rstCount_1][$rstCount_2]
For $i = 0 To $rstCount_1 - 1
   If Mod($i,2) = 0 Then
      For $j = 0 To $rstCount_2 - 1
         $aColArBand[$i][$j] = ";0xFFFFFF"
      Next
   Else
      For $j = 0 To $rstCount_2 - 1
         $aColArBand[$i][$j] = ";0xE6E6E6"
      Next
   EndIf
Next
;Initiate LVEx - using filling array - user colours
;Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting
$iLV = _GUIListViewEx_Init($cLV, $rstArray, 0, 0, False, 1 + 4 + 32 + 1024)

;Load the required ListView colour array
_GUIListViewEx_LoadColour($iLV, $aColArBand)
;Set editable columns
_GUIListViewEx_SetEditStatus($iLV, "1-3")

;Set deafult colours to use
Global $aDefCols[4] = ["0x000000", "0xFEFEFE", "0xFFFFFF", "0x778899"]
;Sets default colours for user colour/single cell select enabled ListViews
_GUIListViewEx_SetDefColours($iLV, $aDefCols)

#cs
Melba 23
From 'A Beginner’s Guide To Melba23’s GUIListViewEx UDF':
The UDF registers these 4 messages automatically – if you already have handlers for these messages in your script,
do not register them again using the UDF function (set the relevant parameter of _GUIListViewEx_MsgRegister to False)
but call the relevant UDF handler function (_GUIListViewEx_WM_NOTIFY_Handler) from within your existing handler.
Note that the UDF handler should be called as the final action of the existing handler and the return value should be that returned from the UDF handler
#ce
;prevent the UDF from initially registering the WM_NOTIFY
;If colours used then this function must be run BEFORE GUISetState
;Register required message BEFORE any colour actions (register for sorting, dragging and editing)
;If message handlers already registered, then call the relevant handler function from within that handler
;https://www.autoitscript.com/forum/topic/182492-guilistviewex-bugfix-version-26-apr-19/?do=findComment&comment=1431227
;I'm having difficuties tryng to integrate two features:
_GUIListViewEx_MsgRegister()

GUISetState(@SW_SHOW, $hMainGUI)

;Help: GUI Reference; Advanced GUIGetMsg and Multiple Windows
;When called with the 1 parameter instead of returning an event value an array will be returned,
;array contains the event (in $aArray[0]) and extra information such as the window handle (in $aArray[1])
;Initialize a Local variable.
Local $aMsg = 0

While 1
  ;Assign to $aMsg the advanced GUI messages.
  $aMsg = GUIGetMsg(1)

   ;Switch from GUIs
   Switch $aMsg[1]
      Case $hMainGUI
      ;The event comes from the $hMainGUI
         ;Switch from event ID
         Switch $aMsg[0]
            Case $GUI_EVENT_CLOSE
               ExitLoop
            Case $iShowGui1a
               _Show_GUI1()
         EndSwitch
      Case $hGUI1
      ;The event comes from the $hGUI1
         ;Switch from event ID
         Switch $aMsg[0]
            Case $GUI_EVENT_CLOSE
               ;Re-enable the first GUI and active Tab GUI
               GUISetState(@SW_ENABLE, $hMainGUI)
               GUIDelete($hGUI1)
         EndSwitch
   EndSwitch

   $vRet = _GUIListViewEx_EventMonitor()
   If @error = 3 Then
      MsgBox(0, "", "Non-editable column - " & _GUIListViewEx_GetLastSelItem() & @CRLF)
   EndIf
   Switch @extended
      Case 1 ; This is returned after an edit attempt
         If $vRet = "" Then
            ConsoleWrite("Edit aborted" & @CRLF)
         Else
            ConsoleWrite("Successful edit" & @CRLF)
         EndIf
      Case 9 ; This is returned after a selection change
         ConsoleWrite("New selection: " & $vRet[1] & "x" & $vRet[2] & @CRLF)
   EndSwitch
WEnd

Func _Show_GUI1()
   GUISetState(@SW_DISABLE, $hMainGUI)
   If $iTabPrev = 0 Then
      GUISetState(@SW_DISABLE, $idTab0)
   EndIf

   ;mpower, June 2014
   ;https://www.autoitscript.com/forum/topic/162250-need-explanation-about-gui-parentchild-relationship/?do=findComment&comment=1179058
   ;Note how if you show the child GUI and then click anywhere on the parent GUI the Child GUI will *flash*. This is useful where you don't want a user to dismiss something important...
   $hGUI1 = GUICreate("Test2", $GuiWidth - 400 , 600, -1, -1, -1, $WS_EX_MDICHILD, $hMainGUI)

   $cLV_2 = GUICtrlCreateListView("F0|F1|F2|F3", 2, 2, 600, 500)
   _GUICtrlListView_SetExtendedListViewStyle($cLV_2, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_DOUBLEBUFFER))

   ;Set font
   GUICtrlSetFont($cLV_2, 10, Default, Default, "Segoe UI") ; Note edit control will use same font

   _GUICtrlListView_SetColumnWidth($cLV_2, 0, 27)
   _GUICtrlListView_SetColumnWidth($cLV_2, 1, 100)
   _GUICtrlListView_SetColumnWidth($cLV_2, 2, 100)
   _GUICtrlListView_SetColumnWidth($cLV_2, 3, 100)

   ; Create array and fill listview
   Global $rstArray[10][4]
   $rstCount_1 = Ubound($rstArray)
   $rstCount_2 = Ubound($rstArray, 2)
   For $i = 0 To $rstCount_1 - 1
      For $j = 0 To $rstCount_2 - 1
         $rstArray[$i][$j] =  "SubItem " & $i & "-" & $j
      Next
   Next

   ;Load the ListView with data
   _GUICtrlListView_AddArray($cLV_2, $rstArray)

   ;Melba23
   ;Set array to give alternate line colouring
   Local $aColArBand2[$rstCount_1][$rstCount_2]
   For $i = 0 To $rstCount_1 - 1
      If Mod($i,2) = 0 Then
         For $j = 0 To $rstCount_2 - 1
            $aColArBand2[$i][$j] = ";0xFFFFFF"
         Next
      Else
         For $j = 0 To $rstCount_2 - 1
            $aColArBand2[$i][$j] = ";0xE6E6E6"
         Next
      EndIf
   ;~    ;Check all items, see examples:
   ;~    ;https://www.autoitscript.com/wiki/Snippets_(_Checkboxes_)
   ;~    If $rstArray[$i][10] = True Then
   ;~     _GUICtrlListView_SetItemChecked($cLV_2, $i, True)
   ;~    EndIf
   Next
   ;Initiate LVEx - using filling array - user colours
   ;Note that using the left/right keys only returns a "selection change" message if the ListView has been set up to allow single cell highlighting
   $iLV_2 = _GUIListViewEx_Init($cLV_2, $rstArray, 0, 0, False, 1 + 4 + 32 + 1024)

   ;Load the required ListView colour array
   _GUIListViewEx_LoadColour($iLV_2, $aColArBand2)
   ;Set editable columns
   _GUIListViewEx_SetEditStatus($iLV_2, "1-2")

   ;Initialise tooltip to display 0 column item content for 2 secs when clicked
   _GUIListViewEx_ToolTipInit($iLV_2, "1", 2000)

   ;SPACEBAR (but then we have to prevent to change the checbox state)
   ;_GUIListViewEx_SetEditKey("20")
   ;If @error Then Exit MsgBox(0, "", @error)

   ;~ ;Register required message BEFORE any colour actions (register for sorting, dragging and editing)
   ;~ ;If colours used then this function must be run BEFORE GUISetState
   ;~ _GUIListViewEx_MsgRegister()

   ;Sets default colours for user colour/single cell select enabled ListViews
   _GUIListViewEx_SetDefColours($iLV_2, $aDefCols)

   GUISetState()
EndFunc

 

Many Thanks

Edited by robertocm
[SOLVED] updated code to use _GUIListViewEx_GetLastSelItem
Link to comment
Share on other sites

  • Moderators

robertocm,

Quote

Let me explain better: return the row number of the double click item

Always helps to explain exactly what you want!

Just use the existing _GUIListViewEx_GetLastSelItem function in the UDF:

ConsoleWrite("Non-editable column - " & _GUIListViewEx_GetLastSelItem() & @CRLF)

As to your final point about _GUICtrlListView_GetSelectedIndices - if you use the UDF to add colour to a ListView you are effectively bypassing the normal Windows selection procedure, which is why selection is limited to a single item and I wrote the _GUIListViewEx_GetLastSelItem function to return its coordinates.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple 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

 

Link to comment
Share on other sites

  • Melba23 changed the title to GUIListViewEx - New Version 26 Feb 24

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...