Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm learning to use DEV-C++ 5.11, hoping to make a program I have in mind.
Before I go any further, I would like to change the icon for the resulting program, but it doesn't seem to work.
Here's what I did:
1 - I start a new project (File - New - Project - Windows Application) and name it "test". This creates a generic main.cpp file in the with the WndProc and WinMain functions in it.
2 - I compile and run, it creates a program (test.exe) which does nothing but works. 3 - I delete the .exe file.
3 - I copy an icon file (test.ico) in the directory of the project.
4 - I set the icon as the project icon. (Project - Project Options - General - Icon - Browse - Type - Win32 GUI)
5 - I compile and run again, the resulting program works but still shows that generic icon (in the title bar, on the task bar, in the file explorer and the Alt+Tab selector).
What am I missing? Any help would be greatly appreciated.
P.S. I'm running on Windows 7 and the .ico file is a valid icon file that I took from another program and renamed, for the sake of the test.

What I have tried:

Here's what I did:
1 - I start a new project (File - New - Project - Windows Application) and name it "test". This creates a generic main.cpp file in the with the WndProc and WinMain functions in it.
2 - I compile and run, it creates a program (test.exe) which does nothing but works. 3 - I delete the .exe file.
3 - I copy an icon file (test.ico) in the directory of the project.
4 - I set the icon as the project icon. (Project - Project Options - General - Icon - Browse - Type - Win32 GUI)
5 - I compile and run again, the resulting program works but still shows that generic icon (in the title bar, on the task bar, in the file explorer and the Alt+Tab selector).
Posted
Updated 6-Nov-17 12:19pm
v2
Comments
Kornfeld Eliyahu Peter 5-Nov-17 4:41am    
I have no answer (never even heard of DEV-C++), so I rather ask you something: Why DEV-C++? Visual Studio Community Edition isn't fit?
Member 13503586 5-Nov-17 11:05am    
I tried Visual Studio 2017 Community Edition. It has a nice IDE with a tool to edit the icons. But when I try editing some of them (it won't let me edit all the sizes), I save the result, compile and run, and the result is the same. The icon (little gift box) is unchanged, in the title bar, task bar, file explorer and Alt+Tab selector. I don't understand why. Can you help me? Thanks.
Kornfeld Eliyahu Peter 5-Nov-17 12:26pm    
https://docs.microsoft.com/en-us/visualstudio/ide/how-to-specify-an-application-icon-visual-basic-csharp
Member 13503586 5-Nov-17 13:16pm    
The solution described on that link uses either VisualBasic or C#. I was using C++ (Windows Desktop Application) when starting a new project, so I tried to open a new project in C# (Windows Universal - Blank App) instead, and now it says "Choose the target and minimum platform versions that your Universal Windows application will support." and it offers me nothing but different Windows 10 options, so I leave that as it is offered and then it halts, saying I need to be running Windows 10. I don't think I should have to move from 7 to 10 to set an icon for my program. Typically Microsofty!
enhzflep 5-Nov-17 20:39pm    
Haven't used DevCpp in about 10 years, having moved on to the similarly light-weight and efficient Code::Blocks (i only use VS reluctantly for debugging)
Typically, the program's icon is changed in the resource editor that you use to define dialogs and include resources - the program's icon is merely a resource which is used by the OS..

Within your created WinMain function the application main window is usually registered calling RegisterClassEx:
WNDCLASSEX wc;
// ...
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wc);
HWND hwnd = CreateWindowEx(...);
IDI_APPLICATION is the resource ID of an icon contained in the excutable file. That icon will be shown in the title bar of the window. You may change the ID to any icon ID that is present in the executable.

Each Windows executable contains embedded resources like icons, strings, dialog templates, cursors, version information. An IDE for Windows application creates a set of predefined IDs and provides the related resources.

With Visual Studio the resources are organised in resource source script files (*.rc) and one or more header files with the ID definitions (resource.h for project specific IDs). You can use the VS resource editor to modify these or edit the rc files with a text editor.

I don't know how Dev-C++ handles resources but it should be in a similar manner (a quick research shows that it seems to use rc script files too). You have to add an icon resource by providing an ID and the path to the icon file or edit the existing resource script file to change the path to your icon file.

See also About Resource Files (Windows)[^].
 
Share this answer
 
I finally figured it out!
I replaced the following two lines
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); /* Load a standard icon */
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); /* use the name "A" to use the project icon */

with
wc.hIcon = LoadIcon(hInstance, "A"); 
wc.hIconSm = LoadIcon(hInstance, "A"); 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900