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

📄 docviewview.cpp

📁 第4章 图像增强(对比度增强、灰度变换法、直方图修整法、图像平滑、图像锐化、伪彩色和假彩色增强);
💻 CPP
字号:
// DocViewView.cpp : implementation of the CDocViewView class
//

#include "stdafx.h"
#include "DocView.h"

#include "DocViewDoc.h"
#include "DocViewView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDocViewView

IMPLEMENT_DYNCREATE(CDocViewView, CView)

BEGIN_MESSAGE_MAP(CDocViewView, CView)
	//{{AFX_MSG_MAP(CDocViewView)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	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()

/////////////////////////////////////////////////////////////////////////////
// CDocViewView construction/destruction

CDocViewView::CDocViewView()
{
	// TODO: add construction code here
	m_nLine = 0;
	m_bMouseDown = false;
	m_hCross = AfxGetApp()->LoadStandardCursor(IDC_CROSS);
	m_hArrow = AfxGetApp()->LoadStandardCursor(IDC_ARROW);

}

CDocViewView::~CDocViewView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDocViewView drawing

void CDocViewView::OnDraw(CDC* pDC)
{
	CDocViewDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	pDC->MoveTo(12,34);
	pDC->LineTo(100,200);
	pDC->LineTo(200,200);
	pDC->LineTo(200,300);
	pDC->LineTo(300,200);
}

/////////////////////////////////////////////////////////////////////////////
// CDocViewView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDocViewView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDocViewView message handlers

void CDocViewView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	// TODO: Add your message handler code here and/or call default
	m_bMouseDown = true;
	m_ptStart = point;
	m_ptOld = point;
	SetCapture();
	CRect rect;
	GetClientRect(&rect);
	ClientToScreen(&rect);
	ClipCursor(&rect);
	SetCursor(m_hCross);	//设置鼠标形状为十字形
	
	CView::OnLButtonDown(nFlags, point);
}

void CDocViewView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if( m_bMouseDown )
	{
		m_bMouseDown = false;
		ReleaseCapture();
		ClipCursor( NULL );
		CClientDC dc(this);
		dc.SetROP2( R2_NOT );
		dc.MoveTo( m_ptStart );       //这两行代码擦除从起点(鼠标按下点)到
		dc.LineTo( m_ptOld );          //上次鼠标移动到的位置之间的临时线   
		dc.SetROP2( R2_COPYPEN );
		dc.MoveTo( m_ptStart );      //这两行代码从起点到鼠标当前位置画线
		dc.LineTo( point );                //
	               SetCursor(m_hArrow);          //设置鼠标形状为标准箭头形
	}
	
	CView::OnLButtonUp(nFlags, point);
}

void CDocViewView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if( m_bMouseDown )
	{
		CClientDC dc(this);
		dc.SetROP2( R2_NOT );
		dc.MoveTo( m_ptStart );	//这两行代码擦除从起点(鼠标按下点)到
		dc.LineTo( m_ptOld );	//上次鼠标移动到的位置之间的临时线
		dc.MoveTo( m_ptStart );	//这两行代码从起点到鼠标当前位置画线
		dc.LineTo( point );		// 
		m_ptOld = point;	//鼠标当前位置在下一次鼠标移动事件看来就是"旧位置"
	}
	
	CView::OnMouseMove(nFlags, point);
}

void CDocViewView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	// TODO: Add your message handler code here and/or call default
	if(nChar == VK_RETURN)
	{
		m_strDisplay.Empty();
		m_nLine++;
	}
	else if(m_strDisplay.GetLength() < 64)
		m_strDisplay += nChar;
	CClientDC dc(this);
	TEXTMETRIC tm;
	dc.GetTextMetrics(&tm);
	int nLineHeight = tm.tmHeight + tm.tmExternalLeading;
	dc.TextOut(0, m_nLine * nLineHeight, m_strDisplay);
	CView::OnChar(nChar, nRepCnt, nFlags);
	
	CView::OnChar(nChar, nRepCnt, nFlags);
}

⌨️ 快捷键说明

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