tags:

views:

502

answers:

2

I'm trying to determine the window position of an application. I know SetWindowPos() would set the window position at a certain position with a specific sizing. I would like to retrieve this information, but I have noticed some negative values in there. When I save these values into the registry and then load them on the next instance, I can't replicate the sizing and placement information accurately. Is this even the most accurate function to be used in the first place?

Thanks.

+2  A: 

Yes, GetWindowRect is the function you want. Negative values should only be possible on multiple monitor systems, when the window is above or to the left of the primary monitor.

SetWindowPos will set the position relative to the window's parent window, so you'll have to adjust the coordinates before you call it.

Mark Ransom
+2  A: 

You should be calling the GetWindowPlacement method to get the WINDOWPLACEMENT structure which has not only the window position, but the state of the window (minimized, maximized, etc, etc).

In turn, you should store this information in the registry in addition to the position values and set the state of the window when reading the values back from the registry.

casperOne
When I set the WINDOWPLACEMENT structure for the first time, I won't know how to set the length element of this structure. In this case, what should be done to this element (similar to other elements)?
stanigator
Why wouldn't you know this? It is the length of the structure in bytes, which you can get by using sizeof(wp) where wp is the WINDOWPLACEMENT structure variable.
casperOne