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

📄 mymouseview.cpp

📁 数据结构中
💻 CPP
字号:
// myMouseView.cpp : implementation of the CMyMouseView class
//

#include "stdafx.h"
#include "myMouse.h"

#include "myMouseDoc.h"
#include "myMouseView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMyMouseView

IMPLEMENT_DYNCREATE(CMyMouseView, CView)

BEGIN_MESSAGE_MAP(CMyMouseView, CView)
	//{{AFX_MSG_MAP(CMyMouseView)
	ON_WM_CHAR()
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CMyMouseView construction/destruction

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

}

CMyMouseView::~CMyMouseView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMyMouseView drawing

void CMyMouseView::OnDraw(CDC* pDC)
{
	CMyMouseDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	CRect dcRect;
	GetClientRect(&dcRect);
	//创建一支红色实体模式画刷
	CBrush NewBrush2(RGB(255,200,0)); 
	//将新画刷选入设备环境中
	CBrush * pOldBrush = pDC->SelectObject( &NewBrush2 );
	//绘制矩形
    int m=dcRect.right/15;
	int n=dcRect.bottom/11;
	int arr[11][15]={
		{0,1,0,0,0,1,1,0,0,0,1,1,1,1,1},
		{1,0,0,0,1,1,0,1,1,1,0,0,1,1,1},
		{0,1,1,0,0,0,0,1,1,1,1,0,0,1,1},
		{1,1,0,1,1,1,1,0,1,1,0,1,1,0,0},
		{1,1,0,1,0,0,1,0,1,1,1,1,1,1,1},
		{0,0,1,1,0,1,1,1,0,1,0,0,1,1,1},
		{0,1,1,1,1,0,0,1,1,1,1,1,1,1,1},
		{0,0,1,1,0,1,1,0,1,1,1,1,1,0,1},
		{1,1,0,0,0,1,1,0,1,1,0,0,0,0,0},
		{0,0,1,1,1,1,1,0,0,0,1,1,1,1,0},
		{0,1,0,0,1,1,1,1,1,0,1,1,1,1,0}
	};
	int l;
	int k;
	for(l=0;l<11;l++)
	for(k=0;k<15;k++)
	{	
		pDC->Rectangle(k*m,l*n,k*m+m,l*n+n);
	}
	//恢复设备环境中原有的画刷
	pDC->SelectObject( pOldBrush );

	CBrush NewBrush(RGB(150,100,40)); 
	//将新画刷选入设备环境中
	CBrush * pNewBrush = pDC->SelectObject( &NewBrush );
	for(l=0;l<11;l++)
	for(k=0;k<15;k++)
	{	
		if(arr[l][k] == 1)
		pDC->Rectangle(k*m,l*n,k*m+m,l*n+n);
	}
	pDC->SelectObject(pOldBrush);
}

/////////////////////////////////////////////////////////////////////////////
// CMyMouseView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyMouseView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMyMouseView message handlers

void CMyMouseView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	CMyMouseDoc *pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if(nChar = ' ')
	{
		CDC *pDC = CWnd::GetDC();
		CMyMouseDoc* pDoc = GetDocument();
		ASSERT_VALID(pDoc);
		// TODO: add draw code for native data here
		CRect dcRect;
		GetClientRect(&dcRect);
		//创建一支红色实体模式画刷
		CBrush NewBrush2(RGB(160,100,86)); 
		//将新画刷选入设备环境中
		CBrush * pOldBrush = pDC->SelectObject( &NewBrush2 );
		//绘制矩形
		int m=dcRect.right/15;
		int n=dcRect.bottom/11;
		int l;
		int k;
		//CBrush NewBrush(RGB(20,200,40)); 
		//将新画刷选入设备环境中
		//CBrush * pNewBrush = pDC->SelectObject( &NewBrush );

		CBitmap bitmap;
		HBITMAP hBitmap=(HBITMAP)LoadImage(NULL,"G:\\Huang\\testbmp\\minmouse.bmp",IMAGE_BITMAP,m,n,LR_LOADFROMFILE);
		bitmap.Attach(hBitmap);
	
		CDC dcComp;
		dcComp.CreateCompatibleDC(pDC);
		dcComp.SelectObject(&bitmap);
		//CClientDC dc(this);
		//dc.SelectObject(&bitmap);
		////////////////////
		BITMAP bmInfo;
		bitmap.GetObject(sizeof(bmInfo),&bmInfo);

		
		for(l=0;l<11;l++)
		for(k=0;k<15;k++)
		{
			pDC->BitBlt(k*m,l*n,bmInfo.bmWidth,bmInfo.bmHeight,&dcComp,0,0,SRCCOPY);
		//	pDC->Rectangle(k*m,l*n,k*m+m,l*n+n);
			MessageBox(NULL,NULL,MB_OK);
		}
		pDC->SelectObject(pOldBrush);
		ReleaseDC(pDC);


	}
	
	CView::OnChar(nChar, nRepCnt, nFlags);
	Invalidate();
	UpdateWindow();
}

⌨️ 快捷键说明

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