📄 myview.cpp
字号:
// MyView.cpp : implementation of the CMyView class
//
#include "stdafx.h"
#include "My.h"
#include "MyDoc.h"
#include "MyView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyView
IMPLEMENT_DYNCREATE(CMyView, CView)
BEGIN_MESSAGE_MAP(CMyView, CView)
//{{AFX_MSG_MAP(CMyView)
ON_COMMAND(ID_BESTFIT, OnBestFit)
ON_COMMAND(ID_SHRINK, OnShrink)
ON_COMMAND(ID_ZOOMOUT, OnZoomOut)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyView construction/destruction
CMyView::CMyView()
{
// TODO: add construction code here
// 载入位图资源,读位图信息
BITMAP BM;
m_Bitmap.LoadBitmap(IDB_BITMAP1);
m_Bitmap.GetBitmap(&BM);
m_nWidth = BM.bmWidth;
m_nHeight = BM.bmHeight;
m_fTimes = 1.0;
}
CMyView::~CMyView()
{
}
BOOL CMyView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView drawing
// 响应绘制窗口客户区消息
void CMyView::OnDraw(CDC* pDC)
{
CMyDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
// 显示位图
CDC MemDC;
MemDC.CreateCompatibleDC(NULL);
MemDC.SelectObject(&m_Bitmap);
pDC->StretchBlt(0, 0, (int)(m_nWidth*m_fTimes),
(int)(m_nHeight*m_fTimes),
&MemDC, 0, 0, m_nWidth, m_nHeight, SRCCOPY);
}
/////////////////////////////////////////////////////////////////////////////
// CMyView diagnostics
#ifdef _DEBUG
void CMyView::AssertValid() const
{
CView::AssertValid();
}
void CMyView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CMyDoc* CMyView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyDoc)));
return (CMyDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMyView message handlers
// 原样显示
void CMyView::OnBestFit()
{
// TODO: Add your command handler code here
m_fTimes = 1.0;
Invalidate();
}
// 缩小图像
void CMyView::OnShrink()
{
// TODO: Add your command handler code here
m_fTimes = 0.5;
Invalidate();
}
// 放大图像
void CMyView::OnZoomOut()
{
// TODO: Add your command handler code here
m_fTimes = 2.0;
Invalidate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -