// DetailView.cpp : 实现文件 // #include "pch.h" #include "MCA.h" #include "MCADoc.h" #include "DetailView.h" #include "ControlView.h" // CDetailView IMPLEMENT_DYNCREATE(CDetailView, CView) CDetailView::CDetailView() { } CDetailView::~CDetailView() { } BEGIN_MESSAGE_MAP(CDetailView, CView) ON_WM_PAINT() ON_WM_ERASEBKGND() ON_WM_LBUTTONDOWN() ON_WM_RBUTTONDOWN() END_MESSAGE_MAP() // CDetailView 绘图 void CDetailView::OnDraw(CDC* pDc) { // 获取区域 int L, R; if (pDoc == NULL) pDoc = (CMCADoc*)GetDocument(); if (pView == NULL) pView = (CControlView*)pDoc->GetView(RUNTIME_CLASS(CControlView)); L = pView->m_nCursor1; R = pView->m_nCursor2; // 缩放 CRect rect; GetClientRect(&rect); ZF = rect.Width() / (R - L + 1.); // 背景颜色、笔颜色等设置 CDC MemDC; MemDC.CreateCompatibleDC(pDc); CBitmap Bitmap, * OldBitmap; CPen pen(PS_SOLID, 3, RGB(255, 255, 255)); CPen* oldpen = MemDC.SelectObject(&pen); Bitmap.CreateCompatibleBitmap(pDc, rect.Width(), rect.Height()); OldBitmap = MemDC.SelectObject(&Bitmap); MemDC.FillSolidRect(0, 0, rect.Width(), rect.Height(), RGB(119, 7, 243)); // 绘图 int nMaxCount = pDoc->GetMax(L, R) ? pDoc->GetMax(L, R) * 5 / 4 : 1; int nX = (pView->m_nCursorROI - pView->m_nCursor1) * ZF; if (pView->m_sAxisMode == "Linear") { MemDC.MoveTo(1, rect.Height() - pDoc->m_nChannelSmooth[L] * rect.Height() / nMaxCount); for (int i = L; i <= R; i++) MemDC.LineTo((i - L) * ZF, rect.Height() - pDoc->m_nChannelSmooth[i] * rect.Height() / nMaxCount); } else { MemDC.MoveTo(1, rect.Height() - log10(max(pDoc->m_nChannelSmooth[L], 1)) * rect.Height() / log10(nMaxCount)); for (int i = L; i <= R; i++) MemDC.LineTo((i - L) * ZF, rect.Height() - log10(max(pDoc->m_nChannelSmooth[i], 1)) * rect.Height() / log10(nMaxCount)); } // 绘制光标竖线 pen.CreatePen(PS_SOLID, 5, RGB(0, 255, 0)); MemDC.SelectObject(&pen); MemDC.MoveTo(nX, 0); MemDC.LineTo(nX, rect.Height()); //释放资源 pDc->BitBlt(0, 0, rect.Width(), rect.Width(), &MemDC, 0, 0, SRCCOPY); MemDC.SelectObject(oldpen); MemDC.SelectObject(OldBitmap); pen.DeleteObject(); Bitmap.DeleteObject(); MemDC.DeleteDC(); } // CDetailView 诊断 #ifdef _DEBUG void CDetailView::AssertValid() const { CView::AssertValid(); } #ifndef _WIN32_WCE void CDetailView::Dump(CDumpContext& dc) const { CView::Dump(dc); } #endif #endif //_DEBUG // CDetailView 消息处理程序 void CDetailView::OnPaint() { if (pDoc == NULL) pDoc = (CMCADoc*)GetDocument(); if (pView == NULL) pView = (CControlView*)pDoc->GetView(RUNTIME_CLASS(CControlView)); CPaintDC dc(this); // device context for painting OnPrepareDC(&dc); OnDraw(&dc); } BOOL CDetailView::OnEraseBkgnd(CDC* pDC) { return TRUE; } void CDetailView::OnLButtonDown(UINT nFlags, CPoint point) { if (pDoc == NULL) pDoc = (CMCADoc*)GetDocument(); if (pView == NULL) pView = (CControlView*)pDoc->GetView(RUNTIME_CLASS(CControlView)); int nX = point.x / ZF + pView->m_nCursor1; pView->m_nCursorROI = nX; pView->m_nCursorROICount = pDoc->m_nChannelCount[nX]; pView->UpdateData(FALSE); pDoc->UpdateAllViews(NULL); CView::OnLButtonDown(nFlags, point); } void CDetailView::OnRButtonDown(UINT nFlags, CPoint point) { if (pDoc == NULL) pDoc = (CMCADoc*)GetDocument(); if (pView == NULL) pView = (CControlView*)pDoc->GetView(RUNTIME_CLASS(CControlView)); pView->m_nCursor1 = 0; pView->m_nCursor2 = 1023; pView->UpdateData(FALSE); pDoc->UpdateAllViews(NULL); CView::OnRButtonDown(nFlags, point); }