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;
}

(1 votes)
Loading...

Similar Posts

Subscribe
Notify of
5 Answers
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
NorbertWillhelm
11 months ago

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).

NorbertWillhelm
11 months ago

I just thought you were talking about Resource Hacker.

IdenVersio
11 months ago

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