确认当前最小化的窗口是最大化还是正常状态下最小化时 [英] Check if currently minimized window was in maximized or normal state at the time of minimization

查看:223
本文介绍了确认当前最小化的窗口是最大化还是正常状态下最小化时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能分辨出目前最小化的窗口是否在这之前最大化,在C#/的WinForms不是正常状态?

How can I distinguish whether a currently minimized window was maximized before that, as opposed to normal state in C#/WinForms?

if (WindowState == FormWindowState.Minimized)
{
    Properties.Settings.Default.Location = RestoreBounds.Location;
    Properties.Settings.Default.Size = RestoreBounds.Size;
    Properties.Settings.Default.IsMaximized = ...; // How do I know if the window would be restored to maximized?
}



我想让我的窗口执着的位置和状态,使用应用程序的设置而我下面的 http://stackoverflow.com/a/1876326/492336 但如果窗口的最小化我不想结束的时候它开始下应用程序启动最小化(这是什么答案目前有一样)。

I want to make the position and state of my window persistent using the application settings and I'm following http://stackoverflow.com/a/1876326/492336 but if the window was minimized at the time of closing I don't want it to start minimized on the next application start (which is what the answer there currently does).

我要的是为窗口如果它在它最小化的时候被最大化启动最大化,并在其正常状态下启动,如果它已经在其最小化时的正常状态。

What I want is for the window to start maximized if it had been maximized at the time it was minimized, and to start in its normal state if it had been in normal state at the time it was minimized.

推荐答案

的WinForms不公开任何 WindowStateChanged 事件,那么你必须自己跟踪。 Windows会发送一个 WM_SYSCOMMAND 当表单状态变化:

WinForms does not expose any WindowStateChanged event then you have to track it by yourself. Windows will send a WM_SYSCOMMAND when form state changes:

partial class MyForm : Form
{
    public MyForm()
    {
        InitializeComponent();

        _isMaximized = WindowState == FormWindowState.Maximized;
    }

    protected override void WndProc(ref Message m)
    {
        if (m.Msg == WM_SYSCOMMAND)
        {
            int wparam = m.WParam.ToInt32() & 0xfff0;

            if (wparam == SC_MAXIMIZE)
                _isMaximized = true;
            else if (wparam == SC_RESTORE)
                _isMaximized = false;
        }

        base.WndProc(ref m);
    }

    private const int WM_SYSCOMMAND = 0x0112;
    private const int SC_MAXIMIZE = 0xf030;
    private const int SC_RESTORE = 0xf120;
    private bool _isMaximized;
}

这篇关于确认当前最小化的窗口是最大化还是正常状态下最小化时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