views:

1008

answers:

6

I noticed that in Windows, if you maximize a window you can not resize it until you un-maximized it again. This appears to be a normal behaviour, so I would like to remove my resize gripper when the window is maximised.

At the moment I can't find a property to detect if a window is maximized, and although I could add a boolean in my controller, it wouldn't necessarily catch requests to maximize from the OS.

So if you know of a reliable way to test if a window is maximized please let me know.

On a related note, I am using custom chrome, and when I maximize a window it overlaps the windows task bar. I can think of hacks to detect available screen size (using a transparent system chrome window), but it would be good to know of a better method.

Thanks

Rob

A: 

Can you use like this to hook the maximise() event?

Preet Sangha
Yes that should work, but not ideal. You can also build it into your controller for maximizing the window. Not sure the best way to solve the problem on windows only though...
robmcm
A: 

There is Win32 API Call that will do this for you:

BOOL IsZoomed( HWND hWnd );

I'm afraid you can't access this through the AIR runtime!
robmcm
Oh, yes. Sorry. Forgot to check the tags first.
A: 

to get the actual usable space from the screen, use the flash.display.Screen class, or you can use the systemMaxSize() which returns the largest window size allowed by the OS. For maximization you have some events that the window is dispaching when maximized/minimized/restored. You can find more info on the adobe pages (the link under systemMaxSize).

To detect if window is maximized...I don't think there is such a function (I might be wrong) but you can test if the app size is equal with the available screen size which means it's maximized. Or hook on the resize event which is triggered when the app is maximized/minimized/resized

TheBrain
I think using the systemMaxSize() function I can make my own maximise command that just resizes the window. However I will also need to add a little manager for when a user clicks the maximize button when the window size == systemMaxSize() then restore it to the size the window was when the maximize button was last clicked. Shouldn't be too much of a problem though :)
robmcm
A: 

I have figured out how this can best be done thanks to some pointers from TheBrain.

Firstly you need to watch for resize events to the window your want to control:

NativeApplication.nativeApplication.activeWindow.addEventListener(NativeWindowBoundsEvent.RESIZE, onWindowResize);

Then handle that event to decide if the window is maximised or not:

public function onWindowResize(event:NativeWindowBoundsEvent):void
{
    if (event.afterBounds.height >= Screen.mainScreen.visibleBounds.height && event.afterBounds.width >= Screen.mainScreen.visibleBounds.width)
        isMaximised = true;
    else
        isMaximised = false;
}

You then need to catch or create your own maximize button, and when clicked perform the following code:

            if (isMaximised)
            {
                var bounds:Rectangle = Screen.mainScreen.visibleBounds;
                NativeApplication.nativeApplication.activeWindow.bounds = bounds;
            }
            else
            {
                NativeApplication.nativeApplication.activeWindow.bounds = new Rectangle(100, 100, 500, 600);
            }

You can modify the bounds to over maximize (which is handy for custom chrome windows with shadows), and you can also set the application to reset to a default size if the maximize button is clicked when it's already maximized (or do nothing).

I had issues about when to assign the window resize listner, and ended up removing and adding it every time the maximize button was clicked. It's a bit of overkill, but not too bad.

robmcm
Have a look at Ril's answer for a slightly cleaner way to track the state!
robmcm
A: 

In your application (MXML) on the in the init method you ussually call on creationComplete:

<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
 creationComplete="init()" >

Add the following code:

this.addEventListener(NativeWindowDisplayStateEvent.DISPLAY_STATE_CHANGE, trackState);

the method looks like this:

public function trackState(event:NativeWindowDisplayStateEvent):void
    {
     if (event.afterDisplayState == NativeWindowDisplayState.MAXIMIZED)
     {
      isMaximised = true;
     } else {
      isMaximised = false;
     }
    }
Ril
Thanks! That's a cleaner way to track state.
robmcm
A: 

Here is an easier way of checking if a window is maximized:

if(stage.nativeWindow.displayState == NativeWindowDisplayState.MAXIMIZED)
{
    //do something
}
phil mccull