|
-
Nov 13th, 2007, 04:47 AM
#1
Thread Starter
Frenzied Member
Send stuff to notepad...
I've using VB.NET 2005 and I want to open notepad and print stuff to it.
How can i do this??
-
Nov 13th, 2007, 04:49 AM
#2
Re: Send stuff to notepad...
Well you would open notepad with Process.Start("notepad")
Then you would use the FindWindow API to get the window handle to notepad.
Then use SendMessage API to send the data to the app.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 13th, 2007, 04:53 AM
#3
Thread Starter
Frenzied Member
Re: Send stuff to notepad...
I've never used an API before, how do I do this???
-
Nov 13th, 2007, 04:56 AM
#4
Re: Send stuff to notepad...
Download the API Viewer (link in my signature) and set it for vb.net format. The copy the FindWindow and SendMessage definitions and paste into your general declarations section of your vb.net project.
Also, if you search the Forums you will find code examples with these too.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 13th, 2007, 04:59 AM
#5
Thread Starter
Frenzied Member
Re: Send stuff to notepad...
-
Nov 13th, 2007, 05:05 AM
#6
Re: Send stuff to notepad...
Its a library of core Windows OS functions.
Application Program Interface.
Code:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="FindWindow")> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="SendMessage")> _
Private Shared Function SendMessage(ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
End Function
End Class
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 13th, 2007, 05:25 AM
#7
Thread Starter
Frenzied Member
Re: Send stuff to notepad...
Okay I got these easy enough
Code:
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
Private Const WM_SETTEXT = &HC
But can not find any code to go with it
-
Nov 13th, 2007, 05:39 AM
#8
Re: Send stuff to notepad...
I wrote one up for you.
Code:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="FindWindow")> _
Private Shared Function FindWindow(ByVal lpClassName As String, ByVal lpWindowName As String) As Int32
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="FindWindowEx")> _
Private Shared Function FindWindowEx(ByVal hWnd1 As Int32, ByVal hWnd2 As Int32, ByVal lpsz1 As String, ByVal lpsz2 As String) As Int32
End Function
<DllImport("user32.dll", CharSet:=CharSet.Auto, EntryPoint:="SendMessage")> _
Private Shared Function SendMessage(ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As String) As Int32
End Function
Private Const WM_SETTEXT As Int32 = &HC
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
System.Diagnostics.Process.Start("notepad")
Dim iHwnd As Int32
Dim iHwndChild As Int32
Do While iHwnd = 0
iHwnd = FindWindow("Notepad", "Untitled - Notepad")
Loop
iHwndChild = FindWindowEx(iHwnd, 0, "Edit", vbNullString)
SendMessage(iHwndChild, WM_SETTEXT, 0, "WOOT!")
MessageBox.Show(iHwndChild.ToString)
End Sub
End Class
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 13th, 2007, 09:10 AM
#9
Re: Send stuff to notepad...
 Originally Posted by kiwis
What is a API??
I just answerd to a similler question in this forum.
dont blame me for my english.
check wheather you can get an idea from it.
http://www.vbforums.com/showthread.php?t=496268
-
Nov 14th, 2007, 04:11 AM
#10
Re: Send stuff to notepad...
RobDogg,
what happens in the event that the Process never starts?
The example would hang, because of the unneeded Do While Loop.
I would also .waitforinutidle because occasionally the window isn't ready, which is why i think you wanted to do a loop in the first place.
If you insist on using a do loop, then at least verify the process handle exists first.
Then verify the handle of the child window before sending.
-
Nov 14th, 2007, 04:18 AM
#11
Re: Send stuff to notepad...
Yes, that is true but its only a quick example; no Try Catch error handling, no trapping if the process doesnt start etc.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Nov 14th, 2007, 04:28 AM
#12
Re: Send stuff to notepad...
So did you put in the DoWhile Loop, to wait for the process?
That's not usually how you would use the FindWindow API, because it implies that there may be multiple passes through the loop, perhaps many on a slow OS. If there were more than one pass, then there's some kind of problem, and this thread will tie up alot of other things, while it loops.
I just dont get why, since it's unneeded anyway.
Code:
hwnd = FindWindow("Notepad", "Untitled - Notepad")
Same thing right?
Last edited by TTn; Nov 14th, 2007 at 04:32 AM.
-
Nov 14th, 2007, 04:35 AM
#13
Re: Send stuff to notepad...
Well as the process is started you want to make sure its up and running before attempting to find the window.
Ps, "Untitled"
Its just one short example not intended for production app useage.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|