Dietmar Brueckmann

Dietmar Brueckmann

  • 1.7k
  • 66
  • 1.2k

Shutdown -> WM_QUERYENDSESSION in WPF-Project

Nov 5 2023 7:10 PM

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);
        }
    }
}

 


Answers (1)