Who can solve this problem?
Here's the situation. I have an old program in VB6 which I intend to keep as it is. Upgrading it to .NET would be just too troublesome, so that's not an option. What I'd like to accomplish is to develop a program in VB.NET that will allow me to read strings from the old program. For example, I'd like the old VB6 program to send its version (in string type) to the VB.NET program, which in trun will show the version on the VB.NET form (or just store it in the memory).
Is there any way of doing this? I know how to do this between two VB6 programs but I just can't figure it out for .NET. Does anyone here know anything about this? Any reference to a site or examples that I can follow would be just great!
Thanks in advance!
Eric.
Re: Who can solve this problem?
Sorry to resurrect such an ancient post, but I'm having trouble figuring out how to do this exact thing, but in VB.net (VS2005 specifically) instead of VB6. That is, I need to know how to put text into notepad and get text back from it and also how to close it would be nice as well. I already know how to launch it, I mostly just need to know how to control its text a bit.
If anyone can help, I would be most appreciative :)
Thanks in advance.
Quote:
Originally Posted by Arc
This example i made uses Notepad. But it's fairly simple to change it to any program. You just need an API spy program to the title of the program(which is usualy what the title bar says).
All you need is 3 buttons and a textbox
Put this in a module
VB Code:
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
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
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
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Long) As Long
Declare Function SendMessageByNum& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long)
Public Const WM_SETTEXT = &HC
Public Const WM_CLOSE = &H10
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE
Public Const GW_HWNDNEXT = 2
Function GetText(Handle)
GetTrim = SendMessageByNum(Handle, 14, 0&, 0&)
TrimSpace$ = Space$(GetTrim)
GetString = SendMessageByString(Handle, 13, GetTrim + 1, TrimSpace$)
GetText = TrimSpace$
End Function
This goes in 3 different buttons.. 1 button sends text to Notepad, one gets text from Notepad and one closes Notepad.
VB Code:
Private Sub Close_Click()
Dim notepad As Long, editx As Long
notepad = FindWindow("notepad", vbNullString)
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
Call PostMessage(notepad, WM_CLOSE, 0, 0)
End Sub
Private Sub Gettxt_Click()
Dim notepad As Long, editx As Long
notepad = FindWindow("notepad", vbNullString)
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
TheText = GetText(editx)
Text1 = TheText
End Sub
Private Sub SetTxt_Click()
Dim notepad As Long, editx As Long
notepad = FindWindow("notepad", vbNullString)
editx = FindWindowEx(notepad, 0&, "edit", vbNullString)
Call SendMessageByString(editx, WM_SETTEXT, 0, Text1)
End Sub
Just type text into your textbox and click the Settxt button and it will put the text into notepad etc...