Locating the actual associated icon location.

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
jakerdogAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinniewCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jakerdogAuthor Commented:
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
vinniewCommented:
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
jakerdogAuthor Commented:
 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.