Jonathan,
In order to do this, you will need to subclass your form an check for
the
WM_SYSCOMMAND message with the SC_MINIMIZE command. To
do this you derive a new class from NativeWindow (which you can locate
in System.Window.Forms)
public delegate void MsgWindowMessageDelegate(ref Message m, ref bool
handled);
public class MsgWindow : NativeWindow, IDisposable
{
public event MsgWindowMessageDelegate OnMessage;
public MsgWindow(IntPtr handle)
{
this.AssignHandle(handle);
}
protected override void WndProc(ref Message m)
{
bool handled = false;
if( this.OnMessage != null )
this.OnMessage(ref m, ref handled);
if( !handled )
base.WndProc (ref m);
}
#region IDisposable Members
public void Dispose()
{
if( this.Handle != IntPtr.Zero )
this.DestroyHandle();
}
#endregion
}
Now all you need to do is add a private variable in your form of the
MsgWindow type
(i called mine msgWindow) and add the following to your form constructor
this.msgWindow = new MsgWindow(this.Handle);
this.msgWindow.OnMessage +=
new MsgWindowMessageDelegate(msgWindow_OnMessage);
You will also have to create the msgWindow_OnMessage callback method and
catch the message, like so
private void msgWindow_OnMessage(ref Message m, ref bool handled)
{
if(m.Msg == 0x0112 && (int)m.WParam == 0xF020)
{
handled = true;
MessageBox.Show("Minimized clicked");
}
}
The "handled = true" will tell our subclasser that we have handled the
current
message and that we do not want it to call the defult window proc to process
the message (in some cases you would want it to). Now just replace the
messagebox with your custom code.
HTH,
//Andreas