Sign in to follow this  
Followers 0
jcpetu

ListView Sort Help

21 posts in this topic

Hi forum, I'm working in a List View where I need to sort by different column contents, some of them are check box, others text and others numbers. I having some problems with the sorting algorithm which in some cases don't sort when clicking the column so I need to double click to get it working. and the arrow on the column header only changes when double clicking.

If anybody could help  I'll appreciate.

#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1) ;1=Enables OnEvent functions notifications / 0=Disable (Default)

;GUI-----------------------------------------------------------------------------------------------
Global $MainGui, $MsgOk, $MainGuiRefresh, $MainGuiLabelInfo
Global $MainGuiW = @DesktopWidth - 10, $MainGuiH = @DesktopHeight - 90

;LView------------------------------------------------------------------------------------------------
Global $MMenuLVAD
Dim $nSortDir = 0 ; toggle for sort up/down
Dim $bSet = 0 ; detect the 1st call of LVSort() within a sorting sequence
Dim $nCol = -1 ; preserve last column to detect 2nd click (for reverse direction)
Global $nCurCol = -1, $Done = 0

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$MainGui = GUICreate("Test Sort", $MainGuiW, $MainGuiH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPSIBLINGS)) ;
GUISetOnEvent($GUI_EVENT_CLOSE, "EventsCtrl")

$MMenuLVAD = GUICtrlCreateListView("|Value 1|Value 2|Value 3|Value 4|Value 5|Value 6", 10, 82, 761, 321, -1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_SetBkColor($MMenuLVAD, 0xf4ffff)
GUICtrlSetOnEvent($MMenuLVAD, "_Setsort") ; clicking the column header will start the sort
GUICtrlRegisterListViewSort($MMenuLVAD, "LVSort") ; Register the function "SortLV" as the sorting callback


GUISetState(@SW_SHOW)
For $i = 1 To 100
    GUICtrlCreateListViewItem("|PER" & "|" & "Computer" & Random(13467, 23452, 1) & "|" & "Win 7" & "|" & "RTS" & "|" & "User" & Random(100, 500, 1) & "|" & Random(25, 5000, 1), $MMenuLVAD)
    GUICtrlCreateListViewItem("|SEC" & "|" & "Server" & Random(13467, 23452, 1) & "|" & "Win 2013" & "|" & "NML" & "|" & "User" & Random(100, 500, 1) & "|" & Random(10, 1000, 1), $MMenuLVAD)
Next

While 1

WEnd

Func EventsCtrl()
    Local $Msg = @GUI_CtrlId
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
    EndSwitch
EndFunc   ;==>EventsCtrl

Func CloseHandler()
    Switch @GUI_CtrlId
        Case $MsgOk
            GUISetState(@SW_ENABLE, $MainGui)
            GUISetState(@SW_HIDE, @GUI_WinHandle)
            GUISetState(@SW_SHOW, $MainGui)
    EndSwitch
EndFunc   ;==>CloseHandler

Func MenuEvents()
    Local $Msg = @GUI_CtrlId
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
EndFunc   ;==>MenuEvents

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $tNMHDR, $hWndFrom, $iCode
    Local Const $h_lv = GUICtrlGetHandle($MMenuLVAD)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $h_lv
            Switch $iCode
                Case $LVN_COLUMNCLICK ;ListView column clicked
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    _Setsort()
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY

;Sort List View
Func LVSort($hWnd, $nItem1, $nItem2, $nColumn)
    ;Local $nSort, $val1, $val2, $nResult
    Local $val1, $val2
    If $nColumn = $nCol Then ; Switch the sorting direction
        If Not $bSet Then
            $nSortDir = $nSortDir * -1
            $bSet = 1
        EndIf
    Else
        $nSortDir = 1
    EndIf
    $nCol = $nColumn
    Switch $nColumn
        Case 0 ; checkboxes
            $val1 = GetSubItemText($hWnd, $nItem1, $nColumn)
            $val2 = GetSubItemText($hWnd, $nItem2, $nColumn)
            $val1 = _Iif(BitAND(GUICtrlRead($nItem1, 1), $GUI_CHECKED), 1, 0)
            $val2 = _Iif(BitAND(GUICtrlRead($nItem2, 1), $GUI_CHECKED), 1, 0)
        Case 1, 2, 3, 4, 5,6; text
            $val1 = GetSubItemText($hWnd, $nItem1, $nColumn)
            $val2 = GetSubItemText($hWnd, $nItem2, $nColumn)
    EndSwitch
    $nResult = 0 ; No change of item1 and item2 positions
    If $val1 < $val2 Then
        $nResult = -1 ; Put item2 before item1
    ElseIf $val1 > $val2 Then
        $nResult = 1 ; Put item2 behind item1
    EndIf
    $nResult = $nResult * $nSortDir
    Return $nResult
EndFunc   ;==>LVSort

; Retrieve the text of a listview item in a specified column
Func GetSubItemText($nCtrlID, $nItemID, $nColumn)
    Local $stLvfi = DllStructCreate("uint;ptr;int;int[2];int")
    Local $nIndex, $stBuffer, $stLvi, $sItemText
    DllStructSetData($stLvfi, 1, $LVFI_PARAM)
    DllStructSetData($stLvfi, 3, $nItemID)
    $stBuffer = DllStructCreate("char[260]")
    $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi));
    $stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int")
    DllStructSetData($stLvi, 1, $LVIF_TEXT)
    DllStructSetData($stLvi, 2, $nIndex)
    DllStructSetData($stLvi, 3, $nColumn)
    DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer))
    DllStructSetData($stLvi, 7, 260)
    GUICtrlSendMsg($nCtrlID, $LVM_GETITEMA, 0, DllStructGetPtr($stLvi));
    $sItemText = DllStructGetData($stBuffer, 1)
    $stLvi = 0
    $stLvfi = 0
    $stBuffer = 0
    Return $sItemText
