• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 827
  • Last Modified:

Getting text from another program SendMessage? WM_GETTEXT

I am trying to get a large amount of text into my program, from a different program.   I have tried using:

SendMessage progHWND, WM_GETTEXT, 8192, sText

The problem I am having, is the limit to the size of the text buffer.  it's only letting me get a small portion of the text that I need.  Is there a different method that will allow me to get much more?  Or is there a way I can get portions of it at a time?

Thanks in advance.


0
TAF2000
Asked:
TAF2000
  • 2
  • 2
1 Solution
 
Jaime OlivaresCommented:
Hi TAF2000,

Notice that there is a OS limitation in Edit Boxes. 0x7FFF for Win95/98/Me and 0x7FFFFFFF for WinNT/2000/XP
Read at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/editcontrols/editcontrolreference/editcontrolmessages/em_setlimittext.asp 

Good luck,
Jaime.
0
 
zzzzzoocCommented:
>>The problem I am having, is the limit to the size of the text buffer.
Why don't you just increase the size of the buffer?

Form1:
-------------
Option Explicit

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Private Sub Form_Load()
    Dim lngHandle As Long, strBuffer As String, lngLen As Long
    'fill our textbox with a lot of text...
    Text1.Text = String(10000, "a")
    'get the amount of text within it..
    lngHandle = Text1.hwnd
    lngLen = SendMessage(lngHandle, WM_GETTEXTLENGTH, 0, 0)
    'increase our buffer to accommodate the text we're about to get...
    strBuffer = Space(lngLen)
    'get text...
    Call SendMessage(lngHandle, WM_GETTEXT, lngLen, ByVal strBuffer)
    'print to debug...
    Debug.Print strBuffer
End Sub



Mind you, controls may have their own limitations. TextBox limits are around 65k.
0
 
TAF2000Author Commented:
yes, the limt im having problems with is not max int (2147483647) that you refered too..
it is a much lower limitation caused by the string buffer:

Dim sText As String * 8192

it will not let you create a very large string..

so.. is there a way to get around this?  using something else in the sendmessage command?

Thanks
0
 
TAF2000Author Commented:
zzzzzooc,
just saw your message after replying to jaime's comment.  Will give it a shot.
0
 
zzzzzoocCommented:
Oh, one more comment. lngLen may need to be lngLen + 1:

If lngLen > 0 Then
    lngLen = lngLen + 1
    'etc...
End If
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now