469,904 Members | 2,191 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,904 developers. It's quick & easy.

detecting when a form is minimizing

Lee
Hi,

How do I detect when a form is minimizing? specifically when a user clicks
the show desktop button on the taskbar, rather than the minimize button on a
form.

thanks in advance

Apr 21 '06 #1
7 9081
Lee
Sorry I forgot to add, I am using a borderless form.
"Lee" <le*****@hotmail.com> wrote in message
news:Ov*************@TK2MSFTNGP03.phx.gbl...
Hi,

How do I detect when a form is minimizing? specifically when a user
clicks
the show desktop button on the taskbar, rather than the minimize button on
a
form.

thanks in advance

Apr 21 '06 #2
On 21/04/2006 Lee wrote:
Hi,

How do I detect when a form is minimizing? specifically when a user
clicks the show desktop button on the taskbar, rather than the
minimize button on a form.

thanks in advance


I spent yesterday puzzling this out and ended up over-riding the
WndProc as follows:

protected override void WndProc(ref Message message)
{
base.WndProc(ref message);

switch (message.Msg)
{
case WM_SYSCOMMAND:
if ((int)message.WParam == SC_MINIMIZE)
{
this.ShowInTaskbar = false;
notifyIcon1.Visible = true;
this.Visible = false;
m_blnInTray = true;
}
break;
}
}

The constants are:
const int SC_RESTORE = 0xF120;
const int WM_SYSCOMMAND = 0x0112;
const int SC_MINIMIZE = 0xF020;

To restore the Window I use:
SendMessage(this.Handle, WM_SYSCOMMAND, SC_RESTORE, IntPtr.Zero);

I couldn't find a .NET way, but if there is one I would appreciate
knowing about it:-)

--
Jeff Gaines - Damerham Hampshire UK
Using XanaNews 1.18.1.3
Apr 21 '06 #3
Jeff & Lee,
I couldn't find a .NET way, but if there is one I would appreciate
knowing about it:-)


Just override the OnResize or OnSizeChanged methods (or handle the
corresponding events). The WindowState will tell you whether the form
is minimized or not.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 21 '06 #4
Lee
I cannot seem to detect the minimizing event (even by overriding WndProc as
you have), is the minimize event triggered by clicking on the minimize
button on a form somehow different to the show desktop event?

I have noticed however that a form that is set as Topmost does actually stay
displayed when the show desktop button is pressed! Could this be
manipulated somehow?

thanks
"Jeff Gaines" <jg************@yahoo.co.uk> wrote in message
news:xn***************@news.individual.net...
On 21/04/2006 Lee wrote:
Hi,

How do I detect when a form is minimizing? specifically when a user
clicks the show desktop button on the taskbar, rather than the
minimize button on a form.

thanks in advance


I spent yesterday puzzling this out and ended up over-riding the
WndProc as follows:

protected override void WndProc(ref Message message)
{
base.WndProc(ref message);

switch (message.Msg)
{
case WM_SYSCOMMAND:
if ((int)message.WParam == SC_MINIMIZE)
{
this.ShowInTaskbar = false;
notifyIcon1.Visible = true;
this.Visible = false;
m_blnInTray = true;
}
break;
}
}

The constants are:
const int SC_RESTORE = 0xF120;
const int WM_SYSCOMMAND = 0x0112;
const int SC_MINIMIZE = 0xF020;

To restore the Window I use:
SendMessage(this.Handle, WM_SYSCOMMAND, SC_RESTORE, IntPtr.Zero);

I couldn't find a .NET way, but if there is one I would appreciate
knowing about it:-)

--
Jeff Gaines - Damerham Hampshire UK
Using XanaNews 1.18.1.3

Apr 21 '06 #5
Lee
I have tried this;-

protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if (this.WindowState.Equals(FormWindowState.Minimized ))
{
MessageBox.Show("minimized");
}
}
however it still does not fire, just the same with overriding WndPrc, and
OnSizeChanged. Am i missing something obvious?

thanks


"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:e9**************@TK2MSFTNGP05.phx.gbl...
Jeff & Lee,
I couldn't find a .NET way, but if there is one I would appreciate
knowing about it:-)


Just override the OnResize or OnSizeChanged methods (or handle the
corresponding events). The WindowState will tell you whether the form
is minimized or not.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Apr 22 '06 #6
On 21/04/2006 Mattias Sjögren wrote:
Jeff & Lee,
I couldn't find a .NET way, but if there is one I would appreciate
knowing about it:-)


Just override the OnResize or OnSizeChanged methods (or handle the
corresponding events). The WindowState will tell you whether the form
is minimized or not.
Mattias


Thanks Mattias, don't know why I couldn't get that working a couple of
days ago but it works fine now :-)

--
Jeff Gaines - Damerham Hampshire UK
Using XanaNews 1.18.1.3
Apr 22 '06 #7
On 21/04/2006 Lee wrote:
I cannot seem to detect the minimizing event (even by overriding
WndProc as you have), is the minimize event triggered by clicking on
the minimize button on a form somehow different to the show desktop
event?

I have noticed however that a form that is set as Topmost does
actually stay displayed when the show desktop button is pressed!
Could this be manipulated somehow?


Hi Lee

I have now got my form to minimise using the Resize event as Mattias
suggested,and I restore it when its NotifyIcon is Left Clicked.

You're right though about the Show Desktop thing, if I click that my
form disappears but it stays in the TaskBar and its NotifyIcon doesn't
appear so I wonder if it is made hidden rather than minimised? I'm
afraid you need somebody more techy than me to give a definitive answer.

--
Jeff Gaines - Damerham Hampshire UK
Using XanaNews 1.18.1.3
Apr 22 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

19 posts views Thread by Gav | last post: by
5 posts views Thread by needin4mation | last post: by
1 post views Thread by Dean Slindee | last post: by
5 posts views Thread by Dag Sunde | last post: by
1 post views Thread by wwwords | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.