【VC开源代码栏目提醒】:网学会员为需要VC开源代码的朋友们搜集整理了DIBVIEW.CPP相关资料,希望对各位网友有所帮助!
// DibView.cpp : implementation of the CDibView class
//
#include "stdafx.h"
#include "DibLookEx.h"
#include "Dib.h"
#include "DibDoc.h"
#include "MainFrm.h"
#include "DibView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDibView
IMPLEMENT_DYNCREATE(CDibView, CScrollView)
BEGIN_MESSAGE_MAP(CDibView, CScrollView)
//{{AFX_MSG_MAP(CDibView)
ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
ON_WM_QUERYNEWPALETTE()
ON_WM_PALETTECHANGED()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CDibView construction/destruction
CDibView::CDibView()
{
// TODO: add construction code here
}
CDibView::~CDibView()
{
}
BOOL CDibView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDibView drawing
void CDibView::OnDraw(CDC* pDC)
{
CDibDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
if (pDoc->IsValid())
{
int cxDIB = (int)pDoc->Width(); // Size of DIB - x
int cyDIB = (int)pDoc->Height(); // Size of DIB - y
CRect rcDIB;
rcDIB.top = rcDIB.left = 0;
rcDIB.right = cxDIB;
rcDIB.bottom = cyDIB;
CRect rcDest;
if (pDC->IsPrinting()) // printer DC
{
// get size of printer page (in pixels)
int cxPage = pDC->GetDeviceCaps(HORZRES);
int cyPage = pDC->GetDeviceCaps(VERTRES);
// get printer pixels per inch
int cxInch = pDC->GetDeviceCaps(LOGPIXELSX);
int cyInch = pDC->GetDeviceCaps(LOGPIXELSY);
//
// Best Fit case -- create a rectangle which preserves
// the DIB's aspect ratio, and fills the page horizontally.
//
// The formula in the "->bottom" field below calculates the Y
// position of the printed bitmap, based on the size of the
// bitmap, the width of the page, and the relative size of
// a printed pixel (cyInch / cxInch).
//
rcDest.top = rcDest.left = 0;
rcDest.bottom = (int)(((double)cyDIB * cxPage * cyInch)
/ ((double)cxDIB * cxInch));
rcDest.right = cxPage;
}
else // not printer DC
{
rcDest = rcDIB;
}
pDoc->PaintDIB(pDC->m_hDC, &rcDest, &rcDIB);
}
}
/////////////////////////////////////////////////////////////////////////////
// CDibView printing
BOOL CDibView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDibView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDibView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDibView diagnostics
#ifdef _DEBUG
void CDibView::AssertValid() const
{
CScrollView::AssertValid();
}
void CDibView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CDibDoc* CDibView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDibDoc)));
return (CDibDoc*)m_pDocument;
}
#endif //_DEBUG
//////////////////