SFML community forums

Help => Window => Topic started by: Ant on April 03, 2015, 08:29:54 pm

Title: Get Window Position
Post by: Ant on April 03, 2015, 08:29:54 pm
Hello,

I feel like I'm overlooking something.  I need a way to get the window's position without the title bar.

The Window::getPosition function returns the upper left corner of the window's title bar, but I need the upper left corner of the rendered content within the window.
Title: Re: Get Window Position
Post by: Laurent on April 03, 2015, 09:52:48 pm
Why do you need to know that? When you need such information, you're usually doing something wrong.
Title: Re: Get Window Position
Post by: Ant on April 03, 2015, 10:39:34 pm
In certain states of this application, I plan to clamp the OS mouse pointer to specific regions.

For Windows, I use ClipCursor which accepts a rectangle, but this rectangle is relative to the upper left corner of the desktop instead of the application window.  I've tried offsetting the rectangle by the window's position, but the clamp region is still off by the size of the window's title bar.
Title: Re: Get Window Position
Post by: Laurent on April 03, 2015, 11:35:18 pm
If you use the native OS API, then it's easy to get what you want.

RECT area;
GetWindowRect(window.getSystemHandle(), &area);

Not tested, but even if it's not exactly right, it should guide you to a working solution (if this function gives the area of the window with decorations, then you may need GetClientRect + ClientToScreen instead).
Title: Re: Get Window Position
Post by: Ant on April 04, 2015, 12:11:55 am
Yeah I was just looking into these functions.  I haven't produced the results I was looking for yet, but this looks like the way to go.

I just wanted to double if I was overlooking something before I started implementing conversion functions for each operating system.

Thank you for your help, Laurent

Edit:  How do I mark this topic as solved?  Do I just change the title?
Title: Re: Get Window Position
Post by: Laurent on April 04, 2015, 10:05:09 am
No need to do anything when the problem is solved ;)