Sign in to follow this  
Followers 0
MikahS

ListView sorting using sort callback and $LVN_COLUMNCLICK

3 posts in this topic

#1 ·  Posted (edited)

Hello all,

Back again it seems. I've hit a snag in the below script. I use this on win 7 and XP machines frequently and have just realized that sorting using column headers is not 'working' (is not updating listview; it looks like something is going on behind the scenes..) when clicked. Also this does not show the sorting arrow when using the callback sort functionality.

So, to sum up, I am not seeing the arrow keys when clicking the column header to sort. And, it is not sorting the values in the $List1 ListView box on a win XP machine.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <GUIListBox.au3>
#include <GUIEdit.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ScrollBarConstants.au3>
#include <GuiScrollBars.au3>

Local $List1, $List2, $List3, $List4, $GUIhandle
Local $Button19, $Button91, $ButtonAZ, $ButtonZA
Local $hChild_1, $cLabel_1, $cLabel_2, $cLabel_3


GUI()
Repaint()

Local $bSysMsg = False

Local $aRect = _GUICtrlListView_GetItemRect($List1, 0)
$iDeltaY = $aRect[3] - $aRect[1]

_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List2), $SB_BOTH, $ESB_DISABLE_BOTH)
_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List3), $SB_BOTH, $ESB_DISABLE_BOTH)

_GUICtrlListView_RegisterSortCallBack($List1)
_GUICtrlListView_RegisterSortCallBack($List2)
_GUICtrlListView_RegisterSortCallBack($List3)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $GUIhandle
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    Quit()
            EndSwitch
            If $bSysMsg Then
                $bSysMsg = False
                _Resize_ListViews()
            EndIf
        Case $hChild_1
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hChild_1)
            EndSwitch
    EndSwitch
WEnd

Func Repaint()
    Local $L1, $L2, $L3
    _GUICtrlListView_BeginUpdate($List1)
    _GUICtrlListView_DeleteAllItems($List1)
    _GUICtrlListView_BeginUpdate($List2)
    _GUICtrlListView_DeleteAllItems($List2)
    _GUICtrlListView_BeginUpdate($List3)
    _GUICtrlListView_DeleteAllItems($List3)
    For $Index = 0 To 10 Step 1
        $L1 = _GUICtrlListView_AddItem($List1, $Index, $Index)
        $L2 = _GUICtrlListView_AddItem($List2, $Index, $Index)
        $L3 = _GUICtrlListView_AddItem($List3, $Index, $Index)
    Next
    _GUICtrlListView_SetColumnWidth($List1, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($List2, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_EndUpdate($List1)
    _GUICtrlListView_EndUpdate($List2)
    _GUICtrlListView_EndUpdate($List3)
EndFunc   ;==>Repaint

Func Quit()
    _GUICtrlListView_UnRegisterSortCallBack($List1)
    _GUICtrlListView_UnRegisterSortCallBack($List2)
    _GUICtrlListView_UnRegisterSortCallBack($List3)
    Exit
EndFunc   ;==>Quit

Func GUI()
    Local $Index, $LV1, $LV2, $LV3, $L1_EX, $L2_EX, $L3_EX
    $GUIhandle = GUICreate("ArchServer", 680, 575, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX) ;creates the parent window
    $List1 = _GUICtrlListView_Create($GUIhandle, "Computer Name ", 20, 35, 300, 448, -1, $LVS_EX_DOUBLEBUFFER) ;;$ES_READONLY incase you don't want to be able to select text
    $cLabel_1 = GUICtrlCreateLabel("", 20, 35, 300, 448)
    GUICtrlSetState($cLabel_1, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_1, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_1, $GUI_BKCOLOR_TRANSPARENT)
    _GUICtrlListView_SetExtendedListViewStyle($List1, $LVS_EX_TWOCLICKACTIVATE)
    $List2 = _GUICtrlListView_Create($GUIhandle, "Date/Time", 355, 35, 190, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB))
    $cLabel_2 = GUICtrlCreateLabel("", 355, 35, 190, 450)
    GUICtrlSetState($cLabel_2, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_2, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_2, $GUI_BKCOLOR_TRANSPARENT)
    $List3 = _GUICtrlListView_Create($GUIhandle, "Speed", 574, 35, 95, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB))
    $cLabel_3 = GUICtrlCreateLabel("", 574, 35, 95, 450)
    GUICtrlSetState($cLabel_3, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_3, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_3, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateLabel("Additional Info", 20, 489) ;creates the label for $List4
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $List4 = GUICtrlCreateList("", 20, 512, 635, 40, BitOR($WS_BORDER, $WS_VSCROLL), $ES_READONLY)
    GUICtrlSetResizing($List4, $GUI_DOCKAUTO)
    GUICtrlCreateLabel("Active Connections: ", 525, 487) ;creates the label for the active connections
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $ActiveConnections = GUICtrlCreateList("0", 625, 486, 30, 30) ;dynamically updating list of connections as they come in
    GUICtrlSetResizing($ActiveConnections, $GUI_DOCKSIZE)
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUISetState(@SW_SHOW) ;shows the GUI window
    For $Index = 0 To 10 Step 1
        $LV1 = _GUICtrlListView_AddItem($List1, " ") ;adds a default value into $List1
        $LV2 = _GUICtrlListView_AddItem($List2, " ") ;adds a default value into $List2
        $LV3 = _GUICtrlListView_AddItem($List3, " ") ;adds a default value into $List3
    Next
EndFunc   ;==>GUI

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, _
            $ceLines, $cl
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Local Const $iLines = _SendMessage($List1, $LVM_GETTOPINDEX) - _SendMessage($List2, $LVM_GETTOPINDEX)
    _SendMessage($List2, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    _SendMessage($List3, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    Switch $hWndFrom
        Case $List1
            Switch $iCode
                Case $LVN_COLUMNCLICK
                    _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List1)
                    _GUICtrlListView_SetItemSelected($List2, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List3, $sData, True, False)
            EndSwitch
        Case $List2
            Switch $iCode
                Case $LVN_COLUMNCLICK
                    _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List2)
                    _GUICtrlListView_SetItemSelected($List1, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List3, $sData, True, False)
            EndSwitch
        Case $List3
            Switch $iCode
                Case $LVN_COLUMNCLICK
                    _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List3)
                    _GUICtrlListView_SetItemSelected($List1, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List2, $sData, True, False)
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY

