using namespace SNXH; using namespace SNMFC; //无需cad,从dwg中读取缩略图,有的dwg没缩略图,CAD2014打开界面,可以看到缩略图 void ReadThumbnailBmp(const CString strBmpFileName,const CString& strDWGFileName) { CFile file; if( !file.Open(strDWGFileName,CFile::modeRead)) { return ; } int iPosSentinel = 0 ; file.Seek(13,CFile::begin); NFile::Read(file,iPosSentinel); unsigned char iNum = 0 ; file.Seek(iPosSentinel+20,CFile::begin); NFile::Read(file,iNum); for( int i = 0 ; i < iNum ; i++) { unsigned char iType = 0; int iPos = 0 ,iLen = 0 ; NFile::Read(file,iType); NFile::Read(file,iPos); NFile::Read(file,iLen); if( 2 == iType ) { file.Seek(iPos,CFile::begin); CArray<unsigned char,unsigned char> v; v.SetSize(iLen); file.Read(v.GetData(),iLen); { BITMAPFILEHEADER fileHead; CBmp::InitFileHead(fileHead,iLen); CFile f2; f2.Open(strBmpFileName,CFile::modeCreate|CFile::modeWrite); f2.Write(&fileHead,sizeof(fileHead)); f2.Write(v.GetData(),iLen); f2.Close(); } break; } } file.Close(); } void CSNPictureDlg::OnButton1() { ReadThumbnailBmp(_T("d:\\3.dwg"),_T("d:\\1.bmp") ); }