📄 dibsectionview.cpp
字号:
// DIBSectionView.cpp : implementation of the CDIBSectionView class
//
#include "stdafx.h"
#include "DIBSection.h"
#include "DIBSectionDoc.h"
#include "DIBSectionView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDIBSectionView
IMPLEMENT_DYNCREATE(CDIBSectionView, CView)
BEGIN_MESSAGE_MAP(CDIBSectionView, CView)
//{{AFX_MSG_MAP(CDIBSectionView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDIBSectionView construction/destruction
CDIBSectionView::CDIBSectionView()
{
// TODO: add construction code here
}
CDIBSectionView::~CDIBSectionView()
{
}
BOOL CDIBSectionView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDIBSectionView drawing
void CDIBSectionView::OnDraw(CDC* pDC)
{
CDIBSectionDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
/* if(pDoc->m_DIBSection.GetSafeHandle())
{
CRect rect;
GetClientRect(rect);
// pDoc->m_DIBSection.Stretch(pDC, CPoint(0,0), rect.Size());
pDoc->m_DIBSection.Draw(pDC, CPoint(0,0));
}*/
CPaintDC dc(this); // device context for painting
CPen *NewPen=new CPen( PS_SOLID, 2, RGB(50,0,200));
CPen *oldPen=dc.SelectObject(NewPen);
dc.MoveTo(0,24);
dc.LineTo(240,24);
dc.LineTo(240,187);
dc.LineTo(0,187);
delete NewPen;
dc.SelectObject(oldPen);
//pDoc->m_DIBSection.SetBitmap(IDB_PICTURE);
pDoc->m_DIBSection.Stretch(&dc, CPoint(15,30), CSize(210,150));
}
/////////////////////////////////////////////////////////////////////////////
// CDIBSectionView diagnostics
#ifdef _DEBUG
void CDIBSectionView::AssertValid() const
{
CView::AssertValid();
}
void CDIBSectionView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CDIBSectionDoc* CDIBSectionView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDIBSectionDoc)));
return (CDIBSectionDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDIBSectionView message handlers
void CDIBSectionView::OnFileOpen()
{
CDIBSectionDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CString strFilter = "Bitmap Files (*.bmp)|*.bmp|All Files (*.*) |*.*||";
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_EXPLORER, strFilter, NULL);
if (dlg.DoModal() == IDOK)
{
if (pDoc->m_DIBSection.Load(dlg.GetPathName()))
pDoc->SetTitle(dlg.GetFileTitle());
else
AfxMessageBox(_T("Unable to open bitmap file"));
// m_nBitmapID = -1;
Invalidate();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -