Solved

Getting text from another program SendMessage? WM_GETTEXT

Posted on 2004-08-01
5
772 Views
Last Modified: 2008-02-01
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
Comment
Question by:TAF2000
  • 2
  • 2
5 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 11690302
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
 
LVL 17

Accepted Solution

by:
zzzzzooc earned 300 total points
ID: 11690329
>>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
 

Author Comment

by:TAF2000
ID: 11690339
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
 

Author Comment

by:TAF2000
ID: 11690346
zzzzzooc,
just saw your message after replying to jaime's comment.  Will give it a shot.
0
 
LVL 17

Expert Comment

by:zzzzzooc
ID: 11692593
Oh, one more comment. lngLen may need to be lngLen + 1:

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now