真正实现窗口最小化时自动最小化到托盘

来源:互联网 发布:mac系统占用多少空间 编辑:程序博客网 时间:2024/05/29 06:55

   #region 最小化到托盘
        const int WM_SYSCOMMAND = 0x0112;
        const int SC_MINIMIZE = 0xF020;//最小化
        const int SC_MAXIMIZE = 0xF030;//最大化
        const int SC_RESTORE = 0xF120;//还原时
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == WM_SYSCOMMAND)
            {
                int sc = m.WParam.ToInt32();
                if (sc == SC_MINIMIZE)
                {
                    this.Hide();
                }
            }
        }
        #endregion