Write Text In Notepad
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
10 posts
Page 1 of 1
how can i write some text from my application to notepad?
You can find me on Facebook or on Skype mihai_92b
What do you mean? Do you want to be able to write a text document or write a text from you application to notepad(Sending information)?
Agust1337 wrote:What do you mean? Do you want to be able to write a text document or write a text from you application to notepad(Sending information)?Sending Information
You can find me on Facebook or on Skype mihai_92b
U could do it with sendkeys.send("blabla")
Try this but im not sure if it will work
Code: Select all
Original thread: http://www.vbforums.com/showthread.php?t=295769'under public class
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Const WM_SETTEXT = &HC
'the sending information:
Dim notepad As Long
Dim editx As Long
notepad = FindWindow("notepad", vbNullString)
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
Call SendMessageByString(editx, WM_SETTEXT, 0&, "The New Text")
If editx = 0 Then
Msgbox "Cannot Locate Notepad Window "
Exit Sub
End If
Agust1337 wrote:Try this but im not sure if it will workit doesn't work
Code: Select allOriginal thread: http://www.vbforums.com/showthread.php?t=295769'under public class Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long Public Const WM_SETTEXT = &HC 'the sending information: Dim notepad As Long Dim editx As Long notepad = FindWindow("notepad", vbNullString) editx = FindWindowEx(notepad, 0&, "edit", vbNullString) Call SendMessageByString(editx, WM_SETTEXT, 0&, "The New Text") If editx = 0 Then Msgbox "Cannot Locate Notepad Window " Exit Sub End If
You can find me on Facebook or on Skype mihai_92b
This will set the text in a Notepad window:
Code: Select all
<DllImport("user32.dll")> Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
End Function
<DllImport("user32.dll")> Shared Function FindWindowEx(ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr
End Function
<DllImport("user32.dll")> Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
End Function
Const WM_SETTEXT As UInteger = &HC
Private Sub btnSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSet.Click
Dim notepad As IntPtr = FindWindow("notepad", Nothing)
notepad = FindWindowEx(notepad, IntPtr.Zero, "edit", Nothing)
If notepad = IntPtr.Zero Then
MsgBox("Cannot Locate Notepad Window")
Else
SendMessage(notepad, WM_SETTEXT, IntPtr.Zero, "The New Text")
End If
End Sub
Last edited by mandai on Thu Mar 22, 2012 5:02 pm, edited 1 time in total.
This is the code I use:
Code: Select all
That will send Textbox1's text and then press EnterSendKeys.Send(TextBox1.Text & "{enter}")
Code: Select all
That one will just type some textSendKeys.Send("some text")
My name is Tom | Visit my blog where I post new content every day! Tom's Daily Blog | MineCraft is awesome!
By using SendKeys you risk not having the window in focus and the keys not being typed.
SendMessage would be the more reliable method.
SendMessage would be the more reliable method.
10 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023