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

📄 mfcapview.cpp

📁 学习运用MFC封装类的DLL,可以实现GUI 的通用性.
💻 CPP
字号:
// MFCApView.cpp : implementation of the CMFCApView class
//

#include "stdafx.h"
#include "DLLCode.h"
#include "MFCAp.h"

#include "MFCApDoc.h"
#include "MFCApView.h"


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

/////////////////////////////////////////////////////////////////////////////
// CMFCApView

IMPLEMENT_DYNCREATE(CMFCApView, CView)

BEGIN_MESSAGE_MAP(CMFCApView, CView)
	//{{AFX_MSG_MAP(CMFCApView)
		// 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
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMFCApView construction/destruction

CMFCApView::CMFCApView()
{
	// TODO: add construction code here

}

CMFCApView::~CMFCApView()
{
}

BOOL CMFCApView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMFCApView drawing

void CMFCApView::OnDraw(CDC* pDC)
{
	CRect rect;
	rect.top=10;
	rect.left=10;
	rect.right=200;
	rect.bottom=200; 
	DrawEllipse(rect,pDC); 
	
	// DLL class object call
	int a, b, c;
	CString str;
	DLLclass classFromDLL; 
	classFromDLL.Arg = 6; 
	a = classFromDLL.Add(3, 2);
	b = classFromDLL.Sub(3, 2);
	c = classFromDLL.Arg;
	
	// Display data in window
	int y = 250, dy;
	TEXTMETRIC tm;
	pDC->GetTextMetrics(&tm);
	dy = tm.tmHeight + tm.tmExternalLeading; 
	str.Format("DLL class Add function return: %d", a);
	pDC->TextOut(20, y, str);
	y += dy;
	str.Format("DLL class Sub function return: %d", b);
	pDC->TextOut(20, y, str);
	y += dy;
	str.Format("DLL class Arg Variable return: %d", c);
	pDC->TextOut(20, y, str);
	y += dy; 
	a = DLLArg;
	b = DLLfun2(30); 
	str.Format("DLL class Arg Variable return: %d", a);
	pDC->TextOut(20, y, str);
	y += dy;
	str.Format("DLL function \"DLLfun2\" return: %d", b);
   pDC->TextOut(20, y, str);
}

/////////////////////////////////////////////////////////////////////////////
// CMFCApView printing

BOOL CMFCApView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMFCApView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMFCApView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMFCApView diagnostics

#ifdef _DEBUG
void CMFCApView::AssertValid() const
{
	CView::AssertValid();
}

void CMFCApView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMFCApDoc* CMFCApView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMFCApDoc)));
	return (CMFCApDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMFCApView message handlers

⌨️ 快捷键说明

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