?? viewdibdoc.cpp
字號:
// ViewDIBDoc.cpp : implementation of the CViewDIBDoc class
//
#include "stdafx.h"
#include "ViewDIB.h"
#include "ViewDIBDoc.h"
#include "LoadTifDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CViewDIBDoc
IMPLEMENT_DYNCREATE(CViewDIBDoc, CDocument)
BEGIN_MESSAGE_MAP(CViewDIBDoc, CDocument)
//{{AFX_MSG_MAP(CViewDIBDoc)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CViewDIBDoc construction/destruction
CViewDIBDoc::CViewDIBDoc()
{
m_pDib = new CDib;
}
CViewDIBDoc::~CViewDIBDoc()
{
delete m_pDib;
}
BOOL CViewDIBDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CViewDIBDoc serialization
void CViewDIBDoc::Serialize(CArchive& ar)
{
m_pDib->Serialize(ar);
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CViewDIBDoc diagnostics
#ifdef _DEBUG
void CViewDIBDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CViewDIBDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CViewDIBDoc commands
BOOL CViewDIBDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath(lpszPathName, drive, dir, fname, ext);
if (! stricmp(ext, ".gif")) // GIF file
{
CGif gif;
if (! gif.Load(lpszPathName))
return FALSE;
HDIB hDIB = CopyHandle(gif.GetDib()->GetHandle());
if (hDIB == NULL)
return FALSE;
m_pDib->Attach(hDIB);
return TRUE;
}
else if (! stricmp(ext, ".jpg") ||
! stricmp(ext, ".jpe") ||
! stricmp(ext, ".jpeg") ) // JPEG file
{
CJpeg jpeg;
if (! jpeg.Load(lpszPathName))
return FALSE;
HDIB hDIB = CopyHandle(jpeg.GetDib()->GetHandle());
if (hDIB == NULL)
return FALSE;
m_pDib->Attach(hDIB);
return TRUE;
}
else if (! stricmp(ext, ".pcx")) // PCX file
{
CPcx pcx;
if (! pcx.Load(lpszPathName))
return FALSE;
HDIB hDIB = CopyHandle(pcx.GetDib()->GetHandle());
if (hDIB == NULL)
return FALSE;
m_pDib->Attach(hDIB);
return TRUE;
}
else if (! stricmp(ext, ".tga")) // TGA file
{
CTga tga;
if (! tga.Load(lpszPathName))
return FALSE;
HDIB hDIB = CopyHandle(tga.GetDib()->GetHandle());
if (hDIB == NULL)
return FALSE;
m_pDib->Attach(hDIB);
return TRUE;
}
else if (! stricmp(ext, ".tif") ||
! stricmp(ext, ".tiff")) // TIF file
{
CTif tif;
if (! tif.Load(lpszPathName))
return FALSE;
CLoadTifDlg loadTifDlg(lpszPathName, tif.m_wIFDNum);
if (loadTifDlg.DoModal() != IDOK)
return FALSE;
int *nPageList = new int[tif.m_wIFDNum];
int nLoadPageNum = 0;
if (loadTifDlg.m_bLoadAll)
{
nLoadPageNum = tif.m_wIFDNum;
for (int i=0; i<nLoadPageNum; i++)
nPageList[i] = i;
}
else
{
CString s = loadTifDlg.m_strPages;
int nLen = s.GetLength();
for (int i=0;i<nLen;++i)
{
if (s[i] == ' ' || s[i] == 32)
s.Delete(i);
nLen = s.GetLength();
}
while (1)
{
int n = s.Find(',');
if (n == -1)
break;
CString strPage = s.Left(n);
s.Delete(0, n+1);
int nPage = atoi((LPCSTR)strPage) - 1;
if (nPage >=0 && nPage < tif.m_wIFDNum)
nPageList[nLoadPageNum++] = nPage;
if (nLoadPageNum >= tif.m_wIFDNum)
break;
}
if (nLoadPageNum < tif.m_wIFDNum)
{
int nPage = atoi((LPCSTR)s) - 1;
if (nPage >=0 && nPage < tif.m_wIFDNum)
nPageList[nLoadPageNum++] = nPage;
}
}
if (nLoadPageNum == 0)
return FALSE;
CViewDIBApp* pApp = (CViewDIBApp *)AfxGetApp();
for (int i=nLoadPageNum-1; i>0; i--)
{
CString strTitle;
CString s = lpszPathName;
s += " p%d";
strTitle.Format((LPCTSTR)s, nPageList[i]+1);
pApp->AddFile(CopyHandle(tif.m_DibList[nPageList[i]].GetHandle()), (LPCTSTR)strTitle);
}
// set the first selected page as current document
HDIB hDIB = CopyHandle(tif.m_DibList[nPageList[0]].GetHandle());
if (hDIB == NULL)
return FALSE;
m_pDib->Attach(hDIB);
CString s = lpszPathName;
s += " p%d";
m_strTifPathName.Format((LPCTSTR)s, nPageList[0]+1);
m_bLoadTif = TRUE;
pApp->AddToRecentFileList(lpszPathName);
SetModifiedFlag(TRUE);
return TRUE;
}
return CDocument::OnOpenDocument(lpszPathName);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -