Solved

Grab text as it arrives in a RichEdit belonging to an external chat program?

Posted on 2006-06-11
24
1,017 Views
Last Modified: 2013-11-22
I'm creating a C# app which will monitor a chat program's main chat window (a RichEdit control).  I've successfully coded to grab the handle to the RichEdit control, and do stuff like grab the last line of text (using SendMessage along with EM_GETLINE, for example).

However, I'm stumped on how to fire off an event to my C# app when new text enters the foreign chat window. For example, if someone says "hi", I want my app to be able to react and grab the text.  Specifically, the chat program appears to fire off an EM_REPLACESEL message containing the new text.

I need details on how to make it so that my app can be made aware of new text arriving in the foreign app's RichEdit control, so that I can then process the new text.  I don't want to poll for new messages, rather I want to be able to respond to an event created as a result of new text arriving in the RichEdit control.  Maybe using a local hook?  I don't know.

The person providing the best, most detailed solution wins all 500 points.  Please help, thanks.  :-)
0
Comment
Question by:Zoplax
  • 11
  • 8
  • 3
  • +1
24 Comments
 
LVL 4

Expert Comment

by:programmer1024
ID: 16882134
Maybe you want to use the TextChange event? That will fire everytime a key is pressed though, so you'd have to find out when they stopped entering text.
0
 
LVL 6

Author Comment

by:Zoplax
ID: 16883036
The chat application is external to my own, and isn't a C# or .NET application, and also I don't see the users' keypresses just the messages, so I don't know how to access its events other than through Windows messaging.
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 16883233
try to create a windows service that write keystrokes to alog file instead of windows application..
cheers
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 6

Author Comment

by:Zoplax
ID: 16883355
Again my app won't be running such that it can capture user keystrokes at all, it runs alongside the chat program and can only see incoming lines of text from users, not watch them as they type.  Writing keystrokes won't work at all in this case.
0
 
LVL 5

Expert Comment

by:shtson
ID: 16909895
Hai2u,

Have you tried hooking the WndProc of that specific control (I am guessing you have that controls handle) - it should work the same way as you would hook a window. After that is done, open up spy++ and find that control - hook its messages and observe what kinds of messages are received upon text update. You simply add, in your code, a call to the methods you say already work, when that message is received to the WndProc

Lookup: SetWindowsHookEx for the hooking api, and don't forget to remove it :)

Hope I help,
Cheers
Shai
0
 
LVL 6

Author Comment

by:Zoplax
ID: 16910792
Shai I think I've seen some examples illustrating what you're talking about; if I understand correctly, the WndProc is overridden in my app so that I can see all messages arriving to the RichEdit control, and then I would create an event handler which watches the control's messages intercepted by my WndProc...?

Some sample code would be a big help here.  
0
 
LVL 5

Expert Comment

by:shtson
ID: 16910853
Hai2u again,

Yes, but each control is a sort of small windows application on its own, makes you able to catch the messages dropped to that specific control only.

http://support.microsoft.com/default.aspx?scid=kb;en-us;318804 has the out of the box solution. I'll try making you one that actually does what you need during the day (at work, kinda hellish today xD)

Cheers,
Shai

0
 
LVL 6

Author Comment

by:Zoplax
ID: 16922204
Thanks much!  I look forward to seeing your example.  
0
 
LVL 6

Author Comment

by:Zoplax
ID: 16943277
Shai, any luck?  So far you're the prime contender for the points if you're able to provide me a solution.

0
 
LVL 5

Expert Comment

by:shtson
ID: 16943329
Hey Zoplax,

I aint doing this for the points lol :p

But no, I hadn't the time to try doing a full sample here, as i said before - work is hellish...

I have not forgotten and if you dont mind waiting - I will probably have time in the next few days.

FYI, answers are usually not fully coded things - but mostly leads to a solution. This site, after all, is not rent a coder for free ;)

Meanwhile - I do suggest reading the sample by microsoft - it helps alot

Cheers,
Shai
0
 
LVL 6

Author Comment

by:Zoplax
ID: 16946244
No I'm fine with waiting; I've done a lot of my own research but I don't have enough experience under my belt to try some of the ideas I've read about so far.  And my own work is hellish on its own, so much so that lately I've wanted to stay away from my computer as much as possible on my off time.  :-D

I know this isn't a rent-a-coder site too btw, this is just the third time I've asked a question specific to what I'm trying to do here, and so far yours is the best response I've gotten; the other questions are abandoned with no fruitful replies.  

I will check out that sample in the meantime and try to apply it to my C# app for what I'm trying to do.
0
 
LVL 6

Author Comment

by:Zoplax
ID: 16947304
Shai, here's something I found which I'd appreciate your or anyone else's opinion about:

