Adding/drawing Component in native window


I’m new to Juce, and I’m looking for the right way to add
a Juce component in a native window (in a existing C application),
or to paint the component inside this window
(that use Quickdraw).

Any help/example/suggestion will be appreciated
Best Regards


That’s always a tough thing to try to do - best thing would be to look at the juce plugin code, where it uses various tricks to embed juce comps in different types of host.


That’s a thought, making a juce class that can accept a current native window in its constructor so it can wrap things enough to let other juce components go inside? And/or vice-versa?


That’s how the ComponentPeers already work - there’s a special parameter in addToDesktop that’s used by the plugin code to do exactly that.


Hi Guys,

I’ve trying to do the same thing and quite struggle a bit.

I’m working on Mac/PC Audio Plugin but already have a fully working and quite powerful plugin framework, so using JAP is quite out of question.
(it already supports AU, VST, MAS, RTAS, StandAlone, DX)

I’m currently evaluating JUCE as a possible replacement for our inhouse GUI toolkit.

After digging into JAP it seems that there is still some stuff like SetParent or mac equivalent which are still in each plugin system wrapper.

I was wondering if there was a possibility to hide into a class like ComponentWrapper all the native stuff to embed a Component into an existing native window, so JUCE would be more easily pluggable into a plugin environment.

Let me know what do you think.




Hmm, it’s not as simple as that, unfortunately - all the plugin formats are a bit quirky and have specialised code, so I don’t think there’d be very much commonality between them. Whatever I could find that was common I added to the peer classes.


Some time ago I wrote to the list about adding a juce component in a native window.

Looking at the code from juce_VstWrapper.cpp, now I can add and draw my component
in a native window (OSX for the moment) with the following code:


if(hostWindow != NULL)
  SetAutomaticControlDragTrackingEnabledForWindow (hostWindow, true);
  WindowAttributes attributes;
  GetWindowAttributes (hostWindow, &attributes);
  HIViewRef parentView = NULL;
  if ((attributes & kWindowCompositingAttribute) != 0)
    HIViewRef root = HIViewGetRoot (hostWindow);
    HIViewFindByID(root, kHIViewWindowContentID, &parentView);
    if (parentView == NULL)
      parentView = root;
    GetRootControl(hostWindow, (ControlRef*) &parentView);
    if (parentView == NULL)
      CreateRootControl(hostWindow, (ControlRef*) &parentView);
  if(parentView != NULL)
    self->juceComp = new JuceTestComponent(self);
    self->juceComp->addToDesktop(ComponentPeer::windowIsResizable, (void *) parentView);
    self->juceComp->setBounds(self->x_rect.left+2, self->,
                              self->x_box.b_rect.right-self->x_box.b_rect.left-4, self->x_box.b_rect.bottom-self->;
    self->juceComp->setInterceptsMouseClicks(true, true);


The first problem was with mouse interaction: when the mouse pass over the component the application stop to listen mouse events
(like as the component takes and don’t release mouse events):
I solved this problem adding at the end of handleMouseEvent (in juce_mac_windowing.cpp)
the following line:

 CallNextEventHandler(callRef, theEvent);

A second problem was to be able to click on and receive mouse notification in the component.
The only solution I founded was to change the following line in Component::getComponentAt (juce_Component.cpp)
if (flags.visibleFlag && x >= 0 && y >= 0 && x < compW_ && y < compH_ && hitTest (x, y))
if (flags.visibleFlag && x >= 0 && y >= 0 && x < compX_ + compW_ && y < compY_ + compH_ && hitTest (x, y))

Now my component receives mouseDown/ mouseMove/ mouseEnter/ mouseExtit but not mouseDrag and mouseUp (why?)

I need also that when the component receives a mouse event then pass it to the application and other listeners.
Do you have an idea if it is possible and how to do that?

Many thanks for any help and suggestion