例程可以通过VC2010打开转换版本,再编译。
界面有打开文件按钮,可以下载查看使用
源代码为:
- void CEmfReaderDlg::OnBnClickedOk()
- {
- CString szFilter( L"Emf Files (*.emf)|*.emf||" ) ;
- CFileDialog FileDlg(TRUE,CString( L"EMF") ,NULL,
- OFN_FILEMUSTEXIST|OFN_NONETWORKBUTTON|
- OFN_PATHMUSTEXIST,szFilter);
- FileDlg.DoModal();
- // To get the selected file's path and name
- CString strFileName;
- strFileName = FileDlg.GetPathName();
- if(strFileName.IsEmpty())
- return ;
- TRACE(L"FileName:%s\n",strFileName) ;
- memset( &m_EnhMetaHeader , 0 , sizeof( ENHMETAHEADER ) ) ;
- m_strEmfFile = strFileName ;
- if( m_File.GetFileName().GetLength() > 0 )
- m_File.Close() ;
- if (!m_File.Open(strFileName ,CFile::modeRead , &m_FileException))
- {
- TCHAR szError[1024];
- m_FileException.GetErrorMessage(szError, 1024);
- TRACE(L"Couldn't open source file::%s,errormsg:s\n",strFileName,szError) ;
- return ;
- }
- DWORD dwReaded ;
- dwReaded = m_File.Read( &m_EnhMetaHeader , sizeof( ENHMETAHEADER ) ) ;
- if( dwReaded < sizeof( ENHMETAHEADER ) )
- {
- TRACE("Read meta header error!\n") ;
- m_File.Close() ;
- return ;
- }
- if( m_EnhMetaHeader.dSignature!=0x464d4520)
- {
- TRACE("This file is not emf file.\n");
- m_File.Close() ;
- return;
- }
- if ( m_EnhMetaHeader.nDescription > 0 )
- {
- //file.Seek(eh.offDescription,CFile::begin);
- TCHAR *szDesciption ;
- szDesciption = new TCHAR[m_EnhMetaHeader.nDescription+1] ;
- memset( szDesciption , 0 , sizeof( TCHAR) * (m_EnhMetaHeader.nDescription+1));
- dwReaded = m_File.Read(szDesciption , m_EnhMetaHeader.nDescription * sizeof( TCHAR) ) ;
- if( dwReaded == m_EnhMetaHeader.nDescription * sizeof( TCHAR) )
- {
- TRACE(L"description:%s\n",szDesciption);
- }
- //file.Seek( sizeof( ENHMETAHEADER ) , CFile::begin) ;
- delete szDesciption ;
- }
- CreateMemDCandBitmap() ;
- m_dwEmfRecord = 0 ;
- }
复制代码
|