asalamo 3alikom
i'm using Vc++6 , i want the code to open a file from any type then i take the content of that file and put in a variable of type CString
plz help me as soon as possible
thanks 4 u all
asalamo 3alikom
i'm using Vc++6 , i want the code to open a file from any type then i take the content of that file and put in a variable of type CString
plz help me as soon as possible
thanks 4 u all
السلام عليكم ,,
استعمل الفئة CFile ,, ومرر اسم الملف ونوع طريقة الفتح للبارمتر الثاني في المشيد ,,
واستعمل الدوال الموجودة في الفئة أمثال ,, Open ,, لتحصل على البيانات الخاصة بالملف ,, في متغير CString ,, ممرر كبارمتر الى الدالة Open ,,
انتبه لحجم الملف فلو كان كبيرا فستتعب قليلا في عملية نقله من والى مكان آخر ,, أقصد بكبير فوق ال 20 ميجابايت ,,
لو كنت أمام جهازي لأعطيتك مثال مباشر ,, لكن للأسف أنا بعيد الآن !!
void CMaverickEditDlg::OnFileOpen()
{
CFileException fileException;
UINT nActual = 0;
CFileDialog D(true);
CFile MyFile;
DWORD FileSize;
if (D.DoModal() == IDOK){
FileName = D.GetFileName();
if (MyFile.Open(FileName, CFile::modeReadWrite, &fileException))
{
FileSize = MyFile.GetLength();
char *ReadBuffer = new char[FileSize];
nActual = MyFile.Read(ReadBuffer, FileSize);
MyFile.Close();
m_Text.Format("%s",ReadBuffer);
Contents = m_Text;
UpdateData(false);
delete ReadBuffer;
*ReadBuffer = NULL;
}
}
}void CMaverickEditDlg::SaveContents()
{
CFile MyFile;
CFileException FileException;
UpdateData(true);
UINT FileSize = m_Text.GetLength();
char *Buffer = new char[FileSize];
Buffer = m_Text.GetBuffer(FileSize);
if (MyFile.Open(FileName,CFile::modeWrite,&FileException))
{
MyFile.Write(Buffer,FileSize);
MyFile.Close();
}
}بالترتيب هذا كود الفتح و الكتابة من Maverick NotePad
راكان الحنيطي
Be Open Source

جزاكم الله خيرا علي المساعدة
وربنا يوفقكم
هذا الموضوع مغلق.