EndFunc   ;==>GetSubItemText

Func _Iif($fTest, $vTrueVal, $vFalseVal)
    If $fTest Then Return $vTrueVal
    Return $vFalseVal
EndFunc   ;==>_Iif

Func _Setsort()
    $bSet = 0 ; initialize for new sorting
    GUICtrlSendMsg($MMenuLVAD, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($MMenuLVAD), 0)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($MMenuLVAD), "int", 0, "int", 1)
    Local $iFormat
    Local Const $hHeader = _GUICtrlListView_GetHeader($MMenuLVAD)
    ; clear existing arrows
    For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1
        $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $x)
        If BitAND($iFormat, $HDF_SORTDOWN) Then
            _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTDOWN))
        ElseIf BitAND($iFormat, $HDF_SORTUP) Then
            _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTUP))
        EndIf
    Next
    ; set arrow in current column
    Local $nColumn = GUICtrlGetState($MMenuLVAD)
    $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $nColumn)
    If $nSortDir == 1 And $nCol == $nColumn Then ; ascending
        _GUICtrlHeader_SetItemFormat($hHeader, $nColumn, BitOR($iFormat, $HDF_SORTUP))
    Else ; descending
        _GUICtrlHeader_SetItemFormat($hHeader, $nColumn, BitOR($iFormat, $HDF_SORTDOWN))
    EndIf
EndFunc   ;==>_Setsort

Thanks in advance and regards.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

?

#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1) ;1=Enables OnEvent functions notifications / 0=Disable (Default)

Global $MainGui, $MsgOk, $MainGuiRefresh, $MainGuiLabelInfo
Global $MainGuiW = @DesktopWidth - 10, $MainGuiH = @DesktopHeight - 90


$MainGui = GUICreate("Test Sort", $MainGuiW, $MainGuiH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPSIBLINGS)) ;
GUISetOnEvent($GUI_EVENT_CLOSE, "EventsCtrl")

$MMenuLVAD = GUICtrlCreateListView("|Value 1|Value 2|Value 3|Value 4|Value 5|Value 6", 10, 82, 761, 321, -1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_SetBkColor($MMenuLVAD, 0xf4ffff)

GUICtrlSetOnEvent($MMenuLVAD, "_Setsort") 

_GUICtrlListView_RegisterSortCallBack($MMenuLVAD)  

GUISetState(@SW_SHOW)

For $i = 1 To 100
    GUICtrlCreateListViewItem("|PER" & "|" & "Computer" & Random(13467, 23452, 1) & "|" & "Win 7" & "|" & "RTS" & "|" & "User" & Random(100, 500, 1) & "|" & Random(25, 5000, 1), $MMenuLVAD)
    GUICtrlCreateListViewItem("|SEC" & "|" & "Server" & Random(13467, 23452, 1) & "|" & "Win 2013" & "|" & "NML" & "|" & "User" & Random(100, 500, 1) & "|" & Random(10, 1000, 1), $MMenuLVAD)
Next

While 1
  Sleep(10)
WEnd


Func _Setsort()
   _GUICtrlListView_SortItems($MMenuLVAD, GUICtrlGetState($MMenuLVAD))
EndFunc   ;==>_Setsort

Func EventsCtrl()
    Local $Msg = @GUI_CtrlId
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            _GUICtrlListView_UnRegisterSortCallBack($MMenuLVAD)
            GUIDelete()
            Exit
    EndSwitch
EndFunc   ;==>EventsCtrl
Edited by mikell

Share this post


Link to post
Share on other sites

I´m sorry, here the complete code.

#NoTrayIcon
#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1) ;1=Enables OnEvent functions notifications / 0=Disable (Default)

;GUI-----------------------------------------------------------------------------------------------
Global $MainGui, $MsgOk, $MainGuiRefresh, $MainGuiLabelInfo
Global $MainGuiW = @DesktopWidth - 10, $MainGuiH = @DesktopHeight - 90

;LView------------------------------------------------------------------------------------------------
Global $MMenuLVAD
Dim $nSortDir = 0 ; toggle for sort up/down
Dim $bSet = 0 ; detect the 1st call of LVSort() within a sorting sequence
Dim $nCol = -1 ; preserve last column to detect 2nd click (for reverse direction)
Global $nCurCol = -1, $Done = 0

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$MainGui = GUICreate("Test Sort", $MainGuiW, $MainGuiH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPSIBLINGS)) ;
GUISetOnEvent($GUI_EVENT_CLOSE, "EventsCtrl")

$MMenuLVAD = GUICtrlCreateListView("|Value 1|Value 2|Value 3|Value 4|Value 5|Value 6", 10, 82, 761, 321, -1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_SetBkColor($MMenuLVAD, 0xf4ffff)
GUICtrlSetOnEvent($MMenuLVAD, "_Setsort") ; clicking the column header will start the sort
GUICtrlRegisterListViewSort($MMenuLVAD, "LVSort") ; Register the function "SortLV" as the sorting callback


GUISetState(@SW_SHOW)
For $i = 1 To 100
    GUICtrlCreateListViewItem("|PER" & "|" & "Computer" & Random(13467, 23452, 1) & "|" & "Win 7" & "|" & "RTS" & "|" & "User" & Random(100, 500, 1) & "|" & Random(25, 5000, 1), $MMenuLVAD)
    GUICtrlCreateListViewItem("|SEC" & "|" & "Server" & Random(13467, 23452, 1) & "|" & "Win 2013" & "|" & "NML" & "|" & "User" & Random(100, 500, 1) & "|" & Random(10, 1000, 1), $MMenuLVAD)
Next

While 1

WEnd

Func EventsCtrl()
    Local $Msg = @GUI_CtrlId
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
    EndSwitch
EndFunc   ;==>EventsCtrl

Func CloseHandler()
    Switch @GUI_CtrlId
        Case $MsgOk
            GUISetState(@SW_ENABLE, $MainGui)
            GUISetState(@SW_HIDE, @GUI_WinHandle)
            GUISetState(@SW_SHOW, $MainGui)
    EndSwitch
EndFunc   ;==>CloseHandler

Func MenuEvents()
    Local $Msg = @GUI_CtrlId
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
EndFunc   ;==>MenuEvents

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $tNMHDR, $hWndFrom, $iCode
    Local Const $h_lv = GUICtrlGetHandle($MMenuLVAD)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $h_lv
            Switch $iCode
                Case $LVN_COLUMNCLICK ;ListView column clicked
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    _Setsort()
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY

;Sort List View
Func LVSort($hWnd, $nItem1, $nItem2, $nColumn)
    ;Local $nSort, $val1, $val2, $nResult
    Local $val1, $val2
    If $nColumn = $nCol Then ; Switch the sorting direction
        If Not $bSet Then
            $nSortDir = $nSortDir * -1
            $bSet = 1
        EndIf
    Else
        $nSortDir = 1
    EndIf
    $nCol = $nColumn
    Switch $nColumn
        Case 0 ; checkboxes
            $val1 = GetSubItemText($hWnd, $nItem1, $nColumn)
            $val2 = GetSubItemText($hWnd, $nItem2, $nColumn)
            $val1 = _Iif(BitAND(GUICtrlRead($nItem1, 1), $GUI_CHECKED), 1, 0)
            $val2 = _Iif(BitAND(GUICtrlRead($nItem2, 1), $GUI_CHECKED), 1, 0)
        Case 1, 2, 3, 4, 5,6; text
            $val1 = GetSubItemText($hWnd, $nItem1, $nColumn)
            $val2 = GetSubItemText($hWnd, $nItem2, $nColumn)
    EndSwitch
    $nResult = 0 ; No change of item1 and item2 positions
    If $val1 < $val2 Then
        $nResult = -1 ; Put item2 before item1
    ElseIf $val1 > $val2 Then
        $nResult = 1 ; Put item2 behind item1
    EndIf
    $nResult = $nResult * $nSortDir
    Return $nResult
EndFunc   ;==>LVSort

; Retrieve the text of a listview item in a specified column
Func GetSubItemText($nCtrlID, $nItemID, $nColumn)
    Local $stLvfi = DllStructCreate("uint;ptr;int;int[2];int")
    Local $nIndex, $stBuffer, $stLvi, $sItemText
    DllStructSetData($stLvfi, 1, $LVFI_PARAM)
    DllStructSetData($stLvfi, 3, $nItemID)
    $stBuffer = DllStructCreate("char[260]")
    $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi));
    $stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int")
    DllStructSetData($stLvi, 1, $LVIF_TEXT)
    DllStructSetData($stLvi, 2, $nIndex)
    DllStructSetData($stLvi, 3, $nColumn)
    DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer))
    DllStructSetData($stLvi, 7, 260)
    GUICtrlSendMsg($nCtrlID, $LVM_GETITEMA, 0, DllStructGetPtr($stLvi));
    $sItemText = DllStructGetData($stBuffer, 1)
    $stLvi = 0
    $stLvfi = 0
    $stBuffer = 0
    Return $sItemText
EndFunc   ;==>GetSubItemText

Func _Iif($fTest, $vTrueVal, $vFalseVal)
    If $fTest Then Return $vTrueVal
    Return $vFalseVal
EndFunc   ;==>_Iif

