Results 1 to 9 of 9

Thread: [RESOLVED] How to get "hidden" versions of file/folder icons

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    416

    Resolved [RESOLVED] How to get "hidden" versions of file/folder icons

    I'm using SHGetFileInfo to get icons for files/folders. But what I can't figure out is how to get the "hidden" version of these icons. When a file or folder has its hidden attribute set, the icon changes to fainter version of the normal icon. How is this achieved?

    For example, here are two images taken from Explorer. The first shows the icon without the hidden attribute and the second with the hidden attribute. When I use SHGetFileIcon to get the icon for this file I always get the non-hidden version, regardless of what the attribute on the file is.

    Name:  Example Normal File Icon.jpg
Views: 391
Size:  2.4 KB
    Name:  Example Hidden File Icon.jpg
Views: 379
Size:  2.3 KB
    Last edited by AAraya; Aug 4th, 2017 at 11:20 AM.

  2. #2
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: How to get "hidden" versions of file/folder icons

    AA

    Perhaps you could post a code snippet showing how you are "trapping" for the file attribute and
    trying to determine which icon to use.

    Spoo

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    416

    Re: How to get "hidden" versions of file/folder icons

    Quote Originally Posted by Spooman View Post
    AA

    Perhaps you could post a code snippet showing how you are "trapping" for the file attribute and
    trying to determine which icon to use.

    Spoo
    I'm using a variation of dilettante's "System Default Icons" project from here: http://www.vbforums.com/showthread.p...=1#post4926693. Here is the core routine which gets the icon.

    Code:
    Public Function GetSmallDefaultIconIndex( _
        ByRef Icon As StdPicture, _
        ByVal Path As String, _
        Optional ByVal Attributes As VbFileAttribute) As Long
        'Returns -1 on failure or else a system icon imagelist index value to use.
        '
        'On success the icon image is returned via Icon.
        Dim SHFILEINFO As SHFILEINFO
        
        GetSmallDefaultIconIndex = -1
        
        If Attributes And vbDirectory Then
            Path = "" 'Do not use vbNullString here.
        End If
        If SHGetFileInfo(StrPtr(Path), _
                         Attributes, _
                         SHFILEINFO, _
                         LenB(SHFILEINFO), _
                         SHGFI_ICON Or SHGFI_SMALLICON) Then
            Set Icon = GetIconPicture(SHFILEINFO.hIcon)
            If Not (Icon Is Nothing) Then GetSmallDefaultIconIndex = SHFILEINFO.iIcon
        End If
    End Function
    The icon is loaded into an image list and properly displayed. So there's no need to post that code. There's no problem with the file attributes I'm passing in either as they are obtained using the WinAPI GetFileAttributes(). I've examined the attributes reported for the files and they are correct and I've also verified that they are properly passed into this routine by stepping through the code. All works great except for hidden files/folders showing normal icons rather than hidden versions.

    I guess that my question boils down to:
    Is the SHGetFileInfo routine expected to return the hidden version of icons or is that achieved by some other routine?
    Last edited by AAraya; Aug 4th, 2017 at 11:19 AM.

  4. #4
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: How to get "hidden" versions of file/folder icons

    AA

    Short answer .. I dunno.
    We'd better wait for dilettante

    Spoo

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to get "hidden" versions of file/folder icons

    Don't know if there is a simple ready-made function/API to do this for you, but there may be.

    I doubt SHGetFileInfo would get it for you. If it would, then all you would need to do, I think, is to pass vbHidden as the file attribute and include the flag: SHGFI_USEFILEATTRIBUTES. But that doesn't work for me.

    I am guessing one of two things are happening:

    1) The listview icons are from an image list, so the ImageList_DrawEx function could be used, blending the icon with listview backcolor or white? May not be the answer and did not attempt it. That API might be applicable to v5 of the common controls ImageList; may not apply for v6.

    2) Another option may be to draw the icon with 50% transparency. This could be done using your favorite method to render images with transparency, i.e., GDI+ or AlphaBlend API or by modifying the icon mask bits to be 50% less opaque. The latter modifies the icon which is what I would think is desired. If interested, you can find good icon parsing routines on this site or elsewhere. Then it's a matter of walking the mask bits and adjusting them 50% more transparent, 50% less opaque.

    Rendering at 50% produced the one on the left. The one on the right is screen capture from Explorer. They are pretty close to being identical, but I did not attempt a pixel by pixel comparison.
    Name:  Untitled.png
