Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problems of Updating contents in an Edit box in vc6

Problems of Updating contents in an Edit box in vc6

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpquestionannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cppcook
    wrote on last edited by
    #1

    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

    Z D 2 Replies Last reply
    0
    • C cppcook

      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

      Z Offline
      Z Offline
      Zac Howland
      wrote on last edited by
      #2
      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

      C 1 Reply Last reply
      0
      • C cppcook

        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

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • Z Zac Howland
          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

          C Offline
          C Offline
          cppcook
          wrote on last edited by
          #4

          Thanks a lot Zac and David!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups