no result with WM_GETTEXT

  • Thread starter =?iso-8859-1?Q?Seb_Sch=F6ps?=
  • Start date
?

=?iso-8859-1?Q?Seb_Sch=F6ps?=

Hello,

I try to read the content of an open Notepad window, but I don't get WM_GETTEXT to work with Visual Basic .NET. I have the correct handle for the Notepad window and get the number of signs with wm_gettextlength, but no results for wm_gettext.

Here is how I try it:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Object, ByVal lParam As Object) As Integer

Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE

dim length, NotepadResult as String

length = SendMessage(handle2, WM_GETTEXTLENGTH, Nothing, 0)
SendMessage(handle2, WM_GETTEXT, length, NotepadResult)

Anyone knows how to get this to work?

Thanks in advance for any help!

Regards
Sebastian
 
H

Herfried K. Wagner [MVP]

* Seb Schöps said:
I try to read the content of an open Notepad window, but I don't get WM_GETTEXT to work with Visual Basic
.NET. I have the correct handle for the Notepad window and get the number of signs with wm_gettextlength, but no
results for wm_gettext.

Here is how I try it:

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As
Integer, ByVal wParam As Object, ByVal lParam As Object) As Integer

Declare 'wParam' and 'lParam' as 'Int32' and pass a 0.
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE

dim length

'... As Int32'.
, NotepadResult as String

length = SendMessage(handle2, WM_GETTEXTLENGTH, Nothing, 0)

\\\
NotepadResult = Strings.StrDup(length, " "c)
///

SendMessage(handle2, WM_GETTEXT, length, NotepadResult)

\\\
MsgBox(NotepadResult)
///
 
S

Seb Schöps

Thanks Herfried,

that solved my problem.

But I had to declare lParam as String:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Object, ByVal
lParam As String) As Integer

Thanks again!

Regards
Sebastian
 
S

Seb Schöps

Correction:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Int32, ByVal
lParam As String) As Integer

Seb Schöps said:
Thanks Herfried,

that solved my problem.

But I had to declare lParam as String:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Object, ByVal
lParam As String) As Integer

Thanks again!

Regards
Sebastian
 
H

Herfried K. Wagner [MVP]

* "Seb Schöps said:
But I had to declare lParam as String:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"
(ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Object, ByVal
lParam As String) As Integer

That's true for 'WM_GETTEXT'. You can overload 'SendMessage'.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top