📄 dpoview.cpp
字号:
// DPOView.cpp : implementation of the CDPOView class
//
#include "stdafx.h"
#include "DPO.h"
#include "DPODoc.h"
#include "DPOView.h"
#include "DIB.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDPOView
CDIB dib;
HANDLE hMYDIB;
HANDLE hDIBBW;
LPBITMAPINFOHEADER lpbi;
CDIB* m_pDib;
POINT currentp;
IMPLEMENT_DYNCREATE(CDPOView, CScrollView)
BEGIN_MESSAGE_MAP(CDPOView, CScrollView)
//{{AFX_MSG_MAP(CDPOView)
ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
ON_COMMAND(ID_MENU_ONGRAY, OnToGray)
ON_COMMAND(ID_MENU_WhiteBlack, OnWhiteBlack)
ON_COMMAND(ID_FILE_SAVE_AS, OnFileSaveAs)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDPOView construction/destruction
CDPOView::CDPOView()
{
// TODO: add construction code here
}
CDPOView::~CDPOView()
{
}
BOOL CDPOView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDPOView drawing
void CDPOView::OnDraw(CDC* pDC)
{
CDPODoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if(hMYDIB==NULL)
return;
lpbi = (LPBITMAPINFOHEADER)GlobalLock(hMYDIB);
dib.PaintDIBTrue(pDC->GetSafeHdc(),
CRect(0,0,lpbi->biWidth,lpbi->biHeight),
hMYDIB,
CRect(0,0,lpbi->biWidth,lpbi->biHeight),
SRCCOPY);
CSize sizeTotal;
sizeTotal.cx = lpbi->biWidth;
sizeTotal.cy = lpbi->biHeight;
SetScrollSizes(MM_TEXT, sizeTotal);
}
void CDPOView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CDPOView printing
BOOL CDPOView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDPOView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDPOView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDPOView diagnostics
#ifdef _DEBUG
void CDPOView::AssertValid() const
{
CScrollView::AssertValid();
}
void CDPOView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CDPODoc* CDPOView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDPODoc)));
return (CDPODoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDPOView message handlers
void CDPOView::OnFileOpen()
{
// TODO: Add your command handler code here
LPCTSTR lpszFilter="BMP Files(*.bmp)|*.bmp|All Files|*.*||";
CFileDialog dlg(TRUE,lpszFilter,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,lpszFilter,NULL);
if(dlg.DoModal() == IDOK)
{
CString filename;
filename = dlg.GetPathName();
hMYDIB = dib.LoadDIB(filename);
if(!hMYDIB)
{
AfxMessageBox("open file error");
return;
}
Invalidate();
}
}
void CDPOView::OnFileSaveAs()
{
// TODO: Add your command handler code here
LPCTSTR lpszFilter="BMP Files(*.bmp)|*.bmp|All Files|*.*||";
CFileDialog dlg(FALSE,lpszFilter,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,lpszFilter,NULL);
if(dlg.DoModal() == IDOK)
{
CString filename;
filename = dlg.GetPathName();
dib.SaveDIB(hMYDIB,filename);
if(!hMYDIB)
{
return;
}
Invalidate();
}
}
void CDPOView::OnToGray()
{
// TODO: Add your command handler code here
hMYDIB = dib.ToGray(hMYDIB);
Invalidate();
}
//设置域值
//设置域值
//设置域值
void CDPOView::OnWhiteBlack()
{
// TODO: Add your command handler code here
hMYDIB = dib.WB(hMYDIB,24);
Invalidate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -