Winform创建仅接收消息的窗口

internal class MessageOnlyWindow : NativeWindow
{
    private const string WindowName = "MessageOnlyWindow";

    public LowLevelView()
    {
        var createParams = new CreateParams
        {
            Style = 0,
            ExStyle = 0,
            ClassStyle = 0,
            Caption = WindowName
        };
        if (Environment.OSVersion.Platform == PlatformID.Win32NT)
        {
            createParams.Parent = (IntPtr)(-3);
        }

        CreateHandle(createParams);
    }

    protected override void WndProc(ref Message m)
    {
        if (m.Msg >= 0x0400)
        {
            Debug.WriteLine(m.Msg);
        }

        base.WndProc(ref m);
    }
}
posted @ 2024-02-21 10:07  xhubobo  阅读(14)  评论(0编辑  收藏  举报