?? askdlg.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; //時域矩形區(qū)和頻域矩形區(qū)
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)); //對畫圖區(qū)域進行縮放
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)); //對畫圖區(qū)域進行縮放
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 + -