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

📄 paintdlg.cpp

📁 数字信号处理作业
💻 CPP
字号:
// PaintDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Createfilter.h"
#include "PaintDlg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CPaintDlg dialog


CPaintDlg::CPaintDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPaintDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPaintDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	index = 0;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}


void CPaintDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPaintDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPaintDlg, CDialog)
	//{{AFX_MSG_MAP(CPaintDlg)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPaintDlg message handlers

void CPaintDlg::DrawLine(int n, float max,float *num)
{
	int LineCount;
	float detaX ,detaY;
	CRect rect;
	CStatic *pWndLine;
	//得到对应的画板
	switch (n)
	{
	case 1:
		pWndLine = (CStatic *)GetDlgItem(IDC_PALETTE1);	
		LineCount = LineCount1;
		break;
	case 2:
		pWndLine = (CStatic *)GetDlgItem(IDC_PALETTE2);
		LineCount = LineCount2;
		break;
	case 3:
		pWndLine = (CStatic *)GetDlgItem(IDC_PALETTE3);
		LineCount = LineCount2;
		break;	
	}	
	//得到画板的大小
	pWndLine->GetClientRect(&rect);
	CClientDC pLinwDC(pWndLine);
	pLinwDC.SetBkMode(TRANSPARENT);                //设置文字背景颜色
	pLinwDC.SetMapMode(MM_TEXT);                   //Y轴向下,画图时候要加负号
	//设置原点
	pLinwDC.SetViewportOrg(int(rect.right/(LineCount+2)),int(rect.bottom/2));
	detaX = (float)(rect.right/(LineCount+2));               //x轴间距
	detaY = (float)(0.5 * (rect.Height()-30) / max);       //y轴间距,重新计算,以及y的大小
	CPen axisPen, pointPen;
	CPen *pOldPen;
	CFont bigFont, smallFont,smallestFont;
	CFont *pOldFont;	
	axisPen.CreatePen(PS_SOLID,2,RGB(0,0,0));     //黑线
	if (index == 1)
	{
		pointPen.CreatePen(PS_SOLID,1,RGB(255,0,0));  //红线
	}
	else
		pointPen.CreatePen(PS_SOLID,1,RGB(128,0,255));  //紫色
	bigFont.CreatePointFont(100,"Arial",NULL);
	smallFont.CreatePointFont(80,"Arial",NULL);   //小字体
	smallestFont.CreatePointFont(60,"Arial",NULL);
	pOldPen = pLinwDC.SelectObject(&axisPen);	
	//绘制x,y坐标轴
	pLinwDC.MoveTo(0,0);
	pLinwDC.LineTo((int)(detaX*LineCount),0);
	pLinwDC.MoveTo((int)(detaX*LineCount),0);
	pLinwDC.LineTo((int)(detaX*LineCount-8),-4);
	pLinwDC.MoveTo((int)(detaX*LineCount),0);
	pLinwDC.LineTo((int)(detaX*LineCount-8),4);
	pLinwDC.MoveTo(0,rect.bottom/2-10);
	pLinwDC.LineTo(0,-1*(rect.bottom/2-10));
	//求最大值的次方数,用于标注10的几次方
	//之后要创建字体
	CString str;
	pOldFont  = pLinwDC.SelectObject(&bigFont);
 	str.Format("%d",10);
 	pLinwDC.TextOut(0,-1*(rect.bottom/2-2),str);
	pLinwDC.SelectObject(&smallFont);
 	int ymax =(int)log10(max);
 	str.Format("%d",ymax);
 	pLinwDC.TextOut(0+14,-1*(rect.bottom/2),str);

	//绘制线段
	
	pLinwDC.SelectObject(&pointPen);
//	pLinwDC.SelectObject(pOldFont);
	pLinwDC.SelectObject(&smallestFont);
	pLinwDC.SelectObject(&smallFont);
	int i,x,y;
// 	int interBiaozhu = (int)(LineCount / 5);
 	int interBiaozhu ;
	if (LineCount < 10)
	{
		interBiaozhu = 5;
	} 
	else
	{
		interBiaozhu = log10(LineCount);
		interBiaozhu = pow(10.0,interBiaozhu)/2;
	} 
	float y1;
	for (i=0; i<LineCount; i++)
	{
		if (i % interBiaozhu == 0 && i !=0)
		{
			str.Format("%d",i);
			pLinwDC.TextOut((int)(i * detaX - 4) , 3, str);
		}

		x = (int)(i * detaX);
		y1 = num[i];
		y = (int)(y1 * detaY);
		if (y == 0)
		{
			pLinwDC.Ellipse(x-2,-2,x+2,2);
		} 
		else
		{
			pLinwDC.MoveTo(x,0);
			pLinwDC.LineTo(x,-y);
			pLinwDC.Ellipse(x-2,-y-2,x+2,-y+2);
		}
	}
	pLinwDC.SelectObject(pOldPen);
//  pLinwDC.SelectObject(pOldFont);
	axisPen.DeleteObject();
	pointPen.DeleteObject();	
	bigFont.DeleteObject();
	smallFont.DeleteObject();
	smallestFont.DeleteObject();
}

BOOL CPaintDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();	
	// TODO: Add extra initialization here
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CPaintDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting	
	CString temp;
	switch (index)
	{
	case 1:
		SetDlgItemText(IDC_TYEPTXT,"横截型");
		break;
	case 2:
		SetDlgItemText(IDC_TYEPTXT,"级联型");
		break;
	}
	//在相应的图标框上左图
	DrawLine(1, ymax, yreal);
	DrawLine(2, ymaxAbs, yAbs);
	DrawLine(3, ymaxArg, yArg);	
	// Do not call CDialog::OnPaint() for painting messages
	// Do not call CDialog::OnPaint() for painting messages
}

void CPaintDlg::OnOK() 
{
	// TODO: Add extra validation here
	DestroyWindow();
//	CDialog::OnOK();
}

void CPaintDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	DestroyWindow();
//	CDialog::OnCancel();
}

void CPaintDlg::PostNcDestroy() 
{
	// TODO: Add your specialized code here and/or call the base class
	delete []yArg;
	delete []yAbs;
	delete []yreal;
	delete this;
	CDialog::PostNcDestroy();
}

⌨️ 快捷键说明

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