M
Michael L. Barker
For days now I've been trying to figure out how to use the SendMessage API
in VB.NET. I've searched the net, and posted all over the place. I have yet
to talk to a person who can help me. I don't mean to sound short about this,
but this is really an easy thing. In VB6, it was cake. So I'm going to try
this once again...
The Declares!
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Int32
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
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA"
(ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByRef
lParam As Int32) As Int32
Const WM_GETTEXT As Int32 = &HD
Const WM_GETTEXTLENGTH As Int32 = &HE
Const WM_SETTEXT As Int32 = &HC
The Code!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim NotePad_Win As Int32 = FindWindow("Notepad", vbNullString)
Dim Notepad_Edit As Int32 = FindWindowEx(NotePad_Win, 0, "Edit",
vbNullString)
SendMessage(Notepad_Edit, WM_SETTEXT, 0, ByVal("Testing!!!!!!!"))
MsgBox(Notepad_Edit)
End Sub
I understand that you can't use ByVal in VB.NET, why is this? What else can
I do? I thought "With Visual Studio.NET you code less, and have more time to
do what you do best 'think'" So what is MS trying to do now, forcing us on
that framework? If so, wrap the API already (ALL OF IT).
in VB.NET. I've searched the net, and posted all over the place. I have yet
to talk to a person who can help me. I don't mean to sound short about this,
but this is really an easy thing. In VB6, it was cake. So I'm going to try
this once again...
The Declares!
Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal
lpClassName As String, ByVal lpWindowName As String) As Int32
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
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA"
(ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByRef
lParam As Int32) As Int32
Const WM_GETTEXT As Int32 = &HD
Const WM_GETTEXTLENGTH As Int32 = &HE
Const WM_SETTEXT As Int32 = &HC
The Code!
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim NotePad_Win As Int32 = FindWindow("Notepad", vbNullString)
Dim Notepad_Edit As Int32 = FindWindowEx(NotePad_Win, 0, "Edit",
vbNullString)
SendMessage(Notepad_Edit, WM_SETTEXT, 0, ByVal("Testing!!!!!!!"))
MsgBox(Notepad_Edit)
End Sub
I understand that you can't use ByVal in VB.NET, why is this? What else can
I do? I thought "With Visual Studio.NET you code less, and have more time to
do what you do best 'think'" So what is MS trying to do now, forcing us on
that framework? If so, wrap the API already (ALL OF IT).