The LPRECT
parameter is a pointer to a RECT
structure (the "LP" prefix actually stands for "long pointer", for historical reasons).
The GetWindowRect
function is going to retrieve the window rectangle for your CWnd
object, but it's going to do so by filling in a RECT
structure with those coordinates. Therefore, you need to create a RECT
structure and pass a pointer to it to the GetWindowRect
function.
It is worth mentioning that the API accepts a pointer to a RECT
structure for full compatibility with Win32. The CRect
MFC class actually inherits from the RECT
structure defined by the SDK, so you can use a CRect
object interchangeably here. Which is nice, because CRect
provides member functions that make it easier to manipulate rectangles.
Sample code:
CWnd* pwndParent = this->GetParent();
CRect rc;
pwndParent->GetWindowRect(&rc);
// rc now contains the rectangle of your window!
Note that the GetWindowRect
function will return the screen coordinates of your window. This is usually not what you want, unless you're trying to reposition the window on the screen. Screen coordinates are tricky to work with because they are relative to the entire virtual screen, which can have negative coordinates in a multi-monitor configuration. Also, if you try and determine the size of the window using its screen coordinates, you'll get the entire size of the window on the screen, including its non-client areas (like the title bar, the min/max/close buttons, etc.).
What you normally want instead are the client coordinates of a window, retrievable by calling the GetClientRect
function in an identical manner. This time, we'll use a RECT
structure, just because we can:
CWnd* pwndParent = this->GetParent();
RECT rcClient;
pwndParent->GetClientRect(&rcClient);
GetSize
method in theCWnd
class. And theGetWindowRect
method needs a parameter which is the pointer to the rectangle where the position and the size of your window will go. – Jabberwocky