Handling WM_CLOSE message in C # Tray application

I found a couple of articles telling me how to use the WM_CLOSE message, but still my application is the one who should handle the WM_CLOSE message.

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



source to share

1 answer

To do this, you need to override the method WndProc

on Form

, which is the main tray icon, and handleWM_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);




All Articles