Func _Setsort()
    $bSet = 0 ; initialize for new sorting
    GUICtrlSendMsg($MMenuLVAD, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($MMenuLVAD), 0)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($MMenuLVAD), "int", 0, "int", 1)
    Local $iFormat
    Local Const $hHeader = _GUICtrlListView_GetHeader($MMenuLVAD)
    ; clear existing arrows
    For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1
        $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $x)
        If BitAND($iFormat, $HDF_SORTDOWN) Then
            _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTDOWN))
        ElseIf BitAND($iFormat, $HDF_SORTUP) Then
            _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTUP))
        EndIf
    Next
    ; set arrow in current column
    Local $nColumn = GUICtrlGetState($MMenuLVAD)
    $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $nColumn)
    If $nSortDir == 1 And $nCol == $nColumn Then ; ascending
        _GUICtrlHeader_SetItemFormat($hHeader, $nColumn, BitOR($iFormat, $HDF_SORTUP))
    Else ; descending
        _GUICtrlHeader_SetItemFormat($hHeader, $nColumn, BitOR($iFormat, $HDF_SORTDOWN))
    EndIf
EndFunc   ;==>_Setsort

Share this post


Link to post
Share on other sites

Did you try the code I posted ?

Share this post


Link to post
Share on other sites

Yes, but it doesn't work. :

Share this post


Link to post
Share on other sites

Is your Autoit version the last one (release 3.3.12.0)  ?

Share this post


Link to post
Share on other sites

I solved it, below the code if useful for anyone.

Thanks a lot mikell.

Regards.

#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1) ;1=Enables OnEvent functions notifications / 0=Disable (Default)

;GUI-----------------------------------------------------------------------------------------------
Global $MainGui, $MsgOk, $MainGuiRefresh, $MainGuiLabelInfo
Global $MainGuiW = @DesktopWidth - 10, $MainGuiH = @DesktopHeight - 90

;LView------------------------------------------------------------------------------------------------
Global $MMenuLVAD
Dim $nSortDir = 0 ; toggle for sort up/down
Dim $bSet = 0 ; detect the 1st call of LVSort() within a sorting sequence
Dim $nCol = -1 ; preserve last column to detect 2nd click (for reverse direction)
Global $nCurCol = -1, $Done = 0
Global $nColumn

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$MainGui = GUICreate("Test Sort", $MainGuiW, $MainGuiH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPSIBLINGS)) ;
GUISetOnEvent($GUI_EVENT_CLOSE, "EventsCtrl")

$MMenuLVAD = GUICtrlCreateListView("|Value 1|Value 2|Value 3|Value 4|Value 5|Value 6", 10, 82, 761, 321, -1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_SetBkColor($MMenuLVAD, 0xf4ffff)
GUICtrlSetOnEvent($MMenuLVAD, "_Setsort") ; clicking the column header will start the sort
GUICtrlRegisterListViewSort($MMenuLVAD, "LVSort") ; Register the function "SortLV" as the sorting callback

GUISetState(@SW_SHOW)
For $i = 1 To 2
    GUICtrlCreateListViewItem("|PER" & "|" & "Computer" & Random(13467, 23452, 1) & "|" & "Win 7" & "|" & "RTS" & "|" & "User" & Random(100, 500, 1) & "|" & Random(25, 5000, 1), $MMenuLVAD)
    GUICtrlCreateListViewItem("|SEC" & "|" & "Server" & Random(13467, 23452, 1) & "|" & "Win 2013" & "|" & "NML" & "|" & "User" & Random(100, 500, 1) & "|" & Random(10, 1000, 1), $MMenuLVAD)
Next
While 1

WEnd

Func EventsCtrl()
    Local $Msg = @GUI_CtrlId
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            Exit
    EndSwitch
EndFunc   ;==>EventsCtrl

Func CloseHandler()
    Switch @GUI_CtrlId
        Case $MsgOk
            GUISetState(@SW_ENABLE, $MainGui)
            GUISetState(@SW_HIDE, @GUI_WinHandle)
            GUISetState(@SW_SHOW, $MainGui)
    EndSwitch
EndFunc   ;==>CloseHandler

Func MenuEvents()
    Local $Msg = @GUI_CtrlId
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
EndFunc   ;==>MenuEvents

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $tNMHDR, $hWndFrom, $iCode
    Local Const $h_lv = GUICtrlGetHandle($MMenuLVAD)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $h_lv
            Switch $iCode
                Case $LVN_COLUMNCLICK ;ListView column clicked
                    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    $nColumn = $tInfo
                    _Setsort()
            EndSwitch
    EndSwitch
EndFunc   ;==>WM_NOTIFY
Func _Setsort()
    $bSet = 0 ; initialize for new sorting
    GUICtrlSendMsg($MMenuLVAD, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($MMenuLVAD), 0)
    DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($MMenuLVAD), "int", 0, "int", 1)
    Local $iFormat
    Local Const $hHeader = _GUICtrlListView_GetHeader($MMenuLVAD)
    ; clear existing arrows
    For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1
        $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $x)
        If BitAND($iFormat, $HDF_SORTDOWN) Then
            _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTDOWN))
        ElseIf BitAND($iFormat, $HDF_SORTUP) Then
            _GUICtrlHeader_SetItemFormat($hHeader, $x, BitXOR($iFormat, $HDF_SORTUP))
        EndIf
    Next
    ; set arrow in current column
    Local $nColumn = GUICtrlGetState($MMenuLVAD)
    $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $nColumn)
    If $nSortDir == 1 And $nCol == $nColumn Then ; ascending
        _GUICtrlHeader_SetItemFormat($hHeader, $nColumn, BitOR($iFormat, $HDF_SORTUP))
    Else ; descending
        _GUICtrlHeader_SetItemFormat($hHeader, $nColumn, BitOR($iFormat, $HDF_SORTDOWN))
    EndIf
