AfxBeginThread and EndThread
-
Dear all, I'm writting a MFC program that enables the user to enter the URL, and then press "Start" button to start downloading the html from that URL. So I have create a WorkerThread to handle the downloading process so that the user can press "Stop" button to terminate the downloading process. After successful or unsuccessful downloading of html, it should call a Text-to-speech function to speak to the user about the status of download. However, the text-to-speech function cannot work when there is another thread running. I have tried to create another thread to call the TTS function, but it failed too. My question is :where does the thread return when it finished?? Is there anyother method to call my TTS() function when the thread is finished? Here is my program: // myappdlg.cpp static UINT workerthreadcontrol ( void * pRTclass ) void myappdlg.OnStart() { downloadHTML(); } void downloadHTML() { ..... CWinThread* pWorkerThread; pWorkerThread = AfxBeginThread ( workerthreadcontrol, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED ); m_Startbtn.EnableWindow( False ); m_Stopbtn.EnableWindow( True ); pWorkerThread->ResumeThread(); ..... } UINT workerthreadcontrol( void * pRTclass ) { myappdlg pDlg = (myappdlg*) pRTclass; pDlg->WorkerThreadProcess(); return 0; } void WorkerThreadProcess() { doing downloading......... } // Where should I put this function??? void TTS( LPCTSTR Text ) { Speak out Text..... } Thanks a lot for your help.... Best Regards, Vickie
-
Dear all, I'm writting a MFC program that enables the user to enter the URL, and then press "Start" button to start downloading the html from that URL. So I have create a WorkerThread to handle the downloading process so that the user can press "Stop" button to terminate the downloading process. After successful or unsuccessful downloading of html, it should call a Text-to-speech function to speak to the user about the status of download. However, the text-to-speech function cannot work when there is another thread running. I have tried to create another thread to call the TTS function, but it failed too. My question is :where does the thread return when it finished?? Is there anyother method to call my TTS() function when the thread is finished? Here is my program: // myappdlg.cpp static UINT workerthreadcontrol ( void * pRTclass ) void myappdlg.OnStart() { downloadHTML(); } void downloadHTML() { ..... CWinThread* pWorkerThread; pWorkerThread = AfxBeginThread ( workerthreadcontrol, this, THREAD_PRIORITY_NORMAL, 0, CREATE_SUSPENDED ); m_Startbtn.EnableWindow( False ); m_Stopbtn.EnableWindow( True ); pWorkerThread->ResumeThread(); ..... } UINT workerthreadcontrol( void * pRTclass ) { myappdlg pDlg = (myappdlg*) pRTclass; pDlg->WorkerThreadProcess(); return 0; } void WorkerThreadProcess() { doing downloading......... } // Where should I put this function??? void TTS( LPCTSTR Text ) { Speak out Text..... } Thanks a lot for your help.... Best Regards, Vickie
If I understand, your problem is you need to know exactly when the worker thread has quit? Right before the return in the thread function, post a message (WM_APP would do) to your dialog to tell the UI thread that the worker thread is done. --Mike-- http://home.inreach.com/mdunn/ The preferred snack of 4 out of 5 Lounge readers.