Hi, I have a problem with setting the "tiny top left icon of the main window". I thought that setIcon() is the method I need to use but the problem is it doesn't do anything. After calling this method, there's no difference - there is still the default icon. Am I missing something?



Assuming you're talking about Windows, right?

The setIcon sets the app icon, so it'll affect the taskbar icon. TBH I've no idea how the one in the title bar works. Do apps even have control over it?

Yes, Windows.


The point is that the taskbar icon changes. But the title bar icon doesn't. I have however found out that when I launch the release version directly (not through Visual Studio). The title bar icon is the same as the taskbar icon, so it seems the problem is solved...


Do apps even have control over it?

I am not sure. Previously I worked with Allegro library and it had a specific call ( to change the "window associated icon", but it might have changed the taskbar icon as well... I am not sure as it has been some time.

You have to send two WM_SETICON messages to the native window.


You need some code like this:

    HANDLE hIcon, hIconSm;

    HWND hWnd = (HWND) getPeer()->getNativeHandle();

    int size   = GetSystemMetrics(SM_CXICON);
    int sizeSm = GetSystemMetrics(SM_CXSMICON);
    // create your icon objects. These objects must not be destroyed until
    // the window is gone or until you set another icon.
    hIcon   = ...;
    hIconSm = ...;

    SendMessage(hWnd, WM_SETICON, ICON_BIG,   (LPARAM) hIcon);
    SendMessage(hWnd, WM_SETICON, ICON_SMALL, (LPARAM) hIconSm);

On windows if you don't set an icon like this, windows will get your application icon by default.


It already does call it twice - see juce_win32_Windowing.cpp, line 1440

So, to the original question, you have to call window.getPeer()->setIcon(), I think after you call setUsingNativeTitleBar() and setResizable() if your code uses these methods.