Func WM_SIZE($hWnd, $msg, $wParam, $lParam)
    _Resize_ListViews()
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

Func _WM_SYSCOMMAND($hWnd, $msg, $wParam, $lParam)
    Const $SC_MAXIMIZE = 0xF030
    Const $SC_RESTORE = 0xF120
    Switch $wParam
        Case $SC_MAXIMIZE, $SC_RESTORE
            $bSysMsg = True
    EndSwitch
EndFunc   ;==>_WM_SYSCOMMAND

Func _Resize_ListViews()
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_1)
    WinMove($List1, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_2)
    WinMove($List2, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_3)
    WinMove($List3, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
EndFunc   ;==>_Resize_ListViews
;========RESIZE FUNCTIONALITY THANKS TO MELBA

All replies are much appreciated! :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites



This is one way to do it.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <GUIListBox.au3>
#include <GUIEdit.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ScrollBarConstants.au3>
#include <GuiScrollBars.au3>

Local $List1, $List2, $List3, $List4, $GUIhandle
Local $Button19, $Button91, $ButtonAZ, $ButtonZA
Local $hChild_1, $cLabel_1, $cLabel_2, $cLabel_3


GUI()
Repaint()

Local $bSysMsg = False

Local $aRect = _GUICtrlListView_GetItemRect($List1, 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $List1 = ' & $List1 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$iDeltaY = $aRect[3] - $aRect[1]

_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List2), $SB_BOTH, $ESB_DISABLE_BOTH)
_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List3), $SB_BOTH, $ESB_DISABLE_BOTH)

_GUICtrlListView_RegisterSortCallBack($List1)
_GUICtrlListView_RegisterSortCallBack($List2)
_GUICtrlListView_RegisterSortCallBack($List3)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $GUIhandle
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $GUI_EVENT_CLOSE = ' & $GUI_EVENT_CLOSE & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
                    Quit()
                Case $List1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
                    _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $List2 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
                    _GUICtrlListView_SortItems($List2, GUICtrlGetState($List2))
                Case $List3 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
                    _GUICtrlListView_SortItems($List3, GUICtrlGetState($List3))
            EndSwitch
            If $bSysMsg Then
                $bSysMsg = False
                _Resize_ListViews()
            EndIf
        Case $hChild_1
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hChild_1)
            EndSwitch
    EndSwitch
WEnd

Func Repaint()
    Local $L1, $L2, $L3
    _GUICtrlListView_BeginUpdate($List1)
    _GUICtrlListView_DeleteAllItems($List1)
    _GUICtrlListView_BeginUpdate($List2)
    _GUICtrlListView_DeleteAllItems($List2)
    _GUICtrlListView_BeginUpdate($List3)
    _GUICtrlListView_DeleteAllItems($List3)
    For $Index = 0 To 10 Step 1
        $L1 = _GUICtrlListView_AddItem($List1, $Index, $Index)
        $L2 = _GUICtrlListView_AddItem($List2, $Index, $Index)
        $L3 = _GUICtrlListView_AddItem($List3, $Index, $Index)
    Next
    _GUICtrlListView_SetColumnWidth($List1, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($List2, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_EndUpdate($List1)
    _GUICtrlListView_EndUpdate($List2)
    _GUICtrlListView_EndUpdate($List3)
EndFunc   ;==>Repaint

Func Quit()
    _GUICtrlListView_UnRegisterSortCallBack($List1)
    _GUICtrlListView_UnRegisterSortCallBack($List2)
    _GUICtrlListView_UnRegisterSortCallBack($List3)
    Exit
EndFunc   ;==>Quit

Func GUI()
    Local $Index, $LV1, $LV2, $LV3, $L1_EX, $L2_EX, $L3_EX
    $GUIhandle = GUICreate("ArchServer", 680, 575, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX) ;creates the parent window
    $List1 = GUICtrlCreateListView( "Computer Name ", 20, 35, 300, 448, -1, $LVS_EX_DOUBLEBUFFER) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLabel_1 = GUICtrlCreateLabel("", 20, 35, 300, 448)
    GUICtrlSetState($cLabel_1, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_1, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_1, $GUI_BKCOLOR_TRANSPARENT)
    _GUICtrlListView_SetExtendedListViewStyle($List1, $LVS_EX_TWOCLICKACTIVATE)
    $List2 = GUICtrlCreateListView("Date/Time", 355, 35, 190, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLabel_2 = GUICtrlCreateLabel("", 355, 35, 190, 450)
    GUICtrlSetState($cLabel_2, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_2, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_2, $GUI_BKCOLOR_TRANSPARENT)
    $List3 = GUICtrlCreateListView( "Speed", 574, 35, 95, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLabel_3 = GUICtrlCreateLabel("", 574, 35, 95, 450)
    GUICtrlSetState($cLabel_3, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_3, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_3, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateLabel("Additional Info", 20, 489) ;creates the label for $List4
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $List4 = GUICtrlCreateList("", 20, 512, 635, 40, BitOR($WS_BORDER, $WS_VSCROLL), $ES_READONLY)
    GUICtrlSetResizing($List4, $GUI_DOCKAUTO)
    GUICtrlCreateLabel("Active Connections: ", 525, 487) ;creates the label for the active connections
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $ActiveConnections = GUICtrlCreateList("0", 625, 486, 30, 30) ;dynamically updating list of connections as they come in
    GUICtrlSetResizing($ActiveConnections, $GUI_DOCKSIZE)
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUISetState(@SW_SHOW) ;shows the GUI window
    For $Index = 0 To 10 Step 1
        $LV1 = _GUICtrlListView_AddItem($List1, " ") ;adds a default value into $List1
        $LV2 = _GUICtrlListView_AddItem($List2, " ") ;adds a default value into $List2
        $LV3 = _GUICtrlListView_AddItem($List3, " ") ;adds a default value into $List3
    Next
EndFunc   ;==>GUI

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, _
            $ceLines, $cl
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Local Const $iLines = _SendMessage($List1, $LVM_GETTOPINDEX) - _SendMessage($List2, $LVM_GETTOPINDEX)
    _SendMessage($List2, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    _SendMessage($List3, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    Switch $hWndFrom
        Case $List1
            Switch $iCode
;~              Case $LVN_COLUMNCLICK
;~                  _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List1)
                    _GUICtrlListView_SetItemSelected($List2, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List3, $sData, True, False)
            EndSwitch
        Case $List2
            Switch $iCode
;~              Case $LVN_COLUMNCLICK
;~                  _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List2)
                    _GUICtrlListView_SetItemSelected($List1, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List3, $sData, True, False)
            EndSwitch
        Case $List3
            Switch $iCode
;~              Case $LVN_COLUMNCLICK
;~                  _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List3)
                    _GUICtrlListView_SetItemSelected($List1, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List2, $sData, True, False)
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY

Func WM_SIZE($hWnd, $msg, $wParam, $lParam)
    _Resize_ListViews()
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

Func _WM_SYSCOMMAND($hWnd, $msg, $wParam, $lParam)
    Const $SC_MAXIMIZE = 0xF030
    Const $SC_RESTORE = 0xF120
    Switch $wParam
        Case $SC_MAXIMIZE, $SC_RESTORE
            $bSysMsg = True
    EndSwitch
EndFunc   ;==>_WM_SYSCOMMAND

Func _Resize_ListViews()
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_1)
    WinMove($List1, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_2)
    WinMove($List2, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_3)
    WinMove($List3, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
EndFunc   ;==>_Resize_ListViews
;========RESIZE FUNCTIONALITY THANKS TO MELBA

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

 

This is one way to do it.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <GUIListBox.au3>
#include <GUIEdit.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ScrollBarConstants.au3>
#include <GuiScrollBars.au3>

Local $List1, $List2, $List3, $List4, $GUIhandle
Local $Button19, $Button91, $ButtonAZ, $ButtonZA
Local $hChild_1, $cLabel_1, $cLabel_2, $cLabel_3


GUI()
Repaint()

Local $bSysMsg = False

Local $aRect = _GUICtrlListView_GetItemRect($List1, 0)
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $List1 = ' & $List1 & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$iDeltaY = $aRect[3] - $aRect[1]

_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List2), $SB_BOTH, $ESB_DISABLE_BOTH)
_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List3), $SB_BOTH, $ESB_DISABLE_BOTH)

_GUICtrlListView_RegisterSortCallBack($List1)
_GUICtrlListView_RegisterSortCallBack($List2)
_GUICtrlListView_RegisterSortCallBack($List3)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")

While 1
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $GUIhandle
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $GUI_EVENT_CLOSE = ' & $GUI_EVENT_CLOSE & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
                    Quit()
                Case $List1 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
                    _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $List2 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
                    _GUICtrlListView_SortItems($List2, GUICtrlGetState($List2))
                Case $List3 ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
                    _GUICtrlListView_SortItems($List3, GUICtrlGetState($List3))
            EndSwitch
            If $bSysMsg Then
                $bSysMsg = False
                _Resize_ListViews()
            EndIf
        Case $hChild_1
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE
                    GUIDelete($hChild_1)
            EndSwitch
    EndSwitch
WEnd

Func Repaint()
    Local $L1, $L2, $L3
    _GUICtrlListView_BeginUpdate($List1)
    _GUICtrlListView_DeleteAllItems($List1)
    _GUICtrlListView_BeginUpdate($List2)
    _GUICtrlListView_DeleteAllItems($List2)
    _GUICtrlListView_BeginUpdate($List3)
    _GUICtrlListView_DeleteAllItems($List3)
    For $Index = 0 To 10 Step 1
        $L1 = _GUICtrlListView_AddItem($List1, $Index, $Index)
        $L2 = _GUICtrlListView_AddItem($List2, $Index, $Index)
        $L3 = _GUICtrlListView_AddItem($List3, $Index, $Index)
    Next
    _GUICtrlListView_SetColumnWidth($List1, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($List2, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_EndUpdate($List1)
    _GUICtrlListView_EndUpdate($List2)
    _GUICtrlListView_EndUpdate($List3)
EndFunc   ;==>Repaint

Func Quit()
    _GUICtrlListView_UnRegisterSortCallBack($List1)
    _GUICtrlListView_UnRegisterSortCallBack($List2)
    _GUICtrlListView_UnRegisterSortCallBack($List3)
    Exit
EndFunc   ;==>Quit

Func GUI()
    Local $Index, $LV1, $LV2, $LV3, $L1_EX, $L2_EX, $L3_EX
    $GUIhandle = GUICreate("ArchServer", 680, 575, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX) ;creates the parent window
    $List1 = GUICtrlCreateListView( "Computer Name ", 20, 35, 300, 448, -1, $LVS_EX_DOUBLEBUFFER) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLabel_1 = GUICtrlCreateLabel("", 20, 35, 300, 448)
    GUICtrlSetState($cLabel_1, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_1, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_1, $GUI_BKCOLOR_TRANSPARENT)
    _GUICtrlListView_SetExtendedListViewStyle($List1, $LVS_EX_TWOCLICKACTIVATE)
    $List2 = GUICtrlCreateListView("Date/Time", 355, 35, 190, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLabel_2 = GUICtrlCreateLabel("", 355, 35, 190, 450)
    GUICtrlSetState($cLabel_2, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_2, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_2, $GUI_BKCOLOR_TRANSPARENT)
    $List3 = GUICtrlCreateListView( "Speed", 574, 35, 95, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB)) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<
    $cLabel_3 = GUICtrlCreateLabel("", 574, 35, 95, 450)
    GUICtrlSetState($cLabel_3, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_3, $GUI_DOCKAUTO)
    GUICtrlSetBkColor($cLabel_3, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateLabel("Additional Info", 20, 489) ;creates the label for $List4
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $List4 = GUICtrlCreateList("", 20, 512, 635, 40, BitOR($WS_BORDER, $WS_VSCROLL), $ES_READONLY)
    GUICtrlSetResizing($List4, $GUI_DOCKAUTO)
    GUICtrlCreateLabel("Active Connections: ", 525, 487) ;creates the label for the active connections
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $ActiveConnections = GUICtrlCreateList("0", 625, 486, 30, 30) ;dynamically updating list of connections as they come in
    GUICtrlSetResizing($ActiveConnections, $GUI_DOCKSIZE)
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUISetState(@SW_SHOW) ;shows the GUI window
    For $Index = 0 To 10 Step 1
        $LV1 = _GUICtrlListView_AddItem($List1, " ") ;adds a default value into $List1
        $LV2 = _GUICtrlListView_AddItem($List2, " ") ;adds a default value into $List2
        $LV3 = _GUICtrlListView_AddItem($List3, " ") ;adds a default value into $List3
    Next
EndFunc   ;==>GUI

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, _
            $ceLines, $cl
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Local Const $iLines = _SendMessage($List1, $LVM_GETTOPINDEX) - _SendMessage($List2, $LVM_GETTOPINDEX)
    _SendMessage($List2, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    _SendMessage($List3, $LVM_SCROLL, 0, $iLines * $iDeltaY)
    Switch $hWndFrom
        Case $List1
            Switch $iCode
;~              Case $LVN_COLUMNCLICK
;~                  _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List1)
                    _GUICtrlListView_SetItemSelected($List2, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List3, $sData, True, False)
            EndSwitch
        Case $List2
            Switch $iCode
;~              Case $LVN_COLUMNCLICK
;~                  _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List2)
                    _GUICtrlListView_SetItemSelected($List1, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List3, $sData, True, False)
            EndSwitch
        Case $List3
            Switch $iCode
;~              Case $LVN_COLUMNCLICK
;~                  _GUICtrlListView_SortItems($List1, GUICtrlGetState($List1))
                Case $NM_CLICK
                    $sData = _GUICtrlListView_GetSelectedIndices($List3)
                    _GUICtrlListView_SetItemSelected($List1, $sData, True, False)
                    _GUICtrlListView_SetItemSelected($List2, $sData, True, False)
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY

Func WM_SIZE($hWnd, $msg, $wParam, $lParam)
    _Resize_ListViews()
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

Func _WM_SYSCOMMAND($hWnd, $msg, $wParam, $lParam)
    Const $SC_MAXIMIZE = 0xF030
    Const $SC_RESTORE = 0xF120
    Switch $wParam
        Case $SC_MAXIMIZE, $SC_RESTORE
            $bSysMsg = True
    EndSwitch
EndFunc   ;==>_WM_SYSCOMMAND

Func _Resize_ListViews()
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_1)
    WinMove($List1, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_2)
    WinMove($List2, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_3)
    WinMove($List3, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
EndFunc   ;==>_Resize_ListViews
;========RESIZE FUNCTIONALITY THANKS TO MELBA

 

While this did enable sorting on XP. It also disabled scrolling on both XP and win 7 and disabled sorting on win 7, so unfortunately I think there is some problems using regular AutoIt ListView creation.

EDIT: Okay, my mistake on the win 7 sorting. Just need to figure out how to do scrolling and (had to use handles instead of CtrlID returned from creation of ListView) highlighting of characters in WM_Notify as it seems it is no longer called with regular AutoIt ListView interaction.

EDIT 2: Alright, got it figured out, it was due to the fact I was not using the handle instead I was using the CtrlID. BrewMan's solution thus solved my problems!

My thanks goes to you BrewManNH! :D

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • mLipok
      By mLipok
      I was not lucky to find the right function so I created it by my self:
      _GUICtrlListView_GetColumnID_ByName()
      Example:
       
      #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <MsgBoxConstants.au3> Example() Func Example() GUICreate("ListView Get Column ID", 400, 300) Local $idListview = GUICtrlCreateListView("Alfa|Beta|Gama", 2, 2, 394, 268) GUISetState(@SW_SHOW) _GUICtrlListView_SetColumnOrder($idListview, "2|0|1") MsgBox($MB_SYSTEMMODAL, "Information", "Column ID: " & _GUICtrlListView_GetColumnID_ByName($idListview, 'Gama')) ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Func _GUICtrlListView_GetColumnID_ByName($hListView, $sColumnToFind) Local $iColumn_Count = _GUICtrlListView_GetColumnCount($hListView) Local $aColumns For $iColumn_idx = 0 To $iColumn_Count - 1 $aColumns = _GUICtrlListView_GetColumn($hListView, $iColumn_idx) If $aColumns[5] = $sColumnToFind Then Return $iColumn_idx EndIf Next Return SetError(1, 0, -1) EndFunc ;==>_GUICtrlListView_GetColumnID_ByName  
    • UEZ
      By UEZ
      Here a small tool I wrote to update my Sysinternal tools collection without the need to download always the whole package or visiting the site to check for updates. I know that there are several tools available (also some tools written in AutoIt) but here another one for the collection. It was good exercise for me to code it.
       
       
        
       
       
      Some files from cannot be downloaded although they are visible on the web site!
       
      Here the download link of the source code only: AutoIt Sysinternal Tools Synchronizer v0.99.1 build 2017-10-23 beta.7z  (1353 downloads previously)
      -=> Requires AutoIt version 3.3.13.20 or higher / tested on Win8.1 real machine and some VMs: Win7 / Vista / Win10
       
      Compiled exe only: @MediaFire
       
      Just select the Sysinternal Tools folder or create one and press the synchronize button to download the selected items. Click on AutoIt label (near to left upper corner) to open menu.
       
      Special thanks to LarsJ, Melba23 and mesale0077 for their help. 
       
      I've still some ideas to implement which are more gimmick related, so it is not finished yet...
      If you want to add your language please check out #Region Language. Thanks. 
       
      Please report any bug or if you have any suggestions.
       
      The language of the tool tip from each of the executable in the left list view were automatically created using Google translator and weren't checked for correctness.
       
      Br,
      UEZ
    • 0Ethan0
      By 0Ethan0
      Ahoy Autoit Community!
      After many trials and errors I am unable to solve a problem I am facing and would appreciate any kind of input or better yet a solution 
      The Premise: An embeded slideshow viewer that runs after double-clicking an item in a ListView (each item will generate a different slideshow images).
      The Setup: GUI with a ListView Control and a simple exit button.
      The Issue: Once double clicked the slide plays however the GUI "locks"/non responsive until the slide is over. Same thing if I click on the "Test" button.
      The Culprit: I believe since it's in the images loop it can't accept any other commands until that loop is over.
      The Wish: I want to be able to use the GUI functions (selecting other items, clicking on button etc.) while the slideshow plays.
      The Code (stripped and simplified as much as I could):
      #include <GuiListView.au3> #include <File.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) HotKeySet("{Esc}", "_Exit") Global $c=0 Global $ssGDI[3], $ssGraphic[2], $ssImage Global Const $bg_color = "000000" Global Const $ssW = 480, $ssH = 320 Global $aFiles = _FileListToArrayRec("d:\testStage\", "*.jpg;*.png;*.bmp;*.gif;*.JPG;*.PNG;*.BMP;*.GIF", $FLTAR_FILES, $FLTAR_NORECUR ,$FLTAR_SORT ,$FLTAR_FULLPATH ) $guiW = 1200 $guiH = 726 $mainWindow = GUICreate("Slideshow Viewer", $guiW, $guiH, -1, -1, $WS_POPUP) $Button1 = GUICtrlCreateButton("Exit", 0, 0, 50, 50) GUICtrlSetOnEvent($Button1, "_Exit") $Button1 = GUICtrlCreateButton("Test", 60, 0, 50, 50) GUICtrlSetOnEvent($Button1, "Test") Global $ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280) _GUICtrlListView_SetColumnWidth ($ListView, 0, 100) _GUICtrlListView_SetColumnWidth ($ListView, 1, 100) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("Name 1|Category 1", $ListView) GUICtrlCreateListViewItem("Name 2|Category 2", $ListView) screenshotWidgetInit($ssW,$ssH, 690, 100) GUISetState(@SW_SHOW, $mainWindow) GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE _Exit() EndSwitch WEnd Func Test() For $k = 1 To UBound($aFiles) - 1 screenshotWidgetTransition($aFiles[$k]) Next EndFunc Func ListView_Click() ConsoleWrite("Left Click") EndFunc Func ListView_DoubleClick() ConsoleWrite("Double Left Click") Test() EndFunc Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $ListView Select Case $event = $NM_CLICK ListView_Click () Case $event = $NM_DBLCLK ListView_DoubleClick () EndSelect EndSelect Return $GUI_RUNDEFMSG EndFunc Func screenshotWidgetTransition($image, $delay = 0, $speed = 1, $sleep = 2000) Local $a, $d = $c, $iX, $iY $ssImage = _GDIPlus_ImageLoadFromFile($image) $iX = _GDIPlus_ImageGetWidth($ssImage) $iY = _GDIPlus_ImageGetHeight($ssImage) $FDesktop=$ssH/$ssW $Fact =1 If $iX > $ssW And $FDesktop > ($iY/$iX) Then $Fact=$ssW/$iX ElseIf $iY > $ssH Then $Fact=$ssH/$iY EndIf $H1 = Round(($Fact * $iY),0) $W1 = Round(($Fact * $iX),0) _GDIPlus_GraphicsDrawImageRect($ssGraphic[$d], $ssImage,($ssW - $W1)/2, ($ssH - $H1) / 2,$W1,$H1) WinSetTrans($ssGDI[$d], "", 0) WinSetOnTop($ssGDI[$d], "", 1) For $a = 0 To 254 Step $speed WinSetTrans($ssGDI[$d], "", $a) Sleep($delay) Next WinSetTrans($ssGDI[$d], "", 254) WinSetOnTop($ssGDI[Not ($d)], "", 0) WinSetTrans($ssGDI[Not ($d)], "", 0) _GDIPlus_GraphicsClear($ssGraphic[Not ($d)]) $c = 1 - $d _GDIPlus_ImageDispose ($ssImage) ; very important to realease the pics Sleep($sleep) EndFunc ;==>screenshotWidgetTransition Func screenshotWidgetInit($ssW,$ssH,$ssX,$ssY) $ssGDI[2] = GUICreate("", $ssW, $ssH, $ssX, $ssY, $WS_POPUP, $WS_EX_MDICHILD, $mainWindow) $ssGDI[0] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2]) $ssGDI[1] = GUICreate("", $ssW, $ssH, 3, 3, $WS_POPUP, $WS_EX_MDICHILD, $ssGDI[2]) ; GUISetBkColor("0x" & $bg_color, $ssGDI[2]) GUISetState(@SW_SHOW, $ssGDI[2]) GUISetState(@SW_SHOW, $ssGDI[0]) GUISetState(@SW_SHOW, $ssGDI[1]) WinSetTrans($ssGDI[0], "", 0) WinSetTrans($ssGDI[1], "", 0) _GDIPlus_Startup() $ssGraphic[0] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[0]) $ssGraphic[1] = _GDIPlus_GraphicsCreateFromHWND($ssGDI[1]) _GDIPlus_GraphicsClear($ssGraphic[0], "0xFF" & $bg_color) _GDIPlus_GraphicsClear($ssGraphic[1], "0xFF" & $bg_color) EndFunc ;==>screenshotWidgetInit Func _Exit() _GDIPlus_ImageDispose($ssImage) _GDIPlus_GraphicsDispose($ssGraphic[0]) _GDIPlus_GraphicsDispose($ssGraphic[1]) GUIDelete($ssGDI[0]) GUIDelete($ssGDI[1]) GUIDelete($ssGDI[2]) _GDIPlus_Shutdown() Exit EndFunc ;==>_Exit I hope someone can shed light on this; perhaps a different approach is needed?
      Thank you in advance!
      P.S.
      The script is patched from different scripts of different users in the forum - thank you again users!
    • Daka
      By Daka
      I know there are listbox and listview, but now I have?
      here is the video of infowindow 
      I tried to read mouse selection like for listbox:
      $listWindow = "[CLASS:TFormResearchGR]" $topicsList = "[CLASS:TMWrapper; INSTANCE:255]" WinWait($listWindow, "", 60) $hdlWindow = WinGetHandle($listWindow) $hdlList = ControlGetHandle($hdlWindow, "", $topicsList) _GUICtrlListBox_ClickItem($hdlList, 0, "left") $countOfList = _GUICtrlListBox_GetCount($hdlList) ConsoleWrite("Count of list: " & $countOfList & @LF) count of list is not working.
      I realiezed that there are difference between listbox and listview, but this is something different.
      and till now I never saw that you can go inside with infotool and also get instances.
       
      so Im confused how to get the list number and the names of selection?
    • AndyS19
      By AndyS19
      I have a listview with 3 columns and I want to set the 3rd column's color based on the item's 'Param' value, but even though I set up for the 3rd column, the entire row always gets the color.
      My test code is below, but here is the pertinent code:
      Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg
      Here is the full test code:
      #include-once ;#cs #NoTrayIcon #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_UseX64=N Opt("GUICloseOnESC", 1) ; ESC closes GUI? (0 = no, 1 = yes) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Opt('MustDeclareVars', 1) OnAutoItExitRegister("_test_exit") Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase #include <GuiListBox.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> Global $__MCP_obj, $__MCP_GUI_hWnd, $idListView, $hListView Global $hMainWin test() Exit Func test() $hMainWin = GUICreate("Test window", 120, 100, @DesktopWidth / 2, -1) GUICtrlCreateButton("Hwnd", 10, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_1stTEST_btn") GUICtrlCreateButton("ID", 50, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_2ndTEST_btn") GUISetOnEvent($GUI_EVENT_CLOSE, "_test_exit") GUISetState(@SW_SHOW) While (1) Sleep(17) WEnd EndFunc ;==>test Func _myColorPicker($obj) logmsg("+++: $obj = 0x" & Hex($obj) & @CRLF) Local $flags = 0 Local $ww, $wh, $x, $y, $w, $h $__MCP_obj = $obj $ww = 350 $wh = 500 $x = 200 $y = 150 $__MCP_GUI_hWnd = GUICreate("myColorPicker", $ww, $wh, $x, $y, $flags) $x = 10 $y = 10 $w = 150 $h = 20 GUICtrlCreateButton("Set caller's color", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_SetColor_btn") $y += $h + 5 $w = $ww - 25 $h = $wh - 100 $idListView = GUICtrlCreateListView("", $x, $y, $w, $h, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $hListView = GUICtrlGetHandle($idListView) $x = $ww / 2 - 50 $y = $wh - 60 $w = 100 $h = 25 GUICtrlCreateButton("Quit Popup", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_QUIT_btn") GUICtrlSetFont($idListView, 8.5, -1, -1, "courier new") _GUICtrlListView_AddColumn($idListView, "Name", 100) _GUICtrlListView_AddColumn($idListView, "Value", 100) _GUICtrlListView_AddColumn($idListView, "Sample", 100) _GUICtrlListView_SetColumnWidth($idListView, 0, 100) _GUICtrlListView_SetColumnWidth($idListView, 1, 80) logmsg("+++: $idListView = " & $idListView) logmsg("+++: $hListView = 0x" & Hex($hListView)) __MCP_populateListView($hListView) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW, $__MCP_GUI_hWnd) EndFunc ;==>_myColorPicker Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg Func __MCP_exit() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_exit Func __MCP_handle_SetColor_btn() If (IsHWnd($__MCP_obj)) Then GUISetBkColor($COLOR_BLUE, $__MCP_obj) Else GUICtrlSetBkColor($__MCP_obj, $COLOR_BLUE) EndIf EndFunc ;==>__MCP_handle_SetColor_btn Func __MCP_populateListView($hWnd) Local $text, $parts, $iIndex Local Static $aItems[] = [ _ "BLACK | " & $CLR_BLACK & "|" & "", _ "BLUE | " & $CLR_BLUE & "|" & "", _ "RED | " & $CLR_RED & "|" & "", _ "WHITE | " & $CLR_WHITE & "|" & "", _ "YELLOW | " & $CLR_YELLOW & "|" & "" _ ] _GUICtrlListView_BeginUpdate($hWnd) _GUICtrlListView_DeleteAllItems($hWnd) For $ndx = 0 To UBound($aItems) - 1 $text = $aItems[$ndx] $parts = StringSplit($text, "|", 2) $parts[0] = StringStripWS($parts[0], 3) $parts[2] = StringStripWS($parts[2], 3) $iIndex = _GUICtrlListView_AddItem($hWnd, $parts[0], -1, $parts[1]) _GUICtrlListView_AddSubItem($hWnd, $iIndex, Hex($parts[1]), 1) _GUICtrlListView_AddSubItem($hWnd, $iIndex, $parts[0], 2) Next _GUICtrlListView_EndUpdate($hWnd) EndFunc ;==>__MCP_populateListView Func __MCP_handle_QUIT_btn() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_handle_QUIT_btn Func handle_1stTEST_btn() _myColorPicker($hMainWin) EndFunc ;==>handle_1stTEST_btn Func handle_2ndTEST_btn() _myColorPicker(@GUI_CtrlId) EndFunc ;==>handle_2ndTEST_btn Func _test_exit() Exit EndFunc ;==>_test_exit