0

I'm trying to get the x and y coordinates of a specific window relative to the screen (e.g. If the window's position on the screen is (100, 300) then I should retrieve an x-coordinate of 100 and a y-coordinate of 300). How can I achieve this so that I can assign the coordinates to some variables?

int x = /*Get x-coordinate*/;
int y = /*Get y-coordinate*/;
Ben
  • 1,299
  • 3
  • 17
  • 37

2 Answers2

2

On Vista and later with Aero glass enabled, you have to use DwmGetWindowAttribute(DWMWA_EXTENDED_FRAME_BOUNDS) to account for glass padding.

Otherwise, you can use GetWindowRect() instead, which does not account for glass padding.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
0
RECT rect;
GetWindowRect(window, &rect);
int x = rect.left;
int y = rect.top;
Tomashu
  • 515
  • 1
  • 11
  • 20
  • 1
    GetWindowRect() does not report correct values when Aero glass is enabled. See http://stackoverflow.com/questions/3192232/ – Remy Lebeau Oct 12 '14 at 16:23