EndFunc   ;==>_Setsort
;Sort List View
Func LVSort($hWnd, $nItem1, $nItem2, $nColumn)
    If Not $bSet Then
        If $nColumn = $nCol Then
            $nSortDir = -$nSortDir
        Else
            $nSortDir = 1
        EndIf
        $bSet = 1
    EndIf
    $nCol = $nColumn
    Switch $nColumn
        Case 0 ; checkboxes
            $val1 = GetSubItemText($hWnd, $nItem1, $nColumn)
            $val2 = GetSubItemText($hWnd, $nItem2, $nColumn)
            $val1 = _Iif(BitAND(GUICtrlRead($nItem1, 1), $GUI_CHECKED), 1, 0)
            $val2 = _Iif(BitAND(GUICtrlRead($nItem2, 1), $GUI_CHECKED), 1, 0)
        Case 1, 2, 3, 4, 5, 6; text
            $val1 = GetSubItemText($hWnd, $nItem1, $nColumn)
            $val2 = GetSubItemText($hWnd, $nItem2, $nColumn)
    EndSwitch
    $nResult = 0 ; No change of item1 and item2 positions
    If $val1 < $val2 Then
        $nResult = -1 ; Put item2 before item1
    ElseIf $val1 > $val2 Then
        $nResult = 1 ; Put item2 behind item1
    EndIf
    $nResult = $nResult * $nSortDir
    Return $nResult
EndFunc   ;==>LVSort

; Retrieve the text of a listview item in a specified column
Func GetSubItemText($nCtrlID, $nItemID, $nColumn)
    Local $stLvfi = DllStructCreate("uint;ptr;int;int[2];int")
    Local $nIndex, $stBuffer, $stLvi, $sItemText
    DllStructSetData($stLvfi, 1, $LVFI_PARAM)
    DllStructSetData($stLvfi, 3, $nItemID)
    $stBuffer = DllStructCreate("char[260]")
    $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi));
    $stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int")
    DllStructSetData($stLvi, 1, $LVIF_TEXT)
    DllStructSetData($stLvi, 2, $nIndex)
    DllStructSetData($stLvi, 3, $nColumn)
    DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer))
    DllStructSetData($stLvi, 7, 260)
    GUICtrlSendMsg($nCtrlID, $LVM_GETITEMA, 0, DllStructGetPtr($stLvi));
    $sItemText = DllStructGetData($stBuffer, 1)
    $stLvi = 0
    $stLvfi = 0
    $stBuffer = 0
    Return $sItemText
EndFunc   ;==>GetSubItemText

Func _Iif($fTest, $vTrueVal, $vFalseVal)
    If $fTest Then Return $vTrueVal
    Return $vFalseVal
EndFunc   ;==>_Iif

Share this post


Link to post
Share on other sites

Hi, again. Now I'm trying to add images and I get some problems: 1.Check box column isn't sorted when checked,  2. images doesn't show up and 3.In column 0 appears the images of the image vector.

Any help will be appreciated.

Thanks in advance and regards.

#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>

Opt("GUIOnEventMode", 1) ;1=Enables OnEvent functions notifications / 0=Disable (Default)

Global $MainGui, $MsgOk, $MainGuiRefresh, $MainGuiLabelInfo
Global $MainGuiW = @DesktopWidth - 10, $MainGuiH = @DesktopHeight - 90


$MainGui = GUICreate("Test Sort", $MainGuiW, $MainGuiH, -1, -1, BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPSIBLINGS)) ;
GUISetOnEvent($GUI_EVENT_CLOSE, "EventsCtrl")

$MMenuLVAD = GUICtrlCreateListView("|Value 1|Value 2|Value 3|Value 4", 10, 82, 761, 321, -1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_SetBkColor($MMenuLVAD, 0xf4ffff)

GUICtrlSetOnEvent($MMenuLVAD, "_Setsort")

_GUICtrlListView_RegisterSortCallBack($MMenuLVAD)
; Load images
Global $hImage = _GUIImageList_Create(24, 24, 5, 3)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -7)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -12)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -3)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -4)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -5)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", -6)
_GUICtrlListView_SetImageList($MMenuLVAD, $hImage, 1) ;   1 - Image list with small icons

GUISetState(@SW_SHOW)

For $i = 0 To 100
    _GUICtrlListView_AddItem($MMenuLVAD, "", $i)
    _GUICtrlListView_AddSubItem($MMenuLVAD, $i, "Computer" & Random(13467, 23452, 1), 1, Random(0, 5, 1))
    _GUICtrlListView_AddSubItem($MMenuLVAD, $i, "User" & Random(100, 500, 1), 2,2)
    _GUICtrlListView_AddSubItem($MMenuLVAD, $i, Random(25, 5000, 1), 3)
    _GUICtrlListView_AddSubItem($MMenuLVAD, $i, Random(1, 800, 1), 4)

