I am trying to make a Soundscape in c++ using Visual Studio 2010.
The program allows playing sound. To stop the music, it uses Keybaord and Mouse as detection devices.
The problem that I am having, when the program detected the keyboard/mouse, it doesn't stop immediately. It requires to play the music until the end then be able to stop.
I hope the program can stop the sound file immediately when program detected the keystrokes are pressed or the mouse is moved.
Hope everybody can give me a hand to solve this problem.
Many Thanks!
here is the code that you may want to have look and help for my improvement.
The WM_PAINT message is probably the worst place to put PlaySound(). Have you monitored how many times this message is received? Check it out and you'll see what I mean. This is probably creating the problem too.
The correct way would be to start the sound asynchronously when the screensaver starts and then cancel it also using PlaySound() (see the function's documentation for details) when input is detected.