Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handle WM_CLOSE message send to C# Tray App

Tags:

c#

.net

I found a couple of articles telling me how to make use of the WM_CLOSE message but never the less my application is the one who has to handle the WM_CLOSE message.

Is there a way to hook up the WM_CLOSE and handle it? Because the WM_CLOSE only closes the tray icon but does not terminate the process itself ...

Regards,

like image 465
inva Avatar asked Mar 22 '12 16:03

inva


1 Answers

To do this you need to override the WndProc method on the Form which is the main tray icon and handle WM_CLOSE

private const int WM_CLOSE = 0x0010;

protected override void WndProc(ref Message m) {
  if (m.Msg == WM_CLOSE) {
    // Close everything
  }
  base.WndProc(ref m);
}
like image 80
JaredPar Avatar answered Sep 24 '22 05:09

JaredPar