Change icon for a Delphi console application

2019-03-18 19:50发布

How do I change the program icon for a Delphi console application?

The application settings is greyed in a console application.

Bye.

5条回答
Explosion°爆炸
2楼-- · 2019-03-18 19:52

if you add

application.Run; 

somewhere in your dpr file you can use the project->options to change the icon. After you have changed the icon just remove "application.Run;" again and you can compile/build with new icon.

查看更多
放我归山
3楼-- · 2019-03-18 20:02

Simply change the Icon in your apps resource file (say your app project is called ConsoleApp.dpr, your app resource file will be ConsoleApp.res)

The main icon resource in there is intuatively called MAINICON, just replace it.

Here is a step by step for C++ Builder (the steps are basically the same in Delphi)

查看更多
smile是对你的礼貌
4楼-- · 2019-03-18 20:13

If the option to change the icon is disabled, then it is because you have deleted or neglected to add the following line from your DPR file:

{$R *.res}

Put it back, or add it if you never had it. The icon setting will be re-enabled, as will the version-information settings. If the resource file does not exist, then the IDE will create it for you. Do not edit that resource file (such as to add your own icons or other resources); it is for the IDE's use only.

查看更多
甜甜的少女心
5楼-- · 2019-03-18 20:14
  1. add {$R *.res} in your DPR file
  2. comment {$APPTYPE CONSOLE} line in your DPR file
  3. edit Project -> Options -> Application -> Icon
  4. uncomment {$APPTYPE CONSOLE} line in your DPR file

Tested with Delphi XE

查看更多
Juvenile、少年°
6楼-- · 2019-03-18 20:16

According to a July 2007 blog article by Nibu Thomas, there seems to be a SetConsoleIcon WinAPI function.

Alternatively just put the icon in a resource file. Windows should use the first icon it encounters in the application's resources as the application icon.

查看更多
登录 后发表回答