{"id":148,"date":"2008-03-15T20:14:19","date_gmt":"2008-03-15T19:14:19","guid":{"rendered":"http:\/\/blog.m-ri.de\/index.php\/2008\/03\/15\/loadicon-macht-es-nicht-richtig\/"},"modified":"2008-04-02T20:39:34","modified_gmt":"2008-04-02T18:39:34","slug":"loadicon-macht-es-nicht-richtig","status":"publish","type":"post","link":"http:\/\/blog.m-ri.de\/index.php\/2008\/03\/15\/loadicon-macht-es-nicht-richtig\/","title":{"rendered":"LoadIcon macht es nicht richtig&#8230;"},"content":{"rendered":"<p>&#8230; oder sollte man sagen: Nicht so wie erwartet.\u00a0<\/p>\n<p>In einer der Micosoft Newsgroup fand sich eine Anfrage, die sich um folgenden Code drehte:<\/p>\n<pre line=\"1\" lang=\"cpp\">HICON m_hIcon[2]; \r\n[...] \r\nm_hIcon[0] = AfxGetApp()-&gt;LoadIcon(IDR_MAINFRAME); \r\nm_hIcon[1] = AfxGetApp()-&gt;LoadIcon(IDR_SMALL); \r\n[...] \r\nSetIcon(m_hIcon[0], TRUE);\u00a0\u00a0 \/\/ Gro\u00dfes Symbol verwenden \r\nSetIcon(m_hIcon[1], FALSE);\u00a0 \/\/ Kleines Symbol verwenden<\/pre>\n<p>Das Problem des Posters war, dass er sich M\u00fche mit dem Layout eine kleines Icons gegeben hat, aber leider immer nur ein verkleinertes 32&#215;32 Icon verwendet wurde.<\/p>\n<p>Das Problem liegt an der Verwendung von LoadIcon! LoadIcon l\u00e4dt immer das Standard-Format 32&#215;32. Bzw. in dem Format, dass durch das System als Standard-Icon-Gr\u00f6\u00dfe vorgegeben wird.<\/p>\n<p>Um es richtig zu machen, muss man das Icon wirklich in der gew\u00fcnschten Gr\u00f6\u00dfe laden. Dazu verwendet man die Funktion LoadImage. Eine kleine Helper Routine LoadIconEx kann dann wie folgt aussehen:<\/p>\n<pre line=\"1\" lang=\"cpp\">HICON LoadIconEx(PCTSTR pszIconName, bool bLargeIcon) \r\n{ \r\n HINSTANCE hInstance = ::AfxFindResourceHandle(pszIconName,RT_GROUP_ICON); \r\n return reinterpret_cast&lt;HICON&gt;(::LoadImage( \r\n\u00a0\u00a0\u00a0    hInstance, \r\n\u00a0\u00a0\u00a0    pszIconName, \r\n\u00a0\u00a0\u00a0    IMAGE_ICON, \r\n\u00a0\u00a0   \u00a0 GetSystemMetrics(bLargeIcon ? SM_CXICON : SM_CXSMICON), \r\n\u00a0\u00a0\u00a0    GetSystemMetrics(bLargeIcon ? SM_CYICON : SM_CYSMICON), \r\n\u00a0\u00a0\u00a0    0)); \r\n}<\/pre>\n<p><!-- Original code\nHICON m_hIcon[2];\n[...]\nm_hIcon[0] = AfxGetApp()->LoadIcon(IDR_MAINFRAME);\nm_hIcon[1] = AfxGetApp()->LoadIcon(IDR_SMALL);\n[...]\nSetIcon(m_hIcon[0], TRUE);   \/\/ Gro\u00dfes Symbol verwenden\nSetIcon(m_hIcon[1], FALSE);  \/\/ Kleines Symbol verwenden\n\nHICON LoadIconEx(PCTSTR pszIconName, bool bLargeIcon)\n{\nHINSTANCE hInstance = ::AfxFindResourceHandle(pszIconName,RT_GROUP_ICON);\nreturn reinterpret_cast<HICON>(::LoadImage(\nhInstance,\npszIconName,\nIMAGE_ICON,\nGetSystemMetrics(bLargeIcon ? SM_CXICON : SM_CXSMICON),\nGetSystemMetrics(bLargeIcon ? SM_CYICON : SM_CYSMICON),\n0));\n}\n--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8230; oder sollte man sagen: Nicht so wie erwartet.\u00a0 In einer der Micosoft Newsgroup fand sich eine Anfrage, die sich um folgenden Code drehte: HICON m_hIcon[2]; [&#8230;] m_hIcon[0] = AfxGetApp()-&gt;LoadIcon(IDR_MAINFRAME); m_hIcon[1] = AfxGetApp()-&gt;LoadIcon(IDR_SMALL); [&#8230;] SetIcon(m_hIcon[0], TRUE);\u00a0\u00a0 \/\/ Gro\u00dfes Symbol verwenden SetIcon(m_hIcon[1], FALSE);\u00a0 \/\/ Kleines Symbol verwenden Das Problem des Posters war, dass er sich M\u00fche &hellip; <a href=\"http:\/\/blog.m-ri.de\/index.php\/2008\/03\/15\/loadicon-macht-es-nicht-richtig\/\" class=\"more-link\"><span class=\"screen-reader-text\">\u201eLoadIcon macht es nicht richtig&#8230;\u201c <\/span>weiterlesen<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30,4,3,2],"tags":[370,100,352,61],"class_list":["post-148","post","type-post","status-publish","format-standard","hentry","category-c","category-mfc","category-programmieren","category-windows-api","tag-c","tag-gui","tag-mfc","tag-winapi"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/posts\/148","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/comments?post=148"}],"version-history":[{"count":0,"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/posts\/148\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/media?parent=148"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/categories?post=148"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.m-ri.de\/index.php\/wp-json\/wp\/v2\/tags?post=148"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}