windows 测试窗口是否最大化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1232442/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Testing to see if a window is maximized
提问by robmcm
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.
我注意到在 Windows 中,如果你最大化一个窗口,你不能调整它的大小,直到你再次取消最大化它。这似乎是一种正常行为,因此我想在窗口最大化时移除调整大小的抓手。
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.
在相关说明中,我使用的是自定义镶边,当我最大化窗口时,它会与 Windows 任务栏重叠。我可以想到检测可用屏幕尺寸的技巧(使用透明的系统镀铬窗口),但最好知道更好的方法。
Thanks
谢谢
Rob
抢
回答by Ril
In your application (MXML) on the in the init method you ussually call on creationComplete:
在您的应用程序 (MXML) 中的 init 方法中,您通常会调用 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;
}
}
回答by robmcm
I have figured out how this can best be done thanks to some pointers from TheBrain.
由于 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).
您可以将边界修改为过度最大化(这对于带有阴影的自定义 chrome 窗口很方便),并且您还可以将应用程序设置为在已经最大化(或什么都不做)时单击最大化按钮时重置为默认大小。
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.
我遇到了关于何时分配窗口调整大小侦听器的问题,最终每次单击最大化按钮时都会删除和添加它。这有点矫枉过正,但还不错。
回答by robmcm
There is Win32 API Call that will do this for you:
有 Win32 API Call 可以为您执行此操作:
BOOL IsZoomed( HWND hWnd );
BOOL IsZoomed( HWND hWnd );
回答by TheBrain
to get the actual usable space from the screen, use the flash.display.Screenclass, 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).
要从屏幕获取实际可用空间,请使用flash.display.Screen类,或者您可以使用systemMaxSize()返回操作系统允许的最大窗口大小。对于最大化,您有一些事件,当最大化/最小化/恢复时窗口正在调度。您可以在 adobe 页面(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
要检测窗口是否最大化...我认为没有这样的功能(我可能错了)但是您可以测试应用程序大小是否与可用屏幕大小相等,这意味着它已最大化。或者钩住应用最大化/最小化/调整大小时触发的调整大小事件
回答by Preet Sangha
回答by Phil McCullick
Here is an easier way of checking if a window is maximized:
这是检查窗口是否最大化的更简单方法:
if(stage.nativeWindow.displayState == NativeWindowDisplayState.MAXIMIZED)
{
//do something
}
回答by Reado
The following worked for me. No need to set event listeners, this code can be used to check the real-time state of the native window:
以下对我有用。无需设置事件监听器,这段代码可用于检查原生窗口的实时状态:
if (nativeWindow.displayState == 'maximized')
{
trace('Maximized');
}
else
{
trace('Minimized');
}