ClipBmpView.cpp
上传用户:sdpcwz
上传日期:2009-12-14
资源大小:1237k
文件大小:3k
- // ClipBmpView.cpp : implementation of the CClipBmpView class
- //
- #include "stdafx.h"
- #include "ClipBmp.h"
- #include "ClipBmpDoc.h"
- #include "ClipBmpView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CClipBmpView
- IMPLEMENT_DYNCREATE(CClipBmpView, CView)
- BEGIN_MESSAGE_MAP(CClipBmpView, CView)
- //{{AFX_MSG_MAP(CClipBmpView)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CClipBmpView construction/destruction
- CClipBmpView::CClipBmpView()
- {
- // TODO: add construction code here
- }
- CClipBmpView::~CClipBmpView()
- {
- }
- BOOL CClipBmpView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CClipBmpView drawing
- void CClipBmpView::OnDraw(CDC* pDC)
- {
- CClipBmpDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- //取得位图
- CBitmap bmp;
- bmp.LoadBitmap(IDB_BITMAP1);
- BITMAP Bitmap;
- bmp.GetBitmap(&Bitmap);
- //创建内存设备场景
- CDC MemDC;
- MemDC.CreateCompatibleDC(pDC);
- //将位图选入内存设备场景
- CBitmap* pOldBmp = MemDC.SelectObject(&bmp);
- //创建椭圆形裁剪区并选入内存设备场景
- CRgn rgn;
- rgn.CreateEllipticRgn(0,0,Bitmap.bmWidth,Bitmap.bmHeight);
- pDC->SelectClipRgn(&rgn);
- //显示设备场景
- pDC->BitBlt(0,0,Bitmap.bmWidth,Bitmap.bmHeight,&MemDC,0,0,SRCCOPY);
- //还原内存设备场景
- MemDC.SelectObject(pOldBmp);
- MemDC.DeleteDC();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CClipBmpView printing
- BOOL CClipBmpView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CClipBmpView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CClipBmpView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CClipBmpView diagnostics
- #ifdef _DEBUG
- void CClipBmpView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CClipBmpView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CClipBmpDoc* CClipBmpView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CClipBmpDoc)));
- return (CClipBmpDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CClipBmpView message handlers