multi-thread question, perhaps
-
I am writing a program where I want a sound file to play while I update the main window. I have everything implemented with the sndPlaySound() function, but when the program runs, it becomes unresponsive as long as the sound clip is running. That is, if the user tries to move the window, the whole thing goes white until the function that is updating the window is finished as well as the sound has stopped playing. I implemented a second thread to try to do nothing but call the sndPlaySound function, but that did not work either. It played the sound, but the window still goes unresponsive if anything interrupts in my functions. Does anyone have ideas on how to do this properly? I have searched through the multi-threaded posts, but haven't found anything so far. Please help, if possible. Or point me in another direction on how to implement this properly. Thanks.:confused:
-
I am writing a program where I want a sound file to play while I update the main window. I have everything implemented with the sndPlaySound() function, but when the program runs, it becomes unresponsive as long as the sound clip is running. That is, if the user tries to move the window, the whole thing goes white until the function that is updating the window is finished as well as the sound has stopped playing. I implemented a second thread to try to do nothing but call the sndPlaySound function, but that did not work either. It played the sound, but the window still goes unresponsive if anything interrupts in my functions. Does anyone have ideas on how to do this properly? I have searched through the multi-threaded posts, but haven't found anything so far. Please help, if possible. Or point me in another direction on how to implement this properly. Thanks.:confused:
You can use the
SND_ASYNC
flag... Look up the documentation for thePlaySound(...)
function. Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
You can use the
SND_ASYNC
flag... Look up the documentation for thePlaySound(...)
function. Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFilesI am already using the SND_ASYNC flag on sndPlaySound function. It seems that the drawing of the window doesn't happen once the user clicks anything in the window.
-
I am already using the SND_ASYNC flag on sndPlaySound function. It seems that the drawing of the window doesn't happen once the user clicks anything in the window.
Are you using any other flags? You might not be combining them correctly. I have used the
SND_ASYNC
flag lots of time and never had it stall anything like you are describing. You do not have any code that is waiting for the sound to finish, do you? Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
Are you using any other flags? You might not be combining them correctly. I have used the
SND_ASYNC
flag lots of time and never had it stall anything like you are describing. You do not have any code that is waiting for the sound to finish, do you? Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFilesNo, I am not using any other flags in the sndPlaySound function. That seems to be working. What i am having a problem with (now that I look at it further), is in my ability to update the window as I need to. I am using a simple 'wait until X amount of time has passed', then I update some values, call Invalidate(); followed by a UpdateWindow(). This all works unless, in the middle of my function where I am drawing the window, the user clicks my window. Then, it doesn't update until the very end of the function and I am not sure why. I originally thought that maybe having the sound play on another thread would help, but it isn't.
-
No, I am not using any other flags in the sndPlaySound function. That seems to be working. What i am having a problem with (now that I look at it further), is in my ability to update the window as I need to. I am using a simple 'wait until X amount of time has passed', then I update some values, call Invalidate(); followed by a UpdateWindow(). This all works unless, in the middle of my function where I am drawing the window, the user clicks my window. Then, it doesn't update until the very end of the function and I am not sure why. I originally thought that maybe having the sound play on another thread would help, but it isn't.
If your "wait until X amount of time has passed" implementation is a blocking one, like calling
Sleep(...)
or going into a spin, you will not be able to pump any messages, so you will not get the Paint message to update the screen. For example, if you are trying to do some cheap animation using old-school-style techniques in a loop, it will not work the same under Windows. If you are doing the above, you can change your wait to use a Timer message, and then when the timer message fires, you can do your updates. Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
If your "wait until X amount of time has passed" implementation is a blocking one, like calling
Sleep(...)
or going into a spin, you will not be able to pump any messages, so you will not get the Paint message to update the screen. For example, if you are trying to do some cheap animation using old-school-style techniques in a loop, it will not work the same under Windows. If you are doing the above, you can change your wait to use a Timer message, and then when the timer message fires, you can do your updates. Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFilesThank you for the help. Can you point me in the direction of Timer message info? I have never heard of this before. Thanks again. Josh
-
Thank you for the help. Can you point me in the direction of Timer message info? I have never heard of this before. Thanks again. Josh
Look up the
WM_TIMER
message and theSetTimer(...)
function. If you need high-accuracy timers, look up multimedia timers. Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFiles -
Look up the
WM_TIMER
message and theSetTimer(...)
function. If you need high-accuracy timers, look up multimedia timers. Peace!-=- James
Please rate this message - let me know if I helped or not! * * *
If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
See DeleteFXPFilesThat was it, thank you. I appreciate the help.:)