How to put an icon in the C++ winforms executable

José Carlos 886 Reputation points
2023-07-27T18:24:08.83+00:00

Hi friends,

I followed some videos and scripts on the internet, but I couldn't put an icon in the executable of a C++ Winforms program.

I'm using VIsual Studio Community 2022 and in the program's properties I can't find the icon selection part.

Tks

Developer technologies | Windows Forms
Developer technologies | C++
Developer technologies | C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
{count} votes

Answer accepted by question author
  1. Minxin Yu 13,506 Reputation points Microsoft External Staff
    2023-07-31T01:47:52.6333333+00:00

    Hi, @José Carlos

    Add icon resource and no other operations are required.

    From User's image

    To enter image description here

    In addition, to import another icon with a lowest custom icon ID into Resource file as an exe icon.

    //resource.h
    #define IDI_ICON2                       99 // the  second icon 
    #define IDI_ICON1                       101
    

    your project.rc file

    IDI_ICON2               ICON                    "XXX\\XXX\\XXX.ico"
    
    IDI_ICON1               ICON                    "icon1.ico"
    

    You may need to restart the computer to clear the cache and rebuild the project to display the second icon.enter image description here

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Castorix31 91,416 Reputation points
    2023-07-27T20:51:48.22+00:00

    Add it from the .rc by double-clicking, then right-click [Add resource...]

    User's image

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.