Thread and ResizableWindow

Hi all…
I’m almost new with threads, but i excepted this to work!

here you can see a simple example of what i want to do:

void DesktopEventsThread::run()
	while (! threadShouldExit())
			int x, y;
			desktop->getMousePosition(x, y);

				if(startTime == -1)
					startTime = Time::getMillisecondCounter();

				if(Time::getMillisecondCounter() - startTime > 1000)
					 MessageManagerLock mml (Thread::getCurrentThread());

					if (! mml.lockWasGained())
						return; // another thread is trying to kill us!

					opening = true;

					ResizableWindow * rw = (ResizableWindow*)TopLevelWindow::getActiveTopLevelWindow();
					rw->setContentComponentSize(400,400); //DEADLOCKKKKKKKKKKKKKK

				startTime = -1;
				opening = false;

Basically, i’m playing with a thread and i want it to just resize the window!
But with the code rw->setContentComponentSize(400,400); I fall in what i suppose is a deadlock!

What am i missing??


I solved, in some way!!!
I was very new to threads and i did very bad!

now i’m a beginner… and i’m learning!

Sorry for boring you… and thanks anyway!


yeah, you really shouldn’t use a thread for that kind of thing - a Timer or just a mouse event handler is the way to go…

Yes Jules, i was to excited to start doing what i wanted to do!

But, now, other 2 little questions:

  1. What’s the most efficient way to continuosly check to mouse position relative to the Desktop (and so also outside the JUCE app)??? I think I can use a timer, as you wrote, but: will it be efficient?

  2. Is it me or is right that when the main juce window (under Windows Vista) is transparent and the component inside this window is transparent too, the app will not receive any mouse events (sure, on the of components where it’s transparent)?

thanks… and forgive me (once again) for my english

Have a look at the global mouse listener stuff in the Desktop class.

And no, the window should still respond to mouse events, at least on pixels which aren’t completely transparent.

Uhm… but with the global mouse listener i can get responses on whatever happens on Juce WINDOW, not on the screen (outside juce window bounds)…
I’m not building a spyware… what i would like to do is that when the mouse is in several position on screen, my app has to response in some way!
So I don’t think that global mouse listener is the right way to do this…

Any suggestion?


But that’s exactly what the global mouse listener does (apart from detecting clicks on other windows)

i really believe you… i completely trust in you… but i can’t get it working!

Check this out:

class JUCEHelloWorldApplication : public JUCEApplication, public MouseListener
    HelloWorldWindow* helloWorldWindow;

        : helloWorldWindow (0)


    void initialise (const String& commandLine)
        helloWorldWindow = new HelloWorldWindow();

    void shutdown()
        if (helloWorldWindow != 0)
            delete helloWorldWindow;

        //remove mouse listener

    void mouseMove(const MouseEvent &e)
	DBG("I can move wherever I want... I'm Mouse... SuperMouse");

The situation is (and I really hope that you will say that it’s impossible and that I wrote something stupid, elsewhere I’m stupid!!!):

MOUSE OVER JUCE WINDOW -> the mouseMove function is called and in the output window (msvc++) i can read the repeated string…

MOUSE NOT OVER JUCE WINDOW - aka MOUSE OVER DESKTOP or OTHER APPS -> the mouse function is not called anymore… so, in the output window (msvc++) i can read nothing…

I think it’s clear now… at least i hope…

thanks jules

And like the documentation says:

void addGlobalMouseListener (MouseListener *const listener) throw ()

Registers a MouseListener that will receive all mouse events that occur on any component.

Oh, sorry - I looked at it again, and you’re quite right, it does only work over components. That’s because it sends a mouse-event object which needs to specify a target component, so if there’s no component, the event can’t be generated.

Best thing to do is just what the Desktop class does internally - run a timer that checks the mouse-pos to see when it changes. That’s very easy to do, just a few lines of code.