Skip to content

Instantly share code, notes, and snippets.

@duanebester
Created July 1, 2015 19:18
Show Gist options
  • Save duanebester/74f9debcf36ad7a5e5dd to your computer and use it in GitHub Desktop.
Save duanebester/74f9debcf36ad7a5e5dd to your computer and use it in GitHub Desktop.
Message Only Window C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MyAPI
{
// Message Only Window
class MessageOnlyWindow : Form
{
public List<Event> events = null;
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
public MessageOnlyWindow()
{
var accessHandle = this.Handle;
}
public void setListCallbacksAndInit(List<Event> callbacks)
{
this.events = callbacks;
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
ChangeToMessageOnlyWindow();
}
private void ChangeToMessageOnlyWindow()
{
IntPtr HWND_MESSAGE = new IntPtr(-3);
SetParent(this.Handle, HWND_MESSAGE);
}
// Override
protected override void WndProc(ref Message m)
{
MyAPI.ProcessWindowsMessage(ref m); // Could pass events list here as well
base.WndProc(ref m);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment