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

📄 upview.cpp

📁 实现了2D地图编辑器的基本功能
💻 CPP
字号:
// UpView.cpp : 实现文件
//

#include "stdafx.h"
#include "MapEditor.h"
#include "UpView.h"
POINT bp;


// CUpView

IMPLEMENT_DYNCREATE(CUpView, CView)

CUpView::CUpView()
{

}

CUpView::~CUpView()
{
}

BEGIN_MESSAGE_MAP(CUpView, CView)
    ON_WM_PAINT()
    ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()


// CUpView 绘图

void CUpView::OnDraw(CDC* pDC)
{
	CDocument* pDoc = GetDocument();
	// TODO: 在此添加绘制代码
    ASSERT_VALID(pDoc);
    if (!pDoc)
        return;

    int i;
	int j,m,n;
	int k = 0;
	CBrush   m_brush;
	CPen     m_pen;
    CRect    m_rect;

    HDC      hdc;
    HBITMAP  m_hbmp;
    m_hbmp = NULL;

    m_brush.CreateSolidBrush(RGB(255,255,255));
	m_pen.CreatePen(PS_SOLID,1,RGB(255,0,0));

    this->GetClientRect(&m_rect);
	pDC->FillRect(&CRect(0,0,m_rect.right,m_rect.bottom),&m_brush);m = 0;
    m = 0;
    k = 0;
    for(i = 0;  i < m_rect.bottom ; i = i + 32)
	{
        n = 0;
		for(j =0; j < m_rect.right; j = j + 32)
		{ 
			m_bmesh[m][n].i = k;
			m_bmesh[m][n].rect  = CRect(j,i, j+32,i+32);
			m_bmesh[m][n].point = CPoint(n*32, m*32);
			k = k + 1;
			n = n + 1;
		}
		m = m + 1;
	}
    x1 = m - 1;
    y1 = n - 1;

   	hdc=CreateCompatibleDC(pDC->m_hDC);
	m_hbmp=(HBITMAP)LoadImage(::AfxGetInstanceHandle(),//
				                         m_Pathname,     //文件名
				                         IMAGE_BITMAP, //位图方式
				                                   0,  //图形宽
				                                   0,  //图形高
				    LR_LOADFROMFILE|LR_CREATEDIBSECTION//方式
				    );
    SelectObject(hdc,m_hbmp);
    BitBlt(pDC->m_hDC,0,0,800,600, hdc,0,0,SRCCOPY);

    pDC->SelectObject(&m_pen);
    for(i = 0; i < m_rect.bottom; i = i + 32)
	{
		pDC->MoveTo(0, i);
		pDC->LineTo((int)m_rect.right,i);
	}

	for(j = 0; j < (int)m_rect.right; j = j + 32)
	{
		pDC->MoveTo(j, 0);
		pDC->LineTo(j,(int)m_rect.bottom);
	}
    pDC->SelectObject(&m_pen);
}


// CUpView 诊断

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

#ifndef _WIN32_WCE
void CUpView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif
#endif //_DEBUG


// CUpView 消息处理程序

void CUpView::OnPaint()
{
    CPaintDC dc(this); // device context for painting
    // TODO: 在此处添加消息处理程序代码
    // 不为绘图消息调用 CView::OnPaint()
	OnDraw(&dc);
}

void CUpView::OnLButtonDown(UINT nFlags, CPoint point)
{
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    int i, j;
	bool flag =  false;

    for(i = 0; i < x1; i++ )
		  {
			  for(j = 0; j < y1 ; j++)
			  {
				  if(PtInRect(&m_bmesh[i][j].rect,point))
				  {
					 bp = m_bmesh[i][j].point;
					 flag = true;
					 break;
				  }
			  } 
			  if(flag)
			  {
				  break;
			  }
		  }

    CView::OnLButtonDown(nFlags, point);
}

⌨️ 快捷键说明

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