📄 wave_fftview.cpp
字号:
// Wave_FftView.cpp : implementation of the CWave_FftView class
//
#include "stdafx.h"
#include "Wave_Fft.h"
#include "Wave_FftDoc.h"
#include "Wave_FftView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CWave_FftView
IMPLEMENT_DYNCREATE(CWave_FftView, CFormView)
BEGIN_MESSAGE_MAP(CWave_FftView, CFormView)
//{{AFX_MSG_MAP(CWave_FftView)
ON_BN_CLICKED(IDC_RADIO_WAVE, OnRadioWave)
ON_BN_CLICKED(IDC_RADIO_WAVE_S, OnRadioWaveS)
ON_BN_CLICKED(IDC_RADIO_NoNoise, OnRADIONoNoise)
ON_BN_CLICKED(IDC_NOISE, OnNoise)
ON_WM_HSCROLL()
ON_BN_CLICKED(IDC_BUTTON_AUTO, OnButtonAuto)
ON_WM_TIMER()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CWave_FftView construction/destruction
CWave_FftView::CWave_FftView()
: CFormView(CWave_FftView::IDD)
{
//{{AFX_DATA_INIT(CWave_FftView)
m_WaveType = 0;
m_NoNoise = 0;
m_Fre = 1.0f;
//}}AFX_DATA_INIT
// TODO: add construction code here
}
CWave_FftView::~CWave_FftView()
{
}
void CWave_FftView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CWave_FftView)
DDX_Control(pDX, IDC_SCROLLBAR, m_Scroll);
DDX_Control(pDX, IDC_MSCHART1, m_MsChart1);
DDX_Control(pDX, IDC_MSCHART2, m_MsChart2);
DDX_Radio(pDX, IDC_RADIO_WAVE, m_WaveType);
DDX_Radio(pDX, IDC_RADIO_NoNoise, m_NoNoise);
DDX_Text(pDX, IDC_EDIT_FRE, m_Fre);
//}}AFX_DATA_MAP
}
BOOL CWave_FftView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
void CWave_FftView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
InitalForm(); //初始化界面
}
/************************************************************************/
/* 功能:初始化 ,对图形显示的初始化 */
/************************************************************************/
void CWave_FftView::InitalForm()
{
m_bAuto=TRUE;
m_Dir=TRUE;
m_Num=512;
m_Data=new double[m_Num];
m_FftData=new double[m_Num];
m_WaveDraw.InitDraw(m_MsChart1,m_MsChart2,m_Num);
//int m_WaveType=2;
m_WaveProcess.GetData(m_Data,m_Num,m_WaveType,m_NoNoise,m_Fre);
// m_WaveDraw.DrawWave(m_MsChart1,m_Data,m_Num);
// m_MsChart1.Refresh();
m_WaveProcess.FFT(m_Data,m_FftData,m_Num,8);
UpdateData(FALSE);
m_Scroll.SetScrollRange(0,1000,10);
m_Scroll.SetScrollPos(100);
m_Fre = 1.0f;
UpdateData(FALSE);
// m_WaveDraw.DrawWave(m_MsChart2,m_FftData,m_Num);
}
/////////////////////////////////////////////////////////////////////////////
// CWave_FftView printing
BOOL CWave_FftView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CWave_FftView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CWave_FftView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CWave_FftView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CWave_FftView diagnostics
#ifdef _DEBUG
void CWave_FftView::AssertValid() const
{
CFormView::AssertValid();
}
void CWave_FftView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CWave_FftDoc* CWave_FftView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWave_FftDoc)));
return (CWave_FftDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWave_FftView message handlers
void CWave_FftView::OnDraw(CDC* pDC)
{
m_WaveDraw.DrawWave(m_MsChart1,m_Data,m_Num);
m_MsChart1.Refresh();
m_WaveDraw.DrawWave(m_MsChart2,m_FftData,m_Num);
m_MsChart2.Refresh();
}
/************************************************************************/
/* 功能:选择波形(正弦波) */
/************************************************************************/
void CWave_FftView::OnRadioWave()
{
m_WaveType=0;
m_WaveProcess.GetData(m_Data,m_Num,m_WaveType,m_NoNoise,m_Fre);
m_WaveProcess.FFT(m_Data,m_FftData,m_Num,8);
ReDraw();
}
/************************************************************************/
/* 功能:选择波形(三角波) */
/************************************************************************/
void CWave_FftView::OnRadioWaveS()
{
m_WaveType=1;
m_WaveProcess.GetData(m_Data,m_Num,m_WaveType,m_NoNoise,m_Fre);
m_WaveProcess.FFT(m_Data,m_FftData,m_Num,8);
ReDraw();
}
void CWave_FftView::OnRADIONoNoise()
{
m_NoNoise=0;
m_WaveProcess.GetData(m_Data,m_Num,m_WaveType,m_NoNoise,m_Fre);
m_WaveProcess.FFT(m_Data,m_FftData,m_Num,8);
ReDraw();
}
void CWave_FftView::OnNoise()
{
m_NoNoise=1;
m_WaveProcess.GetData(m_Data,m_Num,m_WaveType,m_NoNoise,m_Fre);
m_WaveProcess.FFT(m_Data,m_FftData,m_Num,8);
ReDraw();
}
void CWave_FftView::ReDraw()
{
m_WaveDraw.DrawWave(m_MsChart1,m_Data,m_Num);
m_MsChart1.Refresh();
m_WaveDraw.DrawWave(m_MsChart2,m_FftData,m_Num);
m_MsChart2.Refresh();
}
void CWave_FftView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
int minpos,maxpos;
pScrollBar->GetScrollRange(&minpos, &maxpos);
maxpos = pScrollBar->GetScrollLimit();
// Get the current position of scroll box.
int curpos = pScrollBar->GetScrollPos();
// Determine the new position of scroll box.
switch (nSBCode)
{
case SB_LEFT: // Scroll to far left.
curpos = minpos;
break;
case SB_RIGHT: // Scroll to far right.
curpos = maxpos;
break;
case SB_ENDSCROLL: // End scroll.
break;
case SB_LINELEFT: // Scroll left.
if (curpos > minpos)
curpos--;
break;
case SB_LINERIGHT: // Scroll right.
if (curpos < maxpos)
curpos++;
break;
case SB_PAGELEFT: // Scroll one page left.
{
// Get the page size.
SCROLLINFO info;
pScrollBar->GetScrollInfo(&info, SIF_ALL);
if (curpos > minpos)
curpos = max(minpos, curpos - (int) info.nPage);
}
break;
case SB_PAGERIGHT: // Scroll one page right.
{
// Get the page size.
SCROLLINFO info;
pScrollBar->GetScrollInfo(&info, SIF_ALL);
if (curpos < maxpos)
curpos = min(maxpos, curpos + (int) info.nPage);
}
break;
case SB_THUMBPOSITION: // Scroll to absolute position. nPos is the position
curpos = nPos; // of the scroll box at the end of the drag operation.
break;
case SB_THUMBTRACK: // Drag scroll box to specified position. nPos is the
curpos = nPos; // position that the scroll box has been dragged to.
break;
}
// Set the new position of the thumb (scroll box).
pScrollBar->SetScrollPos(curpos);
if(pScrollBar==&m_Scroll)
{
m_Fre = float(curpos)/100;
}
UpdateData(FALSE);
m_WaveProcess.GetData(m_Data,m_Num,m_WaveType,m_NoNoise,m_Fre);
m_WaveProcess.FFT(m_Data,m_FftData,m_Num,8);
ReDraw();
CFormView::OnHScroll(nSBCode, nPos, pScrollBar);
}
void CWave_FftView::OnButtonAuto()
{
CString temp;
UpdateData(TRUE);
((CButton *)GetDlgItem(IDC_BUTTON_AUTO))->GetWindowText(temp);
if (temp=="自动")
{
SetTimer(1,1000,0);
((CButton *)GetDlgItem(IDC_BUTTON_AUTO))->SetWindowText("停止");
}
else
{
KillTimer(1);
((CButton *)GetDlgItem(IDC_BUTTON_AUTO))->SetWindowText("自动");
}
}
void CWave_FftView::OnTimer(UINT nIDEvent)
{
if (nIDEvent==1)
{
if (m_Dir)
{
m_Fre=(m_Fre+0.1)*10/10;
}
else
{
m_Fre=(m_Fre-0.1)*10/10;;
}
m_Scroll.SetScrollPos((int)(m_Fre*100));
if (m_Fre>10)
{
m_Dir=FALSE;
}
else if (m_Fre<0)
{
m_Dir=TRUE;
}
UpdateData(FALSE);
m_WaveProcess.GetData(m_Data,m_Num,m_WaveType,m_NoNoise,m_Fre);
m_WaveProcess.FFT(m_Data,m_FftData,m_Num,8);
ReDraw();
}
CFormView::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -