?? dipview.cpp
字號:
// DipView.cpp : implementation of the CDipView class
//
#include "stdafx.h"
#include "Dip.h"
#include "DipDoc.h"
#include "DipView.h"
#include "PointPro.h"
#include "DlgIntensity.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDipView
IMPLEMENT_DYNCREATE(CDipView, CScrollView)
BEGIN_MESSAGE_MAP(CDipView, CScrollView)
//{{AFX_MSG_MAP(CDipView)
ON_COMMAND(ID_VIEW_HIST, OnViewHist)
ON_UPDATE_COMMAND_UI(ID_VIEW_HIST, OnUpdateViewHist)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CDipView construction/destruction
CDipView::CDipView()
{
// TODO: add construction code here
}
CDipView::~CDipView()
{
}
BOOL CDipView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDipView drawing
void CDipView::OnDraw(CDC* pDC)
{
CDipDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if( !pDoc->m_bImageLoaded)
{
pDoc->LoadImageToDocument();
}
//滾動窗口
CSize sizeTotal;
sizeTotal.cx = pDoc->m_pDibObject->GetWidth();
sizeTotal.cy = pDoc->m_pDibObject->GetHeight();
SetScrollSizes (MM_TEXT, sizeTotal);
//獲取客戶區尺寸
OnPrepareDC(pDC);
CRect Rect;
GetClientRect( &Rect );
//獲取圖像寬度及高度
int nImageWidth, nImageHeight;
nImageWidth = pDoc->m_pDibObject->GetWidth();
nImageHeight = pDoc->m_pDibObject->GetHeight();
//當圖像實際尺寸小于窗口尺寸時,將圖像放在客戶區中間
int nX, nY;
if( nImageWidth < Rect.Width() )
nX = (Rect.Width() - nImageWidth ) / 2;
else
nX = 0;
if( nImageHeight < Rect.Height() )
nY = (Rect.Height() - nImageHeight ) / 2;
else
nY = 0;
if( GetFocus() == this )
pDoc->m_pDibObject->SetPalette(pDC);
pDoc->m_pDibObject->Draw(pDC, nX, nY);
}
void CDipView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CDipView printing
BOOL CDipView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDipView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDipView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDipView diagnostics
#ifdef _DEBUG
void CDipView::AssertValid() const
{
CScrollView::AssertValid();
}
void CDipView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CDipDoc* CDipView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDipDoc)));
return (CDipDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDipView message handlers
void CDipView::OnViewHist()
{
CDipDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
//判斷當前是否有圖像對象
if( pDoc->m_pDibObject == NULL ) return;
//在點處理CPointPro類中創建用來繪制直方圖的數據
CPointPro PointOperation( pDoc->m_pDibObject );
int *pHistogram = PointOperation.GetHistogram();
//生成一個對話框CHistDlg類的實例
CDlgIntensity HistDlg;
//將繪制直方圖的數據傳遞給CHistDlg對話框類的公有成員變量m_pnHistogram
if( pHistogram != NULL )
{
//設置直方圖數據指針
HistDlg.m_pnHistogram = pHistogram;
//設置當前像素值為0的像素數
HistDlg.m_nCurrentPiexsNum = pHistogram[0];
//設置是否為256級灰度圖像
HistDlg.m_bIsGray256 = PointOperation.IsGray256();
}
//顯示對話框
if ( HistDlg.DoModal() != IDOK)
return;
delete [] pHistogram;
}
void CDipView::OnUpdateViewHist(CCmdUI* pCmdUI)
{
CDipDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pCmdUI->Enable( pDoc->m_pDibObject->GetNumBits() >= 8);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -