www.pudn.com > pict.rar > ImageMeasureView.cpp
// ImageMeasureView.cpp : implementation of the CImageMeasureView class
//
#include "stdafx.h"
#include "ImageMeasure.h"
#include "MainFrm.h"
#include "ImageMeasureDoc.h"
#include "ImageMeasureView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CImageMeasureView
IMPLEMENT_DYNCREATE(CImageMeasureView, CScrollView)
BEGIN_MESSAGE_MAP(CImageMeasureView, CScrollView)
//{{AFX_MSG_MAP(CImageMeasureView)
ON_WM_MOUSEMOVE()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CImageMeasureView construction/destruction
CImageMeasureView::CImageMeasureView()
{
// TODO: add construction code here
}
CImageMeasureView::~CImageMeasureView()
{
}
BOOL CImageMeasureView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CImageMeasureView drawing
void CImageMeasureView::OnDraw(CDC* pDC)
{
CImageMeasureDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
pBitmap = &(pDoc->m_Bitmap);
if(pBitmap != NULL)
{
CDC memDC;
memDC.CreateCompatibleDC(pDC);
CBitmap * pOldBitmap = memDC.SelectObject(pBitmap);
pDC->BitBlt(0,0,pDoc->m_lWidth,pDoc->m_lHeight,&memDC,0,0,SRCCOPY);
memDC.SelectObject(pOldBitmap);
}
// TODO: add draw code for native data here
}
void CImageMeasureView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CImageMeasureDoc* pDoc = GetDocument();
CSize sizeTotal(100,100);
if(pDoc->pBits!=NULL)
{
sizeTotal.cx = pDoc->m_lWidth;
sizeTotal.cy = pDoc->m_lHeight;
SetScrollSizes(MM_TEXT, sizeTotal);
}
// TODO: calculate the total size of this view
else
{
SetScrollSizes(MM_TEXT, sizeTotal);
}
}
/////////////////////////////////////////////////////////////////////////////
// CImageMeasureView printing
BOOL CImageMeasureView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CImageMeasureView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CImageMeasureView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CImageMeasureView diagnostics
#ifdef _DEBUG
void CImageMeasureView::AssertValid() const
{
CScrollView::AssertValid();
}
void CImageMeasureView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CImageMeasureDoc* CImageMeasureView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageMeasureDoc)));
return (CImageMeasureDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CImageMeasureView message handlers
void CImageMeasureView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CImageMeasureDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if((HBITMAP) pDoc->m_Bitmap )
{
CClientDC dc(this);
OnPrepareDC(&dc);
CPoint pointTemp=point;
dc.DPtoLP(&pointTemp);
CDC memDC;
CBitmap* pOldBitmap;
RGBQUAD* pRGB;
if(pointTemp.xm_lWidth && pointTemp.ym_lHeight)
{
int redValue,greenValue,blueValue,ColorIndex;
CString string;
switch(pDoc->m_Color)
{
case(8):
ColorIndex=*(pDoc->pBits+pDoc->WIDTH*(pDoc->m_lHeight-1-pointTemp.y)
+pointTemp.x);
pRGB=new RGBQUAD[256];
memDC.CreateCompatibleDC(&dc);
pOldBitmap=memDC.SelectObject(pBitmap);
::GetDIBColorTable((HDC)memDC,0,256,pRGB);
blueValue=pRGB[ColorIndex].rgbBlue;
greenValue=pRGB[ColorIndex].rgbGreen;
redValue=pRGB[ColorIndex].rgbRed;
memDC.SelectObject(pOldBitmap);
delete [] pRGB;
break;
case(24):
blueValue = *(pDoc->pBits+pDoc->WIDTH*(pDoc->m_lHeight-1-pointTemp.y)
+pointTemp.x*3);
greenValue = *(pDoc->pBits+pDoc->WIDTH*(pDoc->m_lHeight-1-pointTemp.y)
+pointTemp.x*3+1);
redValue = *(pDoc->pBits+pDoc->WIDTH*(pDoc->m_lHeight-1-pointTemp.y)
+pointTemp.x*3+2);
break;
default:
break;
}
string.Format(_T("X=%d Y=%d,Red=%d Green=%d Blue=%d"),pointTemp.x,
pointTemp.y,redValue,greenValue,blueValue);
CMainFrame* pFrame=(CMainFrame*) AfxGetMainWnd();
CStatusBar* pStatus=&(pFrame->m_wndStatusBar);
//AfxMessageBox(string);
if(0==pStatus->SetPaneText(1,string))
{
AfxMessageBox("Setting panes failed");
};
}
}
CScrollView::OnMouseMove(nFlags, point);
}