Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
2.33/5 (3 votes)
See more:
Hi there, I am having the big problem with getting the area of hwind with
routine GetWindowRect. Even Spy++ or his implementation returns rectangle, that is smaller than real
area. Its a some special kind of application, I am looking for some alternative to GetWindowRect,
or how can I get all the window area programmatically correct.

What I have tried:

I have tried Spy++, and debug GetWindowRect but it doesn't move me forward.
I need some way figure out how the window sends wrong rectangle, how I can get the right one.
Posted
Updated 30-Mar-20 3:21am
Comments
Richard MacCutchan 30-Mar-20 3:47am    
Please do not repost the same question. You already asked this in the Managed C++ forum.

struct RECT that is returned from GetWindowRect() can also be further manipulated by calling:
GetClientRect()
ScreenToClient()
ClientToScreen()

Yours sound like one of those cases

It would have been helpful if you posted the dimensions of your RECT. If top and left both == 0 then it is Client coordinates and if they are above zero then it is a Screen Coordinates.

You also need to pay attention to your Coordinate Space and Transformation functions:


[^]
 
Share this answer
 
v2
Comments
lacir 30-Mar-20 9:43am    
real dimensions are 600x465
GetClientRect() returns in debugger {LT(0, 0) RB(480, 372) [480 x 372]}
ClientToScreen(hwnd, reinterpret_cast<point*>(&wr.left)); {{LT(72, 0) RB(480, 372) [408 x 372]}}
ClientToScreen(hwnd, reinterpret_cast<point*>(&wr.right)); {LT(72, 0) RB(552, 372) [480 x 372]}
but the area is still smaller 480 x 372 with no regards to ClientToScreen() its given by GetClientRect
Richard MacCutchan 30-Mar-20 9:56am    
In your original question you use GetWindowRect, in this one you are using GetClientRect. You need to learn the difference between these two functions.
lacir 30-Mar-20 10:00am    
Both returns same 480x372 size, just
GetWindowRect returns without positional shift, coordinates LT differs from 0 {LT(95, 310) RB(575, 682) [480 x 372]}
Richard MacCutchan 30-Mar-20 10:08am    
Whatever you are doing there is something wrong with your code. If either of these methods returned the wrong values then more than 90% of all Windows applications would stop working.
Richard MacCutchan 30-Mar-20 10:10am    
I have a strong suspicion that you are getting the wrong Window handle.
I guess that you have some flaw in your code or logic. Read the GetWindowRect documentation and try the sample code. Maybe your problem is about understanding some non client area.

Be sure that you call with correct parameter, especially the window handle.
 
Share this answer
 
Comments
KarstenK 30-Mar-20 5:16am    
Paint your window with some color to see the difference. Than check out the different area. Find your bug ;-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900