📄 imagesyszlf01view.cpp
字号:
// ImageSysZLF01View.cpp : implementation of the CImageSysZLF01View class
//
#include "stdafx.h"
#include "ImageSysZLF01.h"
#include "ImageSysZLF01Doc.h"
#include "ImageSysZLF01View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CImageSysZLF01View
IMPLEMENT_DYNCREATE(CImageSysZLF01View, CFormView)
BEGIN_MESSAGE_MAP(CImageSysZLF01View, CFormView)
//{{AFX_MSG_MAP(CImageSysZLF01View)
ON_COMMAND(ID_MENU_CONVERSECOLOR, OnMenuConversecolor)
ON_COMMAND(ID_MENU_LINEARTRANS, OnMenuLineartrans)
ON_COMMAND(ID_MENU_WINDOWTRANS, OnMenuWindowtrans)
ON_COMMAND(ID_MENU_THRETRANS, OnMenuThretrans)
ON_COMMAND(ID_MENU_EQUEALTRANS, OnMenuEquealtrans)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
ON_WM_RBUTTONDOWN()
ON_COMMAND(ID_MENU_RECOG_CHAPTER02, OnMenuRecogManual)
ON_COMMAND(ID_MENU_RECOG_CHAPTER03, OnMenuRecogChapter03)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CImageSysZLF01View construction/destruction
CImageSysZLF01View::CImageSysZLF01View()
: CFormView(CImageSysZLF01View::IDD)
{
//{{AFX_DATA_INIT(CImageSysZLF01View)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
TRACE("CzlfView: structed!");
m_lyChildFrame=0;
m_lxChildFrame=0;
}
CImageSysZLF01View::~CImageSysZLF01View()
{
}
void CImageSysZLF01View::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CImageSysZLF01View)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BOOL CImageSysZLF01View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CImageSysZLF01View::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
ResizeParentToFit();
}
/////////////////////////////////////////////////////////////////////////////
// CImageSysZLF01View printing
BOOL CImageSysZLF01View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CImageSysZLF01View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CImageSysZLF01View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CImageSysZLF01View::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CImageSysZLF01View diagnostics
#ifdef _DEBUG
void CImageSysZLF01View::AssertValid() const
{
CFormView::AssertValid();
}
void CImageSysZLF01View::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CImageSysZLF01Doc* CImageSysZLF01View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageSysZLF01Doc)));
return (CImageSysZLF01Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CImageSysZLF01View message handlers
void CImageSysZLF01View::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
// 显示等待光标
BeginWaitCursor();
// 获取文档
CImageSysZLF01Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// 获取DIB
HDIB hDIB = pDoc->GetHDIB();
// 判断DIB是否为空
if (hDIB != NULL)
{
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
// 获取DIB宽度
int cxDIB = (int) ::DIBWidth(lpDIB);
// 获取DIB高度
int cyDIB = (int) ::DIBHeight(lpDIB);
::GlobalUnlock((HGLOBAL) hDIB);
CRect rcDIB;
rcDIB.top =0;
rcDIB.left = 0;
rcDIB.right = cxDIB;
rcDIB.bottom = cyDIB;
CRect rcDest;
// 判断是否是打印
if (pDC->IsPrinting())
{
// 是打印,计算输出图像的位置和大小,以便符合页面
// 获取打印页面的水平宽度(象素)
int cxPage = pDC->GetDeviceCaps(HORZRES);
// 获取打印页面的垂直高度(象素)
int cyPage = pDC->GetDeviceCaps(VERTRES);
// 获取打印机每英寸象素数
int cxInch = pDC->GetDeviceCaps(LOGPIXELSX);
int cyInch = pDC->GetDeviceCaps(LOGPIXELSY);
// 计算打印图像大小(缩放,根据页面宽度调整图像大小)
rcDest.top = rcDest.left = 0;
rcDest.bottom = (int)(((double)cyDIB * cxPage * cyInch)
/ ((double)cxDIB * cxInch));
rcDest.right = cxPage;
// 计算打印图像位置(垂直居中)
int temp = cyPage - (rcDest.bottom - rcDest.top);
rcDest.bottom += temp/2;
rcDest.top += temp/2;
}
else
// 非打印
{
// 不必缩放图像
rcDest = rcDIB;
}
// 输出DIB
::PaintDIB(pDC->m_hDC, &rcDest, pDoc->GetHDIB(),
&rcDIB, pDoc->GetDocPalette());
m_lyChildFrame=cyDIB;
m_lxChildFrame=cxDIB;
// // 设定视图大小与图像大小匹配
// this->GetOwner()->SetWindowPos(&wndTop,0,0,cxDIB+50,cyDIB+50,SWP_SHOWWINDOW);
}
// 恢复正常光标
EndWaitCursor();
}
//////////////////////////////////////////////////////////////////
// 响应菜单命令 //
//////////////////////////////////////////////////////////////////
void CImageSysZLF01View::OnMenuConversecolor()
{
// 图像反色
// 获取文档
CImageSysZLF01Doc* pDoc = GetDocument();
// 指向DIB的指针
LPSTR lpDIB;
// 指向DIB象素指针
LPSTR lpDIBBits;
// 线性变换的斜率
FLOAT fA;
// 线性变换的截距
FLOAT fB;
// 反色操作的线性变换的方程是-x + 255
fA = -1.0;
fB = 255.0;
// 锁定DIB
lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->GetHDIB());
//取得每个像素点的所用位数
WORD wBitCount = ((LPBITMAPINFOHEADER)lpDIB)->biBitCount;
// 找到DIB图像象素起始位置
lpDIBBits = ::FindDIBBits(lpDIB);
// 更改光标形状
BeginWaitCursor();
// 调用LinerTrans()函数反色
LinerTrans(lpDIBBits, ::DIBWidth(lpDIB), ::DIBHeight(lpDIB), fA, fB,wBitCount);
// 设置脏标记
pDoc->SetModifiedFlag(TRUE);
// 更新视图
pDoc->UpdateAllViews(NULL);
// 解除锁定
::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
// 恢复光标
EndWaitCursor();
}
void CImageSysZLF01View::OnMenuLineartrans()
{
// 线性变换
// 获取文档
CImageSysZLF01Doc* pDoc = GetDocument();
// 指向DIB的指针
LPSTR lpDIB;
// 指向DIB象素指针
LPSTR lpDIBBits;
// 线性变换的斜率
FLOAT fA;
// 线性变换的截距
FLOAT fB;
// 锁定DIB
lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) pDoc->GetHDIB());
//取得每个像素点的所用位数
WORD wBitCount = ((LPBITMAPINFOHEADER)lpDIB)->biBitCount;
// 找到DIB图像象素起始位置
lpDIBBits = ::FindDIBBits(lpDIB);
// 初始化变量值
fA = 2.0;
fB = -128.0;
// 更改光标形状
BeginWaitCursor();
// 调用LinerTrans()函数进行线性变换
LinerTrans(lpDIBBits, ::DIBWidth(lpDIB), ::DIBHeight(lpDIB), fA, fB,wBitCount);
// 设置脏标记
pDoc->SetModifiedFlag(TRUE);
// 更新视图
pDoc->UpdateAllViews(NULL);
// 解除锁定
::GlobalUnlock((HGLOBAL) pDoc->GetHDIB());
// 恢复光标
EndWaitCursor();
}
void CImageSysZLF01View::OnMenuWindowtrans()
{
// TODO: Add your command handler code here
CString msg="此功能暂未完成!";
AfxMessageBox(msg,IDOK | MB_OK,0);
}
void CImageSysZLF01View::OnMenuThretrans()
{
// TODO: Add your command handler code here
CString msg="此功能暂未完成!";
AfxMessageBox(msg,IDOK | MB_OK,0);
}
void CImageSysZLF01View::OnMenuEquealtrans()
{
// TODO: Add your command handler code here
CString msg="此功能暂未完成!";
AfxMessageBox(msg,IDOK | MB_OK,0);
}
void CImageSysZLF01View::OnEditUndo()
{
// TODO: Add your command handler code here
// 获取文档
CImageSysZLF01Doc* pDoc = GetDocument();
pDoc->RestorePrimitiveImage();
}
void CImageSysZLF01View::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
// 以下代码有问题
CMenu mu;
mu.LoadMenu(IDR_MENU_RK_NOUSE);
mu.TrackPopupMenu(TPM_RIGHTBUTTON ,point.x,point.y,this->GetActiveWindow(),NULL);
CFormView::OnRButtonDown(nFlags, point);
}
void CImageSysZLF01View::OnMenuRecogManual()
{
// TODO: Add your command handler code here
CDlgPatternRecog dlg;
dlg.DoModal();
}
BOOL CImageSysZLF01View::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
// 设定视图大小与图像大小匹配
// this->GetOwner()->SetWindowPos(&wndTop,0,0,m_lxChildFrame,m_lyChildFrame,SWP_SHOWWINDOW);
return CFormView::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
void CImageSysZLF01View::OnMenuRecogChapter03()
{
// TODO: Add your command handler code here
CDlgClusterPatternRecog dlg;
dlg.DoModal();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -