Click here to Skip to main content
15,904,652 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The Code is updated as below now I am able to restart but the not able to stop untill I Click button again.
C++
void CDemoDlg::ReadFileTxt()
{
	
	CFileException fileException;
       if (readFile.Open(strFilePath, CFile::modeRead, &fileException))
       {
            while ((stopSong==true )&&readFile.ReadString(strLine)){}
           
        }
}


void CDemoDlg::OnBnClickedSongPlay()
{
if(stopSong==true)
{
	
	
	stopSong=false;
	readFile.Close(); /*stops but resumes immediately so could not recognize that it actually stopped*/

	
}
else
{
	stopSong=true;
	OnLbnSelchangeListSongs();
	
}

}
Posted
Updated 12-Mar-12 17:40pm
v5
Comments
Herman<T>.Instance 12-Mar-12 7:05am    
What have you tried?
Chandrasekharan P 12-Mar-12 7:15am    
Your question is not clear.
On what condition should the program stop reading the file?
Are you using some kind of a GUI? if yes, then is it come control that is stopping the reading of the text file?

Elaborate your query. It makes people here to visualize it better.
chaiein 12-Mar-12 7:22am    
if (readFile.Open(strFilePath, CFile::modeRead, &fileException))
{
while (readFile.ReadString(strLine))
{
}


I have opened the file and able to read string but i want to stop, in between when i click on a button and resume or restart.
Nelek 12-Mar-12 15:07pm    
chaiein, if you want to add some code of what you are trying or where you are having problems, please use the "improve question" to add it on the original message. If you only use a comment in an answer, it can be not seen by other users.
chaiein 12-Mar-12 23:02pm    
ya sure thanks:)

You should put the reading stuff inside a worker thread and signal to such thread the 'stop reading' condition from the GUI one (i.e. the main thread) setting a flag.
e.g.
C++
// worker thread, the 'stop_reading' variable is set by the GUI thread on button click
if (readFile.Open(strFilePath, CFile::modeRead, &fileException)) 
{ 
    while (readFile.ReadString(strLine) && stop_reading == false) { }
} 
 
Share this answer
 
Comments
chaiein 12-Mar-12 8:03am    
when i give this i am not able to read only its not entering the loop
CPallini 12-Mar-12 9:02am    
Well, as a start condition (before actually starting the thread), the GUI thread should set stop_reading = false;
chaiein 12-Mar-12 23:20pm    
This solved my problem in avoiding the warning message while opening same file again and agian.

i have stopsong=false then read.Close(); This still continues playing.

Second time when i click on the button it goes to else
chaiein 12-Mar-12 23:25pm    
it stops but resumes it .Actually stops but immediately resuming it. SO the stop is not recognizable.
chaiein 14-Mar-12 4:25am    
I got solved this problem i had to set the stopsong properly.Thank you :)
Now DigiManus's question comes to existance. You have a problem now which you have explained. What is that you have tried??

To give you some clues.
1. Implement the Button function
2. Use Ftell/fseek functions for resuming.
3. Close function to close the file.
 
Share this answer
 
Comments
chaiein 12-Mar-12 7:44am    
void CDemoDlg::OnBnClickedSongPlay()
{
if(stopSong==true)
{

readFile.Close();

stopSong=false;
return;
}
else
{

OnLbnSelchangeListSongs();

stopSong=true;
}
return;
}



After close the Readfile is still continues what is the problem in the code above?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900