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

📄 microwavedlg.cpp

📁 电磁场的演示程序
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// MicroWaveDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MicroWave.h"
#include "MicroWaveDlg.h"
#include "math.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern   "C"     BOOL   WINAPI   AnimateWindow(HWND   hWnd,DWORD   dwTime,DWORD   dwFlags); 
/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CMicroWaveDlg dialog

CMicroWaveDlg::CMicroWaveDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMicroWaveDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMicroWaveDlg)
	m_Edit_R = 0.0f;
	m_Edit_X = 0.0f;
	m_ZL_R = 0.0f;
	m_ZL_X = 0.0f;
	m_Z0 = 1.0f;
	m_Result = _T("");
	time=0;
	m_RADIO = 12;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	Step_Num=1;
/*
	angle=19;
	interval=15;
	step=3;

	angle=angle/360*2*PI;
	interval=interval/360*2*PI;
	step=step/360*2*PI;
*/

}

void CMicroWaveDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMicroWaveDlg)
	DDX_Control(pDX, IDC_SECOND, m_Title2);
	DDX_Control(pDX, IDC_FIRST, m_Title1);
	DDX_Text(pDX, IDC_EDIT_R, m_Edit_R);
	DDX_Text(pDX, IDC_EDIT_X, m_Edit_X);
	DDX_Text(pDX, IDC_EDIT_ZL_R, m_ZL_R);
	DDX_Text(pDX, IDC_EDIT_ZL_X, m_ZL_X);
	DDX_Text(pDX, IDC_EDIT_Z0, m_Z0);
	DDX_Text(pDX, IDC_RESULT, m_Result);
	DDX_Radio(pDX, IDC_RADIO1, m_RADIO);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMicroWaveDlg, CDialog)
	//{{AFX_MSG_MAP(CMicroWaveDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_SIZE()
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO10, OnRadio10)
	ON_BN_CLICKED(IDC_RADIO11, OnRadio11)
	ON_BN_CLICKED(IDC_RADIO12, OnRadio12)
	ON_BN_CLICKED(IDC_RADIO13, OnRadio13)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
	ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
	ON_BN_CLICKED(IDC_RADIO6, OnRadio6)
	ON_BN_CLICKED(IDC_RADIO7, OnRadio7)
	ON_BN_CLICKED(IDC_RADIO8, OnRadio8)
	ON_BN_CLICKED(IDC_RADIO9, OnRadio9)
	ON_WM_MOUSEMOVE()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_RADIO14, OnRadio14)
	ON_WM_CREATE()
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_SECOND, OnSecond)
	ON_BN_CLICKED(IDC_FIRST, OnFirst)
	ON_BN_CLICKED(IDC_STEP, OnStep)
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDC_AUTO, OnAuto)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMicroWaveDlg message handlers

BOOL CMicroWaveDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	SetWindowText("Smith Chart AND 单分支匹配");

	// 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
		initControlPlane();

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMicroWaveDlg::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 MicroWavel,
//  this is automatically done for you by the framework.

