Mega Code Archive

 
Categories / Delphi / Graphic
 

Specify Custom Icon for a Console Mode Delphi Application

Title: Specify Custom Icon for a Console Mode Delphi Application Delphi console mode applications are pure Windows programs that run without a graphical interface. When a console application is started, Windows creates a text-mode console window through which the user can interact with the application. By design, all console mode applications have the same icon (depends on the Windows version). For a normal GUI application you can change the application icon using Project - Options - Application - Application Settings - Icon. For console mode applications this section is disabled - and thus all console mode application have a default icon. Windows by design uses the first icon it locates in an application's resources for the application icon. For console mode applications there's no resource file created - no "{$R *.res}" line in the DPR - thus no icon to use. Specify an Icon for a Console Mode Delphi Application To have a custom icon for a console mode application you need to create a resource file hosting, at least, an icon for the first icon-type resource. Here's what to do: Open Notepad (or any application that can handle ASCII files). Have the next line in the document: 1 icon "myicon.ico" Save this file as "conicon.rc" in the project's folder. You can use any name BUT the extension must be "RC". Of course, ensure that you actually have an icon named "conicon.ico" in the project's folder. Go to Project Manager and add this file to your console mode project. Compile. You should see a new line added to your project's source code file: {$R 'conicon.res' 'conicon.rc'} The top of your console mode program file should look like: program conapp; {$APPTYPE CONSOLE} {$R 'conicon.res' 'conicon.rc'} uses SysUtils; .... Note that your compiled application *has* a different icon, specified by "myicon.ico" What we've done is that we have create a resource file for the application hosting our icon as the first icon-type resource - and Windows is using this icon for our console mode application. Well, that's it :)