[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(
IntPtr hWnd, // 信息发往的窗口的句柄
int Msg, // 消息ID
int wParam, // 参数1
string lParam
);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage2(
IntPtr hWnd, // 信息发往的窗口的句柄
int Msg, // 消息ID
int wParam, // 参数1
IntPtr lParam
);
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
private void button4_Click(object sender, EventArgs e)
{
IntPtr hwnd= FindWindow(null, "testForm");
string info = "my info:ΑΒβδγζηθ";
IntPtr pinfo= Marshal.StringToHGlobalAnsi(info);
SendMessage2(hwnd, Form2.USERMESSAGEID, 12, pinfo);
SendMessage(hwnd, Form2.USERMESSAGEID, 12, info);
}
public const int USERMESSAGEID =0x2021;
protected override void WndProc(ref Message m)
{
switch(m.Msg)
{
case USERMESSAGEID:
{
int wparam= m.WParam.ToInt32();
string str = Marshal.PtrToStringAnsi(m.LParam);
break;
}
}
base.WndProc(ref m);
}
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(
IntPtr hWnd, // 信息发往的窗口的句柄
int Msg, // 消息ID
int wParam, // 参数1
ref My_lParam lParam
);
IntPtr ptr = FindWindow(null, "主界面");
SendMessage(ptr, MYMESSAGE, 1, ref m);//发送消息
protected override void DefWndProc(ref Message m)
{
try
{
switch (m.Msg)
{
case MYMESSAGE:
{
My_lParam ml = new My_lParam();
Type t = ml.GetType();
ml = (My_lParam)m.GetLParam(t);
break;
}
deafult :base.DefWndProc(ref m);
}
catch()
{ }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)