Home » U++ Library support » U++ Callbacks and Timers » How to set a TimeCallback
How to set a TimeCallback [message #50667] |
Sun, 02 December 2018 00:48 |
|
forlano
Messages: 1185 Registered: March 2006 Location: Italy
|
Senior Contributor |
|
|
Hello,
after reading many posts on the forum I am not able to realize what I want.
After pressing button btnStart the program begin to read a sequence of words. This is done via the SAPI library (text to speech). However I want permit the user to stop the reading at any time, button btnStop, even before the end of the sequence. To do it I used a SetTimeCallback linked to the callback Play. This is one of the version I used:
void VegaTab3::Start()
{ btnStart.Disable();
btnStop.Enable();
int int_row = arrp.GetCursor();
if (int_row < 0) return; //prevent the crash of the application when int_row = -1)
for (int i = int_row; i<arrp.GetCount(); i++) {
SetTimeCallback(500, THISBACK1(Play, i));
}
btnStart.Enable();
btnStop.Disable();
}
void VegaTab3::Play(int i)
{
ISpVoice * pVoice = NULL;
if (FAILED(::CoInitialize(NULL))) return ;
//std::wstring in = L"";
WString in;
HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
if(SUCCEEDED(hr))
{
//...
// select a word
// ...
hr = pVoice->Speak((LPCWSTR)in, NULL, NULL); //play it
pVoice->Release();
pVoice = NULL;
}
::CoUninitialize();
}
void VegaTab3::Stop()
{
KillTimeCallback();
btnStart.Enable();
btnStop.Disable();
}
Unfortunatly, in all my temptive, the btnStop cannot be pressed and the reading proceede till the end before I get again the control of the program. It is like the btnStop is freezed.
So the problem is: how to use the timecallback, or any other mean, to start a loop and stop it at any time?
Thanks,
Luigi
|
|
|
Goto Forum:
Current Time: Fri Apr 19 09:29:55 CEST 2024
Total time taken to generate the page: 0.02572 seconds
|