Connecting Tech Pros Worldwide Help | Site Map

no result with WM_GETTEXT

  #1  
Old November 20th, 2005, 10:40 PM
Seb Schöps
Guest
 
Posts: n/a
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

  #2  
Old November 20th, 2005, 10:40 PM
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a

re: no result with WM_GETTEXT


* Seb Schöps <nospam@internet.com> scripsit:[color=blue]
> 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[/color]

Declare 'wParam' and 'lParam' as 'Int32' and pass a 0.
[color=blue]
> Public Const WM_GETTEXT = &HD
> Public Const WM_GETTEXTLENGTH = &HE
>
> dim length[/color]

'... As Int32'.
[color=blue]
> , NotepadResult as String
>
> length = SendMessage(handle2, WM_GETTEXTLENGTH, Nothing, 0)[/color]

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

[color=blue]
> SendMessage(handle2, WM_GETTEXT, length, NotepadResult)[/color]

\\\
MsgBox(NotepadResult)
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
  #3  
Old November 20th, 2005, 10:40 PM
Seb Schöps
Guest
 
Posts: n/a

re: no result with WM_GETTEXT


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

"Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb im Newsbeitrag
news:OAAxL$2ZEHA.2812@TK2MSFTNGP11.phx.gbl...[color=blue]
> * Seb Schöps <nospam@internet.com> scripsit:[color=green]
> > I try to read the content of an open Notepad window, but I don't get[/color][/color]
WM_GETTEXT to work with Visual Basic[color=blue][color=green]
> > .NET. I have the correct handle for the Notepad window and get the[/color][/color]
number of signs with wm_gettextlength, but no[color=blue][color=green]
> > results for wm_gettext.
> >
> > Here is how I try it:
> >
> > Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"[/color][/color]
(ByVal hWnd As IntPtr, ByVal wMsg As[color=blue][color=green]
> > Integer, ByVal wParam As Object, ByVal lParam As Object) As Integer[/color]
>
> Declare 'wParam' and 'lParam' as 'Int32' and pass a 0.
>[color=green]
> > Public Const WM_GETTEXT = &HD
> > Public Const WM_GETTEXTLENGTH = &HE
> >
> > dim length[/color]
>
> '... As Int32'.
>[color=green]
> > , NotepadResult as String
> >
> > length = SendMessage(handle2, WM_GETTEXTLENGTH, Nothing, 0)[/color]
>
> \\\
> NotepadResult = Strings.StrDup(length, " "c)
> ///
>
>[color=green]
> > SendMessage(handle2, WM_GETTEXT, length, NotepadResult)[/color]
>
> \\\
> MsgBox(NotepadResult)
> ///
>
> --
> Herfried K. Wagner [MVP]
> <URL:http://dotnet.mvps.org/>[/color]


  #4  
Old November 20th, 2005, 10:40 PM
Seb Schöps
Guest
 
Posts: n/a

re: no result with WM_GETTEXT


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" <nospam@internet.com> schrieb im Newsbeitrag
news:ccs1uc$5r1$1@online.de...[color=blue]
> 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,[/color]
ByVal[color=blue]
> lParam As String) As Integer
>
> Thanks again!
>
> Regards
> Sebastian
>
> "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> schrieb im[/color]
Newsbeitrag[color=blue]
> news:OAAxL$2ZEHA.2812@TK2MSFTNGP11.phx.gbl...[color=green]
> > * Seb Schöps <nospam@internet.com> scripsit:[color=darkred]
> > > I try to read the content of an open Notepad window, but I don't get[/color][/color]
> WM_GETTEXT to work with Visual Basic[color=green][color=darkred]
> > > .NET. I have the correct handle for the Notepad window and get the[/color][/color]
> number of signs with wm_gettextlength, but no[color=green][color=darkred]
> > > results for wm_gettext.
> > >
> > > Here is how I try it:
> > >
> > > Private Declare Function SendMessage Lib "user32" Alias "SendMessageA"[/color][/color]
> (ByVal hWnd As IntPtr, ByVal wMsg As[color=green][color=darkred]
> > > Integer, ByVal wParam As Object, ByVal lParam As Object) As Integer[/color]
> >
> > Declare 'wParam' and 'lParam' as 'Int32' and pass a 0.
> >[color=darkred]
> > > Public Const WM_GETTEXT = &HD
> > > Public Const WM_GETTEXTLENGTH = &HE
> > >
> > > dim length[/color]
> >
> > '... As Int32'.
> >[color=darkred]
> > > , NotepadResult as String
> > >
> > > length = SendMessage(handle2, WM_GETTEXTLENGTH, Nothing, 0)[/color]
> >
> > \\\
> > NotepadResult = Strings.StrDup(length, " "c)
> > ///
> >
> >[color=darkred]
> > > SendMessage(handle2, WM_GETTEXT, length, NotepadResult)[/color]
> >
> > \\\
> > MsgBox(NotepadResult)
> > ///
> >
> > --
> > Herfried K. Wagner [MVP]
> > <URL:http://dotnet.mvps.org/>[/color]
>
>[/color]


  #5  
Old November 20th, 2005, 10:40 PM
Herfried K. Wagner [MVP]
Guest
 
Posts: n/a

re: no result with WM_GETTEXT


* "Seb Schöps" <nospam@internet.com> scripsit:[color=blue]
> 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[/color]

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

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Yet another threading/invoking question... MuZZy answers 25 December 23rd, 2005 09:25 PM