I'm working on a program that needs to check the bounding rectangle of external application windows. I've found multiple API methods that do just that, GetWindowRect() , GetWindowPlacem ent(), and GetWindowInfo() to name a few. For the most part they works very well. I pass a MainWindowHandl e to the method and they returns some information about the window. I'm gonna explain what each of the methods return, so if you want to skip it, scroll til you see MY QUESTION in bold.
GetWindowRect() returns a RECT object, not to be confused with a Rectangle. RECT contains the top, left, right, and bottom coordinates instead of top, left, width, and height. (I know that Rectangle does contain right and bottom, but it returns width and height instead)
GetWindowPlacem ent() returns a WINDOWPLACEMENT object, which contains a bit more information including flags to determine if the window is maximized, minimized, or normal and what state to restore it to. It also contains a RECT that tells what the window's normal position is, that is, the size and location of the window when it is returned to it's normal (not maximized or minimized) state.
Finally, GetWindowInfo() returns a WINDOWINFO object. This contains the most information yet. It still has a RECT object containing the size and location of the window, but it also has another RECT with the size and location of the client area of the window. There's also two values that hold the size of the window's borders.
MY QUESTION
Ok, sorry for that, I wanted to make sure you were familiar with what I'm working with.
Here's my issue, when a window is maximized it's borders are not visible, but all of the methods that return a window rectangle still appear to take those into account. I have two monitors each with a resolution of 1920x1200, for a total of 3840x1200, set up in dual screen. When I maximize a window in the left monitor and get it's RECT I get this (assuming no task bar):
{Left=-8,Top=-8,Right=1928,Bo ttom=1208}
I should get:
{Left=0,Top=0,R ight=1920,Botto m=1200}
Now it's simple enough to detect if the values of Left and Top are negative and invert and subtract them from the right and bottom. But what if I have a window maximized in the right monitor? In that case I get this RECT (again assuming no task bar):
{Left=1912,Top=-8,Right=3848,Bo ttom=1208}
I should get:
{Left=1920,Top= 0,Right=3840,Bo ttom=1200}
In this case the "-8" pixels are actually part of the left monitor, so they don't read as negative, though they are outside of that screen's bounds.
I'm at a complete loss as to how I could detect and fix this problem, so I'm hoping that some of the smart helpful people here could...well, help me out.
Thank you in advance, and I apologize for the length of the post, I just thought thorough explanation would help me get the answer I need.
GetWindowRect() returns a RECT object, not to be confused with a Rectangle. RECT contains the top, left, right, and bottom coordinates instead of top, left, width, and height. (I know that Rectangle does contain right and bottom, but it returns width and height instead)
GetWindowPlacem ent() returns a WINDOWPLACEMENT object, which contains a bit more information including flags to determine if the window is maximized, minimized, or normal and what state to restore it to. It also contains a RECT that tells what the window's normal position is, that is, the size and location of the window when it is returned to it's normal (not maximized or minimized) state.
Finally, GetWindowInfo() returns a WINDOWINFO object. This contains the most information yet. It still has a RECT object containing the size and location of the window, but it also has another RECT with the size and location of the client area of the window. There's also two values that hold the size of the window's borders.
MY QUESTION
Ok, sorry for that, I wanted to make sure you were familiar with what I'm working with.
Here's my issue, when a window is maximized it's borders are not visible, but all of the methods that return a window rectangle still appear to take those into account. I have two monitors each with a resolution of 1920x1200, for a total of 3840x1200, set up in dual screen. When I maximize a window in the left monitor and get it's RECT I get this (assuming no task bar):
{Left=-8,Top=-8,Right=1928,Bo ttom=1208}
I should get:
{Left=0,Top=0,R ight=1920,Botto m=1200}
Now it's simple enough to detect if the values of Left and Top are negative and invert and subtract them from the right and bottom. But what if I have a window maximized in the right monitor? In that case I get this RECT (again assuming no task bar):
{Left=1912,Top=-8,Right=3848,Bo ttom=1208}
I should get:
{Left=1920,Top= 0,Right=3840,Bo ttom=1200}
In this case the "-8" pixels are actually part of the left monitor, so they don't read as negative, though they are outside of that screen's bounds.
I'm at a complete loss as to how I could detect and fix this problem, so I'm hoping that some of the smart helpful people here could...well, help me out.
Thank you in advance, and I apologize for the length of the post, I just thought thorough explanation would help me get the answer I need.
Comment