-
Aug 4th, 2017, 09:45 AM
#1
Thread Starter
Hyperactive Member
-
Aug 4th, 2017, 10:52 AM
#2
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
-
Aug 4th, 2017, 11:13 AM
#3
Thread Starter
Hyperactive Member
Re: How to get "hidden" versions of file/folder icons
Originally Posted by Spooman
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.
-
Aug 4th, 2017, 12:15 PM
#4
Re: How to get "hidden" versions of file/folder icons
AA
Short answer .. I dunno.
We'd better wait for dilettante
Spoo
-
Aug 4th, 2017, 03:24 PM
#5
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.
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.
-
Aug 4th, 2017, 03:55 PM
#6
Thread Starter
Hyperactive Member
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!
-
Aug 4th, 2017, 04:15 PM
#7
Re: How to get "hidden" versions of file/folder icons
Originally Posted by AAraya
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).
-
Aug 4th, 2017, 05:41 PM
#8
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.
-
Aug 4th, 2017, 11:02 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|