Solved

Getting text from another program SendMessage? WM_GETTEXT

Posted on 2004-08-01
5
804 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

690 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