www.pudn.com > VX.rar > DTASvmView.cpp
// DTASvmView.cpp : implementation of the CDTASvmView class
//
#include "stdafx.h"
#include "DTASvm.h"
#include "DTASvmDoc.h"
#include "DTASvmView.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CDTASvmView* g_pDTASView = NULL; //定义视图指针型的全局变量(在其他类中声明方可使用)
/////////////////////////////////////////////////////////////////////////////
// CDTASvmView
IMPLEMENT_DYNCREATE(CDTASvmView, CView)
BEGIN_MESSAGE_MAP(CDTASvmView, CView)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CDTASvmView)
ON_WM_CREATE()
ON_WM_SETCURSOR()
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_FILE_SAVE, OnFileSave)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CDTASvmView construction/destruction
CDTASvmView::CDTASvmView()
{
pen_Brown = new CPen(PS_DOT,1,RGB(192,128,0));
}
CDTASvmView::~CDTASvmView()
{
g_pDTASView = NULL;
delete pen_Brown;
}
BOOL CDTASvmView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDTASvmView drawing
void CDTASvmView::OnDraw(CDC* pDC)
{
CDTASvmDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
Drawing();
}
/////////////////////////////////////////////////////////////////////////////
// CDTASvmView printing
BOOL CDTASvmView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDTASvmView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDTASvmView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDTASvmView diagnostics
#ifdef _DEBUG
void CDTASvmView::AssertValid() const
{
CView::AssertValid();
}
void CDTASvmView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CDTASvmDoc* CDTASvmView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDTASvmDoc)));
return (CDTASvmDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDTASvmView message handlers
void CDTASvmView::Drawing() //绘图函数
{
CDC* pDC=GetDC();
CRect clientRect;
GetClientRect(&clientRect);
for(int m = 18 ;m< 20;m++) //绘图示例—显示渐变色
if(Flags_c[m])
{
for(int h=clientRect.left;h<=clientRect.right;h++){
float d=142/float(clientRect.right-clientRect.left);
CPen pen(PS_SOLID,0,RGB(78+h*d,102+h*d,113+h*d));
CPen* oldpen = pDC->SelectObject(&pen);
pDC->MoveTo(clientRect.left+h,clientRect.top);
pDC->LineTo(clientRect.left+h,clientRect.bottom);
pDC->SelectObject(oldpen);
}
break;
}
for(int k = 13 ;k< 18;k++) //绘图示例—显示位图
if(Flags_c[k])
{
CBrush* pTempBrush = NULL;
CBrush OrigBrush;
OrigBrush.FromHandle((HBRUSH)pTempBrush);
CRect rc;
GetClientRect(&rc);
//ScreenToClient(&rc);
try
{
CBitmap bmp;
bmp.LoadBitmap(IDB_BITBRUSH);
CBrush brush(&bmp);
pTempBrush = (CBrush*)pDC->SelectObject(brush);
pDC->Rectangle(rc.left,rc.top, rc.Width(), rc.Height());
pDC->SelectObject(&OrigBrush);
break;
}
catch(CResourceException* e)
{
e->ReportError();
e->Delete();
}
}
for(int j = 8 ;j< 13;j++) // 绘图示例—椭圆
if(Flags_c[j])
{
pDC->Ellipse(&clientRect);
break;
}
for(int i = 0 ;i< 8;i++) // 绘图示例—对角线:得到客户区坐标
if(Flags_c[i])
{
CPen* pOldPen=pDC->SelectObject(pen_Brown);
pDC->MoveTo(clientRect.left,clientRect.top);
pDC->LineTo(clientRect.right,clientRect.bottom);
pDC->MoveTo(clientRect.left,clientRect.bottom);
pDC->LineTo(clientRect.right,clientRect.top);
break;
pDC->SelectObject(pOldPen);
}
ReleaseDC(pDC);
}
int CDTASvmView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
g_pDTASView = this; //给视图指针赋值
return 0;
}
BOOL CDTASvmView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
switch(m_nType)
{
case 0:
::SetCursor(AfxGetApp()->LoadCursor(IDC_CUR_ZOOMIN));
break;
case 1:
::SetCursor(AfxGetApp()->LoadCursor(IDC_CUR_ZOOMOUT));
break;
case 2:
::SetCursor(AfxGetApp()->LoadCursor(IDC_CUR_MOVING));
break;
default:
::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
break;
}
return TRUE;
}
void CDTASvmView::OnRButtonDown(UINT nFlags, CPoint point)
{
m_nType = -1;
CView::OnRButtonDown(nFlags, point);
}
void CDTASvmView::OnFileSave()
{
// TODO: Add your command handler code here
}
void CDTASvmView::OnFileSaveAs()
{
// TODO: Add your command handler code here
}
void CDTASvmView::OnContextMenu(CWnd*, CPoint point)
{
// CG: This block was added by the Pop-up Menu component
{
if (point.x == -1 && point.y == -1){
//keystroke invocation
CRect rect;
GetClientRect(rect);
ClientToScreen(rect);
point = rect.TopLeft();
point.Offset(5, 5);
}
CMenu menu;
VERIFY(menu.LoadMenu(CG_IDR_POPUP_DTASVM_VIEW));
CMenu* pPopup = menu.GetSubMenu(0);
ASSERT(pPopup != NULL);
CWnd* pWndPopupOwner = this;
while (pWndPopupOwner->GetStyle() & WS_CHILD)
pWndPopupOwner = pWndPopupOwner->GetParent();
pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
pWndPopupOwner);
}
}