Regonize the minimize button in a form

R

Rinaldo

Hi,

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

Rinaldo
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
R

Rinaldo

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
 
N

Nicholas Paldino [.NET/C# MVP]

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
 
L

Liz

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);
}
 
R

Rinaldo

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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top