Size from CImageList
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Size from CImageList

  1. #1
    Join Date
    Aug 2006
    Posts
    80

    Size from CImageList

    The documentation states that "An image list is a collection of same-sized images" (http://msdn.microsoft.com/en-us/library/9xc4z2c7.aspx).

    But how do I retrieve that size? I have a pointer to an empty image list. The size was set during creation, but that's out of my control.

  2. #2
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,590

    Re: Size from CImageList

    CImageList::GetImageInfo
    Nobody cares how it works as long as it works

  3. #3
    Join Date
    Aug 2006
    Posts
    80

    Re: Size from CImageList

    GetImageInfo requires the index of an image. In case the list is empty, this will not work. If all images have already been removed when I am given the pointer, I still need to be able to get the size so I can insert an image of the correct size. Any ideas?

  4. #4
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,590

    Re: Size from CImageList

    Okay, then maybe this workaround:

    int n = list.GetImageCount();
    list.SetImageCount(n + 1);
    list.GetImageInfo(n, ...);
    list.SetImageCount(n);
    Nobody cares how it works as long as it works

  5. #5
    Join Date
    Aug 2006
    Posts
    80

    Re: Size from CImageList

    Well, thanks. I was hoping for some less ugly solution, but I guess this will have to do.

  6. #6
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,590

    Re: Size from CImageList

    You're welcome. A solution that works is always better than a solution that doesn't, no matter how ugly the code is
    Nobody cares how it works as long as it works

  7. #7
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,756

    Re: Size from CImageList

    GetImageInfo is a less-than-ideal solution because it goes through the process of extracting an actual image.

    Unfortunately the CImageList class doesn't provide any alternative solution, but the Windows API does.

    Code:
    int cx, cy;
    ImageList_GetIconSize( imgl.m_hImageList, &cx, &cy);

  8. #8
    Join Date
    Aug 2006
    Posts
    80

    Re: Size from CImageList

    Quote Originally Posted by OReubens View Post
    GetImageInfo is a less-than-ideal solution because it goes through the process of extracting an actual image.

    Unfortunately the CImageList class doesn't provide any alternative solution, but the Windows API does.

    Code:
    int cx, cy;
    ImageList_GetIconSize( imgl.m_hImageList, &cx, &cy);
    Excellent! Thank you!!

  9. #9
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,590

    Re: Size from CImageList

    Yeah, that's much better.
    Nobody cares how it works as long as it works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center