Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 702
user2662326 Avatar asked Aug 17 '13 18:08

user2662326


People also ask

What is Lprect?

LPRECT is a derived type which says it is a pointer to RECT . Having a variable of this type, you declared a pointer to nothing, to invalid memory address (the pointer variable is left uninitialized). Your code would expectedly crash the app.

What is Getclientrect?

Retrieves the coordinates of a window's client area. The client coordinates specify the upper-left and lower-right corners of the client area. Because client coordinates are relative to the upper-left corner of a window's client area, the coordinates of the upper-left corner are (0,0).


2 Answers

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;
like image 77
datenwolf Avatar answered Oct 22 '22 15:10

datenwolf


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

like image 3
Michael M. Avatar answered Oct 22 '22 14:10

Michael M.