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 wind
Process.Start with the property ShellExecute set to true; 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.
Some code
Const WM_SETTEXT As Integer = &HC
_
Private Shared Function SendMessage(hWnd As IntPtr, Msg As Integer, wParam As IntPtr, 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