Board index » delphi » Confusing DefaultIcon values in Win32 Registry

Confusing DefaultIcon values in Win32 Registry

Hello all,

Does anyone know why some file associations in the HKEY_CLASSES_ROOT
key in the Win32 Registry have weird DefaultIcon values?  Most are
straightforward: an icon source file followed by the icon index
number.  I am running across some that have a NEGATIVE icon index
number, though, and I don't know how to handle the ExtractIcon API in
those instances.

Hope someone can help!!

---
Rodney M. Savard
Kennewick, Washington
rsav...@oneworld.owt.com
http://www.owt.com/users/rsavard

 

Re:Confusing DefaultIcon values in Win32 Registry


rsav...@oneworld.owt.com (Rodney M. Savard) writes:

Quote
>Hello all,
>Does anyone know why some file associations in the HKEY_CLASSES_ROOT
>key in the Win32 Registry have weird DefaultIcon values?  Most are
>straightforward: an icon source file followed by the icon index
>number.  I am running across some that have a NEGATIVE icon index
>number, though, and I don't know how to handle the ExtractIcon API in
>those instances.

Positive values are indices.  You can pass these indexes directly
to ExtractIcon(), since positive indices are what it expects.

Negative values indicate actual resource identifiers.  You can pass
these (multipled by -1, of course) to good'ol LoadIcon(), since
resource IDs are what it expects.

Regards,
-------------------------------------------------------------------------
Matt Arnold                       |        | ||| | |||| |  | | || ||
marn...@netcom.com                |        | ||| | |||| |  | | || ||
Boston, MA                        |      0 | ||| | |||| |  | | || ||
617.389.7384 (h) 617.576.2760 (w) |        | ||| | |||| |  | | || ||
C++, MIDI, Win32/95 developer     |        | ||| 4 3 1   0 8 3 || ||
-------------------------------------------------------------------------

Re:Confusing DefaultIcon values in Win32 Registry


Rodney M. Savard <rsav...@oneworld.owt.com> wrote in article
<320531ab.3291...@news.owt.com>...

Quote
> Hello all,

> Does anyone know why some file associations in the HKEY_CLASSES_ROOT
> key in the Win32 Registry have weird DefaultIcon values?  Most are
> straightforward: an icon source file followed by the icon index
> number.  I am running across some that have a NEGATIVE icon index
> number, though, and I don't know how to handle the ExtractIcon API in
> those instances.

a Positive number n means use the 'n'th icon. A negative number N means use
the icon with resource id -N.

Chris.

Re:Confusing DefaultIcon values in Win32 Registry


Quote
>Does anyone know why some file associations in the HKEY_CLASSES_ROOT
>key in the Win32 Registry have weird DefaultIcon values?  Most are
>straightforward: an icon source file followed by the icon index
>number.  I am running across some that have a NEGATIVE icon index
>number, though, and I don't know how to handle the ExtractIcon API in
>those instances.

        Just a guess here.. They may indicate stock icons.

_
******************************************************************
Replies are going out late... We've been busy at the
        Borland Developers Conference
******************************************************************
NOTE: This software is currently in early alpha. If you notice any
problems, or RFC non-compliance, please report it to p...@pbe.com
 \------------------------------------------------------------\
  \           Chad Z. Hower  -  phoe...@pobox.com              \
   \  Phoenix Business Enterprises - p...@pbe.com - www.pbe.com  \
    \     Physically in Church Hill, TN - Logically Not Sure     \
     \------------------------------------------------------------\

Quote
>>SQUID - The ultimate 95/NT offline databasing reader

**Special Compile: 3.000A (Alpha)

Re:Confusing DefaultIcon values in Win32 Registry


Quote
marn...@netcom.com (Matt Arnold) wrote:
>Negative values indicate actual resource identifiers.  You can pass
>these (multipled by -1, of course) to good'ol LoadIcon(), since
>resource IDs are what it expects.

Thank you very much for your reply.  However, when using LoadIcon, how
do I tell it WHERE to get the icon from?  In the Win95 Registry,
sometimes the DefaultIcon may be specified as "somefile.dll,-104" or
similar.  If LoadIcon only accepts an ID, what about "somefile.dll"?

Thanks for your help!
---
Rodney M. Savard
Kennewick, Washington
rsav...@oneworld.owt.com
http://www.owt.com/users/rsavard

Re:Confusing DefaultIcon values in Win32 Registry


Rodney M. Savard <rsav...@oneworld.owt.com> wrote in article
<320917b7.171...@news.owt.com>...

