{"id":14153,"date":"2010-05-05T07:00:00","date_gmt":"2010-05-05T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2010\/05\/05\/how-the-shell-converts-an-icon-location-into-an-icon\/"},"modified":"2010-05-05T07:00:00","modified_gmt":"2010-05-05T07:00:00","slug":"how-the-shell-converts-an-icon-location-into-an-icon","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20100505-00\/?p=14153","title":{"rendered":"How the shell converts an icon location into an icon"},"content":{"rendered":"<p>\nA customer had trouble getting an icon to display for a registered\nfile type.\n<\/p>\n<blockquote CLASS=\"q\">\n<p>\nIn my resource file, I specify the icon like this:\n<\/p>\n<pre>\n101 ICON awesome.ico\n<\/pre>\n<p>\nAnd when I register my file type, I set it like this:\n<\/p>\n<pre>\n[HKEY_CLASSES_ROOT\\.xyz\\DefaultIcon]\n@=\"C:\\path\\to\\awesome.exe,101\"\n<\/pre>\n<p>\nHowever, when I view an <tt>.xyz<\/tt> file,\nmy awesome icon doesn&#8217;t appear.\nOn the other hand, if I change the <tt>101<\/tt> to a <tt>0<\/tt>,\nthen it works.\nWhy?\nIsn&#8217;t the number in the resource file the resource&nbsp;ID?\n<\/p>\n<\/blockquote>\n<p>\nWhy yes, in fact, the number in the resource file is indeed\nthe resource&nbsp;ID.\nBut the number after the comma in the <code>Default&shy;Icon<\/code>\n<i>isn&#8217;t<\/i>.\n<\/p>\n<p>\nThe format of shell icon locations (used most visibly\nby <code>Default&shy;Icon<\/code>, but also used in other places)\nis <code>&laquo;file&raquo;,&laquo;index&raquo;<\/code>,\nwhere the index is a zero-based index of the icon in your\nresources.\nIn other words,\nan index of zero means &#8220;Give me the first icon in the file.&#8221;\nThe resource compiler sorts icons numerically by resource&nbsp;ID,\nso the first icon in the file is the icon with the numerically\nlowest resource&nbsp;ID.\nIn the above example, apparently there are no icons with resource&nbsp;IDs\nless than 101;\nthat would explain why asking for icon index zero results in the awesome\nicon.\n<\/p>\n<p>\nThe function behind all this icon hunting is <code>Extract&shy;Icon<\/code>.\nThe icon location string is split up at the comma into a path and\nan integer, and that path and integer are passed to the\n<code>Extract&shy;Icon<\/code> function.\nSince the <code>Extract&shy;Icon<\/code>\nfunction interprets the integer\nas the icon index, that&#8217;s what the integer in your icon location\nstring means.\n<\/p>\n<p>\nIn Windows&nbsp;95, the\n<code>Extract&shy;Icon<\/code> function was enhanced\nso that you could also specify an icon by its resource&nbsp;ID\nby passing its <i>negative<\/i> as the icon index.\nIn other words, if you place a negative number after the comma,\nthen its absolute value is interpreted as the resource&nbsp;ID.\n<\/p>\n<p>\nWe learned some time ago that\nthere&#8217;s a hole in this model:\nIt doesn&#8217;t work if you want a resource&nbsp;ID of 1,\nbecause\n<a HREF=\"http:\/\/blogs.msdn.com\/oldnewthing\/archive\/2005\/05\/26\/422076.aspx\">\nthe value &minus;1\nhas a special meaning to <code>Extract&shy;Icon<\/code><\/a>:\nInstead of extracting an icon, it tells you how many icons there are.\n<\/p>\n<p>\nThe workaround for this is actually straightforward,\nand you should be able to figure it out on your own\nbased on information provided in this article.\nHow do you specify that you want the icon whose resource&nbsp;ID is 1?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A customer had trouble getting an icon to display for a registered file type. In my resource file, I specify the icon like this: 101 ICON awesome.ico And when I register my file type, I set it like this: [HKEY_CLASSES_ROOT\\.xyz\\DefaultIcon] @=&#8221;C:\\path\\to\\awesome.exe,101&#8243; However, when I view an .xyz file, my awesome icon doesn&#8217;t appear. On the [&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-14153","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>A customer had trouble getting an icon to display for a registered file type. In my resource file, I specify the icon like this: 101 ICON awesome.ico And when I register my file type, I set it like this: [HKEY_CLASSES_ROOT\\.xyz\\DefaultIcon] @=&#8221;C:\\path\\to\\awesome.exe,101&#8243; However, when I view an .xyz file, my awesome icon doesn&#8217;t appear. On the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/14153","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=14153"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/14153\/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=14153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=14153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=14153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}