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

📄 jjjfdlg.cpp

📁 我上硕士时完成的第一个作业!!! 可以显示两个离散的数据
💻 CPP
字号:
// jjjfDlg.cpp : implementation file
//

#include "stdafx.h"
#include "jjjf.h"
#include "jjjfDlg.h"
#include "process.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()

/////////////////////////////////////////////////////////////////////////////
// CJjjfDlg dialog

CJjjfDlg::CJjjfDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CJjjfDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CJjjfDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CJjjfDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CJjjfDlg)
	DDX_Control(pDX, IDC_BUTTON3, m_btn);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CJjjfDlg, CDialog)
	//{{AFX_MSG_MAP(CJjjfDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CJjjfDlg message handlers

BOOL CJjjfDlg::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);

	// 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
	m_btn.EnableWindow(false);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CJjjfDlg::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.
#define HIBORDER RGB(0,0,0)
#define LOBORDER RGB(255,40,233)
void CJjjfDlg::OnPaint() 
{

CDC *pDC=GetDC();
		pDC->Draw3dRect(10,10,300,160,LOBORDER,HIBORDER);
    	pDC->Draw3dRect(320,10,300,160,LOBORDER,HIBORDER);
        pDC->Draw3dRect(10,180,610,260,LOBORDER,HIBORDER);

		RECT Rect;
		Rect.left=Rect.top=12;
		Rect.right=308;
			Rect.bottom=168;
CBrush Brush(RGB(255,255,255));
	pDC->FillRect(&Rect,&Brush);


//		RECT Rect;
		Rect.left=322;
		Rect.top=12;
		Rect.right=618;
			Rect.bottom=168;
//CBrush Brush(RGB(255,255,255));
	pDC->FillRect(&Rect,&Brush);

//	RECT Rect;
		Rect.left=12;
		Rect.top=182;
		Rect.right=618;
			Rect.bottom=438;
//CBrush Brush(RGB(255,255,255));
	pDC->FillRect(&Rect,&Brush);


		CDialog::OnPaint();
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CJjjfDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
////////////////????????????????
void CJjjfDlg::OnButton1() 
{
// TODO: Add your control notification handler code here
CDC *pDC=GetDC();
CPen Pen;
Pen.CreatePen(PS_SOLID,12,RGB(0,0,0));

istrm.open("source1.txt");
float b[n];
x=(COMPLEX *)malloc(sizeof(COMPLEX)*n);
for(i=0;i<n;i++)
{
    istrm>>b[i];
	x[i].re=b[i];
	x[i].im=0.0;
}
istrm.close();

pDC->MoveTo(20,140);
pDC->LineTo(290,140);
//char Str1[6];
j=60;
CClientDC dc(this);
dc.TextOut(40,46,"x(n)");
for(i=0;i<n/2;i++)
{	j+=20;
wsprintf(Str1,"%d",i);
dc.TextOut(j,146,Str1);
pDC->MoveTo(j,140);
pDC->LineTo(j,140-20*b[i]);
CBrush Brush(RGB(0,0,0));
pDC->SelectObject(&Brush);
pDC->Ellipse(j-4,140-20*b[i]-6,j+4,142-20*b[i]);
}
dc.TextOut(j+20,146,"......");
jj=1;
if(ii==1&&jj==1)
m_btn.EnableWindow(true);
//free(x);
	}

//////////
void CJjjfDlg::OnButton2() 
{

CDC *pDC=GetDC();
CPen Pen;
Pen.CreatePen(PS_SOLID,12,RGB(255,0,0));
pDC->MoveTo(330,140);
pDC->LineTo(600,140);
j=370;
float b[n];
h=(COMPLEX *)malloc(sizeof(COMPLEX)*n);
istrm.open("source2.txt");
for(i=0;i<n;i++)
{
    istrm>>b[i];
	h[i].re=b[i];
	h[i].im=0.0;
}
istrm.close();
	
CClientDC dc(this);
dc.TextOut(350,46,"y(n)");
for(i=0;i<n/2;i++)
{
	j+=20;
wsprintf(Str1,"%d",i);
dc.TextOut(j,146,Str1);
pDC->MoveTo(j,140);
pDC->LineTo(j,140-20*b[i]);

CBrush Brush(RGB(0,0,0));
pDC->SelectObject(&Brush);
pDC->Ellipse(j-4,140-20*b[i]-6,j+4,142-20*b[i]);
}
dc.TextOut(j+20,146,"......");
ii=1;
if(ii==1&&jj==1)
m_btn.EnableWindow(true);
//free(h);
}
////////////////////////////////////////
void CJjjfDlg::OnButton3() 
{
float b[n];
y=(COMPLEX *)malloc(sizeof(COMPLEX)*n);
z=(COMPLEX *)malloc(sizeof(COMPLEX)*n);
//h=(COMPLEX *)malloc(sizeof(COMPLEX)*n);
 FFT(x,z,m);
//从文件中读出变换后的实部
istrm.open("test1.txt");
for(i=0;i<n;i++)
{
    istrm>>b[i];
//	h[i].re=b[i];
	x[i].re=b[i];
}
istrm.close();	

istrm.open("test2.txt");
for(i=0;i<n;i++)
{
    istrm>>b[i];
//	h[i].im=b[i];
	x[i].im=b[i];
}
istrm.close();

 FFT(h,z,m);
//从文件中读出变换后的实部
istrm.open("test1.txt");
for(i=0;i<n;i++)
{
    istrm>>b[i];
	h[i].re=b[i];
//	x[i].re=b[i];
}
istrm.close();	

istrm.open("test2.txt");
for(i=0;i<n;i++)
{
    istrm>>b[i];
	h[i].im=b[i];
// x[i].im=b[i];
}
istrm.close();
//求共轭	
for(i=0;i<n;i++)
{
	y[i]= Mul(x[i],h[i]);
	y[i].im=-1*y[i].im;
}
FFT(y,z,m);
istrm.open("test1.txt");
for(i=0;i<n;i++)
{
    istrm>>b[i];
	y[i].re=b[i];
}
istrm.close();

istrm.open("test2.txt");
for(i=0;i<n;i++)
{
    istrm>>b[i];
	y[i].im=b[i];
	}
istrm.close();		

//求最终卷积的结果
for(i=0;i<n;i++)
{
	y[i].re=y[i].re/n;
	y[i].im=-1*y[i].im/n;
}
//输出到文件!!!
if((fp2=fopen("dest.txt","w"))==NULL)
	{
      printf("can not open!!!!");
	}
for(i=0;i<n;i++)
{	
fprintf(fp2,"%3.0f",y[i].re);
b[i]=y[i].re;
}
fclose(fp2);

CDC *pDC=GetDC();
CPen Pen;
Pen.CreatePen(PS_SOLID,12,RGB(255,0,0));
pDC->MoveTo(20,410);
pDC->LineTo(590,410);
j=100;
CClientDC dc(this);
dc.TextOut(40,236,"x(n)*y(n)");
for(i=0;i<n;i++)
{
	j+=20;
wsprintf(Str1,"%d",i);
dc.TextOut(j,418,Str1);
      pDC->MoveTo(j,410);
    pDC->LineTo(j,410-20*b[i]);

CBrush Brush(RGB(0,0,0));
pDC->SelectObject(&Brush);
pDC->Ellipse(j-4,410-20*b[i]-4,j+4,414-20*b[i]);
  }
dc.TextOut(j+20,416,"......");
m_btn.EnableWindow(false);

free(x);
free(y);
free(h);
free(z);
}	

⌨️ 快捷键说明

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