// imagebltView.h : interface of the CimagebltView class // #pragma once class CimagebltView : public CView { protected: // create from serialization only CimagebltView(); DECLARE_DYNCREATE(CimagebltView) // Attributes public: CimagebltDoc* GetDocument() const; // Operations public: // Overrides public: virtual void OnDraw(CDC* pDC); // overridden to draw this view virtual BOOL PreCreateWindow(CREATESTRUCT& cs); protected: virtual BOOL OnPreparePrinting(CPrintInfo* pInfo); virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo); virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo); // Implementation public: virtual ~CimagebltView(); #ifdef _DEBUG virtual void AssertValid() const; virtual void Dump(CDumpContext& dc) const; #endif protected: // Generated message map functions protected: DECLARE_MESSAGE_MAP() public: CImage img_bkgnd, img_rocket, img_compose; CDC dc_bkgnd, dc_rocket, dc_compose; CBitmap bm_bkgnd, bm_rocket; LPRECT r; CString m_strImage, m_str_rocket; CDC* pDC; int w, h; public: afx_msg void OnDrawimage(); }; #ifndef _DEBUG // debug version in imagebltView.cpp inline CimagebltDoc* CimagebltView::GetDocument() const { return reinterpret_cast<CimagebltDoc*>(m_pDocument); } #endif /***---------------------------------------------------------------------***/ // imagebltView.cpp : implementation of the CimagebltView class // #include "stdafx.h" #include "imageblt.h" #include "imagebltDoc.h" #include "imagebltView.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // CimagebltView IMPLEMENT_DYNCREATE(CimagebltView, CView) BEGIN_MESSAGE_MAP(CimagebltView, CView) // 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) ON_COMMAND(ID_DRAWIMAGE, &CimagebltView::OnDrawimage) END_MESSAGE_MAP() // CimagebltView construction/destruction CimagebltView::CimagebltView() { // TODO: add construction code here } CimagebltView::~CimagebltView() { } BOOL CimagebltView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } // CimagebltView drawing void CimagebltView::OnDraw(CDC* /*pDC*/) { CimagebltDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; } // CimagebltView printing BOOL CimagebltView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CimagebltView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CimagebltView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } // CimagebltView diagnostics #ifdef _DEBUG void CimagebltView::AssertValid() const { CView::AssertValid(); } void CimagebltView::Dump(CDumpContext& dc) const { CView::Dump(dc); } CimagebltDoc* CimagebltView::GetDocument() const // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CimagebltDoc))); return (CimagebltDoc*)m_pDocument; } #endif //_DEBUG // CimagebltView message handlers void CimagebltView::OnDrawimage() //The menu item handler { // TODO: Add your command handler code here //CFileDialog dlgFile(TRUE); //Get the background and rocket images //dlgFile.DoModal(); //Could use the common file dialog box... //m_strImage = dlgFile.GetPathName(); m_strImage = "C:\\460560\\pgms\\imageblt\\debug\\bg1.JPG"; //or hard-code the file path & name img_bkgnd.Load(m_strImage); //images would have to be there //dlgFile.DoModal(); //m_str_rocket = dlgFile.GetPathName(); m_str_rocket = "C:\\460560\\pgms\\imageblt\\debug\\spaceship.bmp"; img_rocket.Load(m_str_rocket); pDC=GetDC(); //Screen DC w = GetDeviceCaps(pDC->m_hDC, HORZRES); h = GetDeviceCaps(pDC->m_hDC, VERTRES); //** Blit images directly to the screen img_bkgnd.StretchBlt(pDC->m_hDC,0,0,w,h,SRCCOPY); img_rocket.BitBlt(pDC->m_hDC,10,10,SRCCOPY); //*** Or Blit to an offscreen bitmap in an offscreen DC (uncomment ff. lines & comment the 2 above)*** //dc_bkgnd.CreateCompatibleDC(pDC); //offscreen DC to build final image in //bm_bkgnd.CreateCompatibleBitmap(pDC,w,h); //offscreen CBitmap object to hold final img //dc_bkgnd.SelectObject(&bm_bkgnd); //img_bkgnd.StretchBlt(dc_bkgnd,0,0,w,h,SRCCOPY); //Blit background to offscreen DC //img_rocket.BitBlt(dc_bkgnd,10,10,SRCCOPY); //Blit rocket to offscreen DC //CBrush b = CBrush(RGB(255,0,0)); //dc_bkgnd.SelectObject(&b); //dc_bkgnd.Ellipse(100,100,180,150); //draw a red "flying saucer" on offscreen DC //pDC->BitBlt(0,0,w,h,&dc_bkgnd,0,0,SRCCOPY); //Blit final image to the screen //Note, only one access to screen }