Jump to content

Recommended Posts

Posted

Added more information to first post. Minor updates of the examples. New 7z-file at bottom of first post.

  • 2 weeks later...
Posted (edited)

GetSortColumns()
Added a new function to show which column(s) a File/Windows Explorer or Desktop view is sorted by:

Func GetSortColumns()
  Local $iColumns ; Number of sort columns
  $oIFolderView2.GetSortColumnCount( $iColumns )

  ; Get sort columns
  Local $tagSORTCOLUMNS
  For $i = 0 To $iColumns - 1
    $tagSORTCOLUMNS &= $tagSORTCOLUMN & ";"
  Next
  Local $tSortColumns = DllStructCreate( $tagSORTCOLUMNS )
  $oIFolderView2.GetSortColumns( $tSortColumns, $iColumns )

  ; Get data from structure
  Local $tSC, $aSortColumns[2*$iColumns][2]
  For $i = 0 To $iColumns - 1
    $aSortColumns[2*$i+0][0] = "Sort"
    $aSortColumns[2*$i+1][0] = "Column"
    $tSC = DllStructCreate( $tagSORTCOLUMN, DllStructGetPtr( $tSortColumns ) + $i * DllStructGetSize( $tSortColumns ) )
    $aSortColumns[2*$i+0][1] = DllStructGetData( $tSC, "sort" )
    PSGetNameFromPropertyKey( DllStructGetPtr( $tSC ), $aSortColumns[2*$i+1][1] )
    If @error Then PSStringFromPropertyKey( DllStructGetPtr( $tSC ), $aSortColumns[2*$i+1][1] )
  Next

  ; Return sort columns
  Return $aSortColumns
EndFunc

Because the information is extracted from PropertyKeys, column names are displayed this way:

Name          -> System.ItemNameDisplay
Date modified -> System.DateModified
Type          -> System.ItemTypeText
Size          -> System.Size

When I sort files by Type in a Windows Explorer window, I get this information about the sort columns:

Sort   -> -1
Column -> System.ItemTypeText
Sort   -> 0
Column -> {EB4F9DAB-0000-0000-91B9-413D76000090} 0

There are two sort columns. The first is the Type column, which is sorted in descending order. The other doesn't immediately provide any recognizable information. But it's probably used by the internal Microsoft code.

Two new examples. One for the Desktop and one for an Explorer window.

Note that the Desktop example on Windows 10 simply shows an empty ArrayDisplay window. This is because the Name column for the Desktop is not provided with a sort. So $iColumns in the code box above gets the value zero. And thus $aSortColumns becomes an empty array. Probably there is no sorting for the other columns either (the columns can be seen in Details view).

Sorting for the Name column can be set with the code in the next post. And then the sort is displayed in the ArrayDisplay window.

Note that setting a sort for the Name column means that the icons on the Desktop are placed in a different order.

Edited by LarsJ
Updates
Posted

SetSortColumns()
The SetSortColumns() function to set the sort for a column (the columns that can be seen in Details view) is coded this way:

Func SetSortColumns( $sGUID, $iPID, $iSort )
  ; Create SORTCOLUMN structure
  Local $tSortColumn = DllStructCreate( $tagSORTCOLUMN )
  _WinAPI_GUIDFromStringEx( $sGUID, $tSortColumn )
  DllStructSetData( $tSortColumn, "pid", $iPID )
  DllStructSetData( $tSortColumn, "sort", $iSort )

  ; Set sort columns
  $oIFolderView2.SetSortColumns( $tSortColumn, 1 )
EndFunc

This is the Microsoft definition of the IFolderView2.SetSortColumns() method:

HRESULT SetSortColumns(
  SORTCOLUMN *rgSortColumns, // Structure
  int        cColumns        // Integer, number of columns
)

// SORTCOLUMN structure
struct tagSORTCOLUMN {
  PROPERTYKEY   propkey;   // Structure
  SORTDIRECTION direction; // Integer, sort direction, 1 or -1
}

