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

📄 sinadlg.cpp

📁 通过参数设置
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// 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);
	
}

//限制曲线的幅度在既定的区域内画图
int CSinaDlg::fudu1(int m)          
{
	int n;
	if (m>100) //若输入幅度超过100,则除去相应系数
	{
		for (n=2;;n++)
		{  
			if ((m>(pow(10,n)))&&(m<=(pow(10,(n+1)))))
			{      
				break;
			}
		}
	}
	else //若输入幅度<100则不做处理
	{
		n=1;                        
	}
	return n-1;
}

//限制超出的幅度在既定的区域内画图
int CSinaDlg::fudu2(int m,int h)           
{
	int n;
	if (m*(h/2)>100) //若FFT变换后其幅度超出100则做相应处理,限制其在规定绘图区内
	{
		for (n=0;;n++)
		{
			if ((m*(h/2)>(pow(10,n)))&&(m*(h/2)<=(pow(10,(n+1)))))
			{
				break;
			}
		}
	}
    else //若其幅度在100之内则不做处理
	{
		n=1;
	}
	return n+1;
}

void CSinaDlg::OnOK() 
{
	// TODO: Add extra validation here
	// 以下码绘弦线
	int i,j; //循环变量   
	int temp,t1,t2,t3,t4,t5; //中间变量
	CString str;
	CWnd* pWnd=GetDlgItem(IDC_STATIC_SINA); //选择第一个静态文本框  
	CDC*  pControlDC=pWnd->GetDC();
	
	pWnd->Invalidate(); //强制窗口无效	  
	pWnd->UpdateWindow(); //刷新窗口
	
	//设定逻辑坐标物坐标例
	ASSERT_VALID(pControlDC);  
	pControlDC->SetMapMode(MM_ANISOTROPIC);
    pControlDC->SetViewportOrg(50,150); 
    pControlDC->SetWindowExt(50,-150);
    pControlDC->SetViewportExt(50,150); 
	
	//绘制坐标轴
    pControlDC->MoveTo(0,0);
	pControlDC->LineTo(350,0);
	pControlDC->MoveTo(0,-150);
	pControlDC->LineTo(0,150);
	
	//绘制坐标轴上的箭头
	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);
	
	//标注纵坐标轴刻度线
	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");
	}
	
	//标注横坐标轴刻度线
	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));

⌨️ 快捷键说明

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