Re: multithreading(graphics)
Hi,
Sounds like you are doing some realtime plotting there. Are you doing the acquisition yourself, or are you reading the data from a pre-made file? (It gets more complicated if you are doing the acquistion too...)
I've written a few programs like this. You have a lot of options:
1) For the plotting, look at some of the samples on this site (in the misc section). They should handle the drawing part of the task. It's not hard to make the different "channels" different colors, or to turn them on or off. What is difficult to do is to make the graph redraw smoothly and quickly. The samples on this site use a memory dc and PolyLine to redraw. You will want to do the same (assuming you can't just use their code directly).
2) If this is to be a done rather quickly, look at buying a commercial graphing control (if you have the money...). Most of them will allow to fill them in a timer callback...
3) I'm assuming that you want to plot only once every second. Is this correct? You might not need to multithread at this speed. The user won't be able to distinguish between once every second and once every 1.01 seconds. A simple window timer may suffice.
4) The idea is that you have a Start and Stop button. When the user hits Start, the timer starts to call a callback function periodically. In the callback, just grab the data from the file, update the new position in the file (for next time), and load the data into your chart control and call Invalidate. Then update the x-point (time) position for next time. If you are using multiple threads, then the callback is in a different thread (but is much more complex). Note: The multimedia timer callback is always in a different thread. Pass it a HWND to your view to pass data... (or a CWnd*, I'm not sure what the consensus is now).
If you have to multithread, and are using the doc/view system. Think about just using the callback to post a message back to the view (i.e. WM_UPDATE_DATA_NOW). This message could contain the updated file position etc. In your View handler of this message (i.e. OnUpdateDataNow()), do all of your drawing. It will be much easier to grab gdi resources in the view class, then to try and do it accross threads. You can use CEvents to signal the other thread that its ok to pass the next data. That way, at high speeds, you don't flood the message queue.
Another tip: Use memory mapped files. This will allow you to access the entire data file as an array. Windows will take care of buffering, postitioning etc. They work well. (See the book "Advanced Windows" for details).
I hope this will help.
Harvey Hawes
Software Engineer
BioScience Analysis Software Ltd.
Masters Candidate
Cardiovascular/Respiratory Sciences
Faculty of Medicine
University of Calgary
Calgary, Alberta, Canada
Re: multithreading(graphics)
Hi,
If you need help with multi-threading for this kind of process, you can try to ask. I have written a real-time acquisition program working with worker threads (including timing control, message posting, main view updating, etc)...
If I can help...