日期:2014-05-19  浏览次数:20912 次

c#中如何传递文本给记事本程序
Process   pro   =   new   Process();                        
                        pro.StartInfo.FileName=System.Environment.SystemDirectory+@ "\notepad.exe ";
pro.StartInfo.CreateNoWindow   =   true;
pro.Start();

如何把文本(或一些string),传递给这个notepad.exe,让它显示???

------解决方案--------------------
//再给你一种方案
[DllImport( "User32.DLL ")]
public static extern int SendMessage(IntPtr hWnd,
uint Msg, int wParam, string lParam);
[DllImport( "User32.DLL ")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent,
IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
public const uint WM_SETTEXT = 0x000C;
private void button1_Click(object sender, EventArgs e)
{
Process vProcess = Process.Start( "notepad.exe ");
while (vProcess.MainWindowHandle == IntPtr.Zero) vProcess.Refresh();
IntPtr vHandle = FindWindowEx(vProcess.MainWindowHandle,
IntPtr.Zero, "Edit ", null);
SendMessage(vHandle, WM_SETTEXT, 0, "Zswang 路过 ");
}