{"id":21133,"date":"2008-08-22T10:00:00","date_gmt":"2008-08-22T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2008\/08\/22\/destroying-the-module-and-resource-information-associated-with-an-icon\/"},"modified":"2008-08-22T10:00:00","modified_gmt":"2008-08-22T10:00:00","slug":"destroying-the-module-and-resource-information-associated-with-an-icon","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20080822-00\/?p=21133","title":{"rendered":"Destroying the module and resource information associated with an icon"},"content":{"rendered":"<p><P>\nWe&#8217;ve seen that\n<A HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2008\/08\/20\/8880062.aspx\">\nicons and cursors know where they came from<\/A>,\nand the window manager uses this information when you ask it\nto change the size of an icon.\nBut not all icons carry this information,\nonly icons created by passing a <CODE>HINSTANCE<\/CODE> and\na resource name.\n<\/P>\n<P>\nYou can use this to your advantage if you want to destroy\nthe module and resource information associated with an icon.\nFor example, the <CODE>CreateIconIndirect<\/CODE> function\ncreates an icon from raw bitmap information without reference\nto an <CODE>HINSTANCE<\/CODE> or a resource name.\nThis allows you to create icons at runtime, but it also allows\nyou to create an icon that &#8220;throws away&#8221; the bonus information.\n<\/P>\n<PRE>\nHICON CopyIconWithoutResourceInfo(HICON hicoSrc)\n{\n  ICONINFO ii;\n  HICON hico = NULL;\n  if (GetIconInfo(hicoSrc, &amp;ii)) {\n    hico = CreateIconIndirect(&amp;ii);\n    if (ii.hbmMask) DeleteObject(ii.hbmMask);\n    if (ii.hbmColor) DeleteObject(ii.hbmColor);\n  }\n  return hico;\n}\n<\/PRE>\n<P>\nNow, throwing away this information is a desperation move,\nbecause it prevents the window manager from using the original\nresource information when resizing an icon,\nresulting in ugly stretched icons.\n<\/P>\n<P>\nYou might even be throwing this information away by mistake.\nFor example, if your program is asked to produce an icon,\nit&#8217;s best if you load the icon with a function like\n<CODE>LoadImage<\/CODE> because that records the bonus information;\nif the caller decides to resize the icon, it can do so with the\n<CODE>CopyImage<\/CODE> function while retaining full fidelity.\nOn the other hand, if you use a function like\n<CODE>ExtractIcon<\/CODE> or <CODE>CreateIconFromResource<\/CODE>,\nthat will not have the bonus information, and any icon stretching\nthat takes place will end up looking pretty ugly.\n<\/P>\n<P>\n[Raymond is currently away; this message was pre-recorded.]\n<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We&#8217;ve seen that icons and cursors know where they came from, and the window manager uses this information when you ask it to change the size of an icon. But not all icons carry this information, only icons created by passing a HINSTANCE and a resource name. You can use this to your advantage if [&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":[26],"class_list":["post-21133","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>We&#8217;ve seen that icons and cursors know where they came from, and the window manager uses this information when you ask it to change the size of an icon. But not all icons carry this information, only icons created by passing a HINSTANCE and a resource name. You can use this to your advantage if [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/21133","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=21133"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/21133\/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=21133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=21133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=21133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}