读取文件匹配代码
1 BOOL CWBPage::LoadFromFile(CFile *pFile, LONGLONG& lOff, ULONGLONG lFileLength) 2 { 3 if (pFile == NULL) 4 { 5 return FALSE; 6 } 7 8 LONGLONG lPageOff = lOff; //页偏移量 9 //读取页长度 10 ULONGLONG lPageLength; //页内容长度 11 12 pFile->Seek(lPageOff, CFile::begin); 13 pFile->Read((char *)&lPageLength, sizeof(ULONGLONG)); 14 if ((lPageOff + lPageLength) > lFileLength) 15 { 16 return FALSE; 17 } 18 lPageOff += sizeof(ULONGLONG);//偏移量增加 19 20 if (lPageLength <= 1) //如果是空页 21 { 22 lOff = lPageOff; 23 return TRUE; 24 } 25 26 //读取所有对象 27 //int nlayerIndex = 1; //对象图层号 28 while ((ULONGLONG)(lPageOff - lOff) < lPageLength) 29 { 30 //读取对象类型 31 char chObjType; 32 pFile->Seek(lPageOff, CFile::begin); 33 pFile->Read(&chObjType, 1); 34 int nObjType = (int)chObjType; 35 36 switch (nObjType) 37 { 38 case WB_OBJ_LINE: //直线 39 { 40 CWBLine *pLine = new CWBLine(); 41 if (NULL == pLine) 42 { 43 return FALSE; 44 } 45 if (!pLine->LoadFromFile(pFile, lPageOff, lFileLength)) 46 { 47 delete pLine; 48 return FALSE; 49 } 50 //pLine->SetLayerIndex(nlayerIndex); //设置对象图层号 51 52 //m_pWBObjList->AddTail(pLine); 53 AddWBObject(pLine, pLine->GetLayerType()); 54 } 55 break; 56 case WB_OBJ_CURVE: //曲线 57 { 58 CWBCurve *pCurve = new CWBCurve(); 59 if (NULL == pCurve) 60 { 61 return FALSE; 62 } 63 if (!pCurve->LoadFromFile(pFile, lPageOff, lFileLength)) 64 { 65 delete pCurve; 66 return FALSE; 67 } 68 //pCurve->SetLayerIndex(nlayerIndex); //设置对象图层号 69 70 //m_pWBObjList->AddTail(pCurve); 71 AddWBObject(pCurve, pCurve->GetLayerType()); 72 } 73 break; 74 case WB_OBJ_ICOCURVE: //图标曲线 75 { 76 CWBIcoCurve *pIcoCurve = new CWBIcoCurve(); 77 if (NULL == pIcoCurve) 78 { 79 return FALSE; 80 } 81 if (!pIcoCurve->LoadFromFile(pFile, lPageOff, lFileLength)) 82 { 83 delete pIcoCurve; 84 return FALSE; 85 } 86 87 AddWBObject(pIcoCurve, pIcoCurve->GetLayerType()); 88 } 89 break; 90 case WB_OBJ_POLYGON: //多边形 91 { 92 CWBPolygon *pPolygon = new CWBPolygon(); 93 if (NULL ==pPolygon) 94 { 95 return FALSE; 96 } 97 if (!pPolygon->LoadFromFile(pFile, lPageOff, lFileLength)) 98 { 99 delete pPolygon; 100 return FALSE; 101 } 102 //pPolygon->SetLayerIndex(nlayerIndex); 103 104 //m_pWBObjList->AddTail(pPolygon); 105 AddWBObject(pPolygon, pPolygon->GetLayerType()); 106 } 107 break; 108 case WB_OBJ_RECT: //矩形 109 { 110 CWBRectangle *pRect = new CWBRectangle(); 111 if (NULL == pRect) 112 { 113 return FALSE; 114 } 115 if (!pRect->LoadFromFile(pFile, lPageOff, lFileLength)) 116 { 117 delete pRect; 118 return FALSE; 119 } 120 //pRect->SetLayerIndex(nlayerIndex); 121 //m_pWBObjList->AddTail(pRect); 122 AddWBObject(pRect, pRect->GetLayerType()); 123 } 124 break; 125 case WB_OBJ_TEXT: //文本 126 { 127 CWBText *pText = new CWBText(); 128 if (NULL == pText) 129 { 130 return FALSE; 131 } 132 if(!pText->LoadFromFile(pFile, lPageOff, lFileLength)) 133 { 134 delete pText; 135 return FALSE; 136 } 137 //pText->SetLayerIndex(nlayerIndex); 138 139 //m_pWBObjList->AddTail(pText); 140 AddWBObject(pText, pText->GetLayerType()); 141 } 142 break; 143 case WB_OBJ_PICTURE: //图片 144 { 145 CWBPicture *pPicture = new CWBPicture(); 146 if (NULL == pPicture) 147 { 148 return FALSE; 149 } 150 if (!pPicture->LoadFromFile(pFile, lPageOff, lFileLength)) 151 { 152 delete pPicture; 153 return FALSE; 154 } 155 //pPicture->SetLayerIndex(nlayerIndex); 156 157 //m_pWBObjList->AddTail(pPicture); 158 AddWBObject(pPicture, pPicture->GetLayerType()); 159 } 160 break; 161 case WB_OBJ_DXF: //dxf 162 { 163 CWBDxf *pDxf = new CWBDxf(); 164 if (NULL == pDxf) 165 { 166 return FALSE; 167 } 168 if (!pDxf->LoadFromFile(pFile, lPageOff, lFileLength)) 169 { 170 delete pDxf; 171 return FALSE; 172 } 173 AddWBObject(pDxf, pDxf->GetLayerType()); 174 } 175 break; 176 case WB_OBJ_FLASH: //flash 177 { 178 CWBFlash *pFlash = new CWBFlash(); 179 if (NULL == pFlash) 180 { 181 return FALSE; 182 } 183 if (!pFlash->LoadFromFile(pFile, lPageOff, lFileLength)) 184 { 185 delete pFlash; 186 return FALSE; 187 } 188 //pFlash->SetLayerIndex(nlayerIndex); 189 190 //m_pWBObjList->AddTail(pFlash); 191 AddWBObject(pFlash, pFlash->GetLayerType()); 192 } 193 break; 194 195 case WB_OBJ_ELLIPSE: //椭圆 196 { 197 CWBEllipse *pEllipse = new CWBEllipse(); 198 if (NULL == pEllipse) 199 { 200 return FALSE; 201 } 202 if(!pEllipse->LoadFromFile(pFile, lPageOff, lFileLength)) 203 { 204 delete pEllipse; 205 return FALSE; 206 } 207 //pEllipse->SetLayerIndex(nlayerIndex); 208 //m_pWBObjList->AddTail(pEllipse); 209 AddWBObject(pEllipse, pEllipse->GetLayerType()); 210 } 211 break; 212 case WB_OBJ_TRIANGLE: //三角形 213 { 214 CWBTriangle *pTriangle = new CWBTriangle(); 215 if ( NULL == pTriangle) 216 { 217 return FALSE; 218 } 219 if (!pTriangle->LoadFromFile(pFile, lPageOff, lFileLength)) 220 { 221 delete pTriangle; 222 return FALSE; 223 } 224 //pTriangle->SetLayerIndex(nlayerIndex); 225 226 //m_pWBObjList->AddTail(pTriangle); 227 AddWBObject(pTriangle, pTriangle->GetLayerType()); 228 } 229 break; 230 case WB_OBJ_RHOMBUS: //菱形 231 { 232 CWBRhombus *pRhombus = new CWBRhombus(); 233 if (NULL == pRhombus) 234 { 235 return FALSE; 236 } 237 if (!pRhombus->LoadFromFile(pFile, lPageOff, lFileLength)) 238 { 239 delete pRhombus; 240 return FALSE; 241 } 242 //pRhombus->SetLayerIndex(nlayerIndex); 243 244 //m_pWBObjList->AddTail(pRhombus); 245 AddWBObject(pRhombus, pRhombus->GetLayerType()); 246 } 247 break; 248 case WB_OBJ_PENTAGON: //五边形 249 { 250 CWBPentagon *pPentagon = new CWBPentagon(); 251 if (NULL == pPentagon) 252 { 253 return FALSE; 254 } 255 if (!pPentagon->LoadFromFile(pFile, lPageOff, lFileLength)) 256 { 257 delete pPentagon; 258 return FALSE; 259 } 260 //pPentagon->SetLayerIndex(nlayerIndex); 261 262 //m_pWBObjList->AddTail(pPentagon); 263 AddWBObject(pPentagon, pPentagon->GetLayerType()); 264 } 265 break; 266 case WB_OBJ_HEXAGON: //六边形 267 { 268 CWBHexagon *pHexagon = new CWBHexagon(); 269 if (NULL == pHexagon) 270 { 271 return FALSE; 272 } 273 if (!pHexagon->LoadFromFile(pFile, lPageOff, lFileLength)) 274 { 275 delete pHexagon; 276 return FALSE; 277 } 278 //pHexagon->SetLayerIndex(nlayerIndex); 279 280 //m_pWBObjList->AddTail(pHexagon); 281 AddWBObject(pHexagon, pHexagon->GetLayerType()); 282 } 283 break; 284 case WB_OBJ_FIVEPOINTSTART: //五角星 285 { 286 CWBFivepointstart *pFivepointstart = new CWBFivepointstart(); 287 if (NULL == pFivepointstart) 288 { 289 return FALSE; 290 } 291 if (!pFivepointstart->LoadFromFile(pFile, lPageOff, lFileLength)) 292 { 293 delete pFivepointstart; 294 return FALSE; 295 } 296 //pFivepointstart->SetLayerIndex(nlayerIndex); 297 298 //m_pWBObjList->AddTail(pFivepointstart); 299 AddWBObject(pFivepointstart, pFivepointstart->GetLayerType()); 300 } 301 break; 302 case WB_OBJ_TRAPEZIUM: //梯形 303 { 304 CWBTrapezium *pTrapezium = new CWBTrapezium(); 305 if (NULL == pTrapezium) 306 { 307 return FALSE; 308 } 309 if (!pTrapezium->LoadFromFile(pFile, lPageOff, lFileLength)) 310 { 311 delete pTrapezium; 312 return FALSE; 313 } 314 //pTrapezium->SetLayerIndex(nlayerIndex); 315 316 //m_pWBObjList->AddTail(pTrapezium); 317 AddWBObject(pTrapezium, pTrapezium->GetLayerType()); 318 } 319 break; 320 case WB_OBJ_MEDIA: 321 { 322 //加载新视频 323 CWBMedia* pMedia = new CWBMedia(NULL); 324 if (NULL == pMedia) 325 { 326 return FALSE; 327 } 328 if (!pMedia->LoadFromFile(pFile, lPageOff, lFileLength)) 329 { 330 delete pMedia; 331 pMedia = NULL; 332 return FALSE; 333 } 334 //将新视频的显示状态全部设置为隐藏,否则会在第一页显示出所有的视频 335 if (g_pWhiteBoardView->m_bIsCombin)//主要组合和正常打开有点区别问题wangxiaobin 336 { 337 if (g_PageCount >= 1) 338 { 339 pMedia->HideAndPauseMedia(); 340 } 341 } 342 else 343 { 344 if (g_PageCount > 1) 345 { 346 pMedia->HideAndPauseMedia(); 347 } 348 } 349 350 351 AddWBObject(pMedia, pMedia->GetLayerType()); 352 } 353 break; 354 case WB_OBJ_DOCUMENT: 355 { 356 CWBDocument *pDoc = new CWBDocument(); 357 if (NULL == pDoc) 358 { 359 return FALSE; 360 } 361 pDoc->SetPageIndex(g_PageCount); 362 if (!pDoc->LoadFromFile(pFile, lPageOff, lFileLength)) 363 { 364 delete pDoc; 365 return FALSE; 366 } 367 //pDoc->SetLayerIndex(nlayerIndex); 368 369 //m_pWBObjList->AddTail(pDoc); 370 AddWBObject(pDoc, pDoc->GetLayerType()); 371 } 372 break; 373 case WB_OBJ_COMBINE: 374 { 375 CWBCombine *pCombine = new CWBCombine(); 376 if (NULL == pCombine) 377 { 378 return FALSE; 379 } 380 if (!pCombine->LoadFromFile(pFile, lPageOff, lFileLength)) 381 { 382 delete pCombine; 383 return FALSE; 384 } 385 //pCombine->SetLayerIndex(nlayerIndex); 386 387 //m_pWBObjList->AddTail(pCombine); 388 m_nWBMaxLayerId = pCombine->GetPageLayerIndex(); 389 AddWBObject(pCombine, pCombine->GetLayerType()); 390 } 391 break; 392 case WB_OBJ_ANNOTATIONS: 393 { 394 CWBAnnotations *pAnnotations = new CWBAnnotations(); 395 if (NULL == pAnnotations) 396 { 397 return FALSE; 398 } 399 if (!pAnnotations->LoadFromFile(pFile, lPageOff, lFileLength)) 400 { 401 delete pAnnotations; 402 return FALSE; 403 } 404 //pAnnotations->SetLayerIndex(nlayerIndex); 405 406 //m_pWBObjList->AddTail(pAnnotations); 407 AddWBObject(pAnnotations, pAnnotations->GetLayerType()); 408 } 409 break; 410 case WB_OBJ_BAFFLE: 411 { 412 CWBBafflePlate *pBafflePlate = new CWBBafflePlate(); 413 if (NULL == pBafflePlate) 414 { 415 return FALSE; 416 } 417 if (!pBafflePlate->LoadFromFile(pFile, lPageOff, lFileLength)) 418 { 419 delete pBafflePlate; 420 return FALSE; 421 } 422 //pBafflePlate->SetLayerIndex(nlayerIndex); 423 424 //m_pWBObjList->AddTail(pBafflePlate); 425 AddWBObject(pBafflePlate, pBafflePlate->GetLayerType()); 426 } 427 break; 428 default: 429 return FALSE; 430 } 431 } 432 433 //m_dwCurObjLayerIndex = nlayerIndex - 1; //设置当前图层号 434 lOff = lPageOff; 435 return TRUE; 436 }
老版本对象枚举类型代码
1 enum WB_OBJ_TYPE 2 { 3 WB_OBJ_NORMAL = 0, 4 WB_OBJ_LINE, //直线 5 WB_OBJ_CURVE, //曲线 6 WB_OBJ_ICOCURVE,//图标曲线 7 WB_OBJ_POLYGON, //多边形 8 WB_OBJ_RECT, //矩形 9 WB_OBJ_SELECTRECT, //选择框 10 WB_OBJ_PICTURE, //图片 11 WB_OBJ_MOVIE, //视频 12 WB_OBJ_MEDIA, //新视频 13 WB_OBJ_FLASH, //FLASH 14 WB_OBJ_DOCUMENT, //文档 15 WB_OBJ_TEXT, //文字 16 WB_OBJ_ELLIPSE, //椭圆 17 WB_OBJ_TRIANGLE, //三角形 18 WB_OBJ_RHOMBUS, //菱形 19 WB_OBJ_BAFFLE, //挡板 20 WB_OBJ_COMBINE, //组合 21 WB_OBJ_MAQN, //放大镜 22 WB_OBJ_SPOTLIGHT, //聚光灯 23 WB_OBJ_ANNOTATIONS, //标注 24 WB_OBJ_CAMERA, //摄像头 25 WB_OBJ_DUSTBIN, //垃圾箱 26 WB_OBJ_RULER,//直尺 27 WB_OBJ_PROTRACTOR,//量角器 28 WB_OBJ_ANGLE, //生成刻度 29 WB_OBJ_SETSQUARE,//三角板 30 WB_OBJ_COMPASS, //圆规 31 WB_OBJ_ARC, //圆弧 32 WB_OBJ_SECTOR, //扇形 33 WB_OBJ_ARBITRARYTRIANGLE, //任意三角形 34 WB_OBJ_PALLELOGAM, //平行四边形 35 WB_OBJ_PENTAGON, //五边形 36 WB_OBJ_HEXAGON, //六边形 37 WB_OBJ_FIVEPOINTSTART, //五角星 38 WB_OBJ_TRAPEZIUM, //梯形 39 WB_OBJ_DXF //DXF 40 };
新版本对象枚举类型代码
1 enum WB_OBJ_TYPE 2 { 3 WB_OBJ_NORMAL = 0, 4 WB_OBJ_TRAPEZIUM, //梯形 5 WB_OBJ_LINE, //直线 6 WB_OBJ_CURVE, //曲线 7 WB_OBJ_ICOCURVE,//图标曲线 8 WB_OBJ_POLYGON, //多边形 9 WB_OBJ_RECT, //矩形 10 WB_OBJ_SELECTRECT, //选择框 11 WB_OBJ_PICTURE, //图片 12 WB_OBJ_MOVIE, //视频 13 WB_OBJ_MEDIA, //新视频 14 WB_OBJ_FLASH, //FLASH 15 WB_OBJ_DOCUMENT, //文档 16 WB_OBJ_TEXT, //文字 17 WB_OBJ_ELLIPSE, //椭圆 18 WB_OBJ_TRIANGLE, //三角形 19 WB_OBJ_RHOMBUS, //菱形 20 WB_OBJ_BAFFLE, //挡板 21 WB_OBJ_COMBINE, //组合 22 WB_OBJ_MAQN, //放大镜 23 WB_OBJ_SPOTLIGHT, //聚光灯 24 WB_OBJ_ANNOTATIONS, //标注 25 WB_OBJ_CAMERA, //摄像头 26 WB_OBJ_DUSTBIN, //垃圾箱 27 WB_OBJ_RULER,//直尺 28 WB_OBJ_PROTRACTOR,//量角器 29 WB_OBJ_ANGLE, //生成刻度 30 WB_OBJ_SETSQUARE,//三角板 31 WB_OBJ_COMPASS, //圆规 32 WB_OBJ_ARC, //圆弧 33 WB_OBJ_SECTOR, //扇形 34 WB_OBJ_ARBITRARYTRIANGLE, //任意三角形 35 WB_OBJ_PALLELOGAM, //平行四边形 36 WB_OBJ_PENTAGON, //五边形 37 WB_OBJ_HEXAGON, //六边形 38 WB_OBJ_FIVEPOINTSTART, //五角星 39 WB_OBJ_DXF //DXF 40 };
在新版本中由于有人把WB_OBJ_TRAPEZIUM, //梯形
放在了第二行,原来第二行是WB_OBJ_LINE, //直线
保存老版本的时候1代表的是WB_OBJ_LINE, //直线
新版本中1代表的是WB_OBJ_TRAPEZIUM, //梯形
char chObjType;
pFile->Seek(lPageOff, CFile::begin);
pFile->Read(&chObjType, 1);
int nObjType = (int)chObjType;
由于Read()中nOjbType得到的是枚举类型中的对应的整形数,因此在读取老版本中保存的直线时候,匹配到的对象是新版本中的梯形,会去梯形类中读取,导致读取文件失败。