本文介绍了如何从Windows窗体应用程序中打开记事本,并把一些文本的呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用的Process.Start 的属性的ShellExecute 设置为真;
使用剪贴板:www.dreamin$c$c/forums/topic/40011-how-do-i-put-text-in-another-program/
更新
Use Process.Start with the property ShellExecute set to true;
Use the clipboard: www.dreamincode/forums/topic/40011-how-do-i-put-text-in-another-program/
我是新来的编程和Windows窗体开发。我使用VB.NET和Visual Studio 2008。
我的问题是:如何打开从Windows窗体应用程序记事本,然后将一些文本字符串中的记事本窗口
解决方案的Process.Start 返回进程对象,它有一个 MainWindowHandle 属性。在上面提到的链接发送文本代替的FindWindow时使用该句柄。
更新2有些code
常量WM_SETTEXT作为整数=安培; HC <的DllImport(user32.dll中)> _ 私人共享SendMessage函数(HWND作为IntPtr的,消息作为整数,wParam中的IntPtr,<的MarshalAs(UnmanagedType.LPStr)> lParam的作为字符串)作为IntPtr的 端功能 私人共享的Sub Main() 的ProcessStartInfo用于指示Process类 就如何启动一个新的进程。该UseShellExecute告诉 这个过程的类,它(其中包括)应搜索应用 使用PATH环境变量。 昏暗的PIS作为的ProcessStartInfo =新的ProcessStartInfo(NOTEPAD.EXE) pis.UseShellExecute = TRUE 这个过程类用于启动进程 '它返回一个对象,它可用于控制启动的过程 昏暗的记事本作为流程=的Process.Start(PIS) SendMessage函数是用来发送剪贴板消息,记事本的 主窗口。 昏暗textToAdd作为字符串=文本中添加 SendMessage函数(notepad.MainWindowHandle,WM_SETTEXT,IntPtr.Zero,textToAdd) 结束小组I'm new to programming and to Windows Forms development. I'm using VB.NET and Visual Studio 2008.
My question is: How do I open Notepad from a Windows Forms application, and then place some text string in the Notepad window?
解决方案Update
Process.Start returns a Process object which has a MainWindowHandle property. Use that handle when sending text instead of the FindWindow in the above mentioned link.
Update 2Some code
Const WM_SETTEXT As Integer = &HC <DllImport("user32.dll")> _ Private Shared Function SendMessage(hWnd As IntPtr, Msg As Integer, wParam As IntPtr, <MarshalAs(UnmanagedType.LPStr)> lParam As String) As IntPtr End Function Private Shared Sub Main() 'ProcessStartInfo is used to instruct the Process class ' on how to start a new process. The UseShellExecute tells ' the process class that it (amongst other) should search for the application ' using the PATH environment variable. Dim pis As ProcessStartInfo = New ProcessStartInfo("notepad.exe") pis.UseShellExecute = True ' The process class is used to start the process ' it returns an object which can be used to control the started process Dim notepad As Process = Process.Start(pis) ' SendMessage is used to send the clipboard message to notepad's ' main window. Dim textToAdd As String = "Text to add" SendMessage(notepad.MainWindowHandle, WM_SETTEXT, IntPtr.Zero, textToAdd) End Sub
更多推荐
如何从Windows窗体应用程序中打开记事本,并把一些文本的呢?
发布评论