Jump to content

ListView sorting on date


Go to solution Solved by ahha,

Recommended Posts

Newbie to _GUICtrlListView_RegisterSortCallBack and can't get it to sort properly on date in format MM/DD/YYYY.

Example code below.  Q - How do I get the date to sort properly?

;#AutoIt3Wrapper_run_debug_mode=Y
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>

Global $g_id_ListView

Example()
Exit

Func Example()
    Local $idRow1, $idRow2, $idRow3
    GUICreate("ListView Sort Question", 300, 200)
    $g_id_ListView = GUICtrlCreateListView("Row#|Name|Date", 10, 10, 280, 180)
    $id_Row1 = GUICtrlCreateListViewItem("#1|Alice|01/15/2022", $g_id_ListView)
    $id_Row2 = GUICtrlCreateListViewItem("#2|Bob|02/22/2021", $g_id_ListView)
    $id_Row3 = GUICtrlCreateListViewItem("#3|Carol|03/13/2021", $g_id_ListView)
    $id_Row10 = GUICtrlCreateListViewItem("#10|Dave|10/09/2021", $g_id_ListView)
    $id_Row11 = GUICtrlCreateListViewItem("#11|Eve|11/21/2021", $g_id_ListView)

    GUISetState(@SW_SHOW)
    ;$vCompareType = 0  ;not ok as Row# sort #1, #10, and want #1, #2,
    ;$vCompareType = 1  ;not ok as Row# sort #1, #10, and want #1, #2,
    $vCompareType = 2   ;Row# okay but Date messed up
    _GUICtrlListView_RegisterSortCallBack($g_id_ListView, $vCompareType)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $g_id_ListView
                ;MsgBox(0,"","col="&GUICtrlGetState($g_id_ListView))
                _GUICtrlListView_SortItems($g_id_ListView, GUICtrlGetState($g_id_ListView))
        EndSwitch
    WEnd

    _GUICtrlListView_UnRegisterSortCallBack($g_id_ListView)
    GUIDelete($g_id_ListView)
EndFunc   ;Func Example()

 

Link to post
Share on other sites

Luke94,

Thanks.  Working through it but at this point pretty confused.  Yikes DLLs I am at a loss. 

In Example 1 of GUICtrlRegisterListViewSort where does $LVM_SETSELECTEDCOLUMN come from in this code?

GUICtrlSendMsg($idLv, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($idLv), 0)

Also does LVSort routine just pull out and sort on $iColumn = 2?  That is, how are the other columns sorted?  Do they go to some other routine?

I ask because DllStructSetData scares the heck out of me as I don't know what the structure is and what's required or what it does.

I guess a main question is if I sort on a particular column are all the other columns pulled along and sorted as well?

For example:

              Col 0 | Col1 | Col 2

Row 0  R0C0   R0C1    R0C2

Row 1  R1C0   R1C1    R1C2

Row 2  R2C0   R2C1    R2C2

If I sort on Col 1 are the Rows associated with each Column automatically also pulled along?  Or do the other row entries stay fixed and only the items in the selected column sorted?  I ask this because in Example 1 I don't understand how $iResult works or this code below works, because I don't see where things get switched around or sorted.

; Switch the sorting direction
    If $iColumn = $g_iCurCol Then
        If Not $g_bSet Then
            $g_iSortDir = $g_iSortDir * -1
            $g_bSet = True
        EndIf
    Else
        $g_iSortDir = 1
    EndIf

Any answers appreciated.

Link to post
Share on other sites

A simpler way using a workaround : create a col #3 (width=0)  for sorting only

;#AutoIt3Wrapper_run_debug_mode=Y
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#Include <Array.au3>

Global $g_id_ListView

Example()
Exit

Func Example()
    Local $array[5] = [ _ 
    "#1|Alice|01/15/2022", _ 
    "#2|Bob|02/22/2021", _ 
    "#3|Carol|03/13/2021", _ 
    "#10|Dave|10/09/2021", _ 
    "#11|Eve|11/21/2021"]
; _ArrayDisplay($array)

   GUICreate("ListView Sort Question", 300, 200)
   $g_id_ListView = GUICtrlCreateListView("Row#|Name|Date| ", 10, 10, 280, 180)
   For $i = 0 to UBound($array)-1
    GUICtrlCreateListViewItem($array[$i] & "|" & StringRegExpReplace($array[$i], '.*(\d{2})/(\d{2})/(\d{4})', "$3$1$2"), $g_id_ListView)
   Next
   _GUICtrlListView_SetColumnWidth($g_id_ListView, 3, 0)
   GUISetState(@SW_SHOW)
   _GUICtrlListView_RegisterSortCallBack($g_id_ListView)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $g_id_ListView
                ;MsgBox(0,"","col="&GUICtrlGetState($g_id_ListView))
            ; If col 2 is clicked then use col 3 for sorting <<<<<<<<<<<<<<<<<<<<<<
                If GUICtrlGetState($g_id_ListView) = 2 Then _GUICtrlListView_SortItems($g_id_ListView, 3)
        EndSwitch
    WEnd

    _GUICtrlListView_UnRegisterSortCallBack($g_id_ListView)
    GUIDelete($g_id_ListView)
EndFunc   ;Func Example()

 

Link to post
Share on other sites
1 hour ago, Nine said:

@mikell Nice idea.  Only problem is that the arrow (up/down) will be misplaced.

Hi everybody,
I just tried a way to get the sort arrow appear on any column.

179178734_forcearrowindesiredcolumn.png.e334d33d357be79c22aeb6e788ec6801.png

* Left pic shows what we got actually : click on col 2, sort on col 3, arrow displays on col 3 (this col 3 is correctly hidden in the real script, but let's show it in the pics for convenience)

* Right pic shows a way to display it differently : click on col 2, sort on col 3, arrow forced on col 2

To do this, I added a 3rd optional parameter in the called function :

Func _GUICtrlListView_SortItems($hWnd, $iCol, $iCol_Arrow = $iCol)

And replaced $iCol by $iCol_Arrow 3 times in this part of the called function :

$iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol_Arrow)
If $__g_aListViewSortInfo[$iIndex][5] = 1 Then ; ascending
    _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitOR($iFormat, $HDF_SORTUP))
Else ; descending
    _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitOR($iFormat, $HDF_SORTDOWN))
EndIf

Then in mikell's script, the function is called including the 3rd parameter, forcing the arrow to be displayed on column 2 :

If GUICtrlGetState($g_id_ListView) = 2 Then _GUICtrlListView_SortItems($g_id_ListView, 3, 2)

Quickly tested, but if a user isn't confident in reworking an include file, please be careful (always make a copy of the original include file first +++)

Edited by pixelsearch
Link to post
Share on other sites

@pixelsearch

So if I understand correctly you changed in the include file GuiListView.au3

This:

; #FUNCTION# ====================================================================================================================
; Author ........: Gary Frost (gafrost)
; Modified.......:
; ===============================================================================================================================
Func _GUICtrlListView_SortItems($hWnd, $iCol)
    Local $iRet, $iIndex, $pFunction, $hHeader, $iFormat

    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    For $x = 1 To $__g_aListViewSortInfo[0][0]
        If $hWnd = $__g_aListViewSortInfo[$x][1] Then
            $iIndex = $x
            ExitLoop
        EndIf
    Next

    $pFunction = DllCallbackGetPtr($__g_aListViewSortInfo[$iIndex][2]) ; get pointer to call back
    $__g_aListViewSortInfo[$iIndex][3] = $iCol ; $nColumn = column clicked
    $__g_aListViewSortInfo[$iIndex][7] = 0 ; $bSet
    $__g_aListViewSortInfo[$iIndex][4] = $__g_aListViewSortInfo[$iIndex][6] ; nCurCol = $nCol
    $iRet = _SendMessage($hWnd, $LVM_SORTITEMSEX, $hWnd, $pFunction, 0, "hwnd", "ptr")
    If $iRet <> 0 Then
        If $__g_aListViewSortInfo[$iIndex][9] Then ; Use arrow in header
            $hHeader = $__g_aListViewSortInfo[$iIndex][10]
            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
            $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol)
            If $__g_aListViewSortInfo[$iIndex][5] = 1 Then ; ascending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol, BitOR($iFormat, $HDF_SORTUP))
            Else ; descending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol, BitOR($iFormat, $HDF_SORTDOWN))
            EndIf
        EndIf
    EndIf

    Return $iRet <> 0
EndFunc   ;==>_GUICtrlListView_SortItems

to this?

; #FUNCTION# ====================================================================================================================
; Author ........: Gary Frost (gafrost)
; Modified.......:
; ===============================================================================================================================
Func _GUICtrlListView_SortItems($hWnd, $iCol, $iCol_Arrow = $iCol)
    Local $iRet, $iIndex, $pFunction, $hHeader, $iFormat

    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    For $x = 1 To $__g_aListViewSortInfo[0][0]
        If $hWnd = $__g_aListViewSortInfo[$x][1] Then
            $iIndex = $x
            ExitLoop
        EndIf
    Next

    $pFunction = DllCallbackGetPtr($__g_aListViewSortInfo[$iIndex][2]) ; get pointer to call back
    $__g_aListViewSortInfo[$iIndex][3] = $iCol ; $nColumn = column clicked
    $__g_aListViewSortInfo[$iIndex][7] = 0 ; $bSet
    $__g_aListViewSortInfo[$iIndex][4] = $__g_aListViewSortInfo[$iIndex][6] ; nCurCol = $nCol
    $iRet = _SendMessage($hWnd, $LVM_SORTITEMSEX, $hWnd, $pFunction, 0, "hwnd", "ptr")
    If $iRet <> 0 Then
        If $__g_aListViewSortInfo[$iIndex][9] Then ; Use arrow in header
            $hHeader = $__g_aListViewSortInfo[$iIndex][10]
            For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1
                $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol_Arrow)
                If BitAND($iFormat, $HDF_SORTDOWN) Then
                    _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitXOR($iFormat, $HDF_SORTDOWN))
                ElseIf BitAND($iFormat, $HDF_SORTUP) Then
                    _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitXOR($iFormat, $HDF_SORTUP))
                EndIf
            Next
            $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol)
            If $__g_aListViewSortInfo[$iIndex][5] = 1 Then ; ascending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol, BitOR($iFormat, $HDF_SORTUP))
            Else ; descending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol, BitOR($iFormat, $HDF_SORTDOWN))
            EndIf
        EndIf
    EndIf

    Return $iRet <> 0
EndFunc   ;==>_GUICtrlListView_SortItems

Several questions.

1) I was not aware you could assign in a function call like this

Func _GUICtrlListView_SortItems($hWnd, $iCol, $iCol_Arrow = $iCol)

Are the parameters evaluated in order?  Or if the 3rd parameter is passed it overwrites the equation?

2) For the original code: For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1

What happened to x?  That is, I do not see it being used anymore in the modified version of Func _GUICtrlListView_SortItems($hWnd, $iCol, $iCol_Arrow = $iCol)?

 

Link to post
Share on other sites
1 hour ago, ahha said:

Are the parameters evaluated in order?

Yes there are . A couple of examples show it :

f(1, 2)

Func f($p1, $p2, $p3 = $p2)
    ConsoleWrite($p3 & @lf) ; displays 2
EndFunc

========================================
f(1, 2, 3)

Func f($p1, $p2, $p3 = $p2)
    ConsoleWrite($p3 & @lf) ; displays 3
EndFunc

========================================
; What follows displays an error :
; "Variable used without being declared"

f(1, 2)

Func f($p1, $p2, $p3 = $p4, $p4 = 4) ; error
    ConsoleWrite($p3 & @lf)
EndFunc

 

1 hour ago, ahha said:

Or if the 3rd parameter is passed it overwrites the equation?

Yes it does as it's an optional parameter.  Optional parameters are placed at the end of the function definition, after the regular parameters.

 

1 hour ago, ahha said:

For the original code: For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1

What happened to x?  That is, I do not see it being used anymore in the modified version of Func

Well... i don't see it used in the original function, after it ended its job :

For $x = 0 To _GUICtrlHeader_GetItemCount($hHeader) - 1
    ...
Next

This loop is used to make disappear an eventual sort arrow (asc or desc) placed in any column of the listview. When the loop has ended, then $x isn't found anymore in the original function. Same for the reworked function, where the 3 lines patched have nothing to do with $x

Hope it helps :)

Link to post
Share on other sites

@ahha: you patched the wrong lines in your post. Please look at my initial post to make sure what 3 lines need to be patched (they're placed outside the For $x loop, not inside). I'll paste the whole patched function below so it will be clearer :

; #FUNCTION# ==================================================
; Author ........: Gary Frost (gafrost)
; Modified.......: pixelsearch (added a 3rd optional parameter)
; =============================================================

Func _GUICtrlListView_SortItems($hWnd, $iCol, $iCol_Arrow = $iCol)
    Local $iRet, $iIndex, $pFunction, $hHeader, $iFormat

    If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)

    For $x = 1 To $__g_aListViewSortInfo[0][0]
        If $hWnd = $__g_aListViewSortInfo[$x][1] Then
            $iIndex = $x
            ExitLoop
        EndIf
    Next

    $pFunction = DllCallbackGetPtr($__g_aListViewSortInfo[$iIndex][2]) ; get pointer to call back
    $__g_aListViewSortInfo[$iIndex][3] = $iCol ; $nColumn = column clicked
    $__g_aListViewSortInfo[$iIndex][7] = 0 ; $bSet
    $__g_aListViewSortInfo[$iIndex][4] = $__g_aListViewSortInfo[$iIndex][6] ; nCurCol = $nCol
    $iRet = _SendMessage($hWnd, $LVM_SORTITEMSEX, $hWnd, $pFunction, 0, "hwnd", "ptr")
    If $iRet <> 0 Then
        If $__g_aListViewSortInfo[$iIndex][9] Then ; Use arrow in header
            $hHeader = $__g_aListViewSortInfo[$iIndex][10]
            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
            $iFormat = _GUICtrlHeader_GetItemFormat($hHeader, $iCol_Arrow)
            If $__g_aListViewSortInfo[$iIndex][5] = 1 Then ; ascending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitOR($iFormat, $HDF_SORTUP))
            Else ; descending
                _GUICtrlHeader_SetItemFormat($hHeader, $iCol_Arrow, BitOR($iFormat, $HDF_SORTDOWN))
            EndIf
        EndIf
    EndIf

    Return $iRet <> 0
EndFunc   ;==>_GUICtrlListView_SortItems

 

Edited by pixelsearch
Link to post
Share on other sites
  • Solution

Thanks to all for the answers/suggestions.  They provided me lots of information and I learned much. 

Here's my version that does not need to use GUICtrlRegisterListViewSort (thanks @Luke94), does not need a phantom column (thanks @mikell), and takes care of the up/down arrow issue (thanks @pixelsearch).

I basically use an array to load listview with MM/DD/YYYY format, then when header is clicked I alter array to YYYYMMDD format, load it back into listview, let listview use the regular sort, then load listview back to the array, convert array back to MM/DD/YYYY format and reload listview.

I know a lot of loads/reloads but it's straightforward and I understand it (excuse all the debug statements, it helps me :). 

Any comments welcomed.