void CMicroWaveDlg::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
	{
		CPaintDC dc(this);

		CRect rc1;
    	GetClientRect(&rc1);

    	rc1.right-=OFFSET;
			//移动控件
		InvalidateControlPlane();

		CBrush bkbrush(BKRGB);

		dc.SelectObject(bkbrush);
		dc.Rectangle(&rc1);

		dc.SetMapMode(MM_ANISOTROPIC);//坐标映射
		dc.SetWindowExt(2300,-2300);
		if(b_Mark2)
		{
			rc1.bottom=rc1.bottom*2/3-50;
		}
		dc.SetViewportExt((rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height(),(rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height());
		dc.SetViewportOrg(rc1.right/2,rc1.bottom/2);
		
		CPen pen(PS_SOLID,1,LINERGB),*poldpen;
		poldpen=dc.SelectObject(&pen);
		dc.Arc(CRect(-1000,-1000,1000,1000),CPoint(-1000,0),CPoint(-1000,0));
		
		dc.DPtoLP(&rc1);
		dc.MoveTo(-1200,0);
		dc.LineTo(1200,0);


		if ((!m_Ptr_Array.GetSize())||b_Mark1)
		{
			draw_chart();
		}
		

		if (b_Mark2)
		{
			for (int i=0;i<m_Ptr_Array.GetSize();i++)
			{
				draw_graph((CGraph*)m_Ptr_Array.GetAt(i)) ;
		
			}

		}

		dc.SelectObject(poldpen);


		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMicroWaveDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMicroWaveDlg::OnSize(UINT nType, int cx, int cy) 
{
	CDialog::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	Invalidate();

//	InvalidateControlPlane();


}

void CMicroWaveDlg::drawx(float x,COLORREF pen_rgb,int pen_wid)
{
	CClientDC dc(this);

	CRect rc1;
	GetClientRect(&rc1);
	rc1.right-=OFFSET;
	dc.SetMapMode(MM_ANISOTROPIC);
	dc.SetWindowExt(2300,-2300);
	if(b_Mark2)
	{
		rc1.bottom=rc1.bottom*2/3-50;
	}

	dc.SetViewportExt((rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height(),(rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height());
	dc.SetViewportOrg(rc1.right/2,rc1.bottom/2);

	CPen pen(PS_SOLID,pen_wid,pen_rgb),*poldpen;
	poldpen=dc.SelectObject(&pen);

	if(x==0)
	{
		dc.MoveTo(1000,0);
		dc.LineTo(-1000,0);
	}
	else if(x>0)
	{

		dc.Arc(CRect(int((1-1/x)*SCALE),0,int((1+1/x)*SCALE),int(2/(x)*SCALE)),CPoint(int((x*x-1)/(x*x+1)*SCALE),int(2*x/(x*x+1)*SCALE)),CPoint(SCALE,0));
	}
	else{

		dc.Arc(CRect((1-1/x)*SCALE,0,(1+1/x)*SCALE,2/(x)*SCALE),CPoint(SCALE,0),CPoint((x*x-1)/(x*x+1)*SCALE,2*x/(x*x+1)*SCALE));

	}
	dc.SelectObject(poldpen);	

}

void CMicroWaveDlg::drawr(float r,COLORREF pen_rgb,int pen_wid)
{
	CClientDC dc(this);

	CRect rc1;
	GetClientRect(&rc1);
	rc1.right-=OFFSET;
	dc.SetMapMode(MM_ANISOTROPIC);
	dc.SetWindowExt(2300,-2300);
	if(b_Mark2)
	{
		rc1.bottom=rc1.bottom*2/3-50;
	}

	dc.SetViewportExt((rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height(),(rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height());
	dc.SetViewportOrg(rc1.right/2,rc1.bottom/2);

	CPen pen(PS_SOLID,pen_wid,pen_rgb),*poldpen;
	poldpen=dc.SelectObject(&pen);

	dc.Arc(CRect((1-2/(1+r))*SCALE,-1/(1+r)*SCALE,SCALE,1/(1+r)*SCALE),CPoint(SCALE,0),CPoint(SCALE,0));

	dc.SelectObject(poldpen);		

}

void CMicroWaveDlg::OnTimer(UINT nIDEvent) 
{
		time++;
		CClientDC dc(this);
   
		CRect rc1;
		GetClientRect(&rc1);
		rc1.right-=OFFSET;
		dc.SetMapMode(MM_ANISOTROPIC);
		dc.SetWindowExt(2300,-2300);
		dc.SetViewportExt((rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height(),(rc1.Width()<=rc1.Height())*rc1.Width()+(rc1.Width()>rc1.Height())*rc1.Height());
		dc.SetViewportOrg(rc1.right/2,rc1.bottom/2);

		CPen pen(PS_DOT,10,RGB(255,0,0)),*poldpen;
		poldpen=dc.SelectObject(&pen);

		if(time%2==1)
		{
			dc.SetROP2(R2_NOT);

		}

	// TODO: Add your message handler code here and/or call default
	if(nIDEvent==ID_TIME_1)//等反射系数圆
	{
		
		dc.Arc(CRect(-500,-500,500,500),CPoint(-500,0),CPoint(-500,0));
		dc.MoveTo(0,0);
		dc.LineTo(300,400);

	}

	else if(nIDEvent==ID_TIME_2)//匹配点
	{

		dc.Ellipse(CRect(-13,-13,13,13));
	}

	else if(nIDEvent==ID_TIME_3)//等R圆
	{
		if(time%2==1)
		{
			drawr(0.5,RGB(255,0,0),10);
		}
		else
		{
			drawr(0.5,RGB(0,255,0),10);

		}
		
	}
	else if(nIDEvent==ID_TIME_4)//开路点
	{
		dc.Ellipse(CRect(SCALE-13,0-13,SCALE+13,0+13));

	}
	else if(nIDEvent==ID_TIME_5)//等X圆
	{
		if(time%2==1)
		{
			drawx(0.5,RGB(255,0,0),10);
		}
		else
		{
			drawx(0.5,RGB(0,255,0),10);

		}

	}
	else if(nIDEvent==ID_TIME_6)//短路点
	{
		dc.Ellipse(CRect(-SCALE-13,0-13,-SCALE+13,0+13));

	}
	else if(nIDEvent==ID_TIME_7)//感抗
	{
		CBrush brush(HS_DIAGCROSS,RGB(0,255,0));
		dc.SelectObject(&brush);
		dc.Pie(CRect(-SCALE,-SCALE,SCALE,SCALE),CPoint(SCALE,0),CPoint(-SCALE,0));
		
	}
	else if(nIDEvent==ID_TIME_8)//容抗
	{
		CBrush brush(HS_DIAGCROSS,RGB(0,255,0));
		dc.SelectObject(&brush);
		dc.Pie(CRect(-SCALE,-SCALE,SCALE,SCALE),CPoint(-SCALE,0),CPoint(SCALE,0));

	}
	else if(nIDEvent==ID_TIME_9)//纯电感
	{

		dc.Arc(CRect(-SCALE,-SCALE,SCALE,SCALE),CPoint(SCALE,0),CPoint(-SCALE,0));

	}
	else if(nIDEvent==ID_TIME_10)//纯电抗
	{
		dc.Arc(CRect(-SCALE,-SCALE,SCALE,SCALE),CPoint(-SCALE,0),CPoint(SCALE,0));

	}
	else if(nIDEvent==ID_TIME_11)//电压波腹点
	{
		dc.MoveTo(CPoint(0,0));
		dc.LineTo(CPoint(SCALE,0));

	}
	else if(nIDEvent==ID_TIME_12)//电压波节点
	{
		dc.MoveTo(CPoint(0,0));
		dc.LineTo(CPoint(-SCALE,0));

	}
	else if(nIDEvent==ID_TIME_14)
	{
		CBrush brush(RGB(0,255,0));
		dc.SelectObject(&brush);
		
		dc.SetROP2(R2_XORPEN);		

		if(time>=2)
		{
			dc.Pie(CRect(-1000,-1000,1000,1000),CPoint(1000*cos(angle-step),1000*sin(angle-step)),CPoint(1000*cos(angle+interval-step),1000*sin(angle+interval-step)));
	
		}
		dc.Pie(CRect(-1000,-1000,1000,1000),CPoint(1000*cos(angle),1000*sin(angle)),CPoint(1000*cos(angle+interval),1000*sin(angle+interval)));
	
		angle=angle+step;

	}
	else if (nIDEvent==TIMER_AUTO)//自动单分支匹配
	{
		OnStep();
		if (time==4)
		{
			KillTimer(nIDEvent);
		
			GetDlgItem(IDC_EDIT_Z0)->EnableWindow(true);
			GetDlgItem(IDC_EDIT_ZL_R)->EnableWindow(true);
			GetDlgItem(IDC_EDIT_ZL_X)->EnableWindow(true);
			GetDlgItem(IDC_STEP)->EnableWindow(true);
			GetDlgItem(IDC_STOP)->EnableWindow(true);

			MessageBox("自动单分支匹配完毕!");
		}
	}


	
	CDialog::OnTimer(nIDEvent);
}




void CMicroWaveDlg::OnRadio1() 
{
	// TODO: Add your control notification handler code here
	Invalidate();	
	for(int i=ID_TIME_1;i<=ID_TIME_14;i++)
	{
		KillTimer(i);
	}
	SetTimer(ID_TIME_1,500,NULL);
	time=0;

}

void CMicroWaveDlg::OnRadio2() 
{

⌨️ 快捷键说明

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