Solved

Locating the actual associated icon location.

Posted on 1997-08-17
4
357 Views
Last Modified: 2013-12-03
Greetings,
  Just started messing with win95 programming, and immediately getting
weird results! Op system or compiler?
  My set-up is: Win95 SR2, Borland c++ 5.01.
  I'm exploring ways of getting icons from files, and associated icons.
I notice that the associated icon I get with extractassociatedicon is
not the same as the icon I see in explorer, specifically when I view the
borland icons for *.rc, *.cpp files. I can get the large and small icons
using SHGetFileInfo, but when I try to find the exact location (file and
icon index) of the icon in order to just use ExtractIcon, neither
ExtAssIcon nor SHGetFileInfo seem to work as expected.
  ExtractAssociatedIcon is supposed to return the file and index that
includes the associated icon, but in my program these parameters are
returned unchanged? Help?
  SHGetFileInfo, called with SHGFI_ICONLOCATION should do pretty much
the same thing as ExtractAssociatedIcon, but also doesn't seem to fill
the info structure as expected!
  Anyone know anything about this?

  Thanks, Neil
0
Comment
Question by:jakerdog
  • 2
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
vinniew earned 50 total points
ID: 1404264
Here's a code snippet that does that:


hImageList = (HIMAGELIST)SHGetFileInfo(mypath, 0, &shfi, sizeof(SHFILEINFO),
                  SHGFI_SYSICONINDEX | SHGFI_LARGEICON);
            if (!hImageList) {
                  *pLargeIcon = hIcon;
                  *pSmallIcon = hIcon;
            }
            else {
                  *pLargeIcon = ImageList_GetIcon(hImageList, shfi.iIcon, ILD_NORMAL);

                  hImageList = (HIMAGELIST)SHGetFileInfo(mypath, 0, &shfi, sizeof(SHFILEINFO),
                        SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
                  if (!hImageList)
                        *pSmallIcon = *pLargeIcon;
                  else
                        *pSmallIcon = ImageList_GetIcon(hImageList, shfi.iIcon, ILD_NORMAL);
            


I think you just shouldn't use ExtractIcon... Use ImageList_GetIcon instead.

V

0
 

Author Comment

by:jakerdog
ID: 1404265
The code above gives the same large icon I was already getting,
but does give a different small icon, but only slightly different.
  I hate to be picky, but notice in my question the statement
"I can get the large and small icons using SHGetFileInfo,..." Well, the answer just gives me another way to do the same thing. The below code produces the same icons as the answer code:
  SHGetFileInfo( szName, 0, &shfi, sizeof(SHFILEINFO),
                SHGFI_ICON | SHGFI_LARGEICON );
   *pLargeicon = shfi.hIcon;

   SHGetFileInfo( szName, 0, &shfi, sizeof(SHFILEINFO),
                 SHGFI_ICON | SHGFI_SMALLICON);
   *pSmallIcon = shfi.hIcon;

      My actual question (note where the question marks are!) had to do with the expected behavior of ExtractAssociatedIcon (as well as SHGetFileInfo) when these functions are called to return the associated file and icon index. My question has more to do with this specific behavior.
   However, the answer code does produce a slightly different small icon then my code, which is interesting. And, referring to my original question, the icons that first appeared differently in Explorer no longer do so!! Curiouser and curiouser!
  And finally, this is a really classy way of getting answers to programming questions!
0
 
LVL 3

Expert Comment

by:vinniew
ID: 1404266
Mmm, as I recall, if you don't specifically ask for the 32X32 icon, the shell renders it from the 16X16, or is it the other way around?  Is that what you mean by getting a slightly different small icon?  Does it look like it's been minimized by some algorithm, or does it look designed?  When I write programs, I have to design both.

V

0
 

Author Comment

by:jakerdog
ID: 1404267
 No, it's the same special small icon, but using my code,
the small icon is drawn a little more brightly (? hard to
describe ?), while the one from your code matches the small
icon from explorer exactly, the colors are all a little
lighter, more washed-out looking.
  They look like the same icon, but yours (and explorer's)
may have a different % mask?
  What's really weird about this little exploration is that
the icons (from *.rc, *.h borland files) no longer show that
slight difference that I noticed when I first asked my
question! Look in bcw.exe at the icons, and notice the grid-like
background. That background used to appear in explorer (on
my machine), now it doesn't!
  Thanks for the answers and follow-ups!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now