?
Solved

Locating the actual associated icon location.

Posted on 1997-08-17
4
Medium Priority
?
364 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

752 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