Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Get Window Position  (Read 3247 times)

0 Members and 1 Guest are viewing this topic.

Ant

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Get Window Position
« 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Get Window Position
« Reply #1 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.
Laurent Gomila - SFML developer

Ant

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: Get Window Position
« Reply #2 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.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Get Window Position
« Reply #3 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).
« Last Edit: April 03, 2015, 11:38:04 pm by Laurent »
Laurent Gomila - SFML developer

Ant

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Re: Get Window Position
« Reply #4 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?
« Last Edit: April 04, 2015, 12:13:46 am by Ant »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Get Window Position
« Reply #5 on: April 04, 2015, 10:05:09 am »
No need to do anything when the problem is solved ;)
Laurent Gomila - SFML developer