使用以下命令,我将在应用程序中发生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);
}
}
}