# Window title and task bar icon

**URL:** <https://forum.juce.com/t/window-title-and-task-bar-icon/24710>\
**Category:** General JUCE discussion\
**Created:** [October 18, 2017, 1:16pm UTC](https://forum.juce.com/t/window-title-and-task-bar-icon/24710 "2017-10-18T13:16:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 18, 2017, 1:16pm UTC](https://forum.juce.com/t/window-title-and-task-bar-icon/24710/1 "2017-10-18T13:16:51Z")

</div>

Hi, looking at the Juce demo code, I can add a system tray icon easily enough (Windows), but I can’t find a way to add the app try icon on the left of the task bar and on the left of the window of my JuceApplication. I’m using the native title bar.  
Can anyone tell me where and when I do this exactly please? Thanks.

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [October 18, 2017, 1:57pm UTC](https://forum.juce.com/t/window-title-and-task-bar-icon/24710/2 "2017-10-18T13:57:58Z")

</div>

> [@DaveH](#):
>
> I can’t find a way to add the app try icon on the left of the task bar and on the left of the window of my JuceApplication. I’m using the native title bar.

I’m not totally what you mean by the left of the task bar (?) but does `SystemTrayIconComponent::setIconImage` do the trick?

For the native title bar:

```auto
    //From within your DocumentWindow or similar
    Image myLogoIconImage;
    setIcon (myLogoIconImage);
    getPeer()->setIcon (myLogoIconImage); //To specifically set the native titlebar icon

```

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 18, 2017, 2:04pm UTC](https://forum.juce.com/t/window-title-and-task-bar-icon/24710/3 "2017-10-18T14:04:31Z")

</div>

Great, thanks. I looks like the getPeer() sets both the app icon and the Window icon so I don’t need the system tray stuff. So that’s all I needed, thanks again.

_edit_ The system tray stuff adds an icon to the right of the task bar, along with the printer/graphics card/USB stick stuff. Steam is the only App I’ve seen to use that area.

p.s. I’m using a 48x48 image, is that OK?

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [October 18, 2017, 5:50pm UTC](https://forum.juce.com/t/window-title-and-task-bar-icon/24710/4 "2017-10-18T17:50:34Z")

</div>

> [@DaveH](#):
>
> The system tray stuff adds an icon to the right of the task bar, along with the printer/graphics card/USB stick stuff.

Oh I see what you mean now!

> [@DaveH](#):
>
> I’m using a 48x48 image, is that OK?

IIRC, either JUCE or the OS resizes the image as needed.

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 18, 2017, 6:48pm UTC](https://forum.juce.com/t/window-title-and-task-bar-icon/24710/5 "2017-10-18T18:48:07Z")

</div>

But for the Mac OSX I use a larger image to keep it looking good?

---

<div class="post-metadata">

**Author:** ![jrlanglois](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jrlanglois/32/21372_2.png) [@jrlanglois](https://forum.juce.com/u/jrlanglois)\
**Post date:** [October 18, 2017, 7:08pm UTC](https://forum.juce.com/t/window-title-and-task-bar-icon/24710/6 "2017-10-18T19:08:47Z")

</div>

256px² I believe for macOS

---

<div class="post-metadata">

**Author:** ![DaveH](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daveh/32/4924_2.png) [@DaveH](https://forum.juce.com/u/DaveH)\
**Post date:** [October 18, 2017, 7:17pm UTC](https://forum.juce.com/t/window-title-and-task-bar-icon/24710/7 "2017-10-18T19:17:26Z")

</div>

Thanks for the info.

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [January 21, 2018, 10:16am UTC](https://forum.juce.com/t/window-title-and-task-bar-icon/24710/8 "2018-01-21T10:16:03Z")

</div>

Is there a particular reason the OS X code for setIcon() is “Todo” still?

> <https://github.com/WeAreROLI/JUCE/blob/develop/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm#L516>

Is it even possible to add an icon to the native window title bar on OS X? I know we can override `virtual void drawDocumentWindowTitleBar (DocumentWindow&...` and provide an icon there.

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [January 21, 2018, 10:29am UTC](https://forum.juce.com/t/window-title-and-task-bar-icon/24710/9 "2018-01-21T10:29:03Z")

</div>

Seems like you can:

> **[Setting a Window’s Title and Represented File](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/WinPanel/Tasks/SettingWindowTitle.html)**
>
> Explains how to use Cocoa windows and panels.

> Setting a Window’s Title and Represented File  
> A titled window can display an arbitrary title or one derived from a filename. The setTitle: method puts an arbitrary string on the title bar. The setTitleWithRepresentedFilename: method formats a filename in the title bar in a readable format and associates the window with that file. You can set the associated file without changing the title using setRepresentedFilename:. You can use the association between the window and the file in any way you see fit. One convenience offered by the NSWindow class is marking the file as having been changed, so that the user is prompted to save it on closing the window. The method for marking the document as having been changed is setDocumentEdited:. When the window closes, its delegate can check if the files has been changed using isDocumentEdited to see whether the document needs to be saved.

> Additionally, starting in OS X version 10.5, you can set a window’s represented document by URL using the setRepresentedURL: method. You can get the URL of the document currently represented by a window using the representedURL method. The window will automatically use the known icon for the file type of the specified file, if one exists. **To customize the document icon, you can use the following code segment:**

> **[[NSWindow standardWindowButton:NSWindowDocumentIconButton] setImage:customImage].**

> By default, a Command-click or Control-click on the rectangle containing a window’s document icon button and title will show a path popup. To customize this behavior, you can implement window:shouldPopUpDocumentPathMenu: in your window’s delegate. You can return NO from this method to stop the window from showing the path popup.

> You can also customize the document icon’s default drag behavior by implementing the window:shouldDragDocumentWithEvent:from:withPasteboard: in the window’s delegate. You can return NO to prohibit dragging the document icon.

Here’s the code they suggest:

```auto
[[NSWindow standardWindowButton:NSWindowDocumentIconButton] setImage:customImage].

```

If you can convert a `juce::Image` to a `NSImage * `, this is possible.  
@jules etc can we get a quick fix pushed for this? I tried to see how you guys do it in `CoreGraphicsContext::drawImage` but it was way above my pay grade/skill level and gave up lol.

edit: [initWithCGImage:size: | Apple Developer Documentation](https://developer.apple.com/documentation/appkit/nsimage/1519939-initwithcgimage?language=objc) and `static CGImageRef juce::CoreGraphicsImage::createImage()`

maybe something like this?

```auto
void setIcon(const Image& customImage) {
    auto rgbColourSpace = CGColorSpaceCreateDeviceRGB();
    auto greyColourSpace = CGColorSpaceCreateDeviceGray();
    auto cgImageRef = juce_createCoreGraphicsImage(customImage,
                                                  customImage.getFormat() == Image::PixelFormat::SingleChannel ? greyColourSpace : rgbColourSpace,
                                                  false);
    auto nsImage = [[NSImage alloc] initWithCGImage:cgImageRef size:NSMakeSize(customImage.getWidth(), customImage.getHeight())];
    [[window standardWindowButton:NSWindowDocumentIconButton] setImage:nsImage];
}

```

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [February 2, 2018, 9:29pm UTC](https://forum.juce.com/t/window-title-and-task-bar-icon/24710/10 "2018-02-02T21:29:51Z")

</div>

bump @jules

---

<div class="post-metadata">

**Author:** ![matkatmusic](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@matkatmusic](https://forum.juce.com/u/matkatmusic)\
**Post date:** [February 10, 2018, 9:28am UTC](https://forum.juce.com/t/window-title-and-task-bar-icon/24710/11 "2018-02-10T09:28:42Z")

</div>

not even a glance from @jules or @ed95 or @fabian?

it’s still not implemented even on the develop branch:

> <https://github.com/WeAreROLI/JUCE/blob/develop/modules/juce_gui_basics/native/juce_mac_NSViewComponentPeer.mm#L519>

please check out my comments a few posts ago that provides a possible solution, or at the very least, a direction to get this missing feature on OS X Native Titlebars added.
