[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Code to monitor a chat window?

Posted on 2006-05-01
11
Medium Priority
?
363 Views
Last Modified: 2008-02-01
I need code which will process messages I grab from a control within a chat window (a RichEdit control).  The code needs to monitor the control and copy text meeting certain criteria (e.g. with certain usernames in the line).

One hitch, the control exists outside the scope of my C# program.  I am "spying" on a process in a separate chat program to be able to pluck out the data from the RichEdit control.  Because of this I don't think I would be able to access the event model (e.g. Change event) of the foreign application, instead I need to read the control (using SendMessage along with EM_GETLINE and others), load the data into a StringCollection or other object within the scope of my C# app, and then process the data.

Would it be best to use a WHILE loop, within which I constantly poll the RichEdit control for new messages, and only act if a new message arrives that needs to be processed?  Or is there some other way?


0
Comment
Question by:Zoplax
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 12

Expert Comment

by:topdog770
ID: 16579690
Take a look at this, shows how to create a C# app similiar to Spy


http://msdn.microsoft.com/msdnmag/issues/06/04/ManagedSpy/
0
 
LVL 6

Author Comment

by:Zoplax
ID: 16589177
That's helpful but I need something more specific to what I'm trying to do.

The chat window I want to monitor will be changing constantly, new lines will appear in the RichEdit control while the chat program is running.

I need to have it so that my C# application knows when a new line of text has been added to the chat window (the RichEdit control in a foreign process), so it can then use SendMessage to retrieve that line of text and place it in a StringCollection or other array type of object for further processing.
0
 
LVL 7

Expert Comment

by:jj819430
ID: 16591620
You are probably going about this in the wrong way.
Do a keyStroke monitor and only monitor when the app you want has focus.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Author Comment

by:Zoplax
ID: 16596508
Well the thing is I already have functional C# code which gets the data I need; I have code which uses the Windows API to find a handle to the chat window, find a handle to the RichEdit control, and then uses SendMessage along with EM_GETLINE to get the text contained in the control.

The main issue for me now is how to get the data out of the control as it's getting updated.  Do I constantly poll using a WHILE loop (doable but wasteful) or can I somehow tap into the events of the foreign RichEdit control so that my program knows when new text has been added, and only acts at that point in time?  

I know this can be done, I've seen articles related to this, but I don't know enough about hooks to code this myself.  Before I invest the time to research and figure out a way myself I'm offering up the points to see if anyone here will be able to provide sample code for me to serve this need.  :)
0
 
LVL 12

Expert Comment

by:topdog770
ID: 16597030
Assuming that the program you are trying to monitor is a .NET app, the code in that spy program should do exactly what you are trying to accomplish.
0
 
LVL 7

Expert Comment

by:jj819430
ID: 16597963
well you can specify a delay. Unfortunately you are not going to get an event for this that you can hook into. You can listen for keystrokes and use that as a means of triggering, but essentially no matter what you are going to end up with a loop checking system.
0
 
LVL 6

Author Comment

by:Zoplax
ID: 16598421
topdog770:  No the app in question isn't a .NET app.

jj819430:  I found a link to an example where someone created a DLL using C++ to hook into a program, then had that DLL interface with a separate C# program so that the DLL served as a kind of middleman to forward events from the program to the C# app.  Here are the links that person provided:

The C++ DLL project:
http://evemon.evercrest.com/svn/eve...EVEMon.WinHook/

A C# class that loads it up, installs the global hook, and listens for the signals from it:
http://evemon.evercrest.com/svn/eve...kup&pathrev=202

0
 
LVL 12

Expert Comment

by:topdog770
ID: 16598535
cool, thanks for the links!
0
 

Accepted Solution

by:
GranMod earned 0 total points
ID: 16968204
PAQed with points refunded (222)

GranMod
Community Support Moderator
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Integration Management Part 2
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…

873 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