// Rtf2Html.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "Rtf2Html2.h" #include "afxhtml.h" CWinApp theApp; // Win32 App with MFC support CRichEditCtrl g_ctlRichEdit; // the two controls CHtmlEditCtrl g_ctlEditHtml; // This is needed to load the RichEdit control from a file static DWORD CALLBACK MyStreamInCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { CFile* pFile = (CFile*) dwCookie; *pcb = pFile->Read(pbBuff, cb); return 0; } void LoadRtfFile( LPCTSTR pszFilename ) { wchar_t szFilter[] = L"RTF files (*.rtf)|*.rtf;|" L"All Files (*.*)|*.*||"; CFileDialog dlg(TRUE,0,pszFilename,6,szFilter ); if ( dlg.DoModal()!=IDOK ) { return; } CFile cf( dlg.GetPathName(),CFile::modeRead ); // CFile cf( pszFilename,CFile::modeRead ); EDITSTREAM es; es.dwCookie = (DWORD)&cf; es.pfnCallback = MyStreamInCallback; g_ctlRichEdit.StreamIn( SF_RTF, es ); // load from the file } int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0); AfxInitRichEdit2(); // needed for using CRichEditCtrl CWnd* pWnd = CWnd::GetDesktopWindow(); CRect r(0,0,200,200); g_ctlRichEdit.Create( ES_MULTILINE, r, pWnd, 1111); g_ctlEditHtml.Create( 0,0, r, pWnd, 2222 ); LoadRtfFile( argv[1] ); // read the RTF file into the ctrl g_ctlRichEdit.SetSel(0,-1); // select all in the RTF ctrl g_ctlRichEdit.Copy(); // copy to clipboard g_ctlEditHtml.Paste(); // paste into the Html Edit ctrl g_ctlEditHtml.SaveAs( L"C:\\temp\\test.html"); // save HTML return 0; }