如何通知我的应用程序时显示桌面/最小化所有/所有窗口最小化? [英] how to notify my application when show desktop/minimize all/ all windows minimized?

查看:206
本文介绍了如何通知我的应用程序时显示桌面/最小化所有/所有窗口最小化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通知我的应用程序时显示桌面/最小化所有/使用C#

how to notify my application when show desktop/minimize all/ all windows minimized using c#

推荐答案

下面可能让你启动。这仅仅是一个标准的形式就可以了(命名listMessages)的列表框。当我执行桌面最小化/ SHOWALL,形式捕获WM_SIZE消息和消息M值输出到列表框。您的形式可能不响应典型的最小化和最大化的事件,但它应该会从Windows消息泵这些消息。至于检测是否已显示出任何另一个窗口,这是一个有点更复杂,但可以做的还有....

The following might get you started. This is just a standard form with a ListBox on it (named listMessages). When I perform a desktop minimize/showall, the form catches the WM_SIZE messages and outputs the Message m values to the ListBox. Your form may not respond to typical minimize and maximize events but it should receive these messages from the windows message pump. As far as detecting if any another window has been shown that's a bit more involved but can be done as well....

using System;
using System.Windows.Forms;

namespace MinimizeAll
{
    public partial class Form1 : Form
    {
        private const int WmSize = 5;
        private const int SizeRestored = 0;
        private const int SizeMinimized = 1;
        private const int SizeMaximized = 2;
        private const int SizeShow = 3;
        private const int SizeHide = 4;

        public Form1()
        {
            InitializeComponent();
        }

        protected override void WndProc(ref Message m)
        {
            try
            {
                if (m.Msg == WmSize)
                {
                    var wparam = m.WParam.ToInt32();

                    switch (wparam)
                    {
                        case SizeRestored:
                        case SizeMinimized:
                        case SizeMaximized:
                        case SizeShow:
                        case SizeHide:
                            var output = string.Format("{0}{1:X} {2:X} {3:X} {4:X} {5:X}", prefix, m.Msg, m.WParam.ToInt32(), m.LParam.ToInt32(), m.HWnd.ToInt32(), m.Result.ToInt32());
                            listMessages.Items.Add(output);
                            break;
                        default:
                            // this is just a demo (code police)...
                            base.WndProc(ref m);
                            return;
                    }
                }
                else
                {
                    base.WndProc(ref m);
                }
            }
            catch (Exception)
            {
                listMessages.Items.Add("err");
                base.WndProc(ref m);
            }
        }
    }
}

这篇关于如何通知我的应用程序时显示桌面/最小化所有/所有窗口最小化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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