Solved

Getting text from another program SendMessage? WM_GETTEXT

Posted on 2004-08-01
5
781 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 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