With WinForms it is easy:
but how to do it in WPF, what is the place for WndProc
namespace WinFormsApp1
{
public partial class Form1 : Form
{
private static int WM_QUERYENDSESSION = 0x11;
public Form2()
{
InitializeComponent();
}
protected override void WndProc(ref Message m)
{
if (m.Msg == WM_QUERYENDSESSION)
{
MessageBox.Show("logoff, shutdown, or reboot");
}
base.WndProc(ref m);
}
}
}
Sam HobbsPosted Nov 5, 2023, 11:26 PM
Code Snippet
Except you might need to do something different for the return value, it has been a few years since I did any of that. I leave that for you to find.