#AutoIt3Wrapper_run_debug_mode=Y
#include <Debug.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
AutoItSetOption("MustDeclareVars", 1)
;v1a - original
;v1b - creating array that we can array->listview, and listview->array
;v1c - changing $aListView because using _GUICtrlListView_AddArray
;v1d - try using all UDF _ functions as mixing could cause issues
;v1e - cleaning out extraneous code
;v1f - released

Global $debug = 0, $g_h_GUI, $g_id_ListView

Example()
Exit

Func Example()
    Local $idRow1, $idRow2, $idRow3, $i, $j, $iRow, $jCol, $string, $aTemp
    $g_h_GUI = GUICreate("ListView Sort Question", 300, 200)    ;get handle in case we need it later
    ;$g_id_ListView = _GUICtrlListView_Create($g_h_GUI, "Row#|Name|Date       ", 10, 10, 280, 180)  ;v1d
    $g_id_ListView = GUICtrlCreateListView("Row#|Name|Date       ", 10, 10, 280, 180)

    ;v1c
    $iRow = 5
    $jCol = 3
    Local $aListView[$iRow][$jCol] = _
    [ _
    ["#1","Alice","01/15/2022"] , _
    ["#2","Bob","02/22/2021"] , _
    ["#3","Carol","03/13/2021"] , _
    ["#10","Dave","10/09/2021"] , _
    ["#11","Eve","11/21/2021"] _
    ]

    ;_DebugArrayDisplay($aListView)
    _GUICtrlListView_AddArray($g_id_ListView, $aListView)   ;load listview

    GUISetState(@SW_SHOW)
    ;$vCompareType = 0  ;not ok as Row# sort #1, #10, and want #1, #2,
    ;$vCompareType = 1  ;not ok as Row# sort #1, #10, and want #1, #2,
    Local $vCompareType = 2 ;Row# okay but Date messed up
    _GUICtrlListView_RegisterSortCallBack($g_id_ListView, $vCompareType)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $g_id_ListView
                ;Pause("col="&GUICtrlGetState($g_id_ListView))
                If GUICtrlGetState($g_id_ListView) = 2 Then     ;date column so we do a special sort
                    For $i = 0 to $iRow - 1     ;overwrite in array col MM/DD/YYYY with YYYYMMDD for sorting purposes
                        $string = $aListView[$i][2] ;initially MM/DD/YYYY format
                        $string = StringRight($string, 4) & StringLeft($string, 2) & StringMid($string, 4, 2)       ;now in YYYYMMDD format
                        $aListView[$i][2] = $string ;stuff into array
                    Next
                    If $debug <> 0 Then _DebugArrayDisplay($aListView, "$aListView after converting to YYYYMMDD format")
                    _GUICtrlListView_DeleteAllItems($g_id_ListView) ;clear out listview
                    Pause("Listview cleared")
                    _GUICtrlListView_AddArray($g_id_ListView, $aListView)   ;reload listview from array
                    Pause("Listview reloaded with YYYYMMDD date format")
                    _GUICtrlListView_SortItems($g_id_ListView, GUICtrlGetState($g_id_ListView)) ;use standard sort
                    Pause("Standard sort used on YYYYMMDD date format")

                    For $i = 0 to $iRow - 1     ;get each row of listview into array
                        $aTemp = _GUICtrlListView_GetItemTextArray($g_id_ListView, $i)      ;get row $i into $aTemp [0] has count
                        For $j = 1 to $aTemp[0]
                            $aListView[$i][$j - 1] = $aTemp[$j]     ;stick it back into $aListView
                        Next
                    Next
                    If $debug <> 0 Then _DebugArrayDisplay($aListView, "After loop: $aListView after reading $g_id_ListView")
                    ;now convert YYYYMMDD in array to MM/DD/YYYY format then load array into listview
                    For $i = 0 to $iRow - 1     ;overwrite in array col YYYYMMDD with MM/DD/YYYY
                        $string = $aListView[$i][2] ;YYYYMMDD format
                        $string = StringMid($string, 5, 2) &"/"& StringRight($string, 2) &"/"& StringLeft($string, 4)   ;now in MM/DD/YYYY format
                        $aListView[$i][2] = $string ;stuff into array
                    Next
                    If $debug <> 0 Then _DebugArrayDisplay($aListView, "$aListView after YYYYMMDD to MM/DD/YYYY")
                    ;now stuff back into listview
                    _GUICtrlListView_DeleteAllItems($g_id_ListView) ;clear out listview
                    _GUICtrlListView_AddArray($g_id_ListView, $aListView)   ;reload listview from array
                    Pause("Listview reloaded with MM/DD/YYYY date format")

                Else
                    ;use standard sort
                    _GUICtrlListView_SortItems($g_id_ListView, GUICtrlGetState($g_id_ListView)) ;use standard sort
                EndIf

        EndSwitch
    WEnd


    _GUICtrlListView_UnRegisterSortCallBack($g_id_ListView)
    GUIDelete($g_id_ListView)