Next

While 1
    Sleep(10)
WEnd

Func _Setsort()
    _GUICtrlListView_SortItems($MMenuLVAD, GUICtrlGetState($MMenuLVAD))
EndFunc   ;==>_Setsort

Func EventsCtrl()
    Local $Msg = @GUI_CtrlId
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            _GUICtrlListView_UnRegisterSortCallBack($MMenuLVAD)
            GUIDelete()
            Exit
    EndSwitch
EndFunc   ;==>EventsCtrl

Share this post


Link to post
Share on other sites

1) Sort is done on the text value, not checked state

2) Check $LVS_EX_SUBITEMIMAGES (and _GUICtrlListView_SetExtendedListViewStyle)

3) Use a non-existing image index e.g. 1000

Share this post


Link to post
Share on other sites

Hi Larsj, OK with 1) and  2) it works now :thumbsup: ,

but for 3) from _GUICtrlListView_RegisterSortCallBack Autoit Help:

This function will sort listviews that have icons, checkboxes, sub-item icons. :

Thanks a lot and regards.

Share this post


Link to post
Share on other sites

Does any sorting happen when calling the sort routine?


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

jcpetu. Yes, the sort function can handle different kind of listviews. The sort is still by the text value. Add some text values to your items, and see it for your self.

To sort by the checked state you have to create your own sort function, or use some kind of work around.

Share this post


Link to post
Share on other sites

Thanks a lot LarsJ.

Share this post


Link to post
Share on other sites

MikahS

Does any sorting happen when calling the sort routine?

 

yes,  the sort rotine sorts every type of data (date, text, number) but checkboxes.

Share this post


Link to post
Share on other sites

Anyone knows why GUICtrlSetBkColor($MMenuLVAD, $GUI_BKCOLOR_LV_ALTERNATE) doesn't works

