自定义消息和c++一样发。从0x400开始编号,发送需要自己声明api: [DllImport("user32.dll", EntryPoint="PostMessage")] public static extern int PostMessage ( int hwnd, int wMsg, int wParam, int lParam );或者[DllImport("user32.dll", EntryPoint="SendMessage")] public static extern int SendMessage ( int hwnd, int wMsg, int wParam, ref int lParam );然后调用之。
protected override void WndProc(ref Message m) { // 在这里判断自定义消息 if (m.Msg == 1111) { } base.WndProc(ref m); }
[DllImport("user32.dll", EntryPoint="PostMessage")]
public static extern int PostMessage (
int hwnd,
int wMsg,
int wParam,
int lParam
);或者[DllImport("user32.dll", EntryPoint="SendMessage")]
public static extern int SendMessage (
int hwnd,
int wMsg,
int wParam,
ref int lParam
);然后调用之。
{
// 在这里判断自定义消息
if (m.Msg == 1111)
{
}
base.WndProc(ref m);
}
能否各举一个例子
li面怎么转换类型的时候老是不对呢 ,例如要传一个string类型或者byte[]
如果是没有关系的两个窗体,就用WindowsMessage