Hi,

I'm busy working on a word processor, and I could use a bit of help with 2 things. The Savefiledialog, and the Openfiledialog. In terms of the savefiledialog, I have all the code done, and it compiles properly:

public:
void SaveFile()
{
   SaveFileDialog^ saveFile1 = gcnew SaveFileDialog;
      
   saveFile1->DefaultExt = ".txt";
   saveFile1->FileName = "Untitled.txt";
   saveFile1->Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
   saveFile1->InitialDirectory = ::Environment::GetFolderPath::Environment::SpecialFolder::MyDocuments);
      
   if ( saveFile1->ShowDialog() == System::Windows::Forms::DialogResult::OK && saveFile1->FileName->Length > 0 )

      {
         this->txtdisplay->SaveFile( saveFile1->FileName );
      }
   }

(txtdisplay is the richtextbox) This all works well, but only one problem. Let's say we typed in the file, 'This is a test'. When you save it and then open it in notepad, this is what it looks like:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}
\viewkind4\uc1\pard\fs20 this is a test\par
}

see? a whole lot of crap is added to the text file. How can I fix this?

Second of all, I can't even think of any good C++ code for the OpenFileDialog that'll work, I searched google, and none on there either.

Thanks a ton to anyone who can help.

'This is a test'. When you save it and then open it in notepad, this is what it looks like:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}
\viewkind4\uc1\pard\fs20 this is a test\par
}

see? a whole lot of crap is added to the text file. How can I fix this?

The content is in Rich Text Format (RTF). Notepad does not understand it and hence displays it raw. Open the file with e.g. MS Word, and you'll see what you expected.

Thanks a lot, mitrmkar, no wonder they're called 'Rich Text' boxes :)

Now I need a bit of help with the OpenFileDialog. I've found a way to use it:

System::IO::Stream^ myStream;
OpenFileDialog^ openFileDialog1 = gcnew OpenFileDialog;

openFileDialog1->InitialDirectory = ::Environment::GetFolderPath(::Environment::SpecialFolder::MyDocuments);
openFileDialog1->Filter = "Text Files (*.txt)|*.txt";
openFileDialog1->FilterIndex = 1;
openFileDialog1->RestoreDirectory = true;

if ( openFileDialog1->ShowDialog() == ::DialogResult::OK )
{
	if ( (myStream = openFileDialog1->OpenFile()) != nullptr )
	{
	 txtdisplay->Text = myStream;
	   myStream->Close();
	}
}
}

However, I get the following error: cannot convert parameter 1 from 'System::IO::Stream ^' to 'System::String ^'.

Any help would be greatly appreciated.

Aah, nevermind, I just used a different syntax with the openfiledialog :)

Now, I have another question. How would you set it up sort of like Word or Notepad, So that after you open a file, you modify it, and press save, it would automatically save that document?

Sort of like how if you modify a document in word, when you close, a messagebox pops up saying, 'Save changes to Document1?'.

That's exactly what I want. A 'save changes' messagebox that pops up when you close, (if a document's open). And also, for you to be able to press 'save' and it automatically saves up without having to go through the dialog and overwriting the file.

Thanks

This question has already been answered. Start a new discussion instead.