⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bmptextview.cpp

📁 用VC++开发多视图多文档应用程序
💻 CPP
字号:
// BmpTextView.cpp : implementation of the CBmpTextView class
//

#include "stdafx.h"
#include "BmpText.h"

#include "BmpTextDoc.h"
#include "BmpTextView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CBmpTextView

IMPLEMENT_DYNCREATE(CBmpTextView, CScrollView)

BEGIN_MESSAGE_MAP(CBmpTextView, CScrollView)
	//{{AFX_MSG_MAP(CBmpTextView)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_WM_PAINT()
	ON_COMMAND(ID_FILE_CLOSE, OnFileClose)
	ON_COMMAND(ID_FILE_NEW, OnFileNew)
	ON_UPDATE_COMMAND_UI(ID_FILE_SAVE, OnUpdateFileSave)
	ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_AS, OnUpdateFileSaveAs)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBmpTextView construction/destruction

CBmpTextView::CBmpTextView()
{
	// TODO: add construction code here
	isOpenFile=FALSE;

}

CBmpTextView::~CBmpTextView()
{
}

BOOL CBmpTextView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CBmpTextView drawing

void CBmpTextView::OnDraw(CDC* pDC)
{
	CBmpTextDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if(isOpenFile)
	{
		CRect 	rect;
		GetClientRect(&rect);
		
		BITMAP Bmp;
		HBITMAP hbitmap=LoadBitmap(::AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BITMAP_VIEW));
		HDC hMemDC=CreateCompatibleDC(NULL);
		SelectObject(hMemDC,hbitmap);
		GetObject(hbitmap,sizeof(BITMAP),(LPSTR)&Bmp);
		StretchBlt(pDC->m_hDC,0,0,rect.right,rect.bottom,hMemDC,0,0,Bmp.bmWidth,Bmp.bmHeight,SRCCOPY);
		DeleteDC(hMemDC);
		DeleteObject(hbitmap);
	}
}

void CBmpTextView::OnInitialUpdate()
{
	CScrollView::OnInitialUpdate();
	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = sizeTotal.cy = 100;
	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CBmpTextView diagnostics

#ifdef _DEBUG
void CBmpTextView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CBmpTextView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CBmpTextDoc* CBmpTextView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBmpTextDoc)));
	return (CBmpTextDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CBmpTextView message handlers

void CBmpTextView::OnFileOpen() 
{
	// TODO: Add your command handler code here
	isOpenFile=TRUE;
	Invalidate();
	
}

void CBmpTextView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	OnDraw(&dc);
	// TODO: Add your message handler code here
	
	// Do not call CScrollView::OnPaint() for painting messages
}

void CBmpTextView::OnFileClose() 
{
	// TODO: Add your command handler code here
	isOpenFile=FALSE;
	Invalidate();
}

void CBmpTextView::OnFileNew() 
{
	// TODO: Add your command handler code here
	isOpenFile=FALSE;
	Invalidate();
}

void CBmpTextView::OnUpdateFileSave(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(FALSE);
	
}

void CBmpTextView::OnUpdateFileSaveAs(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->Enable(FALSE);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -