WinForm не получает WM_CLOSE из внешней программы - PullRequest
0 голосов
/ 05 февраля 2019

При следующем сообщении я получаю WM_CLOSE события winproc, когда они происходят внутри приложения, например, при нажатии [x] или alt + f4, но когда внешняя программа * отправляет сообщение WM_CLOSE, оно не принимается

using System;
using System.Drawing;
using System.Windows.Forms;

namespace SDPL
{
    public class SDPL : Form
    {
        [STAThread]
        static void Main(string[] args)
        {
            ApplicationContext MainContext = new ApplicationContext();
            MainContext.MainForm = new SDPL(ref MainContext);
            Application.Run(MainContext);
        }

        private ApplicationContext Context;
        private const int WM_CLOSE = 0x0010;
        private const int WM_QUIT = 0x0012;

        public SDPL(ref ApplicationContext MainContext)
        {
            Context = MainContext;

            SuspendLayout();
            AutoScaleDimensions = new SizeF(6F, 13F);
            AutoScaleMode = AutoScaleMode.Font;
            ClientSize = new Size(271, 31);
            MaximizeBox = false;
            MinimizeBox = false;
            Name = "StreamDeck Plugin Executable Launcher";
            ShowInTaskbar = true;
            SizeGripStyle = SizeGripStyle.Hide;
            Text = "StreamDeck Plugin Executable Launcher";
            ResumeLayout(false);
            PerformLayout();

            FormClosing += SDPLHiddenWindow_FormClosing;
        }

        private void SDPLHiddenWindow_FormClosing(object sender, FormClosingEventArgs e)
        {
            MessageBox.Show("Form Closing", "Form Closing", MessageBoxButtons.OK);
            Context.ExitThread();
        }

        [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_CLOSE:
                    MessageBox.Show("Form Closing from WM_CLOSE", "Form Closing", MessageBoxButtons.OK);
                    break;
                case WM_QUIT:
                    MessageBox.Show("Form Closing from WM_QUIT", "Form Closing", MessageBoxButtons.OK);
                    break;
            }
            base.WndProc(ref m);
        }
    }
}

*: The WM_CLOSE отправляется из приложения с использованием метода QT QProcess s Terminate.

...