?? bmpviewerdoc.cpp
字號(hào):
// BmpViewerDoc.cpp : implementation of the CBmpViewerDoc class
//
#include "stdafx.h"
#include "BmpViewer.h"
#include "BmpViewerDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBmpViewerDoc
IMPLEMENT_DYNCREATE(CBmpViewerDoc, CDocument)
BEGIN_MESSAGE_MAP(CBmpViewerDoc, CDocument)
//{{AFX_MSG_MAP(CBmpViewerDoc)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CBmpViewerDoc construction/destruction
CBmpViewerDoc::CBmpViewerDoc()
{
// TODO: add one-time construction code here
}
CBmpViewerDoc::~CBmpViewerDoc()
{
}
/////////////////////////////////////////////////////////////////////////////
// CBmpViewerDoc serialization
void CBmpViewerDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CBmpViewerDoc diagnostics
#ifdef _DEBUG
void CBmpViewerDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CBmpViewerDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CBmpViewerDoc commands
BOOL CBmpViewerDoc::OnNewDocument()
{
// TODO: Add your specialized code here and/or call the base class
return CDocument::OnNewDocument();
}
void CBmpViewerDoc::OnCloseDocument()
{
// TODO: Add your specialized code here and/or call the base class
CloseDIB();
if(lpBmpFile)
{
delete[] lpBmpFile;
lpBmpFile=NULL;
}
CDocument::OnCloseDocument();
}
BOOL CBmpViewerDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
if (!CDocument::OnOpenDocument(lpszPathName))
return FALSE;
// TODO: Add your specialized creation code here
CFile f;
CFileException e;
CString s;
TCHAR message[256];
if (!f.Open(lpszPathName,CFile::modeRead,&e))
{
e.GetErrorMessage(message,256);
CString s;
s.Format(IDS_LOADFILEFAIL,message);
AfxMessageBox(s);
return FALSE;
}
sizeBmpFile=f.GetLength();
lpBmpFile=new char[sizeBmpFile];
if (!lpBmpFile)
{
f.Close();
s.Format(IDS_LOADFILEFAIL,"文件太大");
AfxMessageBox(s);
return FALSE;
}
f.Read(lpBmpFile,sizeBmpFile);
f.Close();
pbfh= (BITMAPFILEHEADER *) lpBmpFile;
if((lpBmpFile[0]!='B') || (lpBmpFile[1]!='M'))
{
s.Format(IDS_LOADFILEFAIL,"BMP文件個(gè)是錯(cuò)誤");
AfxMessageBox(s);
return FALSE;
}
pbih=(BITMAPINFOHEADER *) (lpBmpFile+sizeof(BITMAPFILEHEADER));
if(pbih->biSize!=sizeof(BITMAPINFOHEADER))
{
s.Format(IDS_LOADFILEFAIL,"BMP文件格式錯(cuò)誤");
AfxMessageBox(s);
return FALSE;
}
OpenDIB();
return TRUE;
}
void CBmpViewerDoc::OpenDIB()
{
m_hDD=DrawDibOpen();
}
void CBmpViewerDoc::CloseDIB()
{
if(m_hDD)
{
DrawDibClose(m_hDD);
m_hDD=0;
}
}
void CBmpViewerDoc::Draw(CDC *pDC)
{
DrawDibRealize(m_hDD,pDC->GetSafeHdc(),TRUE);
DrawDibDraw(m_hDD,pDC->GetSafeHdc(),
0,0,
pbih->biWidth,pbih->biHeight,
pbih,NULL,0,0,
pbih->biWidth,pbih->biHeight,
DDF_BACKGROUNDPAL);
}
HDRAWDIB CBmpViewerDoc::GetDrawDib()
{
return m_hDD;
}
CSize CBmpViewerDoc::GetImageSize()
{
return CSize(pbih->biWidth,pbih->biHeight);
}
void CBmpViewerDoc::GetInfo(CString &s)
{
s.Format("%dx%dx",pbih->biWidth,pbih->biHeight);
switch(pbih->biBitCount)
{
case 1: s+="兩色";break;
case 4: s+="16色";break;
case 8: s+="256色";break;
case 16:s+="64K色";break;
case 24:s+="16M色";break;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -