{"id":1103,"date":"2014-05-01T07:00:00","date_gmt":"2014-05-01T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2014\/05\/01\/how-do-i-extract-an-icon-at-a-nonstandard-size-if-iextracticonextract-tells-me-to-go-jump-in-a-lake\/"},"modified":"2014-05-01T07:00:00","modified_gmt":"2014-05-01T07:00:00","slug":"how-do-i-extract-an-icon-at-a-nonstandard-size-if-iextracticonextract-tells-me-to-go-jump-in-a-lake","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20140501-00\/?p=1103","title":{"rendered":"How do I extract an icon at a nonstandard size if IExtractIcon::Extract tells me to go jump in a lake?"},"content":{"rendered":"<p>\nCommenter Ivo notes that\nif you ask\n<code>IExtract&shy;Icon::Extract<\/code> to extract an icon at a\nparticular size, the function can return\n<code>S_FALSE<\/code> which means\n&#8220;Go <strike>jump in a lake<\/strike> do it yourself.&#8221;\nBut\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/10\/20\/10078140.aspx#10078510\">\nhow can you do it yourself<\/a>?\nThe <code>Extract&shy;Icon<\/code> and\n<code>Extract&shy;Icon&shy;Ex<\/code> functions don&#8217;t let you\nspecify a custom size,\nand <code>Load&shy;Image<\/code> doesn&#8217;t work with icon indices\n(only resource IDs).\n<\/p>\n<p>\nThe <code>SH&shy;Def&shy;Extract&shy;Icon<\/code> function comes to the\nrescue.\nThis takes all the parameters of\n<code>IExtract&shy;Icon::Extract<\/code>\n(plus a bonus flags parameter),\nand it will actually do an extraction.\n<\/p>\n<p>\nLet&#8217;s extract an icon from Explorer at 48&times;48, just for illustration.\nAs usual, start with our\n<a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2003\/07\/23\/54576.aspx\">\nscratch program<\/a>, then make these changes:\n<\/p>\n<pre>\n<font COLOR=\"blue\">#include &lt;shlobj.h&gt;<\/font>\nvoid\nPaintContent(HWND hwnd, PAINTSTRUCT *pps)\n{\n  <font COLOR=\"blue\">HICON hico;\n  if (SHDefExtractIcon(TEXT(\"C:\\\\Windows\\\\Explorer.exe\"),\n                       1, 0, &amp;hico, NULL, 48) == S_OK) {\n    <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2010\/07\/29\/10043635.aspx\">DrawIconEx<\/a>(pps-&gt;hdc, 0, 0, hico, 0, 0, 0, NULL, DI_NORMAL);\n    DestroyIcon(hico);\n  }<\/font>\n}\n<\/pre>\n<p>\nRun the program, and observe that it draws the second icon\nfrom Explorer (whatever it is) at a size of\n48&times;48.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Commenter Ivo notes that if you ask IExtract&shy;Icon::Extract to extract an icon at a particular size, the function can return S_FALSE which means &#8220;Go jump in a lake do it yourself.&#8221; But how can you do it yourself? The Extract&shy;Icon and Extract&shy;Icon&shy;Ex functions don&#8217;t let you specify a custom size, and Load&shy;Image doesn&#8217;t work with [&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-1103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Commenter Ivo notes that if you ask IExtract&shy;Icon::Extract to extract an icon at a particular size, the function can return S_FALSE which means &#8220;Go jump in a lake do it yourself.&#8221; But how can you do it yourself? The Extract&shy;Icon and Extract&shy;Icon&shy;Ex functions don&#8217;t let you specify a custom size, and Load&shy;Image doesn&#8217;t work with [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1103","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=1103"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/1103\/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=1103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=1103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=1103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}