Write to Notepad without creating a file
-
Is there a way to write to Notepad from c# without creating a file. I need this because I dont have write permission on the client but I need to show the extracted data in the Notepad. Please guide me in this direction. Live Life King Size Alomgir Miah
-
Is there a way to write to Notepad from c# without creating a file. I need this because I dont have write permission on the client but I need to show the extracted data in the Notepad. Please guide me in this direction. Live Life King Size Alomgir Miah
-
You can do it using the windows API. I don't remember exactly, but you use FindWindow I think, with some paramter like SET_TEXT or something. There's an example that does exactly what you want somewhere on pinvoke.net[^] /\ |_ E X E GG
Thanks a lot for your reply. Private Declare Ansi Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32 Private Const WM_SETTEXT As Integer = &HC Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim hwnd As Integer = FindWindow(vbNullString, "Untitled - Notepad") '/// assuming you have notepad open. Dim x As Integer = FindWindowEx(hwnd, 0, "Edit", vbNullString) Dim strText As String = "some text" If Not x = 0 Then SendMessage(x, WM_SETTEXT, 256, strText) End If End Sub Live Life King Size Alomgir Miah
-
Thanks a lot for your reply. Private Declare Ansi Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer Private Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32 Private Const WM_SETTEXT As Integer = &HC Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim hwnd As Integer = FindWindow(vbNullString, "Untitled - Notepad") '/// assuming you have notepad open. Dim x As Integer = FindWindowEx(hwnd, 0, "Edit", vbNullString) Dim strText As String = "some text" If Not x = 0 Then SendMessage(x, WM_SETTEXT, 256, strText) End If End Sub Live Life King Size Alomgir Miah