DocumentWindow::setIcon


#1

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?

 

Thanks


#2

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?


#3

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 (https://www.allegro.cc/manual/5/al_set_display_icon) 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.


#4

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

see http://msdn.microsoft.com/en-us/library/windows/desktop/ms632643%28v=vs.85%29.aspx

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.

--
Roeland


#5

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


#6

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.

--
Roeland