ScrView.cpp
资源名称:anywhere.zip [点击查看]
上传用户:zhenhuadz
上传日期:2007-01-07
资源大小:1511k
文件大小:3k
源码类别:
远程控制编程
开发平台:
Visual C++
- // ScrView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "anywhere.h"
- #include "ScrView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CScrView
- IMPLEMENT_DYNCREATE(CScrView, CScrollView)
- CScrView::CScrView()
- {
- }
- CScrView::~CScrView()
- {
- }
- BEGIN_MESSAGE_MAP(CScrView, CScrollView)
- //{{AFX_MSG_MAP(CScrView)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CScrView drawing
- void CScrView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
- ASSERT(GetDocument() != NULL);
- SetScrollSizes(MM_TEXT, GetDocument()->GetDocSize());
- /*CSize sizeTotal;
- // TODO: calculate the total size of this view
- sizeTotal.cx = sizeTotal.cy = 100;
- SetScrollSizes(MM_TEXT, sizeTotal);
- CSize sizeTotal(1000,500);
- CSize sizePage(sizeTotal.cx/2,sizeTotal.cy/2);
- CSize sizeLine(sizeTotal.cx/4,sizeTotal.cy/4);
- SetScrollSizes(MM_TEXT,sizeTotal,sizePage,sizeLine);
- */
- }
- void CScrView::OnDraw(CDC* pDC)
- {
- CAnywhereDoc* pDoc = GetDocument();
- //CDibDoc* pDoc = GetDocument();
- HDIB hDIB = pDoc->GetHDIB();
- if (hDIB != NULL)
- {
- LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
- int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x
- int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y
- ::GlobalUnlock((HGLOBAL) hDIB);
- 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;
- }
- ::PaintDIB(pDC->m_hDC, &rcDest, pDoc->GetHDIB(),
- &rcDIB, pDoc->GetDocPalette());
- }
- // TODO: add draw code here
- }
- /////////////////////////////////////////////////////////////////////////////
- // CScrView diagnostics
- #ifdef _DEBUG
- void CScrView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CScrView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CScrView message handlers
- void CScrView::message(CString filename)
- {
- GetDocument()->ReadBmp(filename);
- SetScrollSizes(MM_TEXT, GetDocument()->GetDocSize());
- Invalidate();//显示图片
- }