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

📄 mpstestclientview.cpp

📁 《VC++ 编程技巧与示例 .rar》各个示例代码绝对可用
💻 CPP
字号:
// MPSTestClientView.cpp : implementation of the CMPSTestClientView class
//

#include "stdafx.h"
#include "MPSTestClient.h"

#include "MPSTestClientDoc.h"
#include "MPSTestClientView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMPSTestClientView

IMPLEMENT_DYNCREATE(CMPSTestClientView, CScrollView)

BEGIN_MESSAGE_MAP(CMPSTestClientView, CScrollView)
	//{{AFX_MSG_MAP(CMPSTestClientView)
	ON_WM_DESTROY()
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMPSTestClientView construction/destruction

CMPSTestClientView::CMPSTestClientView()
{
	// TODO: add construction code here
	//●:
	cnt=0;
}

CMPSTestClientView::~CMPSTestClientView()
{
}

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

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMPSTestClientView drawing
//●:

void CMPSTestClientView::OnDraw(CDC* pDC)
{
	CMPSTestClientDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CPen pen, * op;
	COLORREF clr,clr1,clr2;
	clr1=RGB(255,100,100);
	clr2=RGB(100,100,255);
	if(m_OldChanging)
	{
		clr=clr1;
	}
	else
	{
		clr=clr2;
	}

	pen.CreatePen(PS_SOLID,1,clr);
	
	CSize sz;
	sz=pDC->GetTextExtent("A");
	//行距:
	lgap=sz.cy+5;
	//当前数据集绘制坐标:
	spx=10;
	spy=10;
	CString Wage;
	Wage.Format("%d",m_Info.m_Wage);
	//绘图:
	CString str;
	op=pDC->SelectObject(&pen);
	pDC->MoveTo(0,spy);
	pDC->LineTo(500,spy);
	pDC->SetTextColor(clr);
	str=m_Info.m_Name;
	pDC->TextOut(spx,spy+  lgap,str);
	pDC->TextOut(spx,spy+2*lgap,m_Info.m_Career);
	pDC->TextOut(spx,spy+3*lgap,Wage);
	pDC->TextOut(spx,spy+4*lgap,m_Info.m_Things);
	pDC->SelectObject(op);
	pen.DeleteObject();
}

void CMPSTestClientView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();

	// TODO: calculate the total size of this view
	//●:
	CSize sizeTotal;
	sizeTotal.cx =500;
	sizeTotal.cy =600;
	SetScrollSizes(MM_TEXT, sizeTotal);
	if(!OpenMapFile("用户信息"))
	{
		AfxMessageBox("无法打开内存映像文件!");
	}
	memcpy((void * )&m_Info,m_pMapView,sizeof(_Info));
	if(m_Info.m_Exit!=TRUE)
	{
		SetTimer(1,5,NULL);
	}
	else
	{
		PostQuitMessage(0);
	}
	m_OldChanging=m_Info.m_Changing;
}

/////////////////////////////////////////////////////////////////////////////
// CMPSTestClientView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMPSTestClientView diagnostics

#ifdef _DEBUG
void CMPSTestClientView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CMPSTestClientView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CMPSTestClientView message handlers
	//●:

BOOL CMPSTestClientView::OpenMapFile(CString fn)
{
	m_hMapFile = OpenFileMapping(FILE_MAP_READ, //准备只进行读操作;
							   FALSE,//文件名不可继承;
                               fn);//文件名
	if (m_hMapFile == NULL) 
	{ 
		AfxMessageBox("Could not open file-mapping object."); 
		return FALSE;
	}  
	m_pMapView = MapViewOfFile(m_hMapFile, //内存句柄;
								FILE_MAP_READ,//准备只进行读操作;
								0,            // Max. object size. 
								0,            // Size of hFile. 
								0);           // Map entire file.  
	if (m_pMapView == NULL)
	{
		AfxMessageBox("Could not map view of file."); 
		return FALSE;
	} 
	return TRUE;
}


void CMPSTestClientView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	memcpy((void * )&m_Info,m_pMapView,sizeof(_Info));
	if(m_Info.m_Exit!=TRUE)
	{
		SetTimer(1,5,NULL);
	}
	else
	{
		PostQuitMessage(0);
	}
	if(m_OldChanging!=m_Info.m_Changing)
	{
		cnt++;
		Invalidate();
		m_OldChanging=m_Info.m_Changing;
	}
	CScrollView::OnTimer(nIDEvent);
}

void CMPSTestClientView::OnDestroy() 
{
	CScrollView::OnDestroy();
	
	// TODO: Add your message handler code here
	if(!m_hMapFile||!m_pMapView)
	{
		return;
	}

	if (!UnmapViewOfFile(m_pMapView)) 
	{ 
		AfxMessageBox("Could not unmap view of file."); 
	}
	::CloseHandle(m_hMapFile);
}

⌨️ 快捷键说明

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