www.pudn.com > Map_OpenGL.rar > Map_2DView.cpp
// Map_2DView.cpp : implementation file
//
#include "stdafx.h"
#include "Map_OpenGL.h"
#include "Map_2DView.h"
#include "Map_Tool.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMap_2DView
IMPLEMENT_DYNCREATE(CMap_2DView, CView)
CMap_2DView::CMap_2DView()
{
m_mpDC=new CDC;
m_bitmap=new CBitmap;
}
CMap_2DView::~CMap_2DView()
{
}
BEGIN_MESSAGE_MAP(CMap_2DView, CView)
//{{AFX_MSG_MAP(CMap_2DView)
ON_WM_CREATE()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMap_2DView drawing
void CMap_2DView::OnDraw(CDC* pDC)
{
CMap_OpenGLDoc* pDoc = GetDocument();
ASSERT(pDoc);
GetClientRect(m_maprc);
// GetWindowRect(m_maprc);
CBitmap* oldbitmap=m_mpDC->SelectObject(m_bitmap);
CBrush bgbrush((COLORREF)::GetSysColor(COLOR_WINDOW));
CBrush* oldbrush=m_mpDC->SelectObject(&bgbrush);
m_mpDC->PatBlt(m_maprc.left,m_maprc.top,m_maprc.Width(),m_maprc.Height(),PATCOPY);
if(CMap_Tool::map_select==Map_binarydem)
{
pDoc->m_binarydem.InitShow(m_maprc);
pDoc->m_binarydem.ShowDem(m_mpDC);
}
if(CMap_Tool::map_select==Map_texttin)
{
pDoc->m_tindate.InitShow(m_maprc);
pDoc->m_tindate.TinShow(m_mpDC);
}
pDC->BitBlt(m_maprc.left,m_maprc.top,m_maprc.Width(),m_maprc.Height(),m_mpDC,m_maprc.left,m_maprc.top,SRCCOPY);
m_mpDC->SelectObject(oldbitmap);
m_mpDC->SelectObject(oldbrush);
}
/////////////////////////////////////////////////////////////////////////////
// CMap_2DView diagnostics
#ifdef _DEBUG
void CMap_2DView::AssertValid() const
{
CView::AssertValid();
}
void CMap_2DView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMap_2DView message handlers
int CMap_2DView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
CClientDC pDC(this);
// TODO: Add your specialized creation code here
//保存屏幕坐标中水平和垂直方向的值
int m_nFullWidth = GetSystemMetrics(SM_CXSCREEN);
int m_nFullHeight = GetSystemMetrics(SM_CYSCREEN);
//GetSafeHdc()函数的功能是:得到成员函数输出设备的上下文m_hdc
// 如果设备上下文的m_hdc为空,则执行以下的程序,否则不执行
if(m_mpDC->GetSafeHdc() == NULL) //m_pMemDC = new CDC
{
CRect rectMax(0,0,m_nFullWidth,m_nFullHeight);
//CreateCompatibleDC()是在内存中分创建一个与设备上下文对应的设备上下文
m_mpDC->CreateCompatibleDC(&pDC);
//在内存中创建一个于位图相关的设备上下文
m_bitmap->CreateCompatibleBitmap(&pDC,rectMax.right,rectMax.bottom);
//定义一个位图指针变更,保存原有的位图模式
CBitmap* pOldBitmap = m_mpDC->SelectObject(m_bitmap);
//得到系统窗口的画刷颜色
CBrush backgroundBrush((COLORREF)::GetSysColor(COLOR_WINDOW));
//设置并保存原有的画刷颜色
CBrush* pOldBrush = m_mpDC->SelectObject(&backgroundBrush);
//复制模式到指定的矩形范围内
m_mpDC->PatBlt(rectMax.left,rectMax.top,rectMax.Width(),rectMax.Height(),PATCOPY);
//还原位图和画刷设置
m_mpDC->SelectObject(pOldBitmap);
m_mpDC->SelectObject(pOldBrush);
}
return 0;
}
void CMap_2DView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMap_OpenGLDoc* pDoc=GetDocument();
ASSERT(pDoc);
CMainFrame* pFram=(CMainFrame*)AfxGetApp()->m_pMainWnd;
CStatusBar* pst=&pFram->m_wndStatusBar;
CString str_dem;
if(CMap_Tool::map_select==Map_binarydem)
{
double x,y;
pDoc->m_binarydem.ScreenToMap(point.x,point.y,x,y);
str_dem.Format("X=%f;Y=%f",x,y);
pst->SetPaneText(0,str_dem);
}
if(CMap_Tool::map_select==Map_texttin)
{
double x,y;
pDoc->m_tindate.ScreenToMap(point.x,point.y,x,y);
str_dem.Format("X=%f;Y=%f",x,y);
pst->SetPaneText(0,str_dem);
}
CView::OnMouseMove(nFlags, point);
}