Problems of Updating contents in an Edit box in vc6
-
Hi all, I am writing a VC++6.0 application. I need to read from a text file and display the file content in an Edit Box. I use the following codes: CEdit m_fileContent; CFile pFile; m_fileContent.SetWindowText(""); //clear pFile.open(.....); int length = pFile.GetLength(); CString* strContent = new CString(""); pFile.Read(strContent->GetBuffer(0),length); m_fileContent.SetWindowText(strContent->GetBuffer(0)); //update file content strContent->ReleaseBuffer(0); delete strContent; pFile.Close(); Now the problem is: When I first opened a file, it's fine. But When I opened a second file, if the length of the first file is longer than that of the second file, the content is not cleared. Any ideas? thanks, Gavin
-
Hi all, I am writing a VC++6.0 application. I need to read from a text file and display the file content in an Edit Box. I use the following codes: CEdit m_fileContent; CFile pFile; m_fileContent.SetWindowText(""); //clear pFile.open(.....); int length = pFile.GetLength(); CString* strContent = new CString(""); pFile.Read(strContent->GetBuffer(0),length); m_fileContent.SetWindowText(strContent->GetBuffer(0)); //update file content strContent->ReleaseBuffer(0); delete strContent; pFile.Close(); Now the problem is: When I first opened a file, it's fine. But When I opened a second file, if the length of the first file is longer than that of the second file, the content is not cleared. Any ideas? thanks, Gavin
CEdit m_fileContent; CFile pFile; m_fileContent.SetWindowText(""); //clear pFile.open(.....); int length = pFile.GetLength(); //CString* strContent = new CString(""); // why are you putting CString on the heap? This is a waste. CString strContent = _T(""); pFile.Read(strContent.GetBuffer(0),length); strContent.ReleaseBuffer(); m_fileContent.SetWindowText(strContent); //update file content //strContent->ReleaseBuffer(0); // need to do this before using the buffer anywhere //delete strContent; // not needed pFile.Close();
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
Hi all, I am writing a VC++6.0 application. I need to read from a text file and display the file content in an Edit Box. I use the following codes: CEdit m_fileContent; CFile pFile; m_fileContent.SetWindowText(""); //clear pFile.open(.....); int length = pFile.GetLength(); CString* strContent = new CString(""); pFile.Read(strContent->GetBuffer(0),length); m_fileContent.SetWindowText(strContent->GetBuffer(0)); //update file content strContent->ReleaseBuffer(0); delete strContent; pFile.Close(); Now the problem is: When I first opened a file, it's fine. But When I opened a second file, if the length of the first file is longer than that of the second file, the content is not cleared. Any ideas? thanks, Gavin
Try:
CString strContent;
pFile.Read(strContent.GetBuffer(length), length);
strContent.ReleaseBuffer();
pFile.Close();
m_fileContent.SetWindowText(strContent);
"The largest fire starts but with the smallest spark." - David Crow
"Judge not by the eye but by the heart." - Native American Proverb
-
CEdit m_fileContent; CFile pFile; m_fileContent.SetWindowText(""); //clear pFile.open(.....); int length = pFile.GetLength(); //CString* strContent = new CString(""); // why are you putting CString on the heap? This is a waste. CString strContent = _T(""); pFile.Read(strContent.GetBuffer(0),length); strContent.ReleaseBuffer(); m_fileContent.SetWindowText(strContent); //update file content //strContent->ReleaseBuffer(0); // need to do this before using the buffer anywhere //delete strContent; // not needed pFile.Close();
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac