user2662326
user2662326

Reputation: 159

How to use GetWindowRect

Consider the following code:

LPRECT lpRect;
GetWindowRect(hwnd, lpRect);

I don't know how to get information from lpRect; please advise.

Upvotes: 11

Views: 31830

Answers (3)

Mil277
Mil277

Reputation: 1

Or you can just type this inside your CWnd dialog:

CRect rect;
this->GetWindowRect( &rect );

Upvotes: -1

datenwolf
datenwolf

Reputation: 162164

What you wrote is wrong. The Windows API uses a hideous variable and type naming convention. LPRECT means "Long Pointer to Rect", which on your usual architecture is just a RECT*. What you wrote is some uninitialized pointer variable, pointing at some arbitrary location (if you're unlucky something that when modified will crash your program).

This is what you actually require:

RECT rect;
GetWindowRect(hwnd, &rect);

RECT itself is a structure

typedef struct _RECT {
  LONG left;
  LONG top;
  LONG right;
  LONG bottom;
} RECT;

Upvotes: 30

Michael M.
Michael M.

Reputation: 2584

You can get the coordinates of the window :

lpRect->left
lpRect->right
lpRect->top
lpRect->bottom

More information here : http://msdn.microsoft.com/en-us/library/windows/desktop/dd162897(v=vs.85).aspx

Upvotes: 2

Related Questions