2

I am using nana for building a GUI in my C++ application, which basically works fine. However, I have trouble setting the window icon under Windows:

nana::API::window_icon_default(nana::paint::image("hunger.ico"));

There is definitely a file hunger.ico within the same folder as the executable, I double-checked that. That icon file is 32x32 in size (or 16x16). I also tried to retrieve the full path to the icon file, like so:

wchar_t buffer[MAX_PATH];
DWORD len = sizeof(buffer);
GetModuleFileName(nullptr, buffer, len);
std::wstring ws(buffer);
// concatenate ws and "hunger.ico" here

But when I run the (console) application from within VS2015, the default window icon is used. Any ideas what I am missing here?

Matthias
  • 9,817
  • 14
  • 66
  • 125

2 Answers2

1

This call works well for me. The icon appears in the application window title bar and in the task bar.

nana::API::window_icon(
    myform.handle(),
    nana::paint::image("myicon.ico"));

You need to pass in the handle of the application form ( why? shouldn't window_icon() accept the form and extract the handle for itself? ) and the icon file needs to be in the working folder with the different resolutions required

ravenspoint
  • 19,093
  • 6
  • 57
  • 103
0

I hope Jinhao will solve the problem to load the icon to a running program.

...but, I'm not sure, but if what you want is to have your .exe file even in the windows explorer ilustrated with your ico/bmp, you will need to include it into the .exe, and probably nana alone can't do that. I solved that "problem" by adding the icon as a resource to the VS project: in the Solution explorer right-click and Add... a Resource... picking an Icon, that can be New... wich launch an Icon editor from where you can import any image format to your icon. You will need the image file only at compile time, and at run time not.

qPCR4vir
  • 3,521
  • 1
  • 22
  • 32