Some file types show incorrect image when Image Source is set from IShellObject

Shell for WPF Forum

Posted 2 years ago by Rick - Developer, Visual Software Systems LLC
Version: 22.1.3
Platform: .NET 4.7
Environment: Windows 11 (64-bit)
Avatar

I’ve been migrating from directly calling OS functions in my app to the use of Actipro Shell.  This has resolved a couple of issue I’ve had in my app (thank you!) but in doing so I discovered another issue.  I use the Ribbon with the backstage and recent document manager in my app.  In it, some files types do not render the correct 32x32 image when I set ImageSourceLarge to IShellObject.MediumIcon.  So far, I have only seen this with text documents (.txt) on Win 10 and Win 11 machines.  What I get is an image outline with a gray interior.  It does not matter if the application is 32bit or 64bit.  Oddly enough, it shows the correct image on Win 7.  I have also found that on Win 10 and Win 11, File Explorer’s Content view and Word’s Open tab show the correct 32x32 image.  I should note that calls to shell32.dll’s SHGetFileInfo return the correct images.

How can I get the file type image displayed in the recent document manager to match what Windows shows?

Comments (7)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Rick,

It's hard to say what's happening without debugging it here.  Are you able to reproduce this with one of our Shell samples?  If so, please tell us how.  Or if not, please make a new simple sample project that shows the issue and send that to our support address, referencing this thread.  Be sure to exclude the bin/obj folders so they don't get spam blocked.  Thanks!


Actipro Software Support

Posted 2 years ago by Rick - Developer, Visual Software Systems LLC
Avatar

I emailed a sample project.  Thanks!

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Rick,

Thanks for the sample.  The problem here is a little complex.  We can get the icons in 16, 32, 48, and 256 size from the Windows shell image list.  However our shell object image sizes have these mappings to try and match the terminology on the View menu in Windows Explorer:

  • Small - 16
  • Medium - 48
  • Large - 96
  • Extra Large - 256

When you load a "Medium" image, it's actually a 48px one and if you scale it down to 32px like in your sample, the gray lines in the 48px text document icon blend together and make the grayish interior that you saw.  At the moment, it's not possible for external code to load a 32px icon.

We are going to create an enhancement request for this for the next major version. 

We either will need to change around some of our terminology with the image naming to NOT match the Windows Explorer View menu (and would also no longer coincide with ShellListViewLayoutMode options), which would be a breaking change, but would allow you to finally get 32px images from us. 

Or we add another way to get a SmallMedium (32px) image.

It feels like the breaking change might be the better way to go, but it would affect a lot of code and we don't want to do that unless on a major version change.  We will post here when we have an update in the future.


Actipro Software Support

Posted 2 years ago by Rick - Developer, Visual Software Systems LLC
Avatar

I'm not sure this is worth a large breaking change, tbh.  I can think of a couple of other ways you might do this:  

1) Add a new ShellListLayoutMode of 'Content', which uses 32px images.  Of course, that would mean also enhancing the ShellListView control to present this view, but it keeps it consistent with Windows File Explorer's View menu

2) Add a new method to the IShellObject that lets the caller get the image in any size supported by Windows (16, 32, 48, 96, 256, 1024).  If you prefer to implement as properties, you could do this in two: one to get/set the desired size and another to get the icon in the size set by the first proeperty.  I feel this would be the least disruptive way to go and the Windows API already supports this, I believe, without scaling if the underlying source contains that size.  

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Rick,

Image loading is probably the most time consuming part of shell object display, so to aid in performance, we cache images that are loaded.  That's why they get stored in properties on the internal WindowsShellObjects and not always returned dynamically via something like a GetImage method.  

We could look into adding a ShellListViewLayoutMode.Content option, but it still relies on the IShellObject image properties, which would have to be adjusted.

We'll dig into options further once we get into working on an implementation.  Thank you for the thoughts.


Actipro Software Support

Answer - Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Rick,

We've refactored some IShellObject image handling for the upcoming 23.1 version.  In v23.1, you'll be able to call IShellObject.MediumIcon to get the 32x32 size icon (was previously 48x48).  The LargeIcon property is updated to return a 48x48 size icon (was previously 96x96).


Actipro Software Support

Posted 2 years ago by Rick - Developer, Visual Software Systems LLC
Avatar

Excellent, Thank you!

The latest build of this product (v24.1.3) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.