⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 askdlg.cpp

📁 基于MFC
💻 CPP
字号:
// ASkDlg.cpp : implementation file
//

#include "StdAfx.h"
#include "ASk.h"
#include "ASkDlg.h"
#include "math.h"
#include "string.h"
#include"StuCodeinfo.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CASkDlg dialog

CASkDlg::CASkDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CASkDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CASkDlg)
	m_InitialInput = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CASkDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CASkDlg)
	DDX_Text(pDX, IDC_InitialInput_EDIT1, m_InitialInput);
	DDV_MinMaxInt(pDX, m_InitialInput, 0, 9999);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CASkDlg, CDialog)
	//{{AFX_MSG_MAP(CASkDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_EN_CHANGE(IDC_InitialInput_EDIT1, OnChangeInitialInputEDIT1)
	ON_BN_CLICKED(IDC_BaseSignal, OnBaseSignal)
	ON_BN_CLICKED(IDC_PassLpf1, OnPassLpf1)
	ON_BN_CLICKED(IDC_Mudulate, OnMudulate)
	ON_BN_CLICKED(IDC_Noise, OnNoise)
	ON_BN_CLICKED(IDC_Channel, OnChannel)
	ON_BN_CLICKED(IDC_PassBpf, OnPassBpf)
	ON_BN_CLICKED(IDC_Demodulate, OnDemodulate)
	ON_BN_CLICKED(IDC_PassLpf2, OnPassLpf2)
	ON_BN_CLICKED(IDC_Judge, OnJudge)
	ON_EN_CHANGE(IDC_TIMEDOMAIN, OnChangeTimedomain)
	ON_BN_CLICKED(IDC_TIMEDOMAIN, OnTimedomain)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CASkDlg message handlers

BOOL CASkDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
  
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CASkDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CASkDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
		DrawGraph(StuA.Sa,16*F,StuA.A,StuA.n); 
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CASkDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CASkDlg::OnChangeInitialInputEDIT1() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here

	UpdateData(TRUE);
    StuA.c=m_InitialInput;

}
void CASkDlg::OnBaseSignal() 
{
	// TODO: Add your control notification handler code here
	//m_Input.DoModal();
	StuA.D_transfer_H();
	StuA.Sample();
	StuA.DFT_FFT();
    Invalidate();




}

void CASkDlg::OnPassLpf1() 
{
	// TODO: Add your control notification handler code here
	StuA.Lpf1();
	StuA.DFT_FFT();
	Invalidate();

	
}

void CASkDlg::OnMudulate() 
{
	// TODO: Add your control notification handler code here
	StuA.Modulate();
	StuA.DFT_FFT();
	Invalidate();
	
}

void CASkDlg::OnNoise() 
{
	// TODO: Add your control notification handler code here
	StuA.Noise();
	
}

void CASkDlg::OnChannel() 
{
	// TODO: Add your control notification handler code here
	StuA.Channel();
	Invalidate();

}

void CASkDlg::OnPassBpf() 
{
	// TODO: Add your control notification handler code here
	StuA.Bpf();
	Invalidate();
	
}

void CASkDlg::OnDemodulate() 
{
	// TODO: Add your control notification handler code here
	StuA.Demodulate();
	Invalidate();
}

void CASkDlg::OnPassLpf2() 
{
	// TODO: Add your control notification handler code here
	StuA.Lpf2();
	Invalidate();

}

void CASkDlg::OnJudge() 
{
	// TODO: Add your control notification handler code here
	StuA.Judge();
	Invalidate();
	
}

void CASkDlg::DrawGraph(double x[],int N,double y[],int M )	//x[]为时域数据数组,N为长度;y[]为频谱幅值数组,M为长度
{
	CPoint Start;											//坐标原点
	CRect TimeRect,FreqRect,MyRect;							//时域矩形区和频域矩形区
	int i,Width,Height,CoordinateX=5;						//坐标轴上标尺高度(像素)
	double Kx=0.02,Ky=0.16;									//Kx,Ky为长宽缩放系数,[0,1]
	double StepX;											//StepX为横坐标步进										
	double Ratio;											//纵轴缩放系数
	CClientDC dc(this);

	/******************************画时域图*****************************************/
	GetDlgItem(IDC_TIME)->GetWindowRect(&TimeRect);			//取得屏幕坐标
	ScreenToClient(&TimeRect);								//取得相对于窗口坐标
	Width=TimeRect.Width();
	Height=TimeRect.Height();
	TimeRect.DeflateRect(int(Width*Kx/2),int(Height*Ky/2));	//对画图区域进行缩放
	TimeRect.OffsetRect(0,6);
	MyRect=TimeRect;
	Width=MyRect.Width();
	StepX=Width/double(N);
	Ratio=0;
	for(i=0;i<N;i++)										//找出最大绝对值
		if(fabs(x[i]) > Ratio)
			Ratio=fabs(x[i]);
	Ratio=Ratio/(MyRect.Height()/2);						//一个像素代表的数值大小
	Start.x=MyRect.TopLeft().x;
	Start.y=MyRect.TopLeft().y+MyRect.Height()/2;
	dc.MoveTo(Start);
	dc.LineTo(Start.x+int(i*StepX),Start.y);				//画出横坐标轴
	for(i=0;i<=N;i++)										//画出坐标轴标尺
	{
		if(i%(N/16) == 0)
		{
			dc.MoveTo(Start.x+int(i*StepX),Start.y);
			dc.LineTo(Start.x+int(i*StepX),Start.y-CoordinateX);
		}
	}
	dc.MoveTo(Start.x,Start.y+MyRect.Height()/2);
	dc.LineTo(Start.x,Start.y-MyRect.Height()/2);			//画出纵坐标轴
	dc.MoveTo(Start);										//回到原点
	for(i=0;i<N;i++)
	{
		dc.LineTo(Start.x+int(i*StepX),Start.y-int(x[i]/Ratio));//画出曲线
	}

	/******************************画频域图*****************************************/
	GetDlgItem(IDC_FREQ)->GetWindowRect(&FreqRect);			//取得屏幕坐标
	ScreenToClient(&FreqRect);								//取得相对于窗口坐标
	Width=FreqRect.Width();
	Height=FreqRect.Height();
	FreqRect.DeflateRect(int(Width*Kx/2),int(Height*Ky/2));	//对画图区域进行缩放
	FreqRect.OffsetRect(0,6);
	MyRect=FreqRect;
	Width=MyRect.Width();
	StepX=Width/double(M);
	Ratio=0;
	for(i=0;i<M;i++)										//找出最大绝对值
		if(fabs(y[i]) > Ratio)
			Ratio=fabs(y[i]);
	Ratio=Ratio/MyRect.Height();							//一个像素代表的数值大小
	Start.x=MyRect.TopLeft().x;
	Start.y=MyRect.TopLeft().y+MyRect.Height();
	dc.MoveTo(Start);
	dc.LineTo(Start.x+int(i*StepX),Start.y);				//画出横坐标轴
	for(i=0;i<=M;i++)										//画出坐标轴标尺
	{
		if(i%(M/8) == 0)
		{
			dc.MoveTo(Start.x+int(i*StepX),Start.y);
			dc.LineTo(Start.x+int(i*StepX),Start.y-CoordinateX);
		}
	}
	dc.MoveTo(Start);
	dc.LineTo(Start.x,Start.y-MyRect.Height());				//画出纵坐标轴
	dc.MoveTo(Start);										//回到原点
	for(i=0;i<M;i++)
	{
		dc.LineTo(Start.x+int(i*StepX),Start.y-int(y[i]/Ratio));//画出曲线
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -