www.pudn.com > EnergyMap.rar > EnergyMapView.cpp
// EnergyMapView.cpp : implementation of the CEnergyMapView class
//
#include "stdafx.h"
#include "EnergyMap.h"
#include "EnergyMapDoc.h"
#include "EnergyMapView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEnergyMapView
IMPLEMENT_DYNCREATE(CEnergyMapView, CScrollView)
BEGIN_MESSAGE_MAP(CEnergyMapView, CScrollView)
//{{AFX_MSG_MAP(CEnergyMapView)
ON_COMMAND(ID_DRAWENERGYMAP, OnDrawenergymap)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CEnergyMapView construction/destruction
CEnergyMapView::CEnergyMapView()
{
// TODO: add construction code here
OpenFileResult=false;
}
CEnergyMapView::~CEnergyMapView()
{
}
BOOL CEnergyMapView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CEnergyMapView drawing
void CEnergyMapView::OnDraw(CDC* pDC)
{
CEnergyMapDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
sizeTotal.cx=DrawMap.trace*1.5;
sizeTotal.cy=DrawMap.sample*1.5;
CRect rect;
GetClientRect(&rect);
pDC->SetMapMode(MM_ISOTROPIC);
pDC->SetWindowExt(DrawMap.trace*1.5,DrawMap.sample*1.5);
pDC->SetViewportOrg(rect.right/2,rect.bottom/2);
pDC->SetViewportExt(rect.right,rect.bottom);
//CBitmap *oldBitmap;
CDC MemDC;
MemDC.CreateCompatibleDC(pDC);
if (DrawResult) {
MemDC.SelectObject(m_Bitmap);
}
pDC->BitBlt(-DrawMap.trace/2,-DrawMap.sample/2,256,4096,&MemDC,0,0,SRCCOPY);
}
void CEnergyMapView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CEnergyMapView printing
BOOL CEnergyMapView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CEnergyMapView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CEnergyMapView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CEnergyMapView diagnostics
#ifdef _DEBUG
void CEnergyMapView::AssertValid() const
{
CScrollView::AssertValid();
}
void CEnergyMapView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CEnergyMapDoc* CEnergyMapView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEnergyMapDoc)));
return (CEnergyMapDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEnergyMapView message handlers
void CEnergyMapView::OnDrawenergymap()
{
if (DrawResult=OpenFileResult) {
DrawMap.GetBitmap(&m_Bitmap);
if(DrawMap.DrawEnergyMap())
Invalidate();
}
}
void CEnergyMapView::OnFileOpen()
{
// TODO: Add your command handler code here
OpenFileResult=DrawMap.OpenFile();
}
LRESULT CEnergyMapView::OnDoRealize(WPARAM wParam,LPARAM lParam)
{
CClientDC dc(this);
dc.SelectPalette(&m_Palette,FALSE);
if(dc.RealizePalette())
GetDocument()->UpdateAllViews(NULL);
return 0L;
}