open new notepad.exe and write content to it [duplicate]

*爱你&永不变心* 提交于 2019-12-13 11:14:30

问题


I would like to launch a new notepad instance and write content to it from my desktop app (WPF). After that it is user's discretion to save the file or not. (I know I can launch new notepad instance using System.Diagnostics.Process.Start("notepad.exe"))

Just like the process if some one manually wants to create a .txt file. He first opens notepad from start menu. Then write something and then save in desired folder.

Is it possible?


回答1:


try this one source

 [DllImport("user32.dll", EntryPoint = "FindWindowEx")]
        public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
        [DllImport("User32.dll")]
        public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, string lParam);
        private void button1_Click(object sender, EventArgs e)
        {
            Process [] notepads=Process.GetProcessesByName("notepad");
            if(notepads.Length==0)return;            
            if (notepads[0] != null)
            {
                IntPtr child= FindWindowEx(notepads[0].MainWindowHandle, new IntPtr(0), "Edit", null);
                SendMessage(child, 0x000C, 0, textBox1.Text);
            }
        }


来源:https://stackoverflow.com/questions/31021002/open-new-notepad-exe-and-write-content-to-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!