Norbert
Norbert

Reputation: 312

GetWindowRect() fails, but IsWindow() is not

I am trying to get the size of an external window:

POINT point;

point.x = 100;
point.y = 100;

HWND hwnd = WindowFromPoint(point);

LPRECT pRect = {0};
bool ret1 = IsWindow(hwnd);
bool ret = GetWindowRect(hwnd, pRect);

The return value of IsWindow is true, but GetWindowRect fails with the following error:

1400: Invalid window handle

What can be wrong?

Upvotes: 0

Views: 3122

Answers (1)

Jonathan Potter
Jonathan Potter

Reputation: 37132

It's not the window handle that's invalid, but the null pointer you're passing as the second parameter to GetWindowRect().

LPRECT pRect = {0};

This simply defines a pointer to a RECT and initializes the pointer to 0. You need to provide an actual RECT structure, as in:

RECT rc = { 0 };
GetWindowRect(hwnd, &rc);

Upvotes: 9

Related Questions