// 11BitBltView.cpp : CMy11BitBltView 類別的實作
//

#include "stdafx.h"
#include "11BitBlt.h"

#include "11BitBltDoc.h"
#include "11BitBltView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CMy11BitBltView

IMPLEMENT_DYNCREATE(CMy11BitBltView, CView)

BEGIN_MESSAGE_MAP(CMy11BitBltView, CView)
	// 標準列印命令
	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()

// CMy11BitBltView 建構/解構

CMy11BitBltView::CMy11BitBltView()
{
	// TODO: 在此處加入建構程式碼

}

CMy11BitBltView::~CMy11BitBltView()
{
}

BOOL CMy11BitBltView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 經由修改 CREATESTRUCT cs 達到修改視窗類別或樣式的目的

	return CView::PreCreateWindow(cs);
}

// CMy11BitBltView 描繪

void CMy11BitBltView::OnDraw(CDC* pDC)
{
	CMy11BitBltDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	// TODO: 在此加入原生資料的繪製程式碼
    CDC dcMem;
    dcMem.CreateCompatibleDC(pDC);
	dcMem.SetMapMode(MM_TEXT);

    CBitmap bitmap, *pOldBitmap;
    bitmap.LoadBitmap(IDB_BITMAP1);

    pOldBitmap = (CBitmap *) dcMem.SelectObject(&bitmap);

    pDC->BitBlt(100,-100,181,136, &dcMem, 0,0,SRCCOPY);

	BITMAP bmp;
	bitmap.GetBitmap(&bmp);
	TRACE("width=%d height=%d\n", bmp.bmWidth, bmp.bmHeight);

/*	CSize srcSize(bmp.bmWidth, bmp.bmHeight);
	pDC->DPtoLP(&srcSize);
	TRACE("%d %d %d %d\n", srcSize.cx, srcSize.cy);
*/
    pDC->StretchBlt(100,-200,200,-200, &dcMem, 0,0, bmp.bmWidth, bmp.bmHeight, SRCCOPY);

    dcMem.SelectObject(pOldBitmap);

}


// CMy11BitBltView 列印

BOOL CMy11BitBltView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 預設的準備
	return DoPreparePrinting(pInfo);
}

void CMy11BitBltView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 列印前加入額外的初始設定
}

void CMy11BitBltView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 列印後加入清除
}


// CMy11BitBltView 診斷

#ifdef _DEBUG
void CMy11BitBltView::AssertValid() const
{
	CView::AssertValid();
}

void CMy11BitBltView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CMy11BitBltDoc* CMy11BitBltView::GetDocument() const // 非偵錯版本是內嵌
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMy11BitBltDoc)));
	return (CMy11BitBltDoc*)m_pDocument;
}
#endif //_DEBUG


// CMy11BitBltView 訊息處理常式

void CMy11BitBltView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
{
	// TODO: 在此加入特定的程式碼和 (或) 呼叫基底類別
/*
    CRect rect;
	GetClientRect(&rect);
	pDC->SetViewportOrg(0, rect.Height());
	TRACE("%d\n", rect.Height());
	*/
	pDC->SetMapMode(MM_LOENGLISH);

	CView::OnPrepareDC(pDC, pInfo);
}
