how to notify my application when show desktop/minimize all/ all windows minimized using c#
-
Hi, You might wish to clarify : are you saying right now that : because of your use of some WinAPI calls, that clicking the icon in the "Quick Launch" of the taskbar ... that normally automatically hides all windows ... is leaving your application still visible ? Important to distinguish between whether you are talking about "hiding" your application (making it not visible), whether your application is (behaves as) a "topmost window," or not, and whether your application is, under any circumstances ever minimized. – BillW Jan 02 '10 at 13:40
-
@BillW yes my application is visible even after show desktop button is clicked but my application is not topmost window, i dont want to hide my application. i just want to hide/show one form in my application. (the form is a smaller in size which is a top most window) – Suriyan Suresh Jan 02 '10 at 13:46
-
Hi, I'm not going to be able to help you with this, but there are some real api gurus on SO ! I wonder if what you are really asking might be this : "How can I get my application notified ... at run-time ... when the user clicks the 'Show Desktop' icon (it's a short-cut, under-the-hood, actually) that normally hides all application windows ?" After all, if you can get a notification, you can then configure your application's forms/windows as you like. Hope this is a helpful comment; this comment may address only one part of what you are asking, I think. – BillW Jan 02 '10 at 14:30
-
5i hope you don't get an answer to this. Programs trying to override what the user wants is exactly why Microsoft stopped provided API access to various things. There's no notification when the user closes a notification area balloon, in case developers try to show it again. Programs cannot add items to the start menu's most commonly used programs list, becaue prople think their application is important. You can't lock icons on the desktop, because software would. You cannot give yourself focus, because programs would. And hopefully there is no way to prevent your app from being hidden. – Ian Boyd Jan 08 '10 at 21:51
-
duplicate: http://stackoverflow.com/questions/2006027/detect-all-windows-minimized-from-c-application – serhio Jan 10 '10 at 16:31
5 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);
}
}
}
}

- 924
- 13
- 22
-
1http://www.pinvoke.net/index.aspx is an invaluable resource when it comes to doing this type of work and may further you along as well. – Dave Jellison Jan 03 '10 at 12:45
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.

- 831
- 1
- 8
- 13
Add Reference of Microsoft Shell Controls And Automation
In COM
Use Namespace Shell32
Code:
Shell32.Shell s32 = new Shell32.Shell();
Call s32 object in your desired state..

- 2,752
- 8
- 42
- 63

- 36
- 3
So... in order to minimize all the windows you can use the following:
Add to your project the "Microsoft Shell Controls And Automation" COM reference(References=>Add=>COM).
then do the folowing:
Shell32.ShellClass shell = new Shell32.ShellClass();
shell.MinimizeAll(); // can also do: shell.UndoMinimizeAll();
or with the late binding:
Object shell;
shell = CreateObject("Shell.Application");
shell.MinimizeAll();
Now I am not sure if you can use some events of this COM (like AllMinimized)...
In order to prevent a WinForm application from minimizing(via Minimize button):
void Form1_Resize(object sender, System.EventArgs e) // Handles Form1.Resize
{
if (this.WindowState == FormWindowState.Minimized)
this.WindowState = FormWindowState.Normal;
}
You can also take a look here: http://pinvoke.net/default.aspx/user32.EnumDesktopWindows

- 28,010
- 62
- 221
- 374
In order for you application to know when it is minimized (the most probable event for how desktop/minimize all/ all windows minimized, You need to check on the
this.WindowState
property of your application's current form. if it is minimized then it should be equal to
FormWindowState.Minimized
Edited: try this out:
foreach (Process proc in Process.GetProcesses())
{
/// check proc.StartInfo.ProcessWindowStyle here
/// it Gets window state to use when the process is started.
}
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo_properties.aspx

- 701
- 1
- 11
- 21
-
-
edited the whole answer, to show the codes better try this out:
foreach (Process proc in Process.GetProcesses())
{
/// check proc.StartInfo.ProcessWindowStyle here
/// it Gets window state to use when the process is started.
}
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo_properties.aspx – AceMark Jan 12 '10 at 06:59 -
I have edited my previous answer to format and show the codes you need better. – AceMark Jan 12 '10 at 08:23