Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm on a quest to figure out how to identify different icon overlays through Excel VBA.

There is a cloud syncing software and I am trying to identify whenever the syncing of my excel file has finished or still in progress. I was able to achieve a basic level of reliability by following the modification date of some meta(?) files but there is not enough consistency to fully rely on this method.

The result of my searches is a big punch in the face, since there is not much info about it in VBA. Basically all I have found that everyone uses advanced languages like C++ to handle these things.

The closest source I've got in VBA does something similar with the System Tray and uses the shell32.dll calling the appropiate windows api (link). But I have no idea how to make it to the Shell Icon Overlay Identifier.

What do you guys think, is there a possible way to make it through VBA or I have to learn C++?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
226 views
Welcome To Ask or Share your Answers For Others

1 Answer

Awesome! It is possible! The SHGetFileInfo method works!

It gives me values according to the current overlays. Here is the code for any other crazy people who wanna mess around with it:

Const SHGFI_ICON = &H100
Const SHGFI_OVERLAYINDEX = &H40
Const MAX_PATH = 260
Const SYNCED = 100664316    'own specific value
Const UNDSYNC = 117442532   'own specific value

Private Type SHFILEINFO
    hIcon As Long                       'icon
    iIcon As Long                       'icon index
    dwAttributes As Long                'SFGAO_ flags
    szDisplayName As String * MAX_PATH  'display name (or path)
    szTypeName As String * 80           'type name
End Type

Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" _
    (ByVal pszPath As String, _
    ByVal dwFileAttributes As Long, _
    psfi As SHFILEINFO, _
    ByVal cbFileInfo As Long, _
    ByVal uFlags As Long) As Long

Private Sub GetThatInfo()
    Dim FI As SHFILEINFO
    SHGetFileInfo "E:Test.xlsm", 0, FI, Len(FI), SHGFI_ICON Or SHGFI_OVERLAYINDEX
    Select Case FI.iIcon
        Case SYNCED
            Debug.Print "Synchronized"
        Case UNDSYNC
            Debug.Print "Synchronization in progress"
        Case Else
            Debug.Print "Some shady stuff is going on!"
    End Select    
End Sub

Thanks for the tip again!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...