How can I change the default .exe icon in Visual Studio 2012 (C++)

百般思念 提交于 2019-12-22 09:58:12

问题


I was wondering if there was a way to change the default icon that VS2012 makes when I compile my app. Just for those wondering, I am trying to change the .exe program's icon, not the window icon at the top left of the window and on the start menu. I already know how to do that. I have been Google-ing this for ever and it always shows up how to change the window icon, not the actual file's icon. Thanks in advance!!!

EDIT: This is what I want to do...

I want to replace this...

with this...

]

Thanks, hope this clarifies.


回答1:


  1. Add an icon in the resource section of you C++ project. This icon will be shown as an Application icon for your executable. [Note: make sure you are in the Resource View window, not the Solution Explorer window. Then right-click on the rc folder to Add Resource...]

  2. I have tried this with Win32 Console Application and it shows the icon in the Explorer as Application Icon. This should work with other types of applications also.

  3. Also note that while adding the icon you need to add different size images for the Icon like 16*16, 32*32. These different icon images will be used by Windows Explorer to display Application Icon in different View Modes(Small Icons, Medium Icons, Larget Icons, Extra Large icons etc.)




回答2:


Adding icon to executable

Tested for VS2012 Express

Create a icon.rc file next to your .vcxproj file and fill it with the following text:

// Icon Resource Definition
#define MAIN_ICON                       102
MAIN_ICON               ICON                    "your_icon.ico"

Then add the following to your .vcxproj file anywhere within the Project tag:

<ItemGroup>
    <ResourceCompile Include="icon.rc">
    </ResourceCompile>
</ItemGroup>

Additional options

If you want you may forward definitions to your icon.rc file like so:

<ItemGroup>
    <ResourceCompile Include="icon.rc">
        <AdditionalOptions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">/D_DEBUG %(AdditionalOptions)</AdditionalOptions>
    </ResourceCompile>
</ItemGroup>

Notice the /D_DEBUG definition, which defines _DEBUG for your resource file. Then within your icon.rc file check for definitions normally:

#define MAIN_ICON 102
#if defined(_DEBUG)
MAIN_ICON               ICON                    "debug_icon.ico"
#else
MAIN_ICON               ICON                    "release_icon.ico"
#endif



回答3:


This is not really how it works. The size of the icon of your program as displayed by Windows isn't determined by you, the user selects it. It is a user preference, very simple to change on later Windows versions by just rolling the mouse scroll button on the desktop. And an icon doesn't have just a single size, it is capable of storing multiple images. Windows picks the one that fits best. And the one you get when starting a new project is just a stock one that's stored in the project template. You can change it by tinkering with the project template .zip file but that's kinda pointless, you want to give your program a custom icon that personalizes it.

Best thing to do is to steal, beg or borrow one, making a good looking icon is an art. Lots of web sites where you can download free ones. If you want to take a shot at creating your own then that's supported as well. Simply double-click the project's .rc file to open the resource view, open the Icon node and double-click the default icon to open the icon editor. You add a new size with Image + New Image Type. Plenty of freeware icon editors available as well.




回答4:


If its a Win32 application then you can add a resource to your project and then put the icon in there. Then you can assign the icon to your application by sending the WM_SETICON method. For MFC applications, resources are already present and there is a nominated icon resource that you can just change.

You can also load it directly from an external file as suggested here:

Setting program icon without resources using the WIN32 API

I would recommend the resource route though. Resources get embedded in your executable and it is the recommended way to do this sort of thing in Win32 and MFC.



来源:https://stackoverflow.com/questions/16026262/how-can-i-change-the-default-exe-icon-in-visual-studio-2012-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!