⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 graphicsdoc.cpp

📁 这些源代码
💻 CPP
字号:
// GraphicsDoc.cpp : implementation of the CGraphicsDoc class
//

#include "stdafx.h"
#include "Graphics.h"

#include "GraphicsDoc.h"
#include "GraphicsView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CGraphicsDoc

IMPLEMENT_DYNCREATE(CGraphicsDoc, CDocument)

BEGIN_MESSAGE_MAP(CGraphicsDoc, CDocument)
	//{{AFX_MSG_MAP(CGraphicsDoc)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGraphicsDoc construction/destruction

CGraphicsDoc::CGraphicsDoc()
{
	m_hBuf = NULL;
	m_dwSize = 0;
}

CGraphicsDoc::~CGraphicsDoc()
{
}

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

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

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CGraphicsDoc serialization

void CGraphicsDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		if (m_hBuf != NULL)
		{
			GlobalFree (m_hBuf);
			m_hBuf = NULL;
			m_dwSize = 0;
			UpdateAllViews (NULL, 1);
		}
		m_dwSize = ar.GetFile()->GetLength ();
		m_hBuf = GlobalAlloc(GMEM_MOVEABLE, m_dwSize);
		char *tmp = (char *) GlobalLock (m_hBuf);
		if (tmp == NULL)
			return;
		ar.Read (tmp, m_dwSize);
		GlobalUnlock (m_hBuf);
		POSITION pos = GetFirstViewPosition();
		while (pos != NULL)
		{
			CView* pView = GetNextView(pos);
			pView->UpdateWindow();
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
// CGraphicsDoc diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CGraphicsDoc commands

void CGraphicsDoc::OnFileOpen() 
{
	CFileDialog cfd (TRUE);
//
// Set the filter string to a combined string, the one
// string for each file type. This is a very long string.
// Notice that the individual filter types are separated
// by a \0.
	cfd.m_ofn.lpstrFilter	= _T("Supported Files Types(*.bmp;*.gif;*.jpg;*.ico;*.emf;*.wmf;)\0*.bmp;*.gif;*.jpg;*.ico;*.emf;*.wmf;\0Bitmaps (*.bmp)\0*.bmp\0GIF Files (*.gif)\0*.gif\0JPEG Files (*.jpg)\0*.jpg\0Icons (*.ico)\0*.ico\0Enhanced Metafiles (*.emf)\0*.emf\0Windows Metafiles (*.wmf)\0*.wmf\0\0");
	cfd.m_ofn.lpstrTitle	= _T("Open Picture File");
	cfd.m_ofn.nMaxFile	= MAX_PATH;
	if (cfd.DoModal () == IDCANCEL)
		return;
	if (m_hBuf != NULL)
	{
		GlobalFree (m_hBuf);
		m_hBuf = NULL;
		m_dwSize = 0;
	}
	CDocument::OnNewDocument ();
	CString strPath = cfd.GetPathName();
	AfxGetApp()->OpenDocumentFile (strPath);
}

HGLOBAL CGraphicsDoc::GetGlobalBuffer()
{
	return (m_hBuf);
}

DWORD CGraphicsDoc::GetGlobalSize()
{
	return (m_dwSize);
}

void CGraphicsDoc::DeleteContents() 
{
	if (m_hBuf != NULL)
	{
		GlobalFree (m_hBuf);
		m_hBuf = NULL;
		m_dwSize = 0;
		UpdateAllViews (NULL, 1);
	}
	CDocument::DeleteContents();
}

⌨️ 快捷键说明

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