PC Review


Reply
Thread Tools Rate Thread

how to determine if a window is maximized?

 
 
jeremiah johnson
Guest
Posts: n/a
 
      16th Jul 2006
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.

--
jeremiah();
 
Reply With Quote
 
 
 
 
=?Utf-8?B?U3RhbmltaXIgU3RveWFub3Y=?=
Guest
Posts: n/a
 
      16th Jul 2006
"jeremiah johnson" wrote:
> I need to know the windowstate in order to move it properly.


Hello Jeremiah,

You can use the USER API GetWindowPlacement to obtain the current status of
a given window -- the showCmd field of the returned WINDOWPLACEMENT structure
should be equal to SW_MAXIMIZE (3) if the window is maximized.

You can find the P/Invoke signature and structure information at
http://www.pinvoke.net/default.aspx/...indowPlacement

--
Best regards,

Stanimir Stoyanov
(E-Mail Removed)
 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgUml0Y2hpZSBbTVZQXQ==?=
Guest
Posts: n/a
 
      16th Jul 2006
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.

--
http://www.peterRitchie.com/blog/
Microsoft MVP, Visual Developer - Visual C#


"jeremiah johnson" wrote:

> 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.
>
> --
> jeremiah();
>

 
Reply With Quote
 
jeremiah johnson
Guest
Posts: n/a
 
      16th Jul 2006
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.

Stanimir Stoyanov wrote:
> "jeremiah johnson" wrote:
>> I need to know the windowstate in order to move it properly.

>
> Hello Jeremiah,
>
> You can use the USER API GetWindowPlacement to obtain the current status of
> a given window -- the showCmd field of the returned WINDOWPLACEMENT structure
> should be equal to SW_MAXIMIZE (3) if the window is maximized.
>
> You can find the P/Invoke signature and structure information at
> http://www.pinvoke.net/default.aspx/...indowPlacement
>


--
jeremiah();
 
Reply With Quote
 
jeremiah johnson
Guest
Posts: n/a
 
      17th Jul 2006
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.

jeremiah johnson wrote:
> 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.
>
> Stanimir Stoyanov wrote:
>> "jeremiah johnson" wrote:
>>> I need to know the windowstate in order to move it properly.

>>
>> Hello Jeremiah,
>>
>> You can use the USER API GetWindowPlacement to obtain the current
>> status of a given window -- the showCmd field of the returned
>> WINDOWPLACEMENT structure should be equal to SW_MAXIMIZE (3) if the
>> window is maximized.
>>
>> You can find the P/Invoke signature and structure information at
>> http://www.pinvoke.net/default.aspx/...indowPlacement
>>

>


--
jeremiah();
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Open in New Window with maximized window =?Utf-8?B?QW50b25pbw==?= Windows XP Internet Explorer 1 14th Jul 2006 09:27 PM
OE 6 Messages open in small window,can't save maximized window set =?Utf-8?B?SGlsYXJ5?= Windows XP Internet Explorer 1 5th Apr 2006 02:30 AM
New window not maximized =?Utf-8?B?SmFjcXVlcw==?= Microsoft Frontpage 1 14th Feb 2006 10:23 PM
RE: non-maximized window =?Utf-8?B?Um9tdQ==?= Microsoft Dot NET Compact Framework 0 20th Jul 2004 08:29 AM
Re: non-maximized window Graham McKechnie Microsoft Dot NET Compact Framework 1 19th Jul 2004 11:39 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:53 PM.