日期:2014-05-18 浏览次数:21309 次
[DllImport("User32.dll", EntryPoint = "SendMessageA")] private static extern int SendMessage( int hWnd, // handle to destination window int Msg, // message int wParam, // first message parameter string lParam // second message parameter ); private static extern int FindWindow(string lpClassName, string lpWindowName); public static void SendMsgToFlashForm(int MSG, IntPtr wParam, string lParam) { int WINDOW_HANDLER = FindWindow(null, @"XXXX"); if (WINDOW_HANDLER == 0) { throw new Exception("Could not find Main window!"); } SendMessage(WINDOW_HANDLER, MSG, wParam, lParam); }
MessageController.SendMsgToFlashForm(MessageManager.MyMessage.WM_SHOW_PROCESS, IntPtr.Zero, "系统开始创建核心对象");
try { switch (m.Msg) { case Utility.CommonUtility.MessageManager.MyMessage.WM_SHOW_PROCESS: { label2.Text = m.LParam.ToString(); break; } default: base.DefWndProc(ref m);//调用基类函数处理非自定义消息。 break; } }
用StringBuild private static extern int SendMessage( int hWnd, // handle to destination window int Msg, // message int wParam, // first message parameter StringBuild lParam // second message parameter );
------解决方案--------------------
同进程可以这样:
[DllImport("User32.dll")] private static extern int SendMessage(int hWnd, int Msg, int wParam, string lParam); private const int WM_USER = 0x0400; private void button1_Click(object sender, EventArgs e) { SendMessage((int)Handle, WM_USER + 10, 0, "Zswang 路过"); } protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_USER + 10: MessageBox.Show(Marshal.PtrToStringAnsi(m.LParam)); break; } base.WndProc(ref m); }
------解决方案--------------------