WndProc method

  • Thread starter Thread starter John S
  • Start date Start date
J

John S

I am trying to use this method to capture a user pressing the "X" in the
upper right-hand corner. I tried using the following code, but anytime I
exit the program it gets hit no matter what I press.

if(m.Msg == 0x0010) { //X button location

MessageBox.Show("Yeah i am close button here");

}

base.WndProc(ref m);

}
 
John,

When u exit the application either by pressing X button or from menu,
WM_CLOSE message is fired and its caught in the wndproc.

If you want to cancel the close operation after hiting close, you have to
use CancelEventArgs in Form_closing event.

The alternative way to code in File->Exit is to use

Application.ExitThread();

This wont hit wndproc. It will force the application to exit.
 
Hi,

You can by looking for non-client mouse message and then checking the
hittest value.

const int WM_NCLBUTTONDOWN = 0x00A1;
const int HTCLOSE = 20;

protected override void WndProc(ref Message m)
{
if ( m.Msg == WM_NCLBUTTONDOWN &&
m.WParam.ToInt32() == HTCLOSE )
{
Console.WriteLine( "X pressed");
}
base.WndProc (ref m);
}

HTH,
greetings
 

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

Back
Top