printbmpdoc.cpp

来自「Visual C++ 的学习资料一」· C++ 代码 · 共 126 行

CPP
126
字号
// printbmpDoc.cpp : implementation of the CPrintbmpDoc class
//

#include "stdafx.h"
#include "printbmp.h"

#include "printbmpDoc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPrintbmpDoc

IMPLEMENT_DYNCREATE(CPrintbmpDoc, CDocument)

BEGIN_MESSAGE_MAP(CPrintbmpDoc, CDocument)
	//{{AFX_MSG_MAP(CPrintbmpDoc)
		// 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()

/////////////////////////////////////////////////////////////////////////////
// CPrintbmpDoc construction/destruction

CPrintbmpDoc::CPrintbmpDoc()
{
	// TODO: add one-time construction code here

}

CPrintbmpDoc::~CPrintbmpDoc()
{
}

BOOL CPrintbmpDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CPrintbmpDoc serialization

void CPrintbmpDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CPrintbmpDoc diagnostics

#ifdef _DEBUG
void CPrintbmpDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CPrintbmpDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CPrintbmpDoc commands

BOOL CPrintbmpDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
//	if (!CDocument::OnOpenDocument(lpszPathName))
//		return FALSE;
	
	// TODO: Add your specialized creation code here
	if (IsModified())
		TRACE0("Warning: OnOpenDocument replaces an unsaved document\n");
	DeleteContents();
	//设置等待鼠标
	BeginWaitCursor();
	//打开位图文件
	HBITMAP hImage = (HBITMAP)LoadImage(NULL, lpszPathName, IMAGE_BITMAP,
		0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION|LR_DEFAULTSIZE);
	EndWaitCursor();
	if (!hImage) {
		DWORD LastError = GetLastError();
		AfxMessageBox("LoadImage failed");
		return FALSE;
	}
	//构造位图对象
	if (!m_Bitmap.Attach(hImage)) 
	{
		AfxMessageBox("Bitmap could not be attached");
		return FALSE;
	}
	SetModifiedFlag(FALSE);
	//更新所有视图
	UpdateAllViews(NULL);
	return TRUE;
}

void CPrintbmpDoc::DeleteContents() 
{
	// TODO: Add your specialized code here and/or call the base class
	//清除位图资源
	if (m_Bitmap.m_hObject != NULL)
		m_Bitmap.DeleteObject();
	CDocument::DeleteContents();
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?