// PROPERTYKEY structure
struct tagPROPERTYKEY {
  GUID  fmtid; // Unique identifier of the PROPERTYKEY
  dword pid;   // Property identifier (PID)
}

And these are the AutoIt definitions:

; PROPERTYKEY Structure (GUID & PID)
Global Const $tagPROPERTYKEY = "struct;ulong Data1;ushort Data2;ushort Data3;byte Data4[8];endstruct" & ";dword pid"

; SORTCOLUMN Structure
Global Const $tagSORTCOLUMN = $tagPROPERTYKEY & ";int sort"

The information needed for the SetSortColumns() function to create the SORTCOLUMN structure is therefore $sGUID and $iPID, which defines the PROPERTYKEY structure, and $iSort, which defines the final SORTCOLUMN structure.

To obtain $sGUID and $iPID from a PROPERTYKEY structure, a new function GetSortColumnsEx() has been added, which returns $sGUID and $iPID in addition to the original information from GetSortColumns().

Output from GetSortColumnsEx() for System.ItemNameDisplay PropertyKey:

GUID   -> {B725F130-47EF-101A-A5F1-02608C9EEBAC}
PID    -> 10
Sort   -> 1
Column -> System.ItemNameDisplay

Because the first part of the PROPERTYKEY structure is a GUID, the value of this GUID can be set with _WinAPI_GUIDFromStringEx().

Posted (edited)

Examples
The examples are shown for a File/Windows Explorer window. The 7z-file at bottom of first post contains similar examples for the Desktop.

8 ) GetSortColumns.au3

#include "..\..\Includes\FileExplorer.au3"
#include <Array.au3>

Example()

Func Example()
  ; File/Windows Explorer on Windows 7, 8, 10
  Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" )
  If Not $hExplorer Then
    MsgBox( 0, "Automating File/Windows Explorer and Desktop", "Could not find window. Terminating." )
    Return
  EndIf

  ; Get an IShellBrowser interface
  GetIShellBrowser( $hExplorer )
  If Not IsObj( $oIShellBrowser ) Then
    MsgBox( 0, "Automating File/Windows Explorer and Desktop", "Could not get an IShellBrowser interface. Terminating." )
    Return
  EndIf

  ; Activate File Explorer
  WinActivate( $hExplorer )
  WinWaitActive( $hExplorer )

  ; Get other interfaces
  GetShellInterfaces()

  ; Get sort columns
  Local $aSortColumns = GetSortColumns()
  _ArrayDisplay( $aSortColumns, "Explorer: $aSortColumns" )
EndFunc

Output:

Sort   -> 1
Column -> System.ItemNameDisplay


9) GetSortColumnsEx.au3

#include "..\..\Includes\FileExplorer.au3"
#include <Array.au3>

Example()

Func Example()
  ; File/Windows Explorer on Windows 7, 8, 10
  Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" )
  If Not $hExplorer Then
    MsgBox( 0, "Automating File/Windows Explorer and Desktop", "Could not find window. Terminating." )
    Return
  EndIf

  ; Get an IShellBrowser interface
  GetIShellBrowser( $hExplorer )
  If Not IsObj( $oIShellBrowser ) Then
    MsgBox( 0, "Automating File/Windows Explorer and Desktop", "Could not get an IShellBrowser interface. Terminating." )
    Return
  EndIf

  ; Activate File Explorer
  WinActivate( $hExplorer )
  WinWaitActive( $hExplorer )

  ; Get other interfaces
  GetShellInterfaces()

  ; Get sort columns
  Local $aSortColumns = GetSortColumnsEx()
  _ArrayDisplay( $aSortColumns, "Explorer: $aSortColumns" )
EndFunc

Output:

GUID   -> {B725F130-47EF-101A-A5F1-02608C9EEBAC}
PID    -> 10
Sort   -> 1
Column -> System.ItemNameDisplay


10) SetSortColumns.au3

#include "..\..\Includes\FileExplorer.au3"

Example()

