Hi all,

I want to read a Rich Text Format file and get texts form it only. So, what I have done is according to RTF specification start to code detecting tags. Actually it is too hard, because RTF format has more that 1000 tags. If I going to find each of them it will take a long time.

So I want to do it in shorter time. Can I do it with CRichEditCtrl?

Yes, I'm going to work it on with MFC. What you think about it? Is it difficult, first time I'm going to do this.

Ok, here what I've done up to now.

First define CWnd object and CRichEditCrtl objects as follows.

CWnd * m_rtfWnd;
	CRichEditCtrl * m_rtfCtrl;
CFile rtfFile;
	BOOL err = rtfFile.Open("G:\\Work On\\CPP\\RTFControl\\TestFile.rtf", CFile::modeReadWrite, NULL);

	if(err !=0)
		int iLength = rtfFile.GetLength();// Data length
		char *pBuffer = new char[iLength];// Data buffer

		rtfFile.Read(pBuffer, iLength);
		CString rtf(pBuffer);

		m_rtfCtrl->Create(WS_CHILD|WS_VISIBLE|WS_BORDER|ES_MULTILINE, CRect(100,100,100,100), m_rtfWnd, 1);// Associate with CRichEditCtrl
		m_rtfCtrl->SetWindowText(rtf);// Set the window text

		int i, nLength, nCount = m_rtfCtrl->GetLineCount();
		CString strText, strLine;

		for(i = 0;i < nCount;i++)
			nLength = m_rtfCtrl->LineLength(i);
			m_rtfCtrl->GetLine(i, strText.GetBuffer(nLength));

			strLine.Format(("i %d '%s' \n", i, strText.GetBuffer(0)));
			AfxMessageBox(strText, MB_OK);

I got an error when I use 'create' to construct rich edit control. I can't find any error there. Do you guys have any idea about it.

This article has been dead for over six months. Start a new discussion instead.