Quote
> marn...@netcom.com (Matt Arnold) wrote:

> >Negative values indicate actual resource identifiers.  You can pass
> >these (multipled by -1, of course) to good'ol LoadIcon(), since
> >resource IDs are what it expects.

> Thank you very much for your reply.  However, when using LoadIcon, how
> do I tell it WHERE to get the icon from?  In the Win95 Registry,
> sometimes the DefaultIcon may be specified as "somefile.dll,-104" or
> similar.  If LoadIcon only accepts an ID, what about "somefile.dll"?

Check out ExtractIcon() in Win32.  It takes the pathname to a loadable
module as well as an integer index into the set of icons in the module's
resource table.  It returns an HICON ready for use.

Although the online help mentions that an index of -1 will return the
number of available icons in the named module, I would (out of curiosity
mind you) try giving it "somefile.dll" and -104 to see if you get the
same icon mentioned in the registry.  Usually, data you see in the
registry is exactly the arguments necessary for one or maybe two APIs
and nothing more.  Let us know if that turns out to be the case...

--

edh
e...@crl.com

Re:Confusing DefaultIcon values in Win32 Registry


Quote
marn...@netcom.com (Matt Arnold) wrote:
>>number, though, and I don't know how to handle the ExtractIcon API in
>>those instances.
>Negative values indicate actual resource identifiers.  You can pass
>these (multipled by -1, of course) to good'ol LoadIcon(), since
>resource IDs are what it expects.

Thanks for everyone's help; I didn't realize that ExtractIcon accepts
a negative icon index.

BTW, the negative icon indexes I'm referring to are not icon resources
in this case.  If you examine the DefaultIcon property for some file
types in the Win95 registry (under HKEY_CLASSES_ROOT), you'll see what
I mean!

Thanks again,
  Rod
---
Rodney M. Savard
Kennewick, Washington
rsav...@oneworld.owt.com
http://www.owt.com/users/rsavard

Re:Confusing DefaultIcon values in Win32 Registry


Quote
"Ed Halley" <e...@crl.com> writes:
>Rodney M. Savard <rsav...@oneworld.owt.com> wrote in article
><320917b7.171...@news.owt.com>...
>> marn...@netcom.com (Matt Arnold) wrote:

>> >Negative values indicate actual resource identifiers.  You can pass
>> >these (multipled by -1, of course) to good'ol LoadIcon(), since
>> >resource IDs are what it expects.

>> Thank you very much for your reply.  However, when using LoadIcon, how
>> do I tell it WHERE to get the icon from?  In the Win95 Registry,
>> sometimes the DefaultIcon may be specified as "somefile.dll,-104" or
>> similar.  If LoadIcon only accepts an ID, what about "somefile.dll"?

Well, you naturally need to load it using LoadLibrary(), pass the
resulting HINSTANCE to LoadIcon() and then free it.  

   HINSTANCE hSomeFile = LoadLibrary("somefile.dll");
   HICON hIcon = LoadIcon(hSomeFile, uIconID);
   FreeLibrary(hSomeFile);

If you see the docs for LoadLibrary(), you'll discover that it
searches several standard locations for files specified without
a full path.  A registry entry like you show above probably
assumes the file is in one of these standard locations.

Also, the Win32 API now has a new function supported in both
Windows 95 and NT 4.0, ExtraAssociatedIcon().

Another Win32 function, LoadImage(), might also help.  Check out
it's LR_LOADFROMFILE flag.  I'm not sure how it works, but it
sounds interesting.

Regards,
-------------------------------------------------------------------------
Matt Arnold                       |        | ||| | |||| |  | | || ||
marn...@netcom.com                |        | ||| | |||| |  | | || ||
Boston, MA                        |      0 | ||| | |||| |  | | || ||
617.389.7384 (h) 617.576.2760 (w) |        | ||| | |||| |  | | || ||
C++, MIDI, Win32/95 developer     |        | ||| 4 3 1   0 8 3 || ||
-------------------------------------------------------------------------

Re:Confusing DefaultIcon values in Win32 Registry


rsav...@oneworld.owt.com (Rodney M. Savard) writes:

Quote
>marn...@netcom.com (Matt Arnold) wrote:
>>>number, though, and I don't know how to handle the ExtractIcon API in
>>>those instances.
>>Negative values indicate actual resource identifiers.  You can pass
>>these (multipled by -1, of course) to good'ol LoadIcon(), since
>>resource IDs are what it expects.
>Thanks for everyone's help; I didn't realize that ExtractIcon accepts
>a negative icon index.

I don't think it does.  The only negative number it accepts is -1, in
which case it returns the total number of icons available in the file
you specify, instead of an icon handle.  Other negative numbers are
not meaningful to ExtractIcon() (although it might treat any negative
number like -1).

Quote
>BTW, the negative icon indexes I'm referring to are not icon resources
>in this case.  If you examine the DefaultIcon property for some file
>types in the Win95 registry (under HKEY_CLASSES_ROOT), you'll see what
>I mean!

I don't see what you mean.

From my Win32 SDK...

   "The registry stores icon information in the HKEY_CLASSES_ROOT
    hierarchy. The DefaultIcon key has a value associated with it.
    The value used is the default value, and it contains a string
    identifying the path and file that contains the icon, and either
    an positive index value or a negative resource identifier that
    specifies the icon resource within the file."

Note that last sentence.

Negative numbers in the DefaultIcon registry entries indicate icon
resource *identifiers* multiplied by -1.  To load one of these icons,
you need to multiply the number by -1 to regain the original positive
icon ID and then pass it to an API call that can load an icon by ID
(such as LoadIcon(), like I mention above).  There's probably another
API that can do it, but it's not ExtractIcon().  ExtractIcon() works
only with icon *indexes*.

Regards,
-------------------------------------------------------------------------
Matt Arnold                       |        | ||| | |||| |  | | || ||
marn...@netcom.com                |        | ||| | |||| |  | | || ||
Boston, MA                        |      0 | ||| | |||| |  | | || ||
617.389.7384 (h) 617.576.2760 (w) |        | ||| | |||| |  | | || ||
C++, MIDI, Win32/95 developer     |        | ||| 4 3 1   0 8 3 || ||
-------------------------------------------------------------------------

Re:Confusing DefaultIcon values in Win32 Registry


Quote
marn...@netcom.com (Matt Arnold) wrote:
>>Thanks for everyone's help; I didn't realize that ExtractIcon accepts
>>a negative icon index.

>I don't think it does.  The only negative number it accepts is -1, in
>which case it returns the total number of icons available in the file

Well, it works!  It may be only a Windows 95 thing, but ExtractIcon
successfully works in the cases where the icon index is negative.  I
love these undocumented "features"... :-)

Quote
>    an positive index value or a negative resource identifier that
>    specifies the icon resource within the file."

Thanks for posting the info from the SDK.  That's the first thing I've
seen that actually mentions the negative numbers there on DefaultIcon.

Quote
>Note that last sentence.

>Negative numbers in the DefaultIcon registry entries indicate icon
>resource *identifiers* multiplied by -1.  To load one of these icons,
>you need to multiply the number by -1 to regain the original positive
>icon ID and then pass it to an API call that can load an icon by ID
>(such as LoadIcon(), like I mention above).  There's probably another
>API that can do it, but it's not ExtractIcon().  ExtractIcon() works
>only with icon *indexes*.

You're probably right; I could use LoadLibrary/LoadIcon to get the
same effect, but ExtractIcon works just fine on those icons!

BTW, to see what I'm talking about in the Registry, look at the
DefaultIcon entry for extensions such as "txt", "wav",  and "mid".  I
have a clean install of Win95 that I use for testing my 32-bit stuff,
and those extensions have negative icons specified as their
DefaultIcon property.  I'm a beta version of Win95 (OEM Service
Release 2, build 1087 or so), but I imagine the original release
version of Win95 (build 950) is the same in this respect.

In any case, I have definite proof that ExtractIcon works on negative
numbers!

Thanks for your help!

---
Rodney M. Savard
Kennewick, Washington
rsav...@oneworld.owt.com
http://www.owt.com/users/rsavard

Re:Confusing DefaultIcon values in Win32 Registry


Quote
>>>Thanks for everyone's help; I didn't realize that ExtractIcon accepts
>>>a negative icon index.

>>I don't think it does.  The only negative number it accepts is -1, in
>>which case it returns the total number of icons available in the file
>Well, it works!  It may be only a Windows 95 thing, but ExtractIcon
>successfully works in the cases where the icon index is negative.  I
>love these undocumented "features"... :-)

I have an API book dated 1992, and it's in there. It's not undocumented.  
Poorly documented maybe...

JE McTaggart
t...@iguana.ruralnet.net

Re:Confusing DefaultIcon values in Win32 Registry


Quote
t...@iguana.ruralnet.net (John McTaggart) writes:
>>>>Thanks for everyone's help; I didn't realize that ExtractIcon accepts
>>>>a negative icon index.

>>>I don't think it does.  The only negative number it accepts is -1, in
>>>which case it returns the total number of icons available in the file
>>Well, it works!  It may be only a Windows 95 thing, but ExtractIcon
>>successfully works in the cases where the icon index is negative.  I
>>love these undocumented "features"... :-)
>I have an API book dated 1992, and it's in there. It's not undocumented.  
>Poorly documented maybe...

This is all my latest (from MSDN subscription CD-ROM) Win32 API dox have
to say about the nIconIndex parameter to ExtractIcon()...

   "Specifies the index of the icon to retrieve. If this value is 0,
    the function returns the handle of the first icon in the specified
    file. If this value is -1, the function returns the total number
    of icons in the specified file."

What does your 1992 API book say?  The above certainly doesn't imply
that negative numbers other than -1 will actually look up an icon.  If
that's true, does this mean ExtractIcon() can never look up icons wih
resource ID 1 (because this would conflict with the special -1 value---
return the icon count---that you can pass to ExtractIcon())?

I not accusing anyone of being wrong, I'm just wondering what's going
on.

Regards,
-------------------------------------------------------------------------
Matt Arnold                       |        | ||| | |||| |  | | || ||
marn...@netcom.com                |        | ||| | |||| |  | | || ||
Boston, MA                        |      0 | ||| | |||| |  | | || ||
617.389.7384 (h) 617.576.2760 (w) |        | ||| | |||| |  | | || ||
C++, MIDI, Win32/95 developer     |        | ||| 4 3 1   0 8 3 || ||
-------------------------------------------------------------------------

Re:Confusing DefaultIcon values in Win32 Registry


Quote
t...@iguana.ruralnet.net (John McTaggart) wrote:
>>>>Thanks for everyone's help; I didn't realize that ExtractIcon accepts
>>>>a negative icon index.

>>>I don't think it does.  The only negative number it accepts is -1, in
>>>which case it returns the total number of icons available in the file

>>Well, it works!  It may be only a Windows 95 thing, but ExtractIcon
>>successfully works in the cases where the icon index is negative.  I
>>love these undocumented "features"... :-)

>I have an API book dated 1992, and it's in there. It's not undocumented.  
>Poorly documented maybe...

I've seen ExtractIcon documented in many places, but not with usage of
negative icon indexes (besides -1).  It seems that negative icon
indexes made their first appearance in Windows 95.

---
Rodney M. Savard
Kennewick, Washington
rsav...@oneworld.owt.com
http://www.owt.com/users/rsavard

Re:Confusing DefaultIcon values in Win32 Registry


Quote
marn...@netcom.com (Matt Arnold) wrote:
>What does your 1992 API book say?  The above certainly doesn't imply
>that negative numbers other than -1 will actually look up an icon.  If
>that's true, does this mean ExtractIcon() can never look up icons wih
>resource ID 1 (because this would conflict with the special -1 value---
>return the icon count---that you can pass to ExtractIcon())?

Hello Matt,

From what I've seen by examining the Windows 95 Registry, negative
icon indexes start at around -100 and go lower than that.  I haven't
seen anything above -100 (besides positive numbers), so I don't think
there's any problem with the special -1 for ExtractIcon.

Hope this helps,
  Rod
---
Rodney M. Savard
Kennewick, Washington
rsav...@oneworld.owt.com
http://www.owt.com/users/rsavard

Re:Confusing DefaultIcon values in Win32 Registry


Quote
marn...@netcom.com (Matt Arnold) wrote:
>>I have an API book dated 1992, and it's in there. It's not undocumented.  
>>Poorly documented maybe...
>This is all my latest (from MSDN subscription CD-ROM) Win32 API dox have
>to say about the nIconIndex parameter to ExtractIcon()...

>   "Specifies the index of the icon to retrieve. If this value is 0,
>    the function returns the handle of the first icon in the specified
>    file. If this value is -1, the function returns the total number
>    of icons in the specified file."
>What does your 1992 API book say?  The above certainly doesn't imply
>that negative numbers other than -1 will actually look up an icon.  If
>that's true, does this mean ExtractIcon() can never look up icons wih
>resource ID 1 (because this would conflict with the special -1 value---
>return the icon count---that you can pass to ExtractIcon())?

Pretty much the same thing.  It says that if the index variable returns with a
-1 then the function value holds the number of icons in the executable.
0 if an error occured, and the handle other wise....

JE McTaggart
t...@iguana.ruralnet.net

Go to page: [1] [2]

Other Threads