CloudView.cpp
资源名称:08.zip [点击查看]
上传用户:ynjin1970
上传日期:2014-10-13
资源大小:6438k
文件大小:5k
源码类别:
中间件编程
开发平台:
Visual C++
- // CloudView.cpp : implementation of the CCloudView class
- //
- #include "stdafx.h"
- #include "Cloud.h"
- #include "CloudDoc.h"
- #include "CloudView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CCloudView
- IMPLEMENT_DYNCREATE(CCloudView, CScrollView)
- BEGIN_MESSAGE_MAP(CCloudView, CScrollView)
- //{{AFX_MSG_MAP(CCloudView)
- ON_WM_CREATE()
- ON_WM_PAINT()
- //}}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()
- /////////////////////////////////////////////////////////////////////////////
- // CCloudView construction/destruction
- CCloudView::CCloudView()
- {
- }
- CCloudView::~CCloudView()
- {
- }
- BOOL CCloudView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CScrollView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCloudView drawing
- void CCloudView::OnDraw(CDC* pDC)
- {
- CCloudDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CSize sizeTotal;
- CDib* pDib = pDoc->m_Dib;
- if(pDib)
- {
- CDC memDC;
- long width,height;
- width=pDib->GetImageWidth();
- height=pDib->GetImageHeight();
- memDC.CreateCompatibleDC(pDC);
- RECT rect;
- GetClientRect(&rect);
- sizeTotal.cx=width;
- sizeTotal.cy=height;
- SetScrollSizes(MM_TEXT, sizeTotal);
- CBitmap* pOldBitmap = memDC.SelectObject(m_bitmap);
- pDib->PaintDIB(memDC.m_hDC,width,height);
- pDC->BitBlt(0, 0,width,height, &memDC, 0, 0, SRCCOPY);
- memDC.SelectObject(pOldBitmap);
- ReleaseDC(&memDC);
- }
- }
- void CCloudView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
- CSize sizeTotal;
- // TODO: calculate the total size of this view
- sizeTotal.cx = sizeTotal.cy = 100;
- SetScrollSizes(MM_TEXT, sizeTotal);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCloudView printing
- BOOL CCloudView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CCloudView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CCloudView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCloudView diagnostics
- #ifdef _DEBUG
- void CCloudView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CCloudView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- CCloudDoc* CCloudView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCloudDoc)));
- return (CCloudDoc*)m_pDocument;
- }
- #endif //_DEBUG
- ////////////////////////////////////////////////////////////////////////////
- int CCloudView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CScrollView::OnCreate(lpCreateStruct) == -1)
- return -1;
- CDC* dc=GetDC();
- m_bitmap=new CBitmap;
- m_bitmap->CreateCompatibleBitmap(dc,4000,3000);
- ReleaseDC(dc);
- return 0;
- }
- /*void CCloudView::OnPaint()
- {
- CCloudDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CPaintDC dc(this); // device context for painting
- CDib* pDib = pDoc->m_Dib;
- if(pDoc->sign==1)
- {
- CSize sizeTotal;
- sizeTotal.cy=pDib->GetImageHeight();
- sizeTotal.cx=pDib->GetImageWidth();
- SetScrollSizes(MM_TEXT, sizeTotal);
- SetDIBitsToDevice(dc.m_hDC,0,0,pDib->GetImageWidth(),
- pDib->GetImageHeight(),
- 0,
- 0,
- 0,
- pDib->GetImageHeight(),pDib->lpDIBBits,
- pDib->bmpInfo,DIB_RGB_COLORS);
- }
- /* if(pDoc->sign==1)
- {
- CDC memDC;
- long width,height;
- width=pDib->GetImageWidth();
- height=pDib->GetImageHeight();
- CSize sizeTotal;
- CDC* pDC=GetDC();
- memDC.CreateCompatibleDC(pDC);
- ReleaseDC(pDC);
- CBitmap bmp;
- CreatBitmap(&bmp,width,height);
- CBitmap* pOldBitmap = memDC.SelectObject(&bmp);
- RECT rect;
- GetClientRect(&rect);
- sizeTotal.cx=rect.right;
- sizeTotal.cy=rect.bottom;
- SetScrollSizes(MM_TEXT, sizeTotal);
- pDib->PaintDIB(memDC.m_hDC,rect.right,rect.bottom);
- dc.BitBlt(0, 0,width,height, &memDC, 0, 0, SRCCOPY);
- memDC.SelectObject(pOldBitmap);
- ReleaseDC(&memDC);
- sizeTotal.cx=width;
- sizeTotal.cy=height;
- SetScrollSizes(MM_TEXT, sizeTotal);
- BYTE* lpDIBBits=pDib->lpDIBBits;
- int w=width;
- int h=height;
- int sign=w%2;
- long total=w*h*3;
- long tmp=0;
- if(sign)
- w+=1;
- for(int i=0;i<=h;i++)
- {
- for(int j=0;j<w;j++)
- {
- pDC->SetPixel(j+10,h-i,RGB(lpDIBBits[tmp+2],lpDIBBits[tmp+1],lpDIBBits[tmp]));
- if(tmp>=total)
- break;
- tmp+=3;
- }
- }
- }
- }*/
- void CCloudView::CreatBitmap(CBitmap *bmp, int width, int height)
- {
- CDC* dc=GetDC();
- bmp->CreateCompatibleBitmap(dc,width,height);
- ReleaseDC(dc);
- }