{"id":12493,"date":"2010-10-20T07:00:00","date_gmt":"2010-10-20T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/10\/20\/how-do-i-get-the-dimensions-of-a-cursor-or-icon\/"},"modified":"2010-10-20T07:00:00","modified_gmt":"2010-10-20T07:00:00","slug":"how-do-i-get-the-dimensions-of-a-cursor-or-icon","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20101020-00\/?p=12493","title":{"rendered":"How do I get the dimensions of a cursor or icon?"},"content":{"rendered":"<p>\nGiven a <code>HICON<\/code> or a <code>HCURSOR<\/code>,\nhow do you get the dimensions of the icon or cursor?\n<\/p>\n<p>\nThe <code>GetIconInfo<\/code> function gets you most of the way there,\nreturning you an <code>ICONINFO<\/code> structure which gives you\nthe mask and color bitmaps (and the hotspot, if a cursor).\nYou can then use the <code>GetObject<\/code> function to get the\nattributes of the bitmap.\nAnd then here&#8217;s the tricky part:\nYou have to massage the data a bit.\n<\/p>\n<pre>\n\/\/ Also works for cursors\nBOOL GetIconDimensions(<a HREF=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa383701(VS.85).aspx\">__in<\/a> HICON hico, __out SIZE *psiz)\n{\n  ICONINFO ii;\n  BOOL fResult = GetIconInfo(hico, &amp;ii);\n  if (fResult) {\n    BITMAP bm;\n    fResult = GetObject(ii.hbmMask, sizeof(bm), &amp;bm) == sizeof(bm);\n    if (fResult) {\n      psiz-&gt;cx = bm.bmWidth;\n      psiz-&gt;cy = ii.hbmColor ? bm.bmHeight : bm.bmHeight \/ 2;\n    }\n    if (ii.hbmMask)  DeleteObject(ii.hbmMask);\n    if (ii.hbmColor) DeleteObject(ii.hbmColor);\n  }\n  return fResult;\n}\n<\/pre>\n<p>\nAs we&#8217;ve learned over the past few days,\nan icon consists of two bitmaps, a <i>mask<\/i> and an <i>image<\/i>.\nA cursor is the same as an icon, but with a hotspot.\n<\/p>\n<p>\nTo get the dimensions of the icon or cursor, just take the dimensions\nof the color bitmap.\nIf you have one.\n<\/p>\n<p>\nIf the icon\/cursor is monochrome, then there is no color bitmap.\nAs we&#8217;ve learned, in that case, the mask and image bitmaps are combined\ninto a single double-height bitmap,\nand the color is reported as <code>NULL<\/code>.\nTo get the size of the image, you therefore have to\ntake the mask bitmap and divide its height by two.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Given a HICON or a HCURSOR, how do you get the dimensions of the icon or cursor? The GetIconInfo function gets you most of the way there, returning you an ICONINFO structure which gives you the mask and color bitmaps (and the hotspot, if a cursor). You can then use the GetObject function to get [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-12493","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Given a HICON or a HCURSOR, how do you get the dimensions of the icon or cursor? The GetIconInfo function gets you most of the way there, returning you an ICONINFO structure which gives you the mask and color bitmaps (and the hotspot, if a cursor). You can then use the GetObject function to get [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/12493","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=12493"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/12493\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=12493"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=12493"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=12493"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}