Func Example()
  ; File/Windows Explorer on Windows 7, 8, 10
  Local $hExplorer = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" )
  If Not $hExplorer Then
    MsgBox( 0, "Automating File/Windows Explorer and Desktop", "Could not find window. Terminating." )
    Return
  EndIf

  ; Get an IShellBrowser interface
  GetIShellBrowser( $hExplorer )
  If Not IsObj( $oIShellBrowser ) Then
    MsgBox( 0, "Automating File/Windows Explorer and Desktop", "Could not get an IShellBrowser interface. Terminating." )
    Return
  EndIf

  ; Activate File Explorer
  WinActivate( $hExplorer )
  WinWaitActive( $hExplorer )

  ; Get other interfaces
  GetShellInterfaces()

  ; Set sort columns
  SetSortColumns( "{B725F130-47EF-101A-A5F1-02608C9EEBAC}", 10, -1 ) ; System.ItemNameDisplay, Name
EndFunc

Desktop: Note that setting a sort for the Name column on Desktop means that the icons are placed in a different order.

 

First post and GetSortColumns() post are updated. This post and previous post have been added. New 7z-file at bottom of first post.

Edited by LarsJ
  • 5 years later...
Posted

@LarsJ 

Hi Larsj,

I made a simple utility that uses the GetFiles function from your FileExplorer to get the selected files. Since I want to upload it to GitHub, can I include your "FileExplorer and Desktop" AU3 files?

Thank you in advance!

Best regards,

Posted
1 hour ago, argumentum said:

Ok, share it !. I'd like to see it :) 
Tho I'd open a separate post to leave this 5 year old thread alone.

Haha, you're right, the necroposter is me 😆. Didn't realize this thread was so old… Perfect timing to bring it back to life thanks to my utility 😅

Posted
1 hour ago, argumentum said:

Ok, share it !. I'd like to see it :) 
Tho I'd open a separate post to leave this 5 year old thread alone.

Anyway, you can check out my project here: https://github.com/roob-p/SuperAdminLauncher (all my code is there, but I haven’t added any releases or Larsj’s files yet because I’m waiting for his approval)

Posted (edited)

Hi @roob,

are you sure about your GitHub link?
I only get a 404 (not found) from GitHub.

https://github.com/roob-p/SuperAdminLauncher ?

Even your profile doesn't exist or at least I can not access it.

Best regards
Sven

Edited by SOLVE-SMART

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Posted
54 minutes ago, roob said:

Anyway, ... ... I’m waiting for his approval)

If your source is open then don't wait for approval, or just claim that I just gave it to you ( am a nice guy )
If your source is not open, then wait.
If "open your own thread for your project" is not in English, then pardon the miscommunication.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
11 hours ago, SOLVE-SMART said:

Hi @roob,

are you sure about your GitHub link?
I only get a 404 (not found) from GitHub.

https://github.com/roob-p/SuperAdminLauncher ?

Even your profile doesn't exist or at least I can not access it.

Best regards
Sven

Hi, my GitHub account became unreachable and I’m not sure why. I’ve opened a support ticket with GitHub. Hopefully all will be restored soon.

Posted
11 hours ago, argumentum said:

If your source is open then don't wait for approval, or just claim that I just gave it to you ( am a nice guy )
If your source is not open, then wait.
If "open your own thread for your project" is not in English, then pardon the miscommunication.

Nice! Yes, I’m thinking of using the MIT license. You’re right about opening a new thread too 😅
Thanks again for the blessing! 🙏 Though now I’ll have to wait for GitHub to restore my account 😅

Posted (edited)
On 9/2/2025 at 11:20 PM, SOLVE-SMART said:

Hi @roob,

are you sure about your GitHub link?
I only get a 404 (not found) from GitHub.

https://github.com/roob-p/SuperAdminLauncher ?

Even your profile doesn't exist or at least I can not access it.

Best regards
Sven

@SOLVE-SMART My GitHub account was temporarily suspended for security reasons. I think the issue was caused by Opera VPN, which I sometimes forget to turn off. Anyway, my account is now fully functional.
In the meantime, I opened this thread: https://www.autoitscript.com/forum/topic/213109-super-admin-launcher-sal

Edited by roob

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.
×
×
  • Create New...