I am developing Internet chatting. I have a question on which I need you to help me out.
Because it is for Internet use, our application is sort of a real-time application on Windows NT and Windows 95. My question is while the program is downloading and playing a wave file through the Internet, if the user clicks on some pull-down menu (actually just using a mouse to hold it) or hits F1 to activate context-sensitive Help, the program will stop playing the audio clip. Is there any way to solve this problem? I noticed that the Sound Recorder in Accessories of Windows NT will not halt under this kind of condition.
My application is SDI, and for some reason we used OnIdle() to check the event to make the program continue to play sound. Do you think PeekMessage will still work for this?
BTW, if you still have a DR. GUI T-shirt, would you mind sending me one?
Mr. Victor Dong
Wouldnt we all like to do two things at onceand do them well? As it turns out, this is a lot easier with Win32 than it was with Win16. Programs that keep doing whatever they do while the UI is working most probably use multiple background threads (which execute independently of the UI). Specifically, a strategy using OnIdle or PeekMessage wont work if your program isnt idleand it wont be idle while a menu is being held down or while a help context is being loaded. So what you need is a background thread to play the sound.
Theres tons of material on multithreading on the MSDN Library CD. As starters, Id recommend the articles Multithreading for Rookies and Multiple Threads in the User Interface. And since youre using MFC, be sure to check out the article on multithreading in the MFC Encyclopedia.
Another technique that helps applications remain responsive is to use asynchronous I/O rather than waiting for I/O to completethis is especially important when doing I/O over a network.