简体   繁体   中英

GetWindowPlacement x & y position

WINDOWPLACEMENT wp = { };
wp.length = sizeof( WINDOWPLACEMENT );
bool result = GetWindowPlacement( Sess.M_hdl , &wp );
Sess.xPos = wp.ptMinPosition.x;
Sess.yPos = wp.ptMinPosition.y;

How is it I deal with the POINT structure on this function, currently it's showing -1 for ptMinPosition.x / ptMinPosition.y and that's an error but result is 1 so the function succeeded.

-1 is an error for the function result, but is perfectly valid as an X or Y ordinate. Within the struct WINDOWPLACEMENT, the field ptMinPosition is the screen coordinates when the window is minimised. For most windows, the location when minimised is off the screen and so (-1,-1) seems quite reasonable.

I have reviewed my own answer. Perhaps you are trying to do the wrong thing with the wrong fields?

The field showCmd may tell you the current state of the window (the documentation is not clear about whether this is an in/out field according to which call you made). Most people only care about the position when the window is supposed to be visible (although you could still position it off the screen programmatically).

Perhaps you should be looking at either the rcNormalPosition field of the structure? You could try calling IsIconic() to find out if the window is minimised, or IsZoomed() to see if it is maximised. If it is neither of these and it is not hidden, you should be able to get the current position information from the RECT field that I mentioned above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM