?? sinadlg.cpp
字號(hào):
// sinaDlg.cpp : implementation file
//
#include "stdafx.h"
#include "sina.h"
#include "sinaDlg.h"
#include "math.h"
#include "fft.h"
#include "math.h"
#define pi 3.1415926
#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();
CBrush m_winBrush;
// 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()
/////////////////////////////////////////////////////////////////////////////
// CSinaDlg dialog
CSinaDlg::CSinaDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSinaDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSinaDlg)
m_amp = 10;
m_fre = 20;
m_dianshu = 256;
m_yibianamp = 80;
m_yibianfre = 100;
m_yibianlen = 100;
m_yibianstart = 100;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSinaDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSinaDlg)
DDX_Control(pDX, IDOK, m_ok);
// DDX_Control(pDX, IDC_STATIC_AMPLITUDE, m_sta_amp);
// DDX_Control(pDX, IDC_STATIC_FREQUENCY, m_sta_fre);
DDX_Text(pDX, IDC_AMPLITUDE, m_amp);
DDX_Text(pDX, IDC_FREQUENCY, m_fre);
DDX_Text(pDX, IDC_DIANSHU, m_dianshu);
DDX_Text(pDX, IDC_YIBIANAMP, m_yibianamp);
DDX_Text(pDX, IDC_YIBIANFRE, m_yibianfre);
DDX_Text(pDX, IDC_YIBIANLEN, m_yibianlen);
DDX_Text(pDX, IDC_YIBIANSTART, m_yibianstart);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSinaDlg, CDialog)
//{{AFX_MSG_MAP(CSinaDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_EN_CHANGE(IDC_FREQUENCY, OnChangeFrequency)
ON_EN_CHANGE(IDC_AMPLITUDE, OnChangeAmplitude)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_EN_CHANGE(IDC_DIANSHU, OnChangeDianshu)
ON_WM_CTLCOLOR()
ON_EN_CHANGE(IDC_YIBIANFRE, OnChangeYibianfre)
ON_EN_CHANGE(IDC_YIBIANAMP, OnChangeYibianamp)
ON_EN_CHANGE(IDC_YIBIANLEN, OnChangeYibianlen)
ON_EN_CHANGE(IDC_YIBIANSTART, OnChangeYibianstart)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSinaDlg message handlers
BOOL CSinaDlg::OnInitDialog()
{
CDialog::OnInitDialog();
SetWindowPos(NULL,0,0,GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN),0);
// 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 iconfor 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 CSinaDlg::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 CSinaDlg::OnPaint()
{
OnOK();
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();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSinaDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSinaDlg::OnChangeFrequency()
{
// 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);
UpdateData(false);
}
void CSinaDlg::OnChangeAmplitude()
{
// 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);
UpdateData(false);
}
void CSinaDlg::OnChangeDianshu()
{
// 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);
UpdateData(false);
}
void CSinaDlg::OnChangeYibianfre()
{
// 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);
UpdateData(false);
}
void CSinaDlg::OnChangeYibianamp()
{
// 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);
UpdateData(false);
}
void CSinaDlg::OnChangeYibianlen()
{
// 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);
UpdateData(false);
}
void CSinaDlg::OnChangeYibianstart()
{
// 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);
UpdateData(false);
}
//限制曲線的幅度在既定的區(qū)域內(nèi)畫圖
int CSinaDlg::fudu1(int m)
{
int n;
if (m>100) //若輸入幅度超過100,則除去相應(yīng)系數(shù)
{
for (n=2;;n++)
{
if ((m>(pow(10,n)))&&(m<=(pow(10,(n+1)))))
{
break;
}
}
}
else //若輸入幅度<100則不做處理
{
n=1;
}
return n-1;
}
//限制超出的幅度在既定的區(qū)域內(nèi)畫圖
int CSinaDlg::fudu2(int m,int h)
{
int n;
if (m*(h/2)>100) //若FFT變換后其幅度超出100則做相應(yīng)處理,限制其在規(guī)定繪圖區(qū)內(nèi)
{
for (n=0;;n++)
{
if ((m*(h/2)>(pow(10,n)))&&(m*(h/2)<=(pow(10,(n+1)))))
{
break;
}
}
}
else //若其幅度在100之內(nèi)則不做處理
{
n=1;
}
return n+1;
}
void CSinaDlg::OnOK()
{
// TODO: Add extra validation here
// 以下碼繪弦線
int i,j; //循環(huán)變量
int temp,t1,t2,t3,t4,t5; //中間變量
CString str;
CWnd* pWnd=GetDlgItem(IDC_STATIC_SINA); //選擇第一個(gè)靜態(tài)文本框
CDC* pControlDC=pWnd->GetDC();
pWnd->Invalidate(); //強(qiáng)制窗口無效
pWnd->UpdateWindow(); //刷新窗口
//設(shè)定邏輯坐標(biāo)物坐標(biāo)例
ASSERT_VALID(pControlDC);
pControlDC->SetMapMode(MM_ANISOTROPIC);
pControlDC->SetViewportOrg(50,150);
pControlDC->SetWindowExt(50,-150);
pControlDC->SetViewportExt(50,150);
//繪制坐標(biāo)軸
pControlDC->MoveTo(0,0);
pControlDC->LineTo(350,0);
pControlDC->MoveTo(0,-150);
pControlDC->LineTo(0,150);
//繪制坐標(biāo)軸上的箭頭
pControlDC->MoveTo(340,5);
pControlDC->LineTo(350,0);
pControlDC->LineTo(340,-5);
pControlDC->MoveTo(-5,145);
pControlDC->LineTo(0,150);
pControlDC->LineTo(5,145);
//定義畫筆
HPEN hP1,hP2,hP3;
hP1=CreatePen(PS_DOT,1,RGB(0,0,0));
SelectObject(*pControlDC,hP1);
//標(biāo)注縱坐標(biāo)軸刻度線
for (i=0;i<11;i++)
{
pControlDC->MoveTo(0,100-20*i);
pControlDC->LineTo(300,100-20*i);
str.Format("%.2f",1-0.2*i);
if(i!=5) pControlDC->TextOut(-40,110-20*i,str);
else pControlDC->TextOut(-40,110-20*i,"0");
}
//標(biāo)注橫坐標(biāo)軸刻度線
for (i=1;i<7;i++)
{
pControlDC->MoveTo(50*i,-100);
pControlDC->LineTo(50*i,100);
if ((i%2)==0)
{
str.Format("%d",50*i);
pControlDC->TextOut(50*i-10,-3,str);
}
}
//重繪被虛線化了的橫軸
hP3=CreatePen(PS_SOLID,1,RGB(0,0,0));
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -