我现在用的是WM_SETTEXT,用这个每次一发送就把上一次的内容给覆盖了
现在的目的是实现追加的功能应该用哪个消息类型。请写出对应的16进制

解决方案 »

  1.   

    先WM_GETTEXT,取原来的内容,然后将这一次需要追加的内容附加在后面,再WM_SETTEXT
      

  2.   


    是的,先WM_GETTEXT,取到的字符串,自己再追加吧,然后WM_SETTEXT
      

  3.   

    WM_GETTEXT  这个获取后怎么相加呢
      

  4.   


                System.Text.UnicodeEncoding converter = new System.Text.UnicodeEncoding();
                byte[] bs1 = converter.GetBytes("你好");
                //---------------------------------------
                //假设bs1是你GetWindowText得到的。前面的代码只是测试用的。
                string textGot = converter.GetString(bs1);
                string textSet = textGot + "吗?";            byte[] bytesToSent = converter.GetBytes(textSet);
                //SetWindowText or SendMessage
      

  5.   

    抱歉,可能意思不太明确,我想知道用WM_GETTEXT怎么获取目标edit中的内容,之后进行累加,是这个部分的代码
      

  6.   

    哦,简单。
    [DllImport("user32.dll", EntryPoint="GetWindowText")]
    public static extern int GetWindowText (
    int hwnd,
    string lpString,
    int cch
    ); 
    调用的时候这样:               
    StringBuilder s = new StringBuilder(512);                              
    int i = GetWindowText(this.Handle, s, s.Capacity);                
    MessageBox.Show(s.ToString());
      

  7.   

     #region 用记事本显示指定的文件内容
            private void lvContent_MouseDoubleClick(object sender, MouseEventArgs e)
            {
                string fileName = this.lvContent.SelectedItems[0].SubItems[2].Text;
                int index = fileName.LastIndexOf(".");
                string fileCategory = "";
                if (index != -1)
                    fileCategory = fileName.Substring(index).ToLower();
                if (fileCategory != ".txt")
                {
                    return;
                }
                Process proc = new Process();
                try
                {
                    // 启动记事本
                    proc.StartInfo.FileName = "notepad.exe";
                    proc.StartInfo.UseShellExecute = false;
                    proc.StartInfo.RedirectStandardInput = true;
                    proc.StartInfo.RedirectStandardOutput = true;
                    proc.Start();
                }
                catch
                {
                    proc = null;
                }
                // 传递数据给记事本
                if (proc != null)
                {
                    // 从数据库中查找   
                    byte[] imgs;
                    try
                    {
                        int id = Convert.ToInt32(lvContent.SelectedItems[0].SubItems[0].Text);
                        string sql = string.Format("select documentContent from document where documentID ={0}", id);
                        DBHelper.conn.Open();
                        SqlCommand cmd = new SqlCommand(sql, DBHelper.conn);
                        cmd.CommandTimeout = 0;
                        imgs = (byte[])cmd.ExecuteScalar();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                        return;
                    }
                    finally
                    {
                        DBHelper.conn.Close();
                    }                // 调用 API, 传递数据
                    while (proc.MainWindowHandle == IntPtr.Zero)
                    {
                        proc.Refresh();
                    }
                    IntPtr vHandle = FindWindowEx(proc.MainWindowHandle, IntPtr.Zero, "Edit", null);
                    string content = System.Text.Encoding.Default.GetString(imgs);
                    SendMessage(vHandle, WM_SETTEXT, 0, content);// 传递数据给记事本
                }
            }        /// <summary>
            /// 传递消息给记事本
            /// </summary>        
            [DllImport("User32.DLL")]
            public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, string lParam);        /// <summary>
            /// 查找句柄
            /// </summary>  
            [DllImport("User32.DLL")]
            public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);        /// <summary>
            /// 记事本需要的常量
            /// </summary>
            public const uint WM_SETTEXT = 0x000C;
            #endregion