http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/889cf15d69810336/83e8b766cdf7a15d?lnk=st&q=GetMsgProc+csharp&rnum=1&hl=en#83e8b766cdf7a15d

This posting describes some code which appears to hook into a process by its Thread ID.  The hook they use (WM_GETMESSAGE) I think would enable me to monitor the messages I need to keep track of in the chat program.  Would I be able to utilize a similar method to this if I can grab the thread ID of the chat application instance?  And if so, how would I get a thread ID in this way?

0
 
LVL 5

Expert Comment

by:shtson
ID: 16949338
Hello again,

Yes, it's uses the same API as the microsoft link I provided earlier.

Actually, today is abit less hectic and I might do it in the next few hours :P

What I'm going to do is this:

Create a winform app with a rich text box.
Create a winfrom app that hooks the other app and loggs events from the rich text box

Would that be what you need?

Cheers,
Shai
0
 
LVL 5

Expert Comment

by:shtson
ID: 16949988
Zoplax,

I've looked into the problem a little more, and what I've found out is this: http://msdn.microsoft.com/msdnmag/issues/06/04/ManagedSpy/

what you should be doing is read through all the document explaining what is the managed spy

and the next thing you should do is download the ManagedSpyLib from Microsot (.NET 2.0)

In the library, you will find ControlProxy which represents a control in a different process (a problem with managed code hooking)

You should create a instance of that class using ControlProxy.FromHandle and send the handle (which you wrote you had)

After you've done that - you may access all the events and access the values of the control.

This library is built on C++ unmanaged code.

I personally work with .NET 1.1 - Thus cannot create a sample for you using that library

Hope you can manage,
Cheers,
Shai
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 16950103
hi there...sorry for being late..

you can find these two projects very usefull especially the first one..but it is in VB:

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=2971&lngWId=10

http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=3080&lngWId=10


GOOD LUCK
0
 
LVL 6

Author Comment

by:Zoplax
ID: 16951133
t_itanium, please read the above posts, I do NOT need code for a keylogger.  Again, the application I'm trying to monitor has a RichEdit control which is used for chat messages, but I'm not running the monitoring app on the chat users' PCs, this is running solely on my PC and the chat messages are arriving via that program, not through the keyboard.  Thanks anyway.

Shai, I will look at the info you linked me to, yeah I figured there would be complications since the program I'm monitoring isn't .NET itself.
0
 
LVL 5

Expert Comment

by:shtson
ID: 16951151
Zoplax,

Its not a complication of the target application
It's just that the windows API has a little problem with accessing different processes' hooks - its not impossible - but totally pointless to implement on ur own when they release a library that does everything that Spy++ does with no effort :P

Cheers and Good luck
Shai
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 16951324
hi again...
here what you  can do.... you can use what i gave you as aprogram that run on the chat computer ...or a service.....and you can use .net remoting that allow this program or service to send information to your PC via tcp ip or any other ...

cheers
0
 
LVL 6

Author Comment

by:Zoplax
ID: 16953120
t_itanium, I don't have access to the remote computers at all, just to the instance of the chat program that's running on my computer and seeing the messages arrive in its RichEdit control.

So far Shai's suggestion about the ManagedSpyLib sounds like the most promising solution.  I'm going to take a closer look and see if I can code a sample to test it out.
0
 
LVL 6

Author Comment

by:Zoplax
ID: 17134558
Sorry it's been a while.  Shai, I read the ManagedSpy article more closely and it sounds like it won't work for my application.

"...ManagedSpy can only show information on .NET Framework-based controls, it doesn't display other window types."

"ManagedSpy is written on top of a *managed* [NOT unmanaged] C++ library called ManagedSpyLib. The purpose of ManagedSpyLib is to allow *programmatic access to .NET Framework-based windows* in another process."

Based on this it sounds like it won't do, the application I'm trying to monitor is NOT .NET based, it was written in non-.NET (unmanaged) C++.  If this is indeed the case, any other suggestions?
0
 
LVL 5

Accepted Solution

by:
shtson earned 500 total points
ID: 17138498
Hey again,

Maybe the following article:
http://www.vbaccelerator.com/home/vb/code/libraries/Hooks/vbAccelerator_Hook_Library/article.asp

but I think there will always be a problem to hook a different process - and for that - you need hacking (and there are NO guides for that)

Cheers,
Shai
0
 
LVL 6

Author Comment

by:Zoplax
ID: 17373037
The accepted solution will be more work than I'd preferred, but it's the best idea so far.
0
 
LVL 5

Expert Comment

by:shtson
ID: 17373137
If it was easy, you wouldn't be asking in ee - would ya ;)

Cheers and Thank you,
Shai
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
This is about my first experience with programming Arduino.

831 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