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
Solved

Locating the actual associated icon location.

Posted on 1997-08-17
4
360 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run Program using VBScript 3 73
Problem updating Access table using VB code 8 55
Slow process to read Excel 15 137
Having a different time zone on your task bar 3 71
zlib is a free compression library (a DLL) on which the popular gzip utility is built.  In this article, we'll see how to use the zlib functions to compress and decompress data in memory; that is, without needing to use a temporary file.  We'll be c…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…

860 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