www.pudn.com > roadextr.rar > roadextrDoc.cpp
// roadextrDoc.cpp : implementation of the CRoadextrDoc class
//
#include "stdafx.h"
#include "roadextr.h"
#include "roadextrDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRoadextrDoc
IMPLEMENT_DYNCREATE(CRoadextrDoc, CDocument)
BEGIN_MESSAGE_MAP(CRoadextrDoc, CDocument)
//{{AFX_MSG_MAP(CRoadextrDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRoadextrDoc construction/destruction
CRoadextrDoc::CRoadextrDoc()
{
// TODO: add one-time construction code here
m_stretchMode =FALSE;
m_ZoomFactor =1;
image =NULL;
}
CRoadextrDoc::~CRoadextrDoc()
{
}
BOOL CRoadextrDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CRoadextrDoc serialization
void CRoadextrDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CRoadextrDoc diagnostics
#ifdef _DEBUG
void CRoadextrDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CRoadextrDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CRoadextrDoc commands
BOOL CRoadextrDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
CString strPathL = lpszPathName;
CString ext(FindExtension(strPathL));
ext.MakeLower();
int type = FindType(ext);
image = new CxImage(strPathL, type);
if (!image->IsValid()){
AfxMessageBox(image->GetLastError());
delete image;
image = NULL;
return FALSE;
}
// UpdateAllViews(NULL,WM_USER_NEWIMAGE);
return TRUE;
}
CString CRoadextrDoc::FindExtension(const CString &name)
{
int len = name.GetLength();
int i;
for (i = len-1; i >= 0; i--){
if (name[i] == '.'){
return name.Mid(i+1);
}
}
return CString("");
}
int CRoadextrDoc::FindType(const CString &ext)
{
int type = 0;
if (ext == "bmp") type = CXIMAGE_FORMAT_BMP;
#if CXIMAGE_SUPPORT_JPG
else if (ext=="jpg"||ext=="jpeg") type = CXIMAGE_FORMAT_JPG;
#endif
//#if CXIMAGE_SUPPORT_GIF
// else if (ext == "gif") type = CXIMAGE_FORMAT_GIF;
//#endif
//#if CXIMAGE_SUPPORT_PNG
// else if (ext == "png") type = CXIMAGE_FORMAT_PNG;
//#endif
//#if CXIMAGE_SUPPORT_MNG
// else if (ext=="mng"||ext=="jng") type = CXIMAGE_FORMAT_MNG;
//#endif
//#if CXIMAGE_SUPPORT_ICO
// else if (ext == "ico") type = CXIMAGE_FORMAT_ICO;
//#endif
//#if CXIMAGE_SUPPORT_TIF
// else if (ext=="tiff"||ext=="tif") type = CXIMAGE_FORMAT_TIF;
//#endif
//#if CXIMAGE_SUPPORT_TGA
// else if (ext=="tga") type = CXIMAGE_FORMAT_TGA;
//#endif
//#if CXIMAGE_SUPPORT_PCX
// else if (ext=="pcx") type = CXIMAGE_FORMAT_PCX;
//#endif
//#if CXIMAGE_SUPPORT_WBMP
// else if (ext=="wbmp") type = CXIMAGE_FORMAT_WBMP;
//#endif
//#if CXIMAGE_SUPPORT_WMF
// else if (ext=="wmf"||ext=="emf") type = CXIMAGE_FORMAT_WMF;
//#endif
//#if CXIMAGE_SUPPORT_J2K
// else if (ext=="j2k"||ext=="jp2") type = CXIMAGE_FORMAT_J2K;
//#endif
//#if CXIMAGE_SUPPORT_JBG
// else if (ext=="jbg") type = CXIMAGE_FORMAT_JBG;
//#endif
//#if CXIMAGE_SUPPORT_JP2
// else if (ext=="jp2"||ext=="j2k") type = CXIMAGE_FORMAT_JP2;
//#endif
//#if CXIMAGE_SUPPORT_JPC
// else if (ext=="jpc"||ext=="j2c") type = CXIMAGE_FORMAT_JPC;
//#endif
//#if CXIMAGE_SUPPORT_PGX
// else if (ext=="pgx") type = CXIMAGE_FORMAT_PGX;
//#endif
//#if CXIMAGE_SUPPORT_RAS
// else if (ext=="ras") type = CXIMAGE_FORMAT_RAS;
//#endif
//#if CXIMAGE_SUPPORT_PNM
// else if (ext=="pnm"||ext=="pgm"||ext=="ppm") type = CXIMAGE_FORMAT_PNM;
//#endif
else type = CXIMAGE_FORMAT_UNKNOWN;
return type;
}