Re: getting text from external application
From: Tom Esh (tjeshGibberish_at_earthlink.net)
Date: 09/04/04
- Next message: Mike D Sutton: "Re: How to get an associated file icon without the Alpha Channel i"
- Previous message: Mike D Sutton: "Re: How to get an associated file icon without the Alpha Channel i"
- In reply to: Charlie Burnham: "getting text from external application"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 04 Sep 2004 09:51:23 -0400
On Fri, 3 Sep 2004 21:26:21 -0400, "Charlie Burnham"
<burnham@tiac.net> wrote:
>Dear Experts.
>
>I'm trying to have my VB6 program operate an external program (MainConcept
>MPEG Encoder) so as to allow my program to change the encoded filename,
>start encoding, stop encoding, etc. This other program is most likely
>compiled VC++ with no particular intent on the part of the programmers to
>allow external control in this way.
>
>I've been able to get this to work pretty well just using VB Shell and
>SendKeys commands, using a timer and select case scheme to sequence tabs and
>button clips. That is, I can send my data to the external program and push
>its buttons, type in text, etc.
>
>The problem is getting data back from the external app. There is a textbox
>that basically gives the status of the encoding procedure, number of frames
>encoded, dropped frames, etc. It is the only textbox on the form. I want
>the string in this box to be available to my calling program in order to
>monitor progress, "closing the loop" as it were. Ideally, the user of my
>program would never see anything but a minimized version of the other
>program.
>....
Charlie,
Fetching the text is farily straightforward and doesn't require any
message subclassing or hooking. First step is decide how you'll
identify the textbox from any other child windows in the same parent
window. I'd suggest using the Spy++ utility on a running instance to
obtain it's child ID which, unlike the hwnd, will not change from one
instance to the next.
Then at runtime, you can use the ID with GetDlgItem to obtain the
textbox hwnd. Once you have the hwnd, you can send the textbox
WM_GETTEXTLENGTH, WM_GETTEXT messages to get the contents. There are
also some Api functions (GetDlgItemText or SendDlgItemMessage) that
will take the ID directly. Ultimately however when dealing with
another process I'd suggest using SendMessageTimeout as it won't lock
your app if the other app is hung or busy. Whichever method you
choose, you can use it in conjuction with a Timer to periodically
check the contents.
Intercepting the other app's messages is only necessary if you need
notification as to ~when~ the textbox contents change (i.e a "Change"
event) instead of using a Timer. Essentially you would need to detect
when the ~parent~ receives an EN_CHANGE notification (via a WM_COMMAND
message) for that particular child textbox. This will involve the use
of a Windows hook (SetWindowsHookEx) which for hooking another process
requres a separate standard (C) dll. There are some excellent (and
free) hook dlls for this sort of thing at http://www.mentalis.org/
-Tom
MVP - Visual Basic
(please post replies to the newsgroup)
- Next message: Mike D Sutton: "Re: How to get an associated file icon without the Alpha Channel i"
- Previous message: Mike D Sutton: "Re: How to get an associated file icon without the Alpha Channel i"
- In reply to: Charlie Burnham: "getting text from external application"
- Messages sorted by: [ date ] [ thread ]