locked
Extract icons from an application RRS feed

  • Question

  • Hi,

    I am using this code below but it always returns me NULL when I am trying to extract an icon from an application.


    HICON hIcon;
    hIcon = (HICON)SendMessage(hwndEnum, WM_GETICON, ICON_SMALL, ICON_SMALL);

    But I always get NULL, even when it points to an application like Windows Media Player. Need help. I am executing this code in Windows Mobile 6.5 emulator.

    Thank you,
    CED
    • Edited by C.E.D Thursday, July 9, 2009 8:52 AM changed a line
    Thursday, July 9, 2009 8:51 AM

Answers

  • Just use SHGetFileInfo for this.
    To get app's main (used) icon just do this:

    private HICON GetFileIcon(LPCTSTR path)
    {
        SHFILEINFO shinfo = {0};
        SHGetFileInfo(path, 0, &shinfo, sizeof(shinfo), SHGFI_ICON | SHGFI_SMALLICON);
    
        return shinfo.hIcon;
    }
    And voila :).

    To get inner resource icons there's other function which was mentioned somewhere in this forum

    If You'll find my answer satisfactory or helpful - mark it as answered! Thank You. PS. Votes also doesn't hurt :).
    • Proposed as answer by Mal Loth Thursday, July 9, 2009 9:45 AM
    • Marked as answer by C.E.D Thursday, July 9, 2009 2:32 PM
    Thursday, July 9, 2009 9:45 AM

All replies

  • Just use SHGetFileInfo for this.
    To get app's main (used) icon just do this:

    private HICON GetFileIcon(LPCTSTR path)
    {
        SHFILEINFO shinfo = {0};
        SHGetFileInfo(path, 0, &shinfo, sizeof(shinfo), SHGFI_ICON | SHGFI_SMALLICON);
    
        return shinfo.hIcon;
    }
    And voila :).

    To get inner resource icons there's other function which was mentioned somewhere in this forum

    If You'll find my answer satisfactory or helpful - mark it as answered! Thank You. PS. Votes also doesn't hurt :).
    • Proposed as answer by Mal Loth Thursday, July 9, 2009 9:45 AM
    • Marked as answer by C.E.D Thursday, July 9, 2009 2:32 PM
    Thursday, July 9, 2009 9:45 AM
  • Thanks again Mal. You are great. Wish I was like you regarding Windows Mobile expertise. But what bugs me is that why did my prior implementation did not work. Documentation says that an application should return its icon when it receives the WM_GETICON message. Is there any problem in that implementation with WM_GETICON.

    Thank you,
    CED
    Thursday, July 9, 2009 2:33 PM
  • With time You'll learn that documentation is one thing, and how OEMs implement "necessary" methods and interfaces is the other matter. My advices come from my experience with many devices and consumer-programist relationships (aka. support) which I also do for the company I work for.

    If You'll be only programist You won't see that on 70% of user devices Your application doesn't work - even if You'll study hard each documentation paper. So my advice is - if You don't have contact with customers - use Google and other known developers blogs (very helpful) instead of documentation. Those famous people like: Joel Ivory Johnson, Chris Craft, Ilya Tumanov, Raffaele Limosani and many others have blogs which are a real treasure for us developers.

    If You'll find my answer satisfactory or helpful - mark it as answered! Thank You. PS. Votes also doesn't hurt :).
    Thursday, July 9, 2009 3:44 PM