EndFunc   ;Func Example()

Func  Pause($text="")
    If $debug <> 0 Then MsgBox(262144, "DEBUG", "Paused: " & $text)
EndFunc

 

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By ahha
      Under program control is there an easy way to move a slider (thumb) to the top or bottom?
      I am aware of Melba23's GUIScrollbars_Ex UDF (https://www.autoitscript.com/forum/topic/113723-scrollbars-made-easy-bugfix-version-2-may-21/) but I believe it's overkill for my simple needs.
      In a listview with a vertical scrollbar when the window is active one can hit Ctrl+Home to move the scrollbar slider (thumb) to the top and Ctrl+End to the bottom.
      One can also right click the slider and choose Scroll Here, Top, Bottom, Page UP, Page Down, Scroll Up, and Scroll Down.
      I must be doing something basically wrong but am stuck.  Move the thumb to the middle before clicking the Top button to test the code below (Bottom is not coded).  I've commented out other trys.  try #3 is a strange fail.
      Any comments on what I'm missing greatly appreciated as I'm stuck
      #AutoIt3Wrapper_run_debug_mode=Y #include <Debug.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <GuiScrollBars.au3> AutoItSetOption("MustDeclareVars", 1) ;v1b - cut out extraneous code Example() Exit Func Example() Local $i, $j, $x, $hGUI, $idListView, $bTop, $bBottom $hGUI = GUICreate("Scrollbar Question", 300, 400) ;get handle in case we need it later $idListView = GUICtrlCreateListView("Col 0", 10, 10, 280, 300) $bTop = GUICtrlCreateButton("Top", 10, 350, 60, 25) $bBottom = GUICtrlCreateButton("Bottom", 120, 350, 60, 25) ;Pause("$hGUI = '" & $hGUI &"'"& @CRLF & "$idListView = '" & $idListView &"'") For $i = 1 to 100 _GUICtrlListView_AddItem($idListView, $i) Next GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $bTop ;drag thumb to middle of scrollbar before clicking Top button ;try #1 - FAILS Opt("WinTitleMatchMode", 2) ;2 = Match any substring in the title $x = WinActivate("Scrollbar Question") ;not $idListview but main GUI $hGUI - neither working If $x <> $hGUI Then Pause("WinActivate FAILED") Send("^{HOME}") ;Ctrl+home ;try#2 - FAILS ;~ $x = WinActivate($hGUI) ;try Main GUI ;~ If $x <> $hGUI Then Pause("WinActivate FAILED") ;~ Send("^{HOME}") ;Ctrl+home ;try#3 - strange FAILS ;~ $x = WinActivate($idListview) ;try $idListview ;~ If $x <> $idListview Then Pause("WinActivate FAILED") ;strange it works BUT if I comment out this line it fails ;~ ;Sleep(1000) ;it's not a time delay issue ;~ Send("^{HOME}") ;Ctrl+home ;try#4 - same strange fail as #3 ;~ $x = WinActivate($idListview) ;try $idListview ;~ If $x <> $idListview Then Pause("WinActivate FAILED") ;~ Send("{UP 100}") ;try#5 - what the heck is going on? same strange fail as #3 ;$x = WinActivate($idListview) ;try $idListview ;~ $x = WinActivate($hGUI) ;try Main GUI ;~ If $x <> $idListview Then Pause("WinActivate FAILED") ;~ MouseWheel($MOUSE_WHEEL_UP, 100) ;_GUIScrollBars_ScrollWindow($hGUI, 0, 100) ;NO - moves the ListView window in the $hGUI ;_GUIScrollBars_ScrollWindow($idListview, 0, 100) ;does not seem to work ;_GUIScrollBars_SetScrollInfoPos($hGUI, $SB_VERT, 30) ;does not work ;_GUIScrollBars_SetScrollInfoPos($idListview, $SB_VERT, 30) ;does not work ;I'm doing something very basic wrong. I need help. Pause("Scrollbar thumb should be at Top") Case $bBottom Pause("In: Case $bBottom") Pause("Scroll bar should be at BOttom") EndSwitch WEnd GUIDelete($idListView) EndFunc ;Func Example() Func Pause($text="") MsgBox(262144, "DEBUG", "Paused: " & $text) EndFunc  
    • By nacerbaaziz
      it recomended to use the builten function
      _DateDiff
       
       
       
      hello autoit team
      i made a simple function to help me get the difference between to date
      i liked to share it with you
      the paramatrs of this function
      is firstdate and lastedate
      the two params is as the following
      year/month/day hours:minuts:seconds
      here is the function
       
      #include <date.au3> func _dateBetween($s_firstDate, $s_lastDate = default) if not (StringRegExp($s_firstDate, "((\d{4})\/(\d{2})\/(\d{2})\s(\d{2})\:(\d{2})\:(\d{2}))", 0) = 1) then Return SetError(1, 0, 0) if $s_lastDate = default then $s_lastDate = @year & "/" & @mon & "/" & @mday & " " & @hour & ":" & @min & ":" & @sec if not (StringRegExp($s_lastDate, "((\d{4})\/(\d{2})\/(\d{2})\s(\d{2})\:(\d{2})\:(\d{2}))", 0) = 1) then Return SetError(2, 0, 0) local $a_FirstSplitDate = StringSplit(StringRegExpReplace($s_firstDate, "((.*)\s(.*))", "$2"), "/", 2) local $a_FirstSplitTime = StringSplit(StringRegExpReplace($s_firstDate, "((.*)\s(.*))", "$3"), ":", 2) local $a_lastSplitDate = StringSplit(StringRegExpReplace($s_lastDate, "((.*)\s(.*))", "$2"), "/", 2) local $a_LastSplitTime = StringSplit(StringRegExpReplace($s_lastDate, "((.*)\s(.*))", "$3"), ":", 2) local $i_firstDateValue = _DateToDayValue($a_FirstSplitDate[0], $a_FirstSplitDate[1], $a_FirstSplitDate[2]) local $i_LastDateValue = _DateToDayValue($a_LastSplitDate[0], $a_LastSplitDate[1], $a_LastSplitDate[2]) if $i_firstDateValue > $i_LastDateValue then Return SetError(3, 0, 0) local $i_totalDays = $i_LastDateValue-$i_firstDateValue if not ($i_totalDays = 0) then if $a_FirstSplitTime[0] <= $a_lastSplitTime[0] then $i_totalDays += 1 $a_lastSplitTime[0] -= $a_FirstSplitTime[0] elseIf $a_FirstSplitTime[0] > $a_lastSplitTime[0] then if $i_totalDays > 0 then $i_totalDays -= 1 $a_FirstSplitTime[0] -= $a_lastSplitTime[0] endIf endIf endIf local $i_totalYears = 0 if $i_totalDays >= 365 then While $i_totalDays >= 365 $i_totalYears += 1 $i_totalDays -= 365 Wend endIf local $i_TotalMonths = 0 if $i_totalDays >= 30 then While $i_totalDays >= 30 $i_totalMonths += 1 $i_totalDays -= 30 Wend endIf local $i_totalWeeks = 0 if $i_totalDays >= 7 then While $i_totalDays >= 7 $i_totalWeeks += 1 $i_totalDays -= 7 Wend endIf $i_totalSeconds = ((($a_FirstSplitTime[0]*60)*60)+($a_FirstSplitTime[1]*60)+($a_FirstSplitTime[2]))-((($a_lastSplitTime[0]*60)*60)+($a_lastSplitTime[1]*60)+($a_LastSplitTime[2])) local $minus = "" if $i_totalSeconds < 0 then $minus = "-" $i_totalSeconds = StringReplace($i_totalSeconds, "-", "") endIf local $i_totalHours = 0 if $i_totalSeconds >= 3600 then While $i_totalSeconds >= 3600 $i_totalHours += 1 $i_totalSeconds -= 3600 Wend endIf local $i_totalminuts = 0 if $i_totalSeconds >= 60 then While $i_totalSeconds >= 60 $i_totalminuts += 1 $i_totalSeconds -= 60 Wend endIf local $a_arrayReturn[7] $a_arrayReturn[0] = $i_totalYears $a_arrayReturn[1] = $i_totalMonths $a_arrayReturn[2] = $i_totalWeeks $a_arrayReturn[3] = $i_totalDays $a_arrayReturn[4] = $minus & $i_totalHours $a_arrayReturn[5] = $minus & $i_totalminuts $a_arrayReturn[6] = $minus & $i_totalSeconds return $a_arrayReturn endFunc  
      here is an example
       
       
      $a_calc = _dateBetween("2015/02/12 23:00:05", "2030/02/12 23:25:50") msgBox(64, "result", StringFormat("the difference is : %i years and %i months and %i weeks and %i days and %i hours and %i minuts and %i seconds", $a_calc[0], $a_calc[1], $a_calc[2], $a_calc[3], $a_calc[4], $a_calc[5], $a_calc[6]))  
      am waiting for your comments
      with my greetings
    • By UEZ
      This project has been discontinued!
       
      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 the live web site cannot be downloaded although they are visible!
       
      Here the download link of the source code only: AutoIt Sysinternal Tools Synchronizer v0.99.6 build 2020-09-23 beta.7z  (1557 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
    • By Cengokill
      Hi everyone,
      I have created a ListView that is in a tab, and I want to display an image in that tab, with the ListView on top.
      However, the image still appears on top of my ListView.
      If I remove the tabs everything works. 
      I looked at the autoit documentation and the <GuiListView.au3> documentation , I can't figure out how to display a background image, and put on top a ListView, inside a tab. 😥
      Here is the code:
      Opt("GUIOnEventMode", 1) $Form1 = GUICreate($Titre, 700, 627, $Form1Width, $Form1Height); main window $tabulation = GUICtrlCreateTab(148,0,700,580); creating tabs $tab1=GUICtrlCreateTabItem("Tab 1"); first tab GUICtrlSetState(-1, $GUI_SHOW); this tab is selected by default $Pic1 = GUICtrlCreatePic("image.jpg", 0, 30, 700, 627) GUICtrlSetState(-1, $GUI_DISABLE). $idListview = GUICtrlCreateListView("list 1|list 2|list 3", 200, 50, 390, 200) GUISetState(@SW_SHOW) While 1     Sleep(100) WEnd Thank you in advance.

    • By Jahar
      Hi All,
      Please help me on how to fetch date/time of last windows 10 system restore point using autoit? Basically its about querying the last restore point.
×
×
  • Create New...