viewdibview.cpp
来自「一个非常全的vc编程的原程序代码是关于图像处理的!」· C++ 代码 · 共 229 行
CPP
229 行
// ViewDIBView.cpp : implementation of the CViewDIBView class
//
#include "stdafx.h"
#include "ViewDIB.h"
#include "ViewDIBDoc.h"
#include "ViewDIBView.h"
#include "MACRO.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CViewDIBView
IMPLEMENT_DYNCREATE(CViewDIBView, CScrollView)
BEGIN_MESSAGE_MAP(CViewDIBView, CScrollView)
//{{AFX_MSG_MAP(CViewDIBView)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CViewDIBView construction/destruction
CViewDIBView::CViewDIBView()
{
// TODO: add construction code here
}
CViewDIBView::~CViewDIBView()
{
}
BOOL CViewDIBView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CViewDIBView drawing
void CViewDIBView::OnDraw(CDC* pDC)
{
CViewDIBDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(!pDoc->m_pDib->IsEmpty())
pDoc->m_pDib->Display(pDC,0,0);
DrawArea(pDC);
}
void CViewDIBView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CViewDIBDoc* pDoc=GetDocument();
int width,height;
if(pDoc!=NULL){
pDoc->OnNewDocument();
}
width=pDoc->m_pDib->GetWidth();
height=pDoc->m_pDib->GetHeight();
CSize sizeTotal;
sizeTotal.cx=sizeTotal.cy=0;
if(width)
sizeTotal.cx=width;
if(height)
sizeTotal.cy=height;
// TODO: calculate the total size of this view
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CViewDIBView printing
BOOL CViewDIBView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CViewDIBView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CViewDIBView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CViewDIBView diagnostics
#ifdef _DEBUG
void CViewDIBView::AssertValid() const
{
CScrollView::AssertValid();
}
void CViewDIBView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CViewDIBDoc* CViewDIBView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CViewDIBDoc)));
return (CViewDIBDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CViewDIBView message handlers
void CViewDIBView::DrawArea(CDC *pDC)
{
CPen pen(PS_DOT,1,RGB(0,0,0));
CPen* pOldPen=pDC->SelectObject(&pen);
pDC->SetROP2(R2_NOT);
if(m_AreaMode==POLYAREA){
int i;
pDC->MoveTo(PolyPoint[3]);
for(i=0;i<4;i++){
pDC->LineTo(PolyPoint[i]);
pDC->Rectangle(PolyPoint[i].x-5,PolyPoint[i].y-5,
PolyPoint[i].x+5,PolyPoint[i].y+5);
pDC->MoveTo(PolyPoint[i]);
}
}
}
void CViewDIBView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC* pDC=GetDC();
if((m_AreaMode==POLYAREA)&&(m_DrawStartFlag==DRAWSTART)&&(m_ActivePoint!=-1)){
// Invalidate();
DrawArea(pDC);
PolyPoint[m_ActivePoint].x=point.x;
PolyPoint[m_ActivePoint].y=point.y;
DrawArea(pDC);
}
CScrollView::OnMouseMove(nFlags, point);
}
void CViewDIBView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_DrawStartFlag=DRAWSTART;
Invalidate();
if(m_AreaMode==POLYAREA){
m_ActivePoint=-1;
for(int i=0;i<4;i++){
if((abs(PolyPoint[i].x-point.x)<=5)
&&(abs(PolyPoint[i].y-point.y)<=5))
m_ActivePoint=i;
}
}
CScrollView::OnLButtonDown(nFlags, point);
}
void CViewDIBView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_DrawStartFlag=DRAWEND;
CScrollView::OnLButtonUp(nFlags, point);
}
void CViewDIBView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDC* pDC=GetDC();
DrawArea(pDC);
if(m_AreaMode==POLYAREA){
for(int i=0;i<4;i++){
PolyPoint[i].x=0;
PolyPoint[i].y=0;
}
}
Invalidate();
m_AreaMode=NULLAREA;
CScrollView::OnRButtonDblClk(nFlags, point);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?