Hi Venu,
I managed that feature once, by cancelling all closing events (user had to select exit from menu). One way to overcome this is to detect the WM_QUERYENDSESSION message from windows
private bool closing = false;
protected override void WndProc(ref Message m)
{
if(m.Msg==0x0011) //WM_QUERYENDSESSION
{
closing = true;
}
base.WndProc(ref m);
}
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if(!closing) // not ready to close yet
{
this.Hide(); // hide the window instead of closing it
e.Cancel = true;
}
}
Happy coding!
Morten Wennevik [C# MVP]