Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to previous message
forlano is currently offline  forlano
Messages: 1105
Registered: March 2006
Location: Italy
Experienced 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
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to properly set a timer
Next Topic: Setting a timer to call Ctrl::Refresh in Ctrl::Paint()
Goto Forum:
  


Current Time: Mon Aug 03 16:35:58 CEST 2020

Total time taken to generate the page: 0.00867 seconds