Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
233 views
in Technique[技术] by (71.8m points)

excel - Identify icon overlay in VBA

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

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

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...