Views: 319
Size:  2.2 KB

    Edited: #1 if doable is likely the best solution since the rendering wouldn't blend into the selection color if applicable. #2 above would blend in and may not end up with best results. Suggest searching this forum for the ImageList_DrawEx function and see if any examples exist in its usage with VB6. Once found, play with the ILD_BLEND50 option.
    Last edited by LaVolpe; Aug 4th, 2017 at 03:32 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2011
    Location
    Palm Coast, FL
    Posts
    416

    Re: How to get "hidden" versions of file/folder icons

    LaVolpe I was not aware that the image lists provided drawing functions!

    I use an image list control that started off as the vbAccelerator image list replacement and its DrawImage function provides a parameter which creates the desired effect. I'll look at the other Image List I uses use (from VBCCR) to see if it has a comparable function.

    Thanks!

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to get "hidden" versions of file/folder icons

    Quote Originally Posted by AAraya View Post
    I use an image list control that started off as the vbAccelerator image list replacement and its DrawImage function provides a parameter which creates the desired effect.
    Well then, you have the source code. You can review it and see exactly how the effect was created (likely using the ImageList_DrawEx function).
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: How to get "hidden" versions of file/folder icons

    There is a lot in that code that looks a little rough, and quite a bit that could stand cleanup. However aside from making it a bit neater I'm not sure there is a lot to be done. Basically there is a call to get the icon handle and then a call to create a StdPicture from it.

    I tried adding the Hidden bit to the Attributes mask passed and it didn't make any difference. I haven't tried passing an actual hidden file or folder and retrieving its icon instead of a generic one for the "type" but that might produce a hidden-item icon image.

    It isn't clear to me how you might get generic Hidden icons, since the Attribute bit didn't do the trick. There seems to be a lot of voodoo and emulation going on to keep these old calls working though. For example SHGetFileInfoA seems to have a few problems on NT systems because it is emulated and not native, though those were emulation bugs that may have been corrected since the Win2K/XP era.

    I'm not sure why anyone might need this anyway, but doing it yourself might be the best answer. The idea of drawing it against your background color with 50% alpha transparency or adjusting the icon mask sounds good.

  9. #9
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    Re: How to get "hidden" versions of file/folder icons

    The simplest way to do this is to display the files in ListView or TreeView control, which you have associated with the system image list.

    Once you do that, all you have to do is assign the LVIS_CUT (TVIS_CUT for TreeView) item state, and it will automatically fade the image like you see in Explorer.


    There's any number of projects that show ListViews associated with the system image list; then you just add something like this:
    Code:
    If (uRecord.uAttrib And SFGAO_HIDDEN) = SFGAO_HIDDEN Then 'where uRecord.uAttrib is whatever variable holds the current files attributes; depending on source you might use FILE_ATTRIBUTE_HIDDEN instead
        lvi.State = LVIS_CUT
        lvi.StateMask = lvi.StateMask Or LVIS_CUT
    End If
    or to do later, LVIS_CUT/LVIS_CUT in the macro:
    Code:
    Public Function ListView_SetItemState(hwndLV As Long, i As Long, State As LVITEM_state, Mask As LVITEM_state) As Boolean
      Dim lvi As LVITEM
      lvi.State = State
      lvi.StateMask = Mask
      ListView_SetItemState = SendMessage(hwndLV, LVM_SETITEMSTATE, ByVal i, lvi)
    End Function

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width