WM_COPY是用来发送给可编辑控件的消息告诉该控件将当前选择文字拷贝质剪贴板。使用WM_COPY消息传递一个结构体?
虾米意思?:)
___________________________________
too simple,sometimes naive :()
___________________________________

解决方案 »

  1.   

    不好意思,应该是WM_COPYDATA,窗口或者进程间传递数据的消息。
      

  2.   

    public const int WM_COPYDATA = &H4A;
    WM_COPYDATA也是一个常量呀!?
      

  3.   

    发送程序:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Runtime.InteropServices;namespace WinFormSendMsg
    {
    public 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 );
    } #region Windows Form Designer generated code
    /// <summary>
    /// &Eacute;è&frac14;&AElig;&AElig;÷&Ouml;§&sup3;&Ouml;&Euml;ù&ETH;è&micro;&Auml;·&frac12;·¨ - &sup2;&raquo;&Ograve;&ordf;&Ecirc;&sup1;&Oacute;&Atilde;&acute;ú&Acirc;&euml;±à&frac14;&shy;&AElig;÷&ETH;&THORN;&cedil;&Auml;
    /// &acute;&Euml;·&frac12;·¨&micro;&Auml;&Auml;&Uacute;&Egrave;&Yacute;&iexcl;&pound;
    /// </summary>
    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 = "·&cent;&Euml;&Iacute;·&frac12;";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// &Oacute;&brvbar;&Oacute;&Atilde;&sup3;&Igrave;&ETH;ò&micro;&Auml;&Ouml;÷&Egrave;&euml;&iquest;&Uacute;&micro;&atilde;&iexcl;&pound;
    /// </summary>
    [STAThread]
    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)
    {
    //·&cent;&Euml;&Iacute;&Iuml;&ucirc;&Iuml;&cent;
    int WINDOW_HANDLER = FindWindow(null,@"&frac12;&Oacute;&Ecirc;&Otilde;·&frac12;"); 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);


    } }
    }
    [StructLayout(LayoutKind.Sequential)] 
    public struct COPYDATASTRUCT
    {
    public IntPtr dwData;
    public int cbData;
    [MarshalAs(UnmanagedType.LPStr)] public string lpData;
    }
    }接受程序:
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Runtime.InteropServices;namespace WindowsFormGetMsg
    {

    public 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 );
    } #region Windows Form Designer generated code
    /// <summary>
    /// &Eacute;è&frac14;&AElig;&AElig;÷&Ouml;§&sup3;&Ouml;&Euml;ù&ETH;è&micro;&Auml;·&frac12;·¨ - &sup2;&raquo;&Ograve;&ordf;&Ecirc;&sup1;&Oacute;&Atilde;&acute;ú&Acirc;&euml;±à&frac14;&shy;&AElig;÷&ETH;&THORN;&cedil;&Auml;
    /// &acute;&Euml;·&frac12;·¨&micro;&Auml;&Auml;&Uacute;&Egrave;&Yacute;&iexcl;&pound;
    /// </summary>
    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 = "&frac12;&Oacute;&Ecirc;&Otilde;·&frac12;";
    this.ResumeLayout(false); }
    #endregion /// <summary>
    /// &Oacute;&brvbar;&Oacute;&Atilde;&sup3;&Igrave;&ETH;ò&micro;&Auml;&Ouml;÷&Egrave;&euml;&iquest;&Uacute;&micro;&atilde;&iexcl;&pound;
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());
    } protected override void DefWndProc(ref System.Windows.Forms.Message m)
    {
    switch(m.Msg)
    {
    //&frac12;&Oacute;&Ecirc;&Otilde;×&Ocirc;&para;¨&Ograve;&aring;&Iuml;&ucirc;&Iuml;&cent; USER&pound;&not;&sup2;&cent;&Iuml;&Ocirc;&Ecirc;&frac34;&AElig;&auml;&sup2;&Icirc;&Ecirc;&yacute;
    case WM_COPYDATA:
    COPYDATASTRUCT mystr = new COPYDATASTRUCT();
    &iexcl;&iexcl;&iexcl;&iexcl;&iexcl;&iexcl; Type mytype = mystr.GetType();&iexcl;&iexcl;&iexcl;&iexcl;&iexcl;&iexcl; mystr =(COPYDATASTRUCT)m.GetLParam(mytype);
    this.textBox1.Text  =mystr.lpData; break;
    default:
    base.DefWndProc(ref m);
    break; } } }
    [StructLayout(LayoutKind.Sequential)] 
    public struct COPYDATASTRUCT
    {
    public IntPtr dwData;
    public int cbData;
    [MarshalAs(UnmanagedType.LPStr)] public string lpData;
    }
    }