Set the icon of the .exe file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Set the icon of the .exe file

  1. #1
    Join Date
    Jan 2003
    Posts
    373

    Unhappy Set the icon of the .exe file

    I have a MFC dialog project, I move all the icons including the IDR_MAINFRAME icon into a resource-only DLL, so there is no icon embedded in the executable file. In the dialog initialization, the dialog loads the icons using LoadIcon(hResdll, MAKEINTRESOURCE(IDI_MYICON))). The icons shows correctly on the dialog.

    But in the Windows Explorer, the icon of the .exe file is not the icon of IDR_MAINFRAME, I check the resource file in the resource-only dll project, the ID number of the IDR_MAINFRAME is the lowest one of all icon ID numbers. I also try
    Code:
    SetClassLongPtr(m_hWnd, GCLP_HICON, (LONG)LoadIcon(hResdll, MAKEINTRESOURCE(IDR_MAINFRAME)));
    But it doesn't work. The IDR_MAINFRAME icon doesn't show in the Explorer window, the system provides a default icon for the .exe file.

    Thanks for any help!
    Last edited by forester; October 9th, 2013 at 07:41 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,291

    Re: Set the icon of the .exe file

    You could add app icon in the resource for exe. (I also use resource dlls for the most of my projects but all my .exe still contain app icon and version block!)
    Victor Nijegorodov

  3. #3
    Join Date
    Jan 2003
    Posts
    373

    Re: Set the icon of the .exe file

    Thank you very much, VictorN!

    So if an executable file contains no icon resource in it, in the Explorer window, because Explorer can't find an icon in the the .exe file, the system will provide a default icon for the .exe file. I should keep at least one icon, i.e., the IDR_MAINFRAME icon in the project, and not move all icons into the resource-only dll.

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,291

    Re: Set the icon of the .exe file

    You should not move but just copy IDR_MAINFRAME icon into the resource-only dll.
    Victor Nijegorodov

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,927

    Re: Set the icon of the .exe file

    Quote Originally Posted by forester View Post
    I have a MFC dialog project, I move all the icons including the IDR_MAINFRAME icon into a resource-only DLL, so there is no icon embedded in the executable file. In the dialog initialization, the dialog loads the icons using LoadIcon(hResdll, MAKEINTRESOURCE(IDI_MYICON))). The icons shows correctly on the dialog.

    But in the Windows Explorer, the icon of the .exe file is not the icon of IDR_MAINFRAME, I check the resource file in the resource-only dll project, the ID number of the IDR_MAINFRAME is the lowest one of all icon ID numbers. I also try
    Code:
    SetClassLongPtr(m_hWnd, GCLP_HICON, (LONG)LoadIcon(hResdll, MAKEINTRESOURCE(IDR_MAINFRAME)));
    But it doesn't work. The IDR_MAINFRAME icon doesn't show in the Explorer window, the system provides a default icon for the .exe file.

    Thanks for any help!
    Just think a little on what you try. You try to set an icon programmatically at run time, which works just fine for dialog. But how Explorer is supposed to know what happens at runtime? Should it be able to decompile your executable to find out where the dialog's icon gets loaded from? Of course it should not, and it can not, and does not. So what other possibilities it has but parsing exe resourses?
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center