Sign in to follow this  

(win32) Getting the dimensions of an icon file?

This topic is 3594 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[i], aDimensions[i], LR_LOADFROMFILE );
if( hIcon )
break; // Icon loaded with size aDimensions[i]xaDimensions[i].
}



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

Share this post


Link to post
Share on other sites

This topic is 3594 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this