Jump to content
  • Advertisement
Sign in to follow this  

(win32) Getting the dimensions of an icon file?

This topic is 3904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm loading an icon with
HICON icon = (HICON)LoadImage(0, file.c_str(), IMAGE_ICON, 16, 16, LR_LOADFROMFILE|LR_SHARED);
I want to find the dimensions of the .ico file before loading it with the LoadImage function. Thanks

Share this post

Link to post
Share on other sites
Actually I don't think this will work well if the icon has multiple images (which is likely the case). The documentation says that if you set cxDesired and cyDesired to 0 (and not use the LR_DEFAULTSIZE flag), the actual resource size is used, but for icons with multiple images, the first one is used, which is typically the smallest I think. If you know your icons will have one image only, use this method. Otherwise, I'm not sure how you can do this (please share if you find out how).

One method that I just thought of to load the largest image in the icon would be to do something like this:

INT aDimentions[] =
{ 256, 128, 64, 48, 32, 24, 16 };
for( UINT i=0; i<sizeof(aDimensions)/sizeof(INT), i++ )
hIcon = (HICON)LoadImage( 0, sFileName, IMAGE_ICON,
aDimensions, aDimensions, LR_LOADFROMFILE );
if( hIcon )
break; // Icon loaded with size aDimensionsxaDimensions.

But I'm not sure if that would work; I didn't try it.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!