private MgFilter msgFilter = new MgFilter();
Application.AddMessageFilter(msgFilter);
public class MgFilter : IMessageFilter
{
const uint WM_USER = 0x0400;
const uint CA_WMCAEVENT = WM_USER + 8400;
const uint CA_CONNECTED = WM_USER + 110;
const uint CA_DISCONNECTED = WM_USER + 120;
const uint CA_SOCKETERROR = WM_USER + 130;
const uint CA_RECEIVEDATA = WM_USER + 210;
const uint CA_RECEIVESISE = WM_USER + 220;
const uint CA_RECEIVEMESSAGE = WM_USER + 230;
const uint CA_RECEIVECOMPLETE = WM_USER + 240;
const uint CA_RECEIVEERROR = WM_USER + 250;
public bool PreFilterMessage(ref Message msg)
{
switch ((uint)msg.LParam)
{
case CA_CONNECTED:
break;
default:
break;
}
return false;
}
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg == 9424)
{
case 0x0400 + 110:
Console.Write("ok");
break;
}
if( m.Msg == 9424 )
Console.Write(((uint)m.WParam).ToString()+"\r\n");
}
-----------------------------------------------------------------------------------------------------
private const int WM_USER = 0x0400;
IntPtr thisHandle;
public Form1()
{
InitializeComponent();
thisHandle = this.Handle;
th = new Thread(new ThreadStart(RunThread));
th.Start();
}
void RunThread()
{
SendMessage(thisHandle, WM_USER + 100, 0, 0);
SendMessage(thisHandle, WM_USER + 101, 0, 0);
}
void AddControl()
{
tb = new TextBox();
Controls.Add(tb);
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
switch (m.Msg)
{
case WM_USER + 100:
AddControl();
break;
}
}