📄 imagecodesview.cpp
字号:
// ImageCodesView.cpp : implementation of the CImageCodesView class
//
#include "stdafx.h"
#include "ImageCodes.h"
#include "ImageCodesDoc.h"
#include "ImageCodesView.h"
//#include "Afxmt.h"
//#include "stdafx.h"
#include "Afxtempl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CString FileName;
extern CArray<CPoint,CPoint&> MaxpointArray;
/////////////////////////////////////////////////////////////////////////////
// CImageCodesView
IMPLEMENT_DYNCREATE(CImageCodesView, CView)
BEGIN_MESSAGE_MAP(CImageCodesView, CView)
//{{AFX_MSG_MAP(CImageCodesView)
ON_WM_VSCROLL()
ON_WM_HSCROLL()
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CImageCodesView construction/destruction
CImageCodesView::CImageCodesView()
{
// TODO: add construction code here
}
CImageCodesView::~CImageCodesView()
{
}
BOOL CImageCodesView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CImageCodesView drawing
void CImageCodesView::OnDraw(CDC* pDC)
{
CImageCodesDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if ( pDoc->newFile == TRUE )
{
pDoc->newFile = FALSE;
OriginX = OriginY = 0;
SetScrollPos( SB_VERT, 0 );
SetScrollPos( SB_HORZ, 0 );
}
// always give this bad boy a "default brush" background
RECT ScreenRect;
GetClientRect( &ScreenRect );
pDC->Rectangle( &ScreenRect );
if ( pDoc->DIB )
pDoc->DIB->Draw( pDC, CPoint( -OriginX,-OriginY ) );
int cx = ScreenRect.right - ScreenRect.left;
int cy = ScreenRect.bottom - ScreenRect.top;
CImageCodesView::SetScrollBarInfo( cx, cy );
if(pDoc->m_Harris)//显示角点
{
HPEN hp;
hp=CreatePen(PS_SOLID,0,RGB(0,255,0));
CPoint pt;
int conersize=MaxpointArray.GetSize();
for(int i=0;i<conersize;i++)
{
pt=MaxpointArray.GetAt(i);
DrawCross(pt,hp);
}
pDoc->m_Harris=FALSE;
DeleteObject(hp);
}
}
void CImageCodesView::SetScrollBarInfo(int cx, int cy)
{
CImageCodesDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if ( pDoc->DIB != NULL)
{
if ( cx >= pDoc->DIB->GetWidth() )
ShowScrollBar( SB_HORZ, FALSE );
else
{
ShowScrollBar( SB_HORZ, TRUE );
int delta = pDoc->DIB->GetWidth() - cx;
SetScrollRange( SB_HORZ, 0, delta );
}
if ( cy >= pDoc->DIB->GetHeight() )
ShowScrollBar( SB_VERT, FALSE );
else
{
ShowScrollBar( SB_VERT, TRUE );
int delta = pDoc->DIB->GetHeight() - cy;
SetScrollRange( SB_VERT, 0, delta );
}
}
else
ShowScrollBar( SB_BOTH, FALSE );
}
/////////////////////////////////////////////////////////////////////////////
// CImageCodesView diagnostics
#ifdef _DEBUG
void CImageCodesView::AssertValid() const
{
CView::AssertValid();
}
void CImageCodesView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CImageCodesDoc* CImageCodesView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageCodesDoc)));
return (CImageCodesDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CImageCodesView message handlers
void CImageCodesView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
RECT WinRect;
int NewPos;
switch( nSBCode )
{
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
SetScrollPos( SB_VERT, nPos );
break;
case SB_BOTTOM:
SetScrollPos( SB_VERT, GetScrollLimit( SB_VERT ) );
break;
case SB_ENDSCROLL:
OriginY = GetScrollPos( SB_VERT );
Invalidate();
break;
case SB_LINEDOWN:
SetScrollPos( SB_VERT, GetScrollPos( SB_VERT ) + 1 );
break;
case SB_LINEUP:
SetScrollPos( SB_VERT, GetScrollPos( SB_VERT ) - 1 );
break;
case SB_PAGEDOWN:
GetClientRect( &WinRect );
NewPos = min( GetScrollLimit( SB_VERT ), GetScrollPos(SB_VERT) + (WinRect.bottom - WinRect.top) );
SetScrollPos( SB_VERT, NewPos );
break;
case SB_PAGEUP:
GetClientRect( &WinRect );
NewPos = min( GetScrollLimit( SB_VERT ), GetScrollPos(SB_VERT) - (WinRect.bottom - WinRect.top) );
SetScrollPos( SB_VERT, NewPos );
break;
case SB_TOP:
SetScrollPos( SB_VERT, 0 );
break;
}
CView::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CImageCodesView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
RECT WinRect;
int NewPos;
switch( nSBCode )
{
case SB_THUMBPOSITION:
case SB_THUMBTRACK:
SetScrollPos( SB_HORZ, nPos );
break;
case SB_BOTTOM:
SetScrollPos( SB_HORZ, GetScrollLimit( SB_VERT ) );
break;
case SB_ENDSCROLL:
OriginX = GetScrollPos( SB_HORZ );
Invalidate();
break;
case SB_LINEDOWN:
SetScrollPos( SB_HORZ, GetScrollPos( SB_HORZ ) + 1 );
break;
case SB_LINEUP:
SetScrollPos( SB_HORZ, GetScrollPos( SB_HORZ ) - 1 );
break;
case SB_PAGEDOWN:
GetClientRect( &WinRect );
NewPos = min( GetScrollLimit( SB_HORZ ), GetScrollPos(SB_HORZ) + (WinRect.right - WinRect.left) );
SetScrollPos( SB_HORZ, NewPos );
break;
case SB_PAGEUP:
GetClientRect( &WinRect );
NewPos = min( GetScrollLimit( SB_HORZ ), GetScrollPos(SB_HORZ) - (WinRect.right - WinRect.left) );
SetScrollPos( SB_HORZ, NewPos );
break;
case SB_TOP:
SetScrollPos( SB_HORZ, 0 );
break;
}
CView::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CImageCodesView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
SetScrollBarInfo( cx, cy );
OriginX = GetScrollPos( SB_HORZ );
OriginY = GetScrollPos( SB_VERT );
Invalidate();
}
void CImageCodesView::OnInitialUpdate()
{
// CView::OnInitialUpdate();
/* CMenu *MainMenu;
MainMenu=GetMenu();
MainMenu->EnableMenuItem(3,MF_BYPOSITION|MF_GRAYED);*/
}
void CImageCodesView::DrawCross(CPoint m_conerpoint, HPEN hPen)
{
CClientDC dc(this);
dc.SelectObject(hPen);
dc.MoveTo(m_conerpoint);
dc.LineTo(m_conerpoint.x,m_conerpoint.y+5);
dc.MoveTo(m_conerpoint);
dc.LineTo(m_conerpoint.x,m_conerpoint.y-5);
dc.MoveTo(m_conerpoint);
dc.LineTo(m_conerpoint.x-5,m_conerpoint.y);
dc.MoveTo(m_conerpoint);
dc.LineTo(m_conerpoint.x+5,m_conerpoint.y);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -