📄 showdibdoc.cpp
字号:
// ShowDIBDoc.cpp : implementation of the CShowDIBDoc class
//
#include "stdafx.h"
#include "ShowDIB.h"
#include "ShowDIBDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CShowDIBDoc
IMPLEMENT_DYNCREATE(CShowDIBDoc, CDocument)
BEGIN_MESSAGE_MAP(CShowDIBDoc, CDocument)
//{{AFX_MSG_MAP(CShowDIBDoc)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShowDIBDoc construction/destruction
CShowDIBDoc::CShowDIBDoc()
{
// TODO: add one-time construction code here
m_pDib = new CDib;
}
CShowDIBDoc::~CShowDIBDoc()
{
delete m_pDib;
}
BOOL CShowDIBDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CShowDIBDoc serialization
void CShowDIBDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CShowDIBDoc diagnostics
#ifdef _DEBUG
void CShowDIBDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CShowDIBDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CShowDIBDoc commands
void CShowDIBDoc::OnFileOpen()
{
// TODO: Add your command handler code here
CString strOpenFileType = "位图文件 (*.bmp;*.dib)|*.bmp; *.dib|All Files (*.*)|*.*||";
CFileDialog FileDlg(TRUE, "*.bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strOpenFileType);
CString strPath;
if (FileDlg.DoModal() == IDOK)
{
strPath = FileDlg.GetPathName();
CFileException fe;
CFile file;
if(!file.Open(strPath, CFile::modeRead | CFile::shareDenyWrite, &fe))
{
ReportSaveLoadException(strPath, &fe, FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
return;
}
BeginWaitCursor();
if(!m_pDib->Read(&file))
{
EndWaitCursor();
return;
}
file.Close();
SetModifiedFlag(FALSE);
UpdateAllViews(NULL);
EndWaitCursor();
}
return;
}
void CShowDIBDoc::OnFileSaveAs()
{
// TODO: Add your command handler code here
CString strSaveFileType = "位图文件 (*.bmp;*.dib)|*.bmp; *.dib|All Files (*.*)|*.*||";
CFileDialog FileDlg(FALSE, "*.bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strSaveFileType);
CFile fileOpen ;
if( FileDlg.DoModal() == IDOK )
{
if(!fileOpen.Open( FileDlg.GetPathName() , CFile::modeCreate|CFile::modeWrite ))
{
AfxMessageBox("cannot create the file to save");
return;
}
if(!m_pDib->Write( &fileOpen ))
return;
fileOpen.Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -