Thread: C++ text editor .NET

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    38

    C++ text editor .NET

    I want a text editor that can open a file in the same format the file is saved in. Everything works except for the editor opening the file in the same format that the file was saved in.

    Suggestions?

    Here's the code for the Save and Open buttons. I assume that is
    the problem.
    Code:
    	private: System::Void OpenBtn_Click(System::Object *  sender, System::EventArgs *  e)
              {
    	OpenFileDialog * fd = new OpenFileDialog();
          if(fd->ShowDialog() == DialogResult::OK)
             { 
    	FileStream * fs = new FileStream(fd->FileName, FileMode::Open);
    	StreamReader * sr = new StreamReader(fs);
    	String * Delimiter1 = sr->ReadLine();
    	 if(Delimiter1 = "$$")
                            String * fontName = sr->ReadLine();
    	else
                            sr->Close();
    	 String * Delimiter2 = sr->ReadLine();
    	 if(Delimiter2 = ";")
    	     int * fontSize = sr->ReadLine();
    	else
    	      sr->Close();
    	String * Delimiter3 = sr->ReadLine();
    	if(Delimiter3 = "$$")
    	{
    	     String * s = sr->ReadToEnd();
                         textBox1->Text = s;
    	}
    	 sr->Close();	
    	}
     }
    
    	private: System::Void SaveBtn_Click(System::Object *  sender, System::EventArgs *  e)
    	 {
    	SaveFileDialog * fd = new SaveFileDialog();
        if(fd->ShowDialog() == DialogResult::OK)
    	{
    	FileStream * fs = new FileStream(fd->FileName, FileMode::OpenOrCreate);
    	StreamWriter * sw = new StreamWriter(fs);
    	sw->WriteLine("$$");
    	sw->WriteLine(textBox1->Font->Name);
    	sw->WriteLine(";");
    	sw->WriteLine(textBox1->Font->Size);
    	sw->WriteLine("$$");
    	sw->WriteLine(textBox1->Text);
    	sw->Flush();
    	sw->Close();
    	}
     }
    Last edited by MB1; 02-23-2006 at 12:30 PM.

  2. #2
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Hi,

    This is a C++ forum. What you posted is not C++, so you may want to seek out another forum.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    the file needs to have formatting instructions at the beginning of the file. Most text files do not have that information. For example, files created by MS-Word have all the formatting instructions embedded in the file, which is why you see a bunch of funny-looking bytes when the file is read by a text editor such as Notepad.exe.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    Quote Originally Posted by 7stud
    Hi,

    This is a C++ forum. What you posted is not C++, so you may want to seek out another forum.

    sure looks like c++ to me although there appears to be a few bugs.
    Last edited by Ancient Dragon; 02-23-2006 at 12:37 PM.

  5. #5
    Registered User
    Join Date
    Feb 2005
    Posts
    38
    Quote Originally Posted by 7stud
    Hi,

    This is a C++ forum. What you posted is not C++, so you may want to seek out another forum.
    It's Visual C++ actually. (Maybe not too good though.)

  6. #6
    Registered User
    Join Date
    Feb 2005
    Posts
    38
    Quote Originally Posted by Ancient Dragon
    the file needs to have formatting instructions at the beginning of the file. Most text files do not have that information. For example, files created by MS-Word have all the formatting instructions embedded in the file, which is why you see a bunch of funny-looking bytes when the file is read by a text editor such as Notepad.exe.

    I'm using notepad to test the save info. Notepad shows:

    $$
    arial
    ;
    12
    $$
    My text that I have saved to a file.

    So I know the info is being saved properly. When I open the text in my editor, the text opens in the editors default format.

  7. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    I got confused by:
    Code:
        private: System::Void 
    ...
    ...
    }

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> It's Visual C++ actually.

    It's generally called Managed C++. Visual C++ usually refers to the IDE that lets you write managed or unmanaged C++ code.

  9. #9
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    So, the code you posted is not anything you wrote, but a macro that the compiler uses on the Save and Open menu items??? If that is true, then 7stud is right -- wrong forum. you need to go on Microsoft's development forums and ask them why it doesn't work.

  10. #10
    Registered User
    Join Date
    Feb 2005
    Posts
    38
    I wrote all of the code except the two lines that start:

    private: System::Void OpenBtn_Click....

    and

    private: System::Void SaveBtn_Click.....

    These two lines are what the compiler writes and then I write the rest of the code as to what I want the Open and Save buttons to do.

    I think the open button is where I messed up.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM
  5. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM