no result with WM_GETTEXT

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Seb Schöps

    no result with WM_GETTEXT

    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_gettextlengt h, but no results for wm_gettext.

    Here is how I try it:

    Private Declare Function SendMessage Lib "user32" Alias "SendMessag eA" (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_GETTEXTLENGT H = &HE

    dim length, NotepadResult as String

    length = SendMessage(han dle2, WM_GETTEXTLENGT H, Nothing, 0)
    SendMessage(han dle2, WM_GETTEXT, length, NotepadResult)

    Anyone knows how to get this to work?

    Thanks in advance for any help!

    Regards
    Sebastian

  • Herfried K. Wagner [MVP]

    #2
    Re: no result with WM_GETTEXT

    * Seb Schöps <nospam@interne t.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_gettextlengt h, but no
    > results for wm_gettext.
    >
    > Here is how I try it:
    >
    > Private Declare Function SendMessage Lib "user32" Alias "SendMessag eA" (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_GETTEXTLENGT H = &HE
    >
    > dim length[/color]

    '... As Int32'.
    [color=blue]
    > , NotepadResult as String
    >
    > length = SendMessage(han dle2, WM_GETTEXTLENGT H, Nothing, 0)[/color]

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

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

    \\\
    MsgBox(NotepadR esult)
    ///

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

    Comment

    • Seb Schöps

      #3
      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 "SendMessag eA"
      (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$2ZEH A.2812@TK2MSFTN GP11.phx.gbl...[color=blue]
      > * Seb Schöps <nospam@interne t.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_gettextlengt h, but no[color=blue][color=green]
      > > results for wm_gettext.
      > >
      > > Here is how I try it:
      > >
      > > Private Declare Function SendMessage Lib "user32" Alias "SendMessag eA"[/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_GETTEXTLENGT H = &HE
      > >
      > > dim length[/color]
      >
      > '... As Int32'.
      >[color=green]
      > > , NotepadResult as String
      > >
      > > length = SendMessage(han dle2, WM_GETTEXTLENGT H, Nothing, 0)[/color]
      >
      > \\\
      > NotepadResult = Strings.StrDup( length, " "c)
      > ///
      >
      >[color=green]
      > > SendMessage(han dle2, WM_GETTEXT, length, NotepadResult)[/color]
      >
      > \\\
      > MsgBox(NotepadR esult)
      > ///
      >
      > --
      > Herfried K. Wagner [MVP]
      > <URL:http://dotnet.mvps.org/>[/color]


      Comment

      • Seb Schöps

        #4
        Re: no result with WM_GETTEXT

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

        "Seb Schöps" <nospam@interne t.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 "SendMessag eA"
        > (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$2ZEH A.2812@TK2MSFTN GP11.phx.gbl...[color=green]
        > > * Seb Schöps <nospam@interne t.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_gettextlengt h, but no[color=green][color=darkred]
        > > > results for wm_gettext.
        > > >
        > > > Here is how I try it:
        > > >
        > > > Private Declare Function SendMessage Lib "user32" Alias "SendMessag eA"[/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_GETTEXTLENGT H = &HE
        > > >
        > > > dim length[/color]
        > >
        > > '... As Int32'.
        > >[color=darkred]
        > > > , NotepadResult as String
        > > >
        > > > length = SendMessage(han dle2, WM_GETTEXTLENGT H, Nothing, 0)[/color]
        > >
        > > \\\
        > > NotepadResult = Strings.StrDup( length, " "c)
        > > ///
        > >
        > >[color=darkred]
        > > > SendMessage(han dle2, WM_GETTEXT, length, NotepadResult)[/color]
        > >
        > > \\\
        > > MsgBox(NotepadR esult)
        > > ///
        > >
        > > --
        > > Herfried K. Wagner [MVP]
        > > <URL:http://dotnet.mvps.org/>[/color]
        >
        >[/color]


        Comment

        • Herfried K. Wagner [MVP]

          #5
          Re: no result with WM_GETTEXT

          * "Seb Schöps" <nospam@interne t.com> scripsit:[color=blue]
          > But I had to declare lParam as String:
          > Private Declare Function SendMessage Lib "user32" Alias "SendMessag eA"
          > (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/>

          Comment

          Working...