How do I create a message-only window from windows forms?

后端 未结 4 892
梦如初夏
梦如初夏 2021-01-21 08:26

I\'m trying to create a message-only window to receive window messages from an MFC library class, within a winforms application.

I\'ve tried subclassing NativeWind

4条回答
  •  星月不相逢
    2021-01-21 08:44

    Try that :

    [DllImport("user32.dll")]
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
    
    static IntPtr HWND_MESSAGE = new IntPtr(-3);
    
    protected override void OnHandleCreated(EventArgs e)
    {
        base.OnHandleCreated(e);
        SetParent(this.Handle, HWND_MESSAGE);
    }
    

提交回复
热议问题