// FileOpenEx.cpp : implementation file // #include "stdafx.h" #include "shen02.h" #include "FileOpenEx.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CFileOpenEx dialog CFileOpenEx::CFileOpenEx( LPCTSTR lpszDefExt /*= NULL*/, LPCTSTR lpszFileName /*= NULL*/, DWORD dwFlags /*= OFN_HIDEREADONLY*/, LPCTSTR lpszFilter /*= NULL*/, CWnd* pParentWnd /*= NULL*/) : CFileDialog(TRUE, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd) { m_bUnfolded = TRUE; m_bFirstTime = TRUE; } void CFileOpenEx::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CFileOpenEx) DDX_Control(pDX, IDC_EDIT_CONTENTS, m_RichEdit); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CFileOpenEx, CDialog) //{{AFX_MSG_MAP(CFileOpenEx) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFileOpenEx message handlers int CFileOpenEx::DoModal() { SetTemplate(NULL, MAKEINTRESOURCE(IDD_OPENFILE_EX)); return CFileDialog::DoModal(); } void CFileOpenEx::OnFileNameChange() { if(m_bUnfolded) { CString FileName = GetPathName(); if(FileName.GetLength()) { OFSTRUCT of; if(OpenFile(FileName, &of, OF_EXIST) != HFILE_ERROR) { PreviewContents(FileName); } } } } DWORD CALLBACK OpenCallback(DWORD dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb ) { CFile *pFile = (CFile *)dwCookie; *pcb = pFile->Read(pbBuff, cb); return 0; } void CFileOpenEx::PreviewContents(LPCSTR lpszFilespec) { CFile File(lpszFilespec, CFile::modeRead); EDITSTREAM es; es.dwCookie = (DWORD)&File; es.dwError = 0; es.pfnCallback = OpenCallback; m_RichEdit.StreamIn(SF_TEXT, es); }