how to determine if a window is maximized?

  • Thread starter Thread starter jeremiah johnson
  • Start date Start date
J

jeremiah johnson

Hi all.

I'm writing a small utility that can move a window from one of my
monitors to the other, when a system hotkey is pressed. I want to keep
the windowstate (maximized or normal) when the window is moved, but I
need to know the windowstate in order to move it properly.

I'm using some P/Invoke calls to get the window handles and the window
placement, which all works well, but I can't find a way to determine if
a window is maximized or minimized. I need to know that so I can know
which bits of the WINDOWPLACEMENT struct to read to get position data.

Thanks.
 
Deborah Kurata has an article in the latest CoDe magazine titled "Retaining
Multiple Sets of User Settings" While the topic isn't directly related to
your question, she uses a sample that stores window size and state (max/min)
upon application exit for each user of the system.

Essentially, she uses the Form.WindowState, Form.FormSize, and
Form.RestoreBounds properties to persist a form's state and size.
 
I had found this page before, but oddly I never thought to check
showCmd. Thank you.

One last thing (that I thought I'd figured out already, but haven't) is
how to determine which screen a window is on *when it is maximized*
using the Win32 API. It is easy to figure it out when it is not
maximized, the placement coordinates give that away, but when a window
is maximized, the Win32 API seems to tell me that the window origin is
-1, -1 no matter which screen the window in question is maximized on.

To clarify, I'm not worried about the form for the program I'm writing
now, its every other window on the user's desktop that I'm interested in
moving around, which is why I have to use user32.dll and P/Invoke to
move them around.

Thanks.
 
I figured it out.

To move a maximized window, you must first restore it to the normal
state (not maximized nor minimized,) move it to the window you want,
then maximize it again.

using a little WINDOWPLACEMENT manipulation I got it all working.

if anyone wants to see my code I'd be happy to share it.

Thanks.
 
Back
Top