$MMenuLVAD = GUICtrlCreateListView("", 10, 82, 761, 321, -1, BitOR($LVS_EX_SUBITEMIMAGES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
GUICtrlSetOnEvent($MMenuLVAD, "_Setsort")
GUICtrlSetBkColor($MMenuLVAD, $GUI_BKCOLOR_LV_ALTERNATE)

Share this post


Link to post
Share on other sites

You do it like this:

 

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

Example()

Func Example()
  Local $listview, $item1, $item2, $item3, $item4, $item5, $item6

  GUICreate("listview items", 220, 250, 100, 200)

  $listview = GUICtrlCreateListView("col1  |col2|col3  ", 10, 10, 200, 150)
  GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)

  $item1 = GUICtrlCreateListViewItem("item2|col22|col23", $listview)
  GUICtrlSetBkColor(-1, 0x00FF00)
  $item2 = GUICtrlCreateListViewItem("item1|col12|col13", $listview)
  GUICtrlSetBkColor(-1, 0x00FF00)
  $item3 = GUICtrlCreateListViewItem("item3|col32|col33", $listview)
  GUICtrlSetBkColor(-1, 0x00FF00)
  $item4 = GUICtrlCreateListViewItem("item4|col22|col23", $listview)
  GUICtrlSetBkColor(-1, 0x00FF00)
  $item5 = GUICtrlCreateListViewItem("item5|col12|col13", $listview)
  GUICtrlSetBkColor(-1, 0x00FF00)
  $item6 = GUICtrlCreateListViewItem("item6|col32|col33", $listview)
  GUICtrlSetBkColor(-1, 0x00FF00)
  GUISetState(@SW_SHOW)

  While 1
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd
EndFunc

Share this post


Link to post
Share on other sites

Like this:

#include <Array.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>

Opt("GUIOnEventMode", 1) ;1=Enables OnEvent functions notifications / 0=Disable (Default)

Global $MainGui, $MsgOk, $MainGuiRefresh, $MainGuiLabelInfo
Global $MainGuiW = @DesktopWidth - 10, $MainGuiH = @DesktopHeight - 90

_GDIPlus_Startup()
Global $Notebook = _GDIPlus_BitmapCreateFromMemory(ScanNew32x32(), True) ;GDI bitmap
Global $Computer = _GDIPlus_BitmapCreateFromMemory(Computer32x32(), True) ;GDI bitmap


$MainGui = GUICreate("Test Sort", 800, 500, 10, 10, BitOR($GUI_SS_DEFAULT_GUI, $WS_CLIPSIBLINGS)) ;
GUISetOnEvent($GUI_EVENT_CLOSE, "EventsCtrl")

;$MMenuLVAD = GUICtrlCreateListView("|Value 1|Value 2|Value 3|Value 4", 10, 82, 761, 321, -1, BitOR($LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER,$LVS_EX_SUBITEMIMAGES))
$MMenuLVAD = GUICtrlCreateListView("", 10, 82, 761, 321, -1, BitOR($LVS_EX_SUBITEMIMAGES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT, $LVS_EX_HEADERDRAGDROP, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER))
GUICtrlSetOnEvent($MMenuLVAD, "_Setsort")
GUICtrlSetBkColor($MMenuLVAD, $GUI_BKCOLOR_LV_ALTERNATE)

_GUICtrlListView_RegisterSortCallBack($MMenuLVAD)

;Add columns
_GUICtrlListView_AddColumn($MMenuLVAD, "", 30)
_GUICtrlListView_AddColumn($MMenuLVAD, "Title 1", 80, 3)
_GUICtrlListView_AddColumn($MMenuLVAD, "Title 2", 80)
_GUICtrlListView_AddColumn($MMenuLVAD, "Title 3", 80)
_GUICtrlListView_AddColumn($MMenuLVAD, "Title 4", 80)

; Load images -->
Global $hImage = _GUIImageList_Create(32, 32, 5, 3)
_GUIImageList_Add($hImage, $Computer)
_GUIImageList_Add($hImage, $Notebook)
_GUIImageList_AddIcon($hImage, @SystemDir&"\"&"shell32.dll", 146)
 _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($MMenuLVAD, 0xff442211, 32, 32))

_GUICtrlListView_SetImageList($MMenuLVAD, $hImage, 1) ;   1 - Image list with small icons

GUISetState(@SW_SHOW)

For $i = 0 To 10

    _GUICtrlListView_AddItem($MMenuLVAD, "", 777) ;777 use index that not exists on the array
    _GUICtrlListView_AddSubItem($MMenuLVAD, $i, "Computer" & Random(13467, 23452, 1), 1, 0)
    _GUICtrlListView_AddSubItem($MMenuLVAD, $i, "User" & Random(100, 500, 1), 2, 1)
    _GUICtrlListView_AddSubItem($MMenuLVAD, $i, Random(25, 5000, 1), 3,2)
    _GUICtrlListView_AddSubItem($MMenuLVAD, $i, Random(1, 800, 1), 4,3)

    GUICtrlSetBkColor(-1, 0xc8d5e6) ;Cyan gray
Next

_GDIPlus_Shutdown()

While 1
    Sleep(10)
WEnd

Func _Setsort()
    _GUICtrlListView_SortItems($MMenuLVAD, GUICtrlGetState($MMenuLVAD))
EndFunc   ;==>_Setsort

Func EventsCtrl()
    Local $Msg = @GUI_CtrlId
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            _GUICtrlListView_UnRegisterSortCallBack($MMenuLVAD)
            _WinAPI_DeleteObject($Notebook)
            _WinAPI_DeleteObject($Computer)
            GUIDelete()
            Exit
    EndSwitch
EndFunc   ;==>EventsCtrl

Func ScanNew32x32()
    Local $ScanNew32x32png
    $ScanNew32x32png &= 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3goUAQsnNhcJAQAACIhJREFUWMOtlklwHNUZx/+vt5lpzWg2SSNpLI0sC1k2XoSMwSCM7bCYShVlpTiQrTA4JLmEYCpJkVtcSVVOWZTKjUoAlUOASlIRwVV4iVFiULBiywvY1u4ZjUbbjGbt7untve4cjCkOkDCO+/IO3a9/v/5//b73CG7DNfzO8YOMsQHG2ABlDIwyUEZBKQOldJgyNvzcs4eGPmsu+X/Ax06eOsCYMyjLvo5IKASPJIE5Dmzbhm3bMEwTZUVBNreGiqKkKGOHf/z97711WwSOnTz1a0kUD3d2dED2eXF1chofnB+H6/GYVcKZLqV80GV1XevXIxoJo1QuIzmfhqbrg0d+9IMXbr6Hv1W4v67u8M67erGaW8NLf3yTcuFgZcfDewvp1tjsamPTSrUlkd+xtRcVtYqpiWtCUzjMNTc1Il8s7brngd2h9989feKWEjh28tQBjyQN775vF959bxTnpqa0x77yeNkny3S8tLa4bOgWD867K9wUh8vxJgWnaSaXHB8LNAquNxwKYuzCJWhVbeBXPz3yFlerAGPO4OaN3UilF3Buakp74ptP5iOBgJ0z9UxAEKvd/nr+kVhLzCMQF8R1XLiMkyQWv3t3Je+IBmMONnV3gVI2WHMJht85frA+EHi6s70Nv3l5iH75ySdy9T4fMxjLiRxXCYoSErK/mQcRbNd1bceB7biwHRcWAxRf1Cimpr2d8RZuNZcL9fT2pYTavp4NtMaa8OHEJNbd2VOS6+ps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AzLpQuL7sLktHX+wrj6fuoKPmnj/wG1Jc98TP5pLwAAAABJRU5ErkJggg=='
    Return Binary(_Base64Decode($ScanNew32x32png))
EndFunc   ;==>_ScanNew32x32png

Func Computer32x32()
    Local $Base64String
    $Base64String &= 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAHJElEQVR42s1Xa1CU1xl+vt3losDqslwUF1EakYtCDGY0SWupyeRHbDsJ40x+GNtqvf6o2kFTM0a8zBgFjBU0JHa8hEmmrXQ06WSIF8DlskSTWpOYcQi1Y2HIAMtV2F32/p2+53z7wccCNtOZjj0zh3POfmfO+7zP877nvEh4zE36vwXQ0tKidzqdJxwOR67YKEmia+fatbYxxkTXzsPXkZGRcnJy8sVpAdy6dWtlVVXVzfb2dgSDQeh0OtG5Me2oBcDHcEOyLE85BgIB7N271zMtAJvN9uPz58832JkRL79+bNw7lTSJz9kEMpmk7gkbmTLn3S8z3GpuhPfTSmzduhXSgwcPIuOMcYZgIBgcGRnxZWRksBADBWfOnLH2yEZsOFA66SCmWY99k5QRmj3a+Ygf6HDJ6LjdhMCnpxUAV69fc81LmTczNiaG6yI2Dg0Owmg0ori4GHY2G6+9WTLBYLgRLbCpjJPT6Bll6PMq/HV9RQCuhADcaGhgP1i4EHq9HvHx8ULvK1euoKCgAEVFRQTAhFffKBk/mH0Pw5rfvTLQ6ZDhDnLjkpCu524zgldPYcuWLZCabM1s0ROLIJPh2bNnw0/BcbW2DgU/fA67d++GXTah8Hcl0xqexIYGzEPyuNslK3tE1ijf7N8QgGsVCoB6q5Utzsig6Awi3hQPh8+Pz7/rwtMJJuzhAFg8flb0aADhDAjKyfAwp1yNWRUA9d5vbAheP6kAuHr9OsvOzBTpkZCQgBGPB5988Xe8tDQbe/bsQS8z48VdIQCqt2wKICEQnoDitV9WDYe8D2UOX/fds0GuPYnNmzdD+qSmhi3JyQEjAImJifB6vaitq8MzK1di3759JIEZP9p65D9TT3+GSfB+NxtLU0kK3XQa7/kw8O1n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4p27ZLWrl0blZ2dvXfNmjW/mTFjhlktPAcGBpT3IbTmr6paxNLbMlhTU/NOa2vrEQLinQTgWFmZMzkpKSZt/nyYzWZxHwh9iYkh8ryd4oBYcN396uu4eJPpDaqSjvDvqgHeeOao1TBPtRgq71RJ1Cq4vLz8zcuXL79FMTMhjkRW0xsQu/6Xvxj58s6XUovNhjiqB1evXs0vI/ZeZaWxq6vL+VR+vmTQ69dRpXyOvI9UDxbRJE8MDW25HmLBt5FaW1vbH0mmyQBoU7TBYEijcZHP5zNRirCIiIgBCqh/Uu8k/T18H2XBDCpWnyUpNq5ateo50t5CcaDnKaUa5WB4zU+sBCmGvqNb1Xbp0qULlF0tBMQzSYIp5uoYXt6rXunIc55fs8jwHGIvnQqZJAIWxxmh/6QcFDv27u7uBwS+h/aPUPfI4TRNAeC/aVJYVwGHV2qPPOCxtscO4N+zbf1+lKO2XAAAAABJRU5ErkJggg=='
    Return Binary(_WinAPI_Base64Decode($Base64String))
EndFunc   ;==>_Base64String


Func _Base64Decode($input_string)
    Local $struct = DllStructCreate("int")
    Local $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", 0, "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
    If @error Or Not $a_Call[0] Then Return SetError(1, 0, "")
    Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")
    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", "str", $input_string, "int", 0, "int", 1, "ptr", DllStructGetPtr($a), "ptr", DllStructGetPtr($struct, 1), "ptr", 0, "ptr", 0)
    If @error Or Not $a_Call[0] Then Return SetError(2, 0, "")
    Return DllStructGetData($a, 1)
EndFunc   ;==>_Base64Decode

Func _WinAPI_Base64Decode($sB64String)
    Local $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "ptr", 0, "dword*", 0, "ptr", 0, "ptr", 0)
    If @error Or Not $aCrypt[0] Then Return SetError(1, 0, "")
    Local $bBuffer = DllStructCreate("byte[" & $aCrypt[5] & "]")
    $aCrypt = DllCall("Crypt32.dll", "bool", "CryptStringToBinaryA", "str", $sB64String, "dword", 0, "dword", 1, "struct*", $bBuffer, "dword*", $aCrypt[5], "ptr", 0, "ptr", 0)
    If @error Or Not $aCrypt[0] Then Return SetError(2, 0, "")
    Return DllStructGetData($bBuffer, 1)
EndFunc   ;==>_WinAPI_Base64Decode

Share this post


Link to post
Share on other sites

No, to use $GUI_BKCOLOR_LV_ALTERNATE you need ControlID for GUICtrlSetBkColor. And to get ControlID you need GUICtrlCreateListViewItem. _GUICtrlListView_AddItem and _GUICtrlListView_AddSubItem are not returning ControlID.

GUICtrlSetBkColor(-1, 0xc8d5e6) is setting backcolor for the listview, since the last ControlID is for the listview. You must set backcolor for the listview items.

Share this post


Link to post
Share on other sites

THANKS a LOT Larsj. :bye: 

Regards.

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