当主窗体最小化到系统托盘时,WM_QUERYENDSESSION不会触发

时间:2014-10-23 17:39:26

标签: c# windows shutdown system-tray wndproc

我正在尝试在系统关闭时捕获WM_QUERYENDSESSION以清理我的应用程序中的某些数据,但看起来WM_QUERYENDSESSION仅在主窗体可见或最小化到任务栏时才会启动。当我的应用程序最小化到系统托盘时,根本不会发生WM_QUERYENDSESSION。

    private static int WM_QUERYENDSESSION = 0x11;
    protected override void WndProc(ref System.Windows.Forms.Message m)
    {
        if (m.Msg == WM_QUERYENDSESSION)
        {
            systemShutdown = true;
        }
        base.WndProc(ref m);

    }

    private void Form1_Shown(object sender, EventArgs e)
    {
        this.WindowState = FormWindowState.Minimized;
        this.ShowInTaskbar = false;
        //WM_QUERYENDSESSION only fires when ShowInTaskbar = true
    }

    private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
    {
        this.ShowInTaskbar = true;
        this.WindowState = FormWindowState.Normal;
    }

所以问题是: 当我的应用程序最小化到系统托盘时,甚至可以捕获WM_QUERYENDSESSION吗?

0 个答案:

没有答案