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

📄 femmplotdoc.cpp

📁 一个2D电磁场FEM计算的VC++源程序
💻 CPP
字号:
// femmplotDoc.cpp : implementation of the CFemmplotDoc class
//

#include "stdafx.h"
#include "femmplot.h"

#include "femmplotDoc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CFemmplotDoc

IMPLEMENT_DYNCREATE(CFemmplotDoc, CDocument)

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

/////////////////////////////////////////////////////////////////////////////
// CFemmplotDoc construction/destruction

CFemmplotDoc::CFemmplotDoc()
{
	// TODO: add one-time construction code here
	hMetaPlot=NULL;
	HasBoundingBox=FALSE;
}

CFemmplotDoc::~CFemmplotDoc()
{
	DeleteEnhMetaFile(hMetaPlot);
}

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

	// clear out any old metafile;
	DeleteEnhMetaFile(hMetaPlot);
	HasBoundingBox=FALSE;

	// grab a new metafile from the clipboard;
	GrabMetafile();

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

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CFemmplotDoc serialization

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

/////////////////////////////////////////////////////////////////////////////
// CFemmplotDoc diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CFemmplotDoc commands

BOOL CFemmplotDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	
	// clear out any old metafile;
	DeleteEnhMetaFile(hMetaPlot);
	HasBoundingBox=FALSE;
	HENHMETAFILE hMetaPlotFile = GetEnhMetaFile(lpszPathName);
	if (hMetaPlotFile!=NULL){
		DWORD len =(DWORD) GetEnhMetaFileBits(hMetaPlotFile,NULL,NULL);
		unsigned char *buff=(unsigned char *) malloc(len);
		if(GetEnhMetaFileBits(hMetaPlotFile,len,buff)==0)
			AfxMessageBox("MetaFile not copied");
		hMetaPlot=SetEnhMetaFileBits(len,buff);
	}
	else AfxMessageBox("Problem opening specified file");

	DeleteEnhMetaFile(hMetaPlotFile);

	// TODO: Add your specialized creation code here
	
	return TRUE;
}

BOOL CFemmplotDoc::OnSaveDocument(LPCTSTR lpszPathName) 
{
	// TODO: Add your specialized code here and/or call the base class
	BOOL flag=TRUE;

	HENHMETAFILE hMetaCopy=CopyEnhMetaFile(hMetaPlot,lpszPathName);
	if (hMetaCopy==NULL){
		AfxMessageBox("Problem writing file to disk");
		flag=FALSE;
	}
	DeleteEnhMetaFile(hMetaCopy);

	return flag; // CDocument::OnSaveDocument(lpszPathName);
}

BOOL CFemmplotDoc::GrabMetafile()
{
	if (IsClipboardFormatAvailable(CF_ENHMETAFILE)==FALSE){
		hMetaPlot=NULL;
		return FALSE;
	
	}
	if (OpenClipboard(NULL)==FALSE)
		AfxMessageBox("Cannot access the Clipboard");
	else{
		HENHMETAFILE hMetaClip = (HENHMETAFILE) GetClipboardData(CF_ENHMETAFILE);
		HGLOBAL hBound = (HGLOBAL) GetClipboardData(CF_TEXT);
		if(hMetaClip==NULL)
		{
			AfxMessageBox("Couldn't GetClipboardData");
		}
		else{
			DWORD len =(DWORD) GetEnhMetaFileBits(hMetaClip,NULL,NULL);
			unsigned char *buff=(unsigned char *) malloc(len);
			if(GetEnhMetaFileBits(hMetaClip,len,buff)==0)
				AfxMessageBox("MetaFile not copied");
			hMetaPlot=SetEnhMetaFileBits(len,buff);
			if(hBound!=NULL){
				sscanf((char *) hBound,"%lf %lf %lf %lf",
					&bb_left,&bb_bottom,&bb_right,&bb_top);
				HasBoundingBox=TRUE;
			}
			EmptyClipboard();
		}

		CloseClipboard();
	}
	
	return TRUE;
}

⌨️ 快捷键说明

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