www.pudn.com > OpenGL实现三维绘图.rar > ProjectView.cpp
// ProjectView.cpp : implementation file
//
#include "stdafx.h"
#include "Test1.h"
#include "ProjectView.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern GLfloat Databuf[ArrayOne][ArrayTwo];
extern bool gbIsGetData;
extern GLfloat xrof,yrof,zrof;//各坐标轴倾角
/////////////////////////////////////////////////////////////////////////////
// CProjectView
IMPLEMENT_DYNCREATE(CProjectView, CView)
CProjectView::CProjectView()
{
m_WitchPro = 0;
this->m_ProName = "";
m_pDC = NULL;
m_bShowBmp = false;
}
CProjectView::~CProjectView()
{
if (m_pDC)
{
delete m_pDC;
m_pDC = NULL;
}
}
BEGIN_MESSAGE_MAP(CProjectView, CView)
//{{AFX_MSG_MAP(CProjectView)
ON_WM_ERASEBKGND()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
ON_MESSAGE(MESSAGE_ANGLECHANGING,AngleChanging)
ON_MESSAGE(MESSAGE_BMPHASBECOPIED,ShowBmpMessageFun)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProjectView drawing
void CProjectView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
CFont *OldFont = pDC->SelectObject(&this->m_pfr->m_13Font);
this->DrawCoordinate(pDC);
// this->DrawRect(pDC);
if (this->m_bShowBmp)
{
HBITMAP hBmp = this->m_pfr->m_pView->m_hBmp;
this->ShowSelArear(hBmp,pDC);
}
pDC->SelectObject(OldFont);
}
/////////////////////////////////////////////////////////////////////////////
// CProjectView diagnostics
#ifdef _DEBUG
void CProjectView::AssertValid() const
{
CView::AssertValid();
}
void CProjectView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CProjectView message handlers
void CProjectView::OnInitialUpdate()
{
CView::OnInitialUpdate();
m_pfr = (CMainFrame*)AfxGetApp()->m_pMainWnd;
}
BOOL CProjectView::OnEraseBkgnd(CDC* pDC)
{
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
CBrush Brush (BLACK);
CBrush* pOldBrush = pDC->SelectObject(&Brush);
CRect ViewClip;
pDC->GetClipBox(&ViewClip);
pDC->PatBlt(ViewClip.left,ViewClip.top,ViewClip.Width(),ViewClip.Height(),PATCOPY);
pDC->SelectObject (pOldBrush );
return TRUE;
}
void CProjectView::DrawRect(CDC *pDC)
{
CRect rc;
this->GetClientRect(&rc);
int cx = rc.right;
int cy = rc.bottom;
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
int yStart = 10;
int nCharWith = tm.tmHeight;
CPen Brightpen(PS_SOLID, 1, RED);
CPen *pOldPen = pDC->SelectObject(&Brightpen);
pDC->SetTextAlign(TA_RIGHT);
pDC->MoveTo(cx - nCharWith*5 - 2, 0);
pDC->LineTo(cx - nCharWith*5 - 2, rc.bottom-30);
pDC->TextOut(cx ,10, "成图参数表");
pDC->SetTextColor(BLUE);
pDC->MoveTo(cx - nCharWith*5 - 1, 10 + nCharWith + 1);
pDC->LineTo(cx , 10 + nCharWith + 1);
pDC->MoveTo(cx - nCharWith*5 - 1, rc.bottom-30);
pDC->LineTo(cx , rc.bottom-30);
pDC->SetTextAlign(TA_LEFT);
pDC->TextOut(cx - nCharWith*5, 10 + nCharWith + 2, "○X轴倾角");
pDC->TextOut(cx - nCharWith*5, 10 + nCharWith*3 + 4, "○Y轴倾角");
pDC->TextOut(cx - nCharWith*5, 10 + nCharWith*5 + 6, "○Z轴倾角");
pDC->SetTextColor(BRIGHT);
pDC->TextOut(cx - nCharWith*5, 10 + nCharWith*2 + 2, this->GetAngle(xrof));
pDC->TextOut(cx - nCharWith*5, 10 + nCharWith*4 + 4, this->GetAngle(yrof));
pDC->TextOut(cx - nCharWith*5, 10 + nCharWith*6 + 6, this->GetAngle(zrof));
pDC->SelectObject(pOldPen);
}
void CProjectView::DrawCoordinate(CDC *pDC)
{
CRect rc;
GetClientRect(&rc);
pDC->SetTextAlign(TA_CENTER);
pDC->SetTextColor(YELLOW);
pDC->SetBkMode(1);
CPen Greenpen(PS_SOLID,1,GREEN);
CPen *pOldPen = pDC->SelectObject(&Greenpen);
CString Show = "选取部位投影窗口" + m_ProName;
pDC->TextOut(rc.right/2,2,Show);
//x轴
pDC->MoveTo(10,rc.bottom-20);
pDC->LineTo(rc.right-30,rc.bottom-20);
pDC->MoveTo(rc.right-30,rc.bottom-20);
pDC->LineTo(rc.right-30-5,rc.bottom-20-5);
pDC->MoveTo(rc.right-30,rc.bottom-20);
pDC->LineTo(rc.right-30-5,rc.bottom-20+5);
//y轴
pDC->MoveTo(10,rc.bottom-20);
pDC->LineTo(10,25);
pDC->MoveTo(10,25);
pDC->LineTo(5,30);
pDC->MoveTo(10,25);
pDC->LineTo(15,30);
if (::gbIsGetData)
return;
pDC->SelectObject(pOldPen);
}
CString CProjectView::GetAngle(int Angle)
{
CString strAngle = "0";
if (Angle > -360 && Angle < 360)
strAngle.Format("%d度", Angle);
else
strAngle.Format("%d度",Angle%360);
return strAngle;
}
void CProjectView::AngleChanging(LPARAM lp, WPARAM wp)
{
this->InvalidatethisRect();
}
void CProjectView::InvalidatethisRect()
{
CRect rc;
GetClientRect(&rc);
int cx = rc.right;
int cy = rc.bottom;
this->InvalidateRect(CRect(15,21,cx-15,cy-30));
}
void CProjectView::OnMouseMove(UINT nFlags, CPoint point)
{
this->SetFocus();
CView::OnMouseMove(nFlags, point);
}
void CProjectView::ShowSelArear(HBITMAP hBmp, CDC *pDC)
{
HBITMAP OldBitmap;
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
CRect rect;
GetClientRect(rect);
OldBitmap=(HBITMAP)MemDC.SelectObject(hBmp);
pDC->BitBlt(20,20,rect.right,rect.bottom,&MemDC,0,0,SRCCOPY);
MemDC.SelectObject(OldBitmap);
}
void CProjectView::ShowBmpMessageFun(LPARAM lp, WPARAM wp)
{
m_bShowBmp = true;
this->InvalidatethisRect();
}