callback avec CALLBACK_WINDOW, waveOutOpen
Bonjour,
Je suis en pleine réalisation d'un petit projet pour manipuler les fichiers wave. J'ai réussi à faire les fonctions nécessaires pour ouvrir le fichier et le lire avec les fonction waveOut... de l'API windows. J'ai maintenant un nouveau problème : j'ai mis en place une fonction de callback, mais elle ne s'exécute pas (le code me semble bon en comparant aux diverses sources que j'ai et la doc ne contredit pas ce code).
in the class (into .h file) :
Code:
1 2 3 4 5 6
|
public: // User declarations
__fastcall TForm1(TComponent* Owner);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(MM_WOM_DONE, TMessage, onWaveDone)
END_MESSAGE_MAP(TForm) |
in the .cpp file :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
void TForm1::onWaveDone(TMessage& msg) // as a waveClose() function
{
// We only care about the WOM_DONE message.
// When we get this message we know that the
// sound has finished playing. We can then
// unprepare the header and close the device.
if (msg.Msg == WOM_DONE) {
int Res = waveOutUnprepareHeader(projectWaveHandle, &projectWaveHeader, sizeof(WAVEHDR));
Memo1->Lines->Add("Playback finished : header unprepared");
CheckWaveError(Res);
Res = waveOutClose(projectWaveHandle);
Memo1->Lines->Add("Wave closed");
CheckWaveError(Res);
}
} |
Quand je lance waveOutOpen :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| bool TForm1::openWave()
{
// Query the device and see if it can play
// this wave format. If so, open the device.
int Res = waveOutOpen(&projectWaveHandle, WAVE_MAPPER, &projectFormat, 0, 0, WAVE_FORMAT_QUERY);
Memo1->Lines->Add("Device checked");
CheckWaveError(Res);
// we have to use a callback function when we play, to detect the end
// CALLBACK_WINDOW tells Windows that we want any wave-out messages sent to our form's window procedure
// so the form will treat this callback with onWaveDone()
if(waveOutOpen(&projectWaveHandle, WAVE_MAPPER, &projectFormat, 0, 0, CALLBACK_WINDOW)!= MMSYSERR_NOERROR)
{
return false;
}
return true;
} |
enfin, la fonction waveOutWrite est exécutée juste après l'appel de la fonction openWave(). Je ne vois pas d'où ne viens pas l'exécution ??
Des idées ??
Merci