Hi ,

Please can anyone help. I have a window(1280x768) that contains a resolution(1920x1080). I am trying to use ScreenToClient to obtain the mouse coordinates while in windowed format. I am drawing a line from a subject to the mouse cursor which works fine in fullscreen but not in windowed.

The ScreenToClient function doesn't quite work because (I speculate) of the resolution. Does anyone know of a way to correct this...?

Thank in advance

Make sure the coordinates you pass are SCREEN coordinates, not Window coordinates. In full screen mode the two are the same, but not in windowed mode.

Thanks Ancient Dragon. The coordinates I pass come from GetCursorPos(). How do I translate from Client to 1920x1080. Maybe times by the differance between windowed res and fullscreen? But how do you do that? Here's my attempt:

// Get mouse position in screen coordinates

// Translate to client coorndinates
ScreenToClient(m_hWindow, &m_MousePos); 

// Save and later pass to line function
Points[0] = D3DXVECTOR2(m_pAnyObject->GetScreenPos()->GetCenterX(),
Points[1] = D3DXVECTOR2(float(m_MousePos.x), 

To make it clearer my window is displaying a squashed (on purpose) fullscreen image.

Ok, you need to work out the ratio between the window and backbuffer and times it with the x and y like this:

RECT ClientRect;

ScreenToClient(m_hWindow, &m_MousePos); 

Points[0] = D3DXVECTOR2(m_pMyObjectHere->GetScreenPos()->GetCenterX(),
Points[1] = D3DXVECTOR2(m_MousePos.x * (float(FULLSCREEN_WIDTH) / ClientRect.right),
            m_MousePos.y * (float(FULLSCREEN_HEIGHT) / ClientRect.bottom));

This works whether the window is windowed, bordered, borderless or fullscreen. Make sure you use/convert your variables here to floats to preserve the exponent. Yippee...!!!