📄 vsbqview.cpp
字号:
// VsbqView.cpp : implementation of the CVsbqView class
//
#include "stdafx.h"
#include "Vsbq.h"
#include "ComSetDlg.h"
#include "VsbqDoc.h"
#include "VsbqView.h"
#include "math.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CVsbqApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CVsbqView
IMPLEMENT_DYNCREATE(CVsbqView, CView)
BEGIN_MESSAGE_MAP(CVsbqView, CView)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CVsbqView)
ON_WM_TIMER()
ON_WM_CREATE()
ON_MESSAGE(UM_WAVETIME, OnWaveTime) //////////////////////////
ON_MESSAGE(UM_STOPWAVETIME, OnStopWaveTime) //////////////////////
ON_MESSAGE(UM_MYPRINTF, OnMyPrint) //////////////////////////
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONUP()
ON_WM_LBUTTONUP()
ON_UPDATE_COMMAND_UI(ID_FILE_PRINT_PREVIEW, OnUpdateFilePrintPreview)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CVsbqView construction/destruction
CVsbqView::CVsbqView()
{
// TODO: add construction code here
m_bLButtonDown = FALSE;
m_bMouseMove = FALSE;
// 游标初始化
graph0.LButtonDownFlage = FALSE;
}
CVsbqView::~CVsbqView()
{
}
void CVsbqView::OnMyPrint()
{
}
BOOL CVsbqView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CVsbqView drawing
void CVsbqView::OnDraw(CDC* pDC)
{
CVsbqDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
BOOL CVsbqView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
BOOL m_bprint;
theApp.m_bPrintFlage = TRUE; //标志打印开始
::PostMessage(theApp.m_hWndBtmView, UM_MYKILLTIMER, 0, 0);
m_bprint = DoPreparePrinting(pInfo);
if(!m_bprint)
{
theApp.m_bPrintFlage = FALSE; //标志打印开始
::PostMessage(theApp.m_hWndBtmView, UM_MYSETTIMER, 0, 0);
}
return m_bprint;
return DoPreparePrinting(pInfo);
}
void CVsbqView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CVsbqView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
theApp.m_bPrintFlage = FALSE; //标志打印结束
::PostMessage(theApp.m_hWndBtmView, UM_SETBUTTON, 0, 0);
}
//打印和打印预览
void CVsbqView::OnPrint(CDC* pDC, CPrintInfo*)
{
int xPixel = 0;
int yPixel = 0;
int oldmapmode = 0;
float RectWidth = 0.0f;
float RectHeight = 0.0f;
float *data= NULL;
CString flage = "";
CPoint points;
CPoint pointe;
CRect rect;
GetClientRect(&rect);
RectWidth = rect.Width();
RectHeight = rect.Height();
xPixel = pDC->GetDeviceCaps(LOGPIXELSX);
yPixel = pDC->GetDeviceCaps(LOGPIXELSX);
xPixel = (int)(8.3*(xPixel/RectWidth));
yPixel = (int)(12*(yPixel/RectHeight));
//坐标系的转换
oldmapmode = pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetViewportOrg(50,100);
pDC->SetViewportExt(xPixel, yPixel);
//画示波器
OscilShow(pDC,points,pointe,rect,TRUE);
// if (theApp.m_bWavePlay)
{
//画波形
// graph0.ComputeValueCH1();
graph0.DrawWave(pDC,TRUE);
}
//边成原来的坐标系
pDC->SetViewportOrg(0,0);
pDC->SetViewportExt(1, 1);
pDC->SetMapMode(oldmapmode);
//定义画波形的画笔
// pOldPen = pDC->SelectObject(pDrawPen);
//画电压波形
//坐标系的转换
/* oldmapmode = pDC->SetMapMode(MM_ANISOTROPIC);
pDC->SetViewportOrg(50, 50);
pDC->SetViewportExt(xPixel, yPixel);
graph0.GetData(1);
graph0.PrintWave(pDC, 1);;
pDC->SetViewportOrg(0, 0);
pDC->SetViewportExt(1, 1);
pDC->SetMapMode(oldmapmode);*/
}
/////////////////////////////////////////////////////////////////////////////
// CVsbqView printing
/////////////////////////////////////////////////////////////////////////////
// CVsbqView diagnostics
#ifdef _DEBUG
void CVsbqView::AssertValid() const
{
CView::AssertValid();
}
void CVsbqView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CVsbqDoc* CVsbqView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVsbqDoc)));
return (CVsbqDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CVsbqView message handlers
void CVsbqView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CClientDC dc(this);
CDC pDC;
pDC.CreateCompatibleDC(&dc);
CRect rect;
GetClientRect(&rect);
CBitmap bitmap, *pOldBmp;
bitmap.CreateCompatibleBitmap(&dc,rect.Width(),rect.Height());
pOldBmp = pDC.SelectObject(&bitmap);
CPoint points;
CPoint pointe;
CString flage = "";
points.x = rect.left;
points.y = rect.top;
pointe.x = rect.right;
pointe.y = rect.bottom;
graph0.TextShow(&pDC,points,pointe);
//画示波器
OscilShow(&pDC,points,pointe,rect,FALSE);
//画示波器中的波形
// CPen pen(PS_SOLID,1,RGB(0,255,0));
// pDC.SelectObject(pen);
if (theApp.m_bWavePlay)
{
//画波形
if (!theApp.m_bPrintFlage)
{
graph0.ComputeValueCH1();
}
graph0.DrawWave(&pDC,FALSE);
}
CPen m_pen1(PS_SOLID,1,GetSysColor(COLOR_BTNFACE));
pDC.SelectObject(m_pen1);
points.x = rect.left+2;
points.y = rect.bottom - rect.Height()/32;
pointe.x = rect.right-28;
pointe.y = rect.bottom ;
graph0.TextShow(&pDC,points,pointe);
points.x = rect.left + 2;
points.y = rect.top;
pointe.x = rect.right - 28;
pointe.y = rect.Height()/32;
graph0.TextShow(&pDC,points,pointe);
dc.BitBlt(rect.left,rect.top,rect.Width(),rect.Height(),
&pDC,rect.left,rect.top,SRCCOPY);
CView::OnTimer(nIDEvent);
}
int CVsbqView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
SetTimer(1,theApp.m_myNewTimer,NULL);
theApp.m_bOscilShow = TRUE;
CdtRange.yMin =0;
CdtRange.yMax =360;
CdtRange.xMin = -20;
CdtRange.xMax =20;
CdtRange.yLattice = 8;
CdtRange.xLattice = 10;
graph0.CreateWave(CdtRange);
theApp.m_Vsbqview = this->m_hWnd;
return 0;
}
void CVsbqView::OscilShow(CDC *pDC,CPoint points,CPoint pointe,
CRect rect,BOOL bpflage)
{
CString flage = "";
points.x = rect.Width()*1/32;
points.y = rect.Height()*1/32;
pointe.x = rect.Width()*31/32;
pointe.y = rect.Height()*31/32;
// 显示当前频率
// float aaa = 50.0f;
// flage.Format("%.2f", aaa);
// flage = "频率: " + flage + " HZ";*/
flage = "CH1: " + theApp.m_strVolete1 + " CH2: " + theApp.m_strVolete2;
graph0.Show(pDC,points,pointe,rect,flage,bpflage);
}
void CVsbqView::OnWaveTime()
{
KillTimer(1);
SetTimer(1,theApp.m_myNewTimer,NULL);
theApp.m_bOscilShow = TRUE;
}
void CVsbqView::OnStopWaveTime()
{
KillTimer(1);
theApp.m_bOscilShow = FALSE;
}
void CVsbqView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (graph0.IsINWave(point) ==1)
{
graph0.LButtonDown(point,1);
m_bLButtonDown = TRUE;
}
else if (graph0.IsINWave(point) ==2)
{
graph0.LButtonDown(point,2);
m_bLButtonDown = TRUE;
}
if (graph0.IsINWave(point) == 3)
{
graph0.LButtonDown(point, 3);
m_bLButtonDown = TRUE;
}
if (graph0.IsINWave(point) == 4)
{
graph0.LButtonDown(point, 4);
m_bLButtonDown = TRUE;
}
CView::OnLButtonDown(nFlags, point);
}
void CVsbqView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_bLButtonDown = TRUE)
{
graph0.OnMouseMove(nFlags, point);
}
CView::OnMouseMove(nFlags, point);
}
void CVsbqView::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CView::OnRButtonUp(nFlags, point);
}
void CVsbqView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
ClipCursor(NULL);
if (graph0.LButtonDownFlage)
{
graph0.OnLButtonUp(nFlags, point);
}
m_bLButtonDown = FALSE;
CView::OnLButtonUp(nFlags, point);
}
void CVsbqView::OnContextMenu(CWnd*, CPoint point)
{
// CG: This block was added by the Pop-up Menu component { if (point.x == -1 && point.y == -1){ //keystroke invocation CRect rect; GetClientRect(rect); ClientToScreen(rect); point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; VERIFY(menu.LoadMenu(CG_IDR_POPUP_VSBQ_VIEW)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
}
void CVsbqView::OnUpdateFilePrintPreview(CCmdUI* pCmdUI)
{
pCmdUI->Enable(TRUE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -