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 Visual Studio Other
{count} votes

Accepted answer
  1. Minxin Yu 13,501 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 90,521 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 Answers by the question author, which helps users to know the answer solved the author's problem.