Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to notify my application when show desktop/minimize all/ all windows minimized?

Tags:

c#

desktop

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

like image 330
Suriyan Suresh Avatar asked Jan 02 '10 13:01

Suriyan Suresh


People also ask

How do I minimize all open windows and show desktop?

If your keyboard has a Windows key (and most current keyboards do), you can press the Windows key and the M key simultaneously to minimize all the currently open windows on your desktop.

How do I get all my minimized windows back?

Most Windows users know that, if you wish to suddenly minimize all your open windows, you can simply click on Win+M keys. Once you do that, all your open windows will get minimized to the taskbar. To restore the windows back, you will have to press Win+Shift+M.

Does the Show desktop button maximize all open apps?

Minimize all windows with one click or tap. The Show desktop button minimizes all the apps on your screen with one click or tap. You can find it in the lower-right corner of your screen.

Where does the application go when it is minimized?

Where do minimized programs go? In Windows, when a program is minimized, it may seem as though it has disappeared. Fortunately, that is not the case. Minimized programs may be located and accessed from the Windows taskbar, which is located at the bottom of any Windows desktop.


2 Answers

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);
            }
        }
    }
}
like image 66
Dave Jellison Avatar answered Sep 28 '22 04:09

Dave Jellison


I completely agree with Ian Boyd's comment. In no way should you try to circumvent defined system behavior. However, to abide by defined system behavior and still (maybe) get what you are looking for, you might want to look into using appbars for your main window which you do not want to have hidden. An appbar, is like the taskbar, it stays visible all of the time except when a fullscreen application is running.

like image 44
chris Avatar answered Sep 28 '22 04:09

chris