1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
...
namespace ExecOnQuit
{
public partial class frmMain : Form
{
....
private static int WM_QUERYENDSESSION = 0x11;
protected override void WndProc(ref System.Windows.Forms.Message m)
{
// Code pompé sur la page de MSDN : http://msdn.microsoft.com/fr-fr/library/microsoft.win32.systemevents.sessionending.aspx
if (m.Msg == WM_QUERYENDSESSION)
{
StreamWriter sw = new StreamWriter(Program.LogFileName, true);
sw.WriteLine("{0} : WndProc(QueryEndSession)", DateTime.Now.ToString() );
sw.Close();
}
// If this is WM_QUERYENDSESSION, the closing event should be
// raised in the base WndProc.
base.WndProc(ref m);
} //WndProc
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
StreamWriter sw = new StreamWriter(Program.LogFileName, true);
sw.WriteLine("{0} : FormClosing(s='{1}',e=[{2},{3}])", DateTime.Now.ToString(), sender.ToString(), e.Cancel, e.CloseReason);
sw.Close();
}
....
}
} |
Partager