📄 8bandlg.cpp
字号:
// 8banDlg.cpp : implementation file
//
#include "stdafx.h"
#include "8ban.h"
#include "8banDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CMy8banDlg dialog
CMy8banDlg::CMy8banDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMy8banDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMy8banDlg)
m_cycle = 100.0f;
m_scope = 10.0f;
m_parse = 0.0f;
m_smp_alter = 1.0f;
m_smp_num = 1024.0f;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMy8banDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMy8banDlg)
DDX_Text(pDX, IDC_EDIT1, m_cycle);
DDX_Text(pDX, IDC_EDIT2, m_scope);
DDX_Text(pDX, IDC_EDIT3, m_parse);
DDX_Text(pDX, IDC_EDIT4, m_smp_alter);
DDX_Text(pDX, IDC_EDIT5, m_smp_num);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMy8banDlg, CDialog)
//{{AFX_MSG_MAP(CMy8banDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMy8banDlg message handlers
BOOL CMy8banDlg::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 CMy8banDlg::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 CMy8banDlg::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();
}
//this->mydraw();
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMy8banDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMy8banDlg::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
UpdateData(true);
int L=0, N=1;
while (N<m_smp_num)
{
++L;
N = 1<<L;
}
int i;
// TODO: Add extra validation here
CWnd* w2= (CWnd*)GetDlgItem(IDC_EDIT7);
CRect rect2;
w2->GetClientRect(&rect2);
CDC *pDC2=w2->GetDC();
for (i=0; i<N; i++)
{
pDC2->LineTo(rect2.left+i, int(rect2.bottom-b[i])-10);
pDC2->MoveTo(rect2.left+i, int(rect2.bottom-b[i])-10);//
}
}
void CMy8banDlg::dft(const int N,
const Complex cin[], Complex cout[])
{
assert(cin);
assert(cout);
assert(N>0);
/* Loop for each X(k).
*/
int k;
for (k=0; k<N; k++)
{
float tr=0, ti=0;
float wn = float(2*PI/N*k);
int n;
/* sum x(n) */
for (n=0; n<N; n++)
{
float w = wn*n;
tr += float(( cin[n].rex*cos(w) + cin[n].imx*sin(w) ));
ti += float(( cin[n].imx*cos(w) - cin[n].rex*sin(w)) );
}
cout[k].rex = tr;
cout[k].imx = ti;
}
}
void CMy8banDlg::module(const Complex cin[],
float pout[], const int N, const int LEVER)
{
assert(cin);
assert(pout);
assert(N>0);
/* Reconstruct data for output.
*/
float gmax = 1;
int i;
for (i=0; i<N; i++)
{
pout[i] = float(sqrt( cin[i].rex*cin[i].rex + cin[i].imx*cin[i].imx ));
if (pout[i] > gmax)
{
gmax = pout[i];
}
}
/* Normalize data.
*/
for (i=0; i<N; i++)
{
pout[i] = (LEVER * pout[i]/gmax);
}
}
void CMy8banDlg::OnButton1()
{
// TODO: Add your control notification handler code here
UpdateData(true);
int L=0, N=1;
while (N<m_smp_num)
{
++L;
N = 1<<L;
}
// initialize data
Complex *cin= (Complex *)malloc(sizeof(Complex)*N);
int i;
for (i=0; i<N; i++)
{
cin[i].rex = cin[i].imx = 0;
}
Complex *cout = (Complex *)malloc(sizeof(Complex)*N);
float *dis = (float *)malloc(sizeof(float)*N);
const float T = m_cycle,
P = m_parse,
A = m_scope,
Ts = m_smp_alter;
const int SN = int(m_smp_num);
for (i=0; i<SN; i++)
{
cin[i].rex = float(A * sin(2*PI*(Ts*i)/T + P));
a[i]+=cin[i].rex;
}
dft(N, cin, cout);
module(cout, dis, N, 100);
for (i=0; i<N; i++)
{
b[i]+=dis[i];
}
CWnd* w1= (CWnd*)GetDlgItem(IDC_EDIT6);
CRect rect1;
w1->GetClientRect(&rect1);
CDC *pDC1=w1->GetDC();
RedrawWindow();
for (i=0; i<N; i++)
{
pDC1->LineTo(rect1.left+i, int(rect1.bottom-a[i])-60);
pDC1->MoveTo(rect1.left+i, int(rect1.bottom-a[i])-60);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -