Problem beim Festlegen des Icons für C++-Programme in Visual Studio 22?
Ich habe ein C++-Programm mit Visual Studio 22 als IDE geschrieben, und ich versuche, ein Icon für das Programm festzulegen.
Wenn ich den Pfad zum Icon angebe, funktioniert es in Visual Studio einwandfrei. Wenn ich das Programm jedoch als ausführbare Datei aus dem Ordner starte, erhalte ich eine Fehlermeldung, die besagt, dass das Icon nicht gefunden werden kann.
Wenn ich außerdem mit Resource Hacker ein Icon hinzufüge, erscheint es zwar in der Taskleiste, aber nicht in der linken oberen Ecke des Programmfensters. Ich suche schon eine Weile nach einer Lösung, konnte aber keine finden. Wenn jemand eine Lösung für dieses Problem hat, wäre ich sehr dankbar dafür.
#include "App.h"
#include "Mainframe.h"
#include "wx/wx.h"
wxIMPLEMENT_APP(App);
bool App::OnInit() {
// Load the icon
wxIcon icon;
icon.LoadFile("Icon.ico", wxBITMAP_TYPE_ICO);
// Create the main frame
MainFrame* mainFrame = new MainFrame("Test Generator");
// Set the icon
mainFrame->SetIcon(icon);
mainFrame->SetClientSize(1000, 875);
mainFrame->Center();
mainFrame->Maximize();
// Show the main frame
mainFrame->Show(true);
return true;
}
The LoadFile function of the wxIcon class loads the icon from a relative path.
In your position, I would check if the Icon.ico file is really in the same directory as your executable file.
By the way: If you want to give your executable file an icon as a resource, I would create a corresponding resource file (.rc).
Thank you, but on the first picture is already a rc datei.
I just thought you were talking about Resource Hacker.
If you make right click on your project and then go to Properties, there should be a text box somewhere where you enter your icon path again
Thanks for the quick answer. But I don’t find what you mean: https://imgur.com/66GKPed