记事本打开并粘贴指定数据

来源:互联网 发布:网络直播招聘深圳 编辑:程序博客网 时间:2024/06/05 22:35


ss.ToString()为你想传到记事本的数据。

 #region [ 启动记事本 ]
            System.Diagnostics.Process Proc;
            try
            {
                // 启动记事本
                Proc = new System.Diagnostics.Process();
                Proc.StartInfo.FileName = "notepad.exe";
                Proc.StartInfo.UseShellExecute = false;
                Proc.StartInfo.RedirectStandardInput = true;
                Proc.StartInfo.RedirectStandardOutput = true;

                Proc.Start();
            }
            catch
            {
                Proc = null;
            }

            #endregion

            #region [ 传递数据给记事本 ]

            if (Proc != null)
            {
                // 调用 API, 传递数据
                while (Proc.MainWindowHandle == IntPtr.Zero)
                {
                    Proc.Refresh();
                }

                IntPtr vHandle = FindWindowEx(Proc.MainWindowHandle, IntPtr.Zero, "Edit", null);

                // 传递数据给记事本
                SendMessage(vHandle, WM_SETTEXT, 0, ss.ToString());
            }

            #endregion

原创粉丝点击