加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

.net – 如何从Windows窗体应用程序中打开记事本并在其中放置一

发布时间:2020-12-14 02:14:57 所属栏目:Windows 来源:网络整理
导读:我正在使用VB.NET和Visual Studio 2008. 我的问题是:如何从Windows窗体应用程序中打开记事本,然后在记事本窗口中放置一些文本字符串? 解决方法 使用Process.Start将属性ShellExecute设置为true; 使用剪贴板: http://www.dreamincode.net/forums/topic/400
我正在使用VB.NET和Visual Studio 2008.

我的问题是:如何从Windows窗体应用程序中打开记事本,然后在记事本窗口中放置一些文本字符串?

解决方法

>使用Process.Start将属性ShellExecute设置为true;
>使用剪贴板: http://www.dreamincode.net/forums/topic/40011-how-do-i-put-text-in-another-program/

更新

Process.Start返回一个具有MainWindowHandle属性的Process对象.在上面提到的链接中发送文本而不是FindWindow时使用该句柄.

更新2

一些代码

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读