一个是WebForm,一个是WinForm,我想让他们进行相互通信,能实现吗?通信的目的有两点:
1、激活对方程序中的事件。
2、主动向对方传递字符串,以备用。
3、获取对方程序中公开的字符串。
本人对程序间通信不是很熟,还请各位高手提供一下源代码。
1、激活对方程序中的事件。
2、主动向对方传递字符串,以备用。
3、获取对方程序中公开的字符串。
本人对程序间通信不是很熟,还请各位高手提供一下源代码。
解决方案 »
- asp怎么判断asp:checkbox是否被选中
- c#程序如何自我毁灭 在程序结束时...将自己也删掉。。做一个类似大部份软件中的卸载程序 在它卸载完后自己本身也删除
- c#引用问题
- openFileDialog路径问题
- 取值赋值的问题
- 局域网聊天程序如何实现类似QQ的文本与图片混合传送?
- 在这个事件里dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
- 父窗体,子窗体连接数据库使用公共变量的问题, 大哥大姐,小弟分不多了,全给了,谢谢赐教
- 关于扩展存储过程的问题
- 控制台程序不能使用"绑定转换器"是吗?
- 怎么用C#写个程序能识别有U盘插入?
- 关于水晶报表的批量打印
如何通过xml来激活对方程序的事件呢?
{ public partial class Form1 : System.Windows.Forms.Form
{ private System.Windows.Forms.TextBox textBox1; private System.ComponentModel.Container components = null; const int WM_COPYDATA = 0x004A; public Form1()
{ InitializeComponent(); } protected override void Dispose(bool disposing)
{ if (disposing)
{ if (components != null)
{ components.Dispose(); } } base.Dispose(disposing); } private void InitializeComponent()
{ this.textBox1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(176, 32); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(160, 21); this.textBox1.TabIndex = 0; this.textBox1.Text = "textBox1"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(432, 266); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.textBox1}); this.Name = "Form1"; this.Text = "接收方窗体"; this.ResumeLayout(false); } static void Main()
{ Application.Run(new Form1()); } protected override void DefWndProc(ref System.Windows.Forms.Message m)
{ switch (m.Msg)
{ case WM_COPYDATA: COPYDATASTRUCT mystr = new COPYDATASTRUCT(); Type mytype = mystr.GetType(); mystr = (COPYDATASTRUCT)m.GetLParam(mytype); this.textBox1.Text = mystr.lpData; break; default: base.DefWndProc(ref m); break; } } } public struct COPYDATASTRUCT
{ public IntPtr dwData; public int cbData; [MarshalAs(UnmanagedType.LPStr)]
public string lpData; }}
{ public partial class Form1 : System.Windows.Forms.Form
{ private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button1; private System.ComponentModel.Container components = null; const int WM_COPYDATA = 0x004A; public Form1()
{ InitializeComponent(); } protected override void Dispose(bool disposing)
{ if (disposing)
{ if (components != null)
{ components.Dispose(); } } base.Dispose(disposing); } private void InitializeComponent()
{ this.textBox1 = new System.Windows.Forms.TextBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(184, 24); this.textBox1.Name = "textBox1"; this.textBox1.Size = new System.Drawing.Size(128, 21); this.textBox1.TabIndex = 0; this.textBox1.Text = "textBox1"; // // button1 // this.button1.Location = new System.Drawing.Point(344, 16); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(112, 32); this.button1.TabIndex = 1; this.button1.Text = "button1"; this.button1.Click += new System.EventHandler(this.button1_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(536, 142); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.button1, this.textBox1}); this.Name = "Form1"; this.Text = "发送方窗体"; this.ResumeLayout(false); } static void Main()
{ Application.Run(new Form1()); } [DllImport("User32.dll", EntryPoint = "SendMessage")] private static extern int SendMessage( int hWnd, // handle to destination window int Msg, // message int wParam, // first message parameter ref COPYDATASTRUCT lParam // second message parameter ); [DllImport("User32.dll", EntryPoint = "FindWindow")] private static extern int FindWindow(string lpClassName, string lpWindowName); private void button1_Click(object sender, System.EventArgs e)
{ int WINDOW_HANDLER = FindWindow(null, @"接收方窗体"); if (WINDOW_HANDLER == 0)
{ } else
{ byte[] sarr = System.Text.Encoding.Default.GetBytes(this.textBox1.Text);
int len = sarr.Length; COPYDATASTRUCT cds; cds.dwData = (IntPtr)100; cds.lpData = this.textBox1.Text; cds.cbData = len + 1; SendMessage(WINDOW_HANDLER, WM_COPYDATA, 0, ref cds); } } } public struct COPYDATASTRUCT
{ public IntPtr dwData; public int cbData; [MarshalAs(UnmanagedType.LPStr)]
public string lpData; }}
或者能不能用以下过程写个代码参考下?1、asp.net传一个数字给这个进程A;
2、进程A将收到的数字乘于999。
3、进程A将结果返回asp.net。
4、asp.net将结果显示在屏幕。
但我觉得WEBserver的方法应最好,可是我不会,请高手给点说明!