Open a window from a dll

Hi, I want to open a juce window from a dll vc++ 6.0.
But all I get is a “empty” window on the desktop where nothig is painted…

Thanks in advance for any help.
Luke

I start in my code with:

void* hhMod;
hhMod = PlatformUtilities::getCurrentModuleInstanceHandle ();
MEMORY_BASIC_INFORMATION mbi;
static int dummy;
VirtualQuery( &dummy, &mbi, sizeof(mbi) );
DWORD hMod = (DWORD)mbi.AllocationBase;
PlatformUtilities::setCurrentModuleInstanceHandle ((HINSTANCE)hMod);
initialiseJuce_GUI();
JUCELukeApplication pJuceLuke;
pJuceLuke.initialise ("");

and my juce application is very closed to the juce demo:
class JuceLukeWindow : public DocumentWindow
{
public:
JuceLukeWindow()
: DocumentWindow (T(“Hello Luke”),
Colours::lightgrey,
DocumentWindow::allButtons,
true)
{
setContentComponent (new JuceLukeContentComponent());
Component* myCoomp = getContentComponent ();
Image areaGantt (Image::RGB, 400, 400, true);
Graphics g (areaGantt);
myCoomp->paint (g);
setVisible (true);
}

~JuceLukeWindow()
{
}

void closeButtonPressed()
{
    JUCEApplication::quit();
}

};

class JUCELukeApplication : public JUCEApplication
{
JuceLukeWindow* juceLukeWindow;
ShinyLookAndFeel shinyLookAndFeel;

public:
JUCELukeApplication()
: juceLukeWindow (0)
{
}

~JUCELukeApplication()
{
}

void initialise (const String& commandLine)
{
    LookAndFeel::setDefaultLookAndFeel (&shinyLookAndFeel);

    juceLukeWindow = new JuceLukeWindow();
	juceLukeWindow->setBounds (100, 100, 400, 500);
	juceLukeWindow->setVisible (true);
}

void shutdown()
{
    if (juceLukeWindow != 0)
        delete juceLukeWindow;

    LookAndFeel::setDefaultLookAndFeel (0);
}

const String getApplicationName()
{
    return T("JuceLuke for JUCE");
}

const String getApplicationVersion()
{
    return T("1.0");
}

bool moreThanOneInstanceAllowed()
{
    return true;
}

void anotherInstanceStarted (const String& commandLine)
{
}

};

hmm… Is this running is some other process’s event loop? If so, you shouldn’t use the JUCEApplication class at all, but just create the components you need and let them get on with it. If there isn’t another event loop running, then that’ll be your problem, because you’ll need one of those.

Hi jules, thanks for your reply.
Yes, there is an external event loop:

I have a java gui application and my c++ dll. Java holds a window and events and it calls my dll to draw inside the window.

Inside c++, from Java params, I can get a DrawingSurface and then a hwnd and a hdc. Using these info I can get a Image and then a Graphics.
I paint all my components using this Graphics (I don’t use a JUCEApplication as you suggested).
Finally I draw my Image using Windows functions (DrawDibDraw).

In this case, how can I drag and drop a component?
Thanks in advance.
Luke

So you’re not actually using juce components, just the graphics stuff? Sounds like a ridiculously complicated way to run an app!

Did you look at the DragAndDropContainer/target classes?

I have an old c++ application using nutcracker and motif without a separation from business logic and graphical calls. This application is called by an already existing Java GUI application which controls all events. I can’t change this situation. I can’t rewrite the all application in java, but I have to remove motif and nutcracker and I think I can use Juce. In this situation I hope I can use Juce to easly drag and drop, resize, scroll juce components which have lot of children components.

yeesh! But it’s certainly doable. If you have any problems, the audio plugin code might be worth looking at, because that runs a juce window in another app too.

Sure, dragging and dropping within juce is easy - did you look at the demo app’s drag-and-drop page?

I didn’t look jet at drag-and-drop page, because I have another problem first: it seems that setBounds to children components works relative to original (0,0) top position and not relative to their parent.
I have a top component with one child, with child1->SetBounds (50,50,50,50).
This child has a child too, with child2->SetBounds(10,10,10,10). Well if I want child2 to be 10 pixel into child1 I have to child2->SetBounds(60,60,10,10) even if there is a child1->addAndMakeVisibile(child2). Anyway I can draw everything but when I use getComponentAt it works only for children of my top component (because they are relative to 0,0) but getComponentAt(61,61) returns child1, not child2, because when getComponentAt tests child2 as child of child1 it calculates x - x of child1 and y - y of child1 but x of child2 is 60 (from top component), not 10 (from child1)…
… I’m wrong, but I don’t know where…

Sorry, that’s too tough to try to decipher, but you’ll just have made some silly mistake somewhere.

In juce_Component.cpp, in Component* Component::getComponentAt (const int x, const int y) if I write:
Component* const c = child->getComponentAt (x - (child->compX_ - compX_), y - (child->compY_ - compY_));
Instead of:
Component* const c = child->getComponentAt (x - child->compX_, y - child->compY_);
now it works, but I’d prefer to catch my mistake and not change your code. I know that your code is right, and mine has the bug. Thanks.

getComponentAt is relative to the component that you call it on. So you’re probably calling it on the wrong component?

I call getComponentAt from my top component and x,y are relative to it.

I think my problem is how I initialize my JUCE components:
My external java application (which controls all events) calls functions in my c++ dll (using JNI) when a mouse event occours or when Java want to repaint the area where I draw my juce components.

  • When Java call me to repaint I call paint for all components.
  • When Java call me because a mouse event occours, I use getComponentAt and decide what action execute based on which component is under mouse position.

Maybe this is a wrong way. What is the right way to incorporate a JUCE window in a Java GUI application? how to embed some JUCE components in a Java window?

Thanks in advanced
Luke

Seems like an almost impossibly difficult way of doing it. Can’t you somehow embed the HWND inside the java window and let the juce event handler do the work? Like a plugin does.

Or look at the ComponentPeer class - the MagnifierComponent uses a special peer internally to encapsulate a component while remapping its paint methods and mouse positions.