Regonize the minimize button in a form

  • Thread starter Thread starter Rinaldo
  • Start date Start date
R

Rinaldo

Hi,

How to regonize when the user clicks the minimize button in a form with
events?

Rinaldo
 
Rinaldo,

You will have to handle the WM_SYSCOMMAND windows message on the form,
looking for where wParam is equal to SC_MINIMIZE. You can do this by
overriding the WndProc method on the Form.
 
Hi Nicholas,

I know that it can be done in C++, but where in C#? Intellisense does'nt
show up those commands?

Rinaldo

Nicholas Paldino said:
Rinaldo,

You will have to handle the WM_SYSCOMMAND windows message on the form,
looking for where wParam is equal to SC_MINIMIZE. You can do this by
overriding the WndProc method on the Form.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rinaldo said:
Hi,

How to regonize when the user clicks the minimize button in a form with
events?

Rinaldo
 
Rinaldo,

You have to override the WndProc method on your form. The msg parameter
(of type Message) has fields which indicate the type of message it is, as
well as the lParam and wParam members.

You will have to look in the C++ header files (winuser.h most likely) or
a site like http://www.pinvoke.net to get the values for WM_SYSCOMMAND and
SC_MINIMIZE.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rinaldo said:
Hi Nicholas,

I know that it can be done in C++, but where in C#? Intellisense does'nt
show up those commands?

Rinaldo

Nicholas Paldino said:
Rinaldo,

You will have to handle the WM_SYSCOMMAND windows message on the form,
looking for where wParam is equal to SC_MINIMIZE. You can do this by
overriding the WndProc method on the Form.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Rinaldo said:
Hi,

How to regonize when the user clicks the minimize button in a form with
events?

Rinaldo
 
Nicholas Paldino said:
Rinaldo,

You will have to handle the WM_SYSCOMMAND windows message on the form,
looking for where wParam is equal to SC_MINIMIZE. You can do this by
overriding the WndProc method on the Form.


protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x112;
const int SC_MINIMIZE = 0xF020;

if (m.Msg == WM_SYSCOMMAND)
{
if (m.WParam == (IntPtr)SC_MINIMIZE)
{
MessageBox.Show("Minimize button was clicked");
}
}
base.WndProc(ref m);
}
 
Liz,

Thank you, just what I needed.

Rinaldo
Liz said:
protected override void WndProc(ref Message m)
{
const int WM_SYSCOMMAND = 0x112;
const int SC_MINIMIZE = 0xF020;

if (m.Msg == WM_SYSCOMMAND)
{
if (m.WParam == (IntPtr)SC_MINIMIZE)
{
MessageBox.Show("Minimize button was clicked");
}
}
base.WndProc(ref m);
}
 
Back
Top