# DocumentWindow::setIcon

**URL:** <https://forum.juce.com/t/documentwindow-seticon/13370>\
**Category:** General JUCE discussion\
**Created:** [August 15, 2014, 9:19am UTC](https://forum.juce.com/t/documentwindow-seticon/13370 "2014-08-15T09:19:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aros](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Aros](https://forum.juce.com/u/Aros)\
**Post date:** [August 15, 2014, 9:19am UTC](https://forum.juce.com/t/documentwindow-seticon/13370/1 "2014-08-15T09:19:43Z")

</div>

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?

&nbsp;

Thanks

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 15, 2014, 9:22am UTC](https://forum.juce.com/t/documentwindow-seticon/13370/2 "2014-08-15T09:22:04Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Aros](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@Aros](https://forum.juce.com/u/Aros)\
**Post date:** [August 16, 2014, 2:41pm UTC](https://forum.juce.com/t/documentwindow-seticon/13370/3 "2014-08-16T14:41:51Z")

</div>

Yes, Windows.

&nbsp;

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

&nbsp;

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

---

<div class="post-metadata">

**Author:** ![roeland-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/roeland-2/32/738_2.png) [@roeland-2](https://forum.juce.com/u/roeland-2)\
**Post date:** [August 18, 2014, 1:50am UTC](https://forum.juce.com/t/documentwindow-seticon/13370/4 "2014-08-18T01:50:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [August 18, 2014, 8:03am UTC](https://forum.juce.com/t/documentwindow-seticon/13370/5 "2014-08-18T08:03:18Z")

</div>

It already does call it twice - see juce\_win32\_Windowing.cpp, line 1440

---

<div class="post-metadata">

**Author:** ![roeland-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/roeland-2/32/738_2.png) [@roeland-2](https://forum.juce.com/u/roeland-2)\
**Post date:** [August 25, 2014, 12:04am UTC](https://forum.juce.com/t/documentwindow-seticon/13370/6 "2014-08-25T00:04:03Z")

</div>

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
