mouseDown coordinates for IBeamCursor


I’m new to JUCE, and I’m having a problem with unexpected behaviour for the I-Beam cursor.

When the cursor is an I-Beam, the x-coordinate passed to Component::mouseDown() is about two pixels left of where I’d expect it to be. To demonstrate this, I’ve put together a small test program that draws a vertical red line where the click was received (see attached screenshot of the program in action). I would have expected to red line to be perfectly aligned with the centre of the IBeam cursor.

Here’s a screenshot of how the application looks when it has received a click - note that the centre of the IBeam and the red line are not aligned:

Is this the correct behaviour, or am I missing something? (e.g. perhaps I’m grabbing the wrong coord, or maybe I should be offsetting the coordinates by some number of pixels for the window border, or maybe this is just how Windows returns IBeam coords? ).



Some version info:
JUCE version: 1.52, and also today’s lastest from git
OS: Windows 7 64 bit

Here’s a minimal application that demonstrates what I’m doing:

#include "JuceLibraryCode/juce_amalgamated.h"

class MainComponent  : public Component
			: m_lastClickPos()
		setSize(600, 300);

    void paint (Graphics& g)
		if (!m_lastClickPos.isOrigin())

	void mouseDown(const MouseEvent& e)
		m_lastClickPos = e.getPosition();

	juce::Point<int> m_lastClickPos;

class MainWindow  : public DocumentWindow
        : DocumentWindow (T("JUCE Test"),
        MainComponent* const contentComponent = new MainComponent();
        setContentOwned(contentComponent, true);
        centreWithSize(getWidth(), getHeight());

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

class JUCETestApplication : public JUCEApplication
        : mainWindow(NULL)

    void initialise(const String& commandLine) { mainWindow = new MainWindow(); }
    void shutdown()							{ mainWindow = NULL; }

    const String getApplicationName()		{ return "JUCE test"; }
    const String getApplicationVersion()	{ return "0.1"; }

    ScopedPointer<MainWindow> mainWindow;


Well, your demo app works perfectly for me (in Vista). There can’t really be any problem with the actual position - this must be just the fact that in your windows set-up, the hot-spot for that cursor shape has been positioned off-centre - no idea how or why that’d happen though!

Hi Jules,

That’s strange! This is a standard Win7 install, and I haven’t done anything like modify the cursors etc.

Perhaps someone else who’s reading this and runs Windows 7 can try the demo app? That would allow us to determine is it’s something specific to Windows 7 or there is something strange going on locally…

I’ll do some googling too…



I can also reproduce the x-offset with Win7/64-bit.


[quote=“ckk”]I can also reproduce the x-offset with Win7/64-bit.


Thanks for trying that Chris, it’s useful to know that this is affecting other Windows 7 users. (I’m also using the 64 bit version of Win7 - I’ll edit my original post to mention this).

Not sure if it’s relevant, but I’m using an NVidia video card with the latest drivers (v270.61). The problem also occurs with older drivers (v258.96).

The problem occurs both with and without the Aero theme enabled.



I’ve just knocked up a quick windows API test app (using no JUCE code at all) and the problem is still present. See the following image:


So we’ve proved that JUCE isn’t involved in the problem.

Good old windows!

Yeah I have noticed some cursor weirdness in Windows 7 64-bit.

But I will stick to Windows for these reasons:

  • Intel Core 2 i7 985
  • Visual Studio > XCode
  • Falcon DRX laptops
  • Games

Hi Everyone,

Although we’ve established that this problem is not caused by JUCE, I’m pretty sure that finding the answer to this is in the interests of most JUCE developers targetting Windows 7 (as most of us need a pixel-accurate I-Beam pointer).

Therefore, I thought it’s worth mentioning that I’ve posted details of the problem in a question on Stack Overflow. If you’re interested in finding the answer, it would be very helpful if you could give the question on Stack Overflow an up-vote please, as this should attract more interest from people who can help. The question is here:

(A quick summary of the extra information that I’ve discovered since last posting about this on the JUCE forum: I’ve dumped out the hotspot information and the pointer bitmap for the I-Beam. There is indeed a two pixel discrepency between the x-coord of the hotspot and the pointer image in the bitmap. The big question is how could this discrepency occur on a default install of Windows 7 64-bit?).



Why don’t we just create a correct i-beam cursor and include it in Juce using BinaryBuilder? Juce can have two cursors, one for the standard system provided and the other for the corrected version.

That would be a good workaround, but I think we’d first need to establish:

a) Is this problem definitely just a case of an incorrect I-Beam hotspot for the default system cursor set? (as opposed to programmer error)
b) If so, which versions of windows does this affect?

It feels slightly wrong to add things to JUCE if we don’t yet 100% understand the extent of problem we want to solve.