📄 mysmithdlg.cpp
字号:
// MySmithDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MySmith.h"
#include "MySmithDlg.h"
#include "SplashDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CMySmithDlg dialog
CMySmithDlg::CMySmithDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMySmithDlg::IDD, pParent),m_u(true),m_length(false)
{
//{{AFX_DATA_INIT(CMySmithDlg)
m_x_edit = 0.0;
m_r_edit = 0.0;
m_fr_edit = 0.0;
m_fi_edit = 0.0;
m_q_edit = 0.0;
m_start_r_edit = 0.0;
m_start_x_edit = 0.0;
m_start_z_edit = 0.0;
m_method_combo = _T("");
m_method_edit = 0.0;
m_method2_edit = 0.0;
m_w = 0.0;
m_b = 0.0;
m_l = 0.0;
m_Zc = 0.0;
m_Zg_l = 0.0;
m_Zg_r = 0.0;
m_Zl_l = 0.0;
m_Zl_r = 0.0;
m_sourse = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMySmithDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMySmithDlg)
DDX_Text(pDX, IDC_X_EDIT, m_x_edit);
DDV_MinMaxDouble(pDX, m_x_edit, -1.e+034, 1.e+036);
DDX_Text(pDX, IDC_R_EDIT, m_r_edit);
DDX_Text(pDX, IDC_Fr_EDIT, m_fr_edit);
DDV_MinMaxDouble(pDX, m_fr_edit, -1., 1.);
DDX_Text(pDX, IDC_Fi_EDIT, m_fi_edit);
DDV_MinMaxDouble(pDX, m_fi_edit, -1., 1.);
DDX_Text(pDX, IDC_Q_EDIT, m_q_edit);
DDV_MinMaxDouble(pDX, m_q_edit, 0., 1.e+039);
DDX_Text(pDX, IDC_START_R, m_start_r_edit);
DDX_Text(pDX, IDC_START_X, m_start_x_edit);
DDX_Text(pDX, IDC_START_Z, m_start_z_edit);
DDX_CBString(pDX, IDC_COMBO1, m_method_combo);
DDX_Text(pDX, IDC_METHOD1, m_method_edit);
DDX_Text(pDX, IDC_METHOD2, m_method2_edit);
DDX_Text(pDX, IDC_OMGA, m_w);
DDX_Text(pDX, IDC_BETA, m_b);
DDV_MinMaxDouble(pDX, m_b, 0., 1.e+042);
DDX_Text(pDX, IDC_LAMD, m_l);
DDV_MinMaxDouble(pDX, m_l, 0., 1.e+032);
DDX_Text(pDX, IDC_Zc, m_Zc);
DDV_MinMaxDouble(pDX, m_Zc, 0., 1.e+032);
DDX_Text(pDX, IDC_Zg_I, m_Zg_l);
DDX_Text(pDX, IDC_Zg_R, m_Zg_r);
DDV_MinMaxDouble(pDX, m_Zg_r, 0., 1.e+062);
DDX_Text(pDX, IDC_Zl_I, m_Zl_l);
DDX_Text(pDX, IDC_Zl_R, m_Zl_r);
DDV_MinMaxDouble(pDX, m_Zl_r, 0., 1.e+031);
DDX_CBString(pDX, IDC_COMBO2, m_sourse);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMySmithDlg, CDialog)
//{{AFX_MSG_MAP(CMySmithDlg)
ON_WM_SYSCOMMAND()
ON_WM_DESTROY()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_MOUSEMOVE()
ON_BN_CLICKED(IDC_F, OnF)
ON_BN_CLICKED(IDC_MOUSE, OnMouse)
ON_BN_CLICKED(IDC_Q, OnQ)
ON_BN_CLICKED(IDC_R, OnR)
ON_BN_CLICKED(IDC_X, OnX)
ON_BN_CLICKED(IDC_R_BUTTON1, OnRPoint)
ON_BN_CLICKED(IDC_R_BUTTON2, OnRCircle)
ON_BN_CLICKED(IDC_F_BUTTON4, OnFButton4)
ON_BN_CLICKED(IDC_F_BUTTON5, OnFButton5)
ON_BN_CLICKED(IDC_START, OnStart)
ON_BN_CLICKED(IDC_Q_BUTTON7, OnQButton7)
ON_BN_CLICKED(IDC_R_BUTTON3, OnRErease)
ON_BN_CLICKED(IDC_Q_BUTTON8, OnQErease)
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_BN_CLICKED(IDC_START_DRAW, OnStartDraw)
ON_BN_CLICKED(IDC_U_SHOW, OnUShow)
ON_BN_CLICKED(IDC_I_SHOW, OnIShow)
ON_BN_CLICKED(IDC_USER, OnUser)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMySmithDlg message handlers
BOOL CMySmithDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
CSplashDlg *dlg =new CSplashDlg(this);
dlg->Create(CSplashDlg::IDD,this);
dlg->ShowWindow(SW_SHOW);
dlg->UpdateWindow();
Sleep(4000);
dlg->DestroyWindow();
// 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 CMySmithDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
void CMySmithDlg::OnDestroy()
{
WinHelp(0L, HELP_QUIT);
CDialog::OnDestroy();
}
// 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 CMySmithDlg::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
{
CClientDC clientDC(this);
CRect rect;
rect.top=rect.left=25;
rect.bottom=rect.right=395;
smith.m_dx=(rect.right-rect.left)/2+rect.left;
smith.m_dy=(rect.bottom-rect.top)/2+rect.top;
if (smith.m_dx>smith.m_dy) smith.m_r=smith.m_dy-rect.bottom;
else smith.m_r=smith.m_dx-rect.left;
CBrush brush(HS_DIAGCROSS,RGB(255,255,255));
clientDC.SelectObject(&brush);
clientDC.Rectangle(rect);
smith.DrawBackGround(&clientDC,rect);
rect.top=423;
rect.left=416;
rect.bottom=614;
rect.right=989;
clientDC.Rectangle(rect);
CPen pen(PS_SOLID,1,RGB(0,0,255));
clientDC.SelectObject(&pen);
clientDC.MoveTo(416,519);
clientDC.LineTo(989,519);
clientDC.MoveTo(416,423);
clientDC.LineTo(416,614);
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMySmithDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMySmithDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(smith.GetDistance(point)<smith.m_r){
CClientDC ClientDC(this);
CRect rect;
rect.top=rect.left=25;
rect.bottom=rect.right=395;
smith.DrawRXCircle(&ClientDC,point,rect);
if(smith.m_mouse){
CString str;
str.Format("%f",smith.m_re);
SetDlgItemText(ID_R,str);
str.Format("%f",smith.m_x);
SetDlgItemText(ID_X,str);
str.Format("%f",smith.m_f);
SetDlgItemText(ID_F,str);
str.Format("%f",smith.m_fr);
SetDlgItemText(ID_FR,str);
str.Format("%f",smith.m_fi);
SetDlgItemText(ID_FI,str);
str.Format("%f",smith.m_ql);
SetDlgItemText(ID_Q,str);
}
}
if(point.x>=416 && point.x<=989 && point.y>=423 && point.y<=614 ){
CClientDC ClientDC(this);
CString str;
str.Format("%f",(989-point.x)*m_l/573);
SetDlgItemText(IDC_Xa,str);
CString str1;
str1.Format("%f",double(519-point.y)/96);
SetDlgItemText(IDC_y,str1);
str1.Format("%f",double(519-point.y)/96/20);
SetDlgItemText(IDC_A,str1);
}
UpdateData(true);
CString str;
if(m_method_combo=="串联传输线"){
str.Format("传输线长度:");
SetDlgItemText(IDC_STATIC_1,str);
str.Format("传输线特性阻抗:");
SetDlgItemText(IDC_STATIC_2,str);
str.Format("λ");
SetDlgItemText(IDC_STATIC_3,str);
}
else if(m_method_combo=="并联开路传输线"){
str.Format("传输线长度:");
SetDlgItemText(IDC_STATIC_1,str);
str.Format("传输线特性阻抗:");
SetDlgItemText(IDC_STATIC_2,str);
str.Format("λ");
SetDlgItemText(IDC_STATIC_3,str);
}
else if(m_method_combo=="串联电抗"){
str.Format("电阻:");
SetDlgItemText(IDC_STATIC_1,str);
str.Format("电纳:");
SetDlgItemText(IDC_STATIC_2,str);
str.Format("Ω");
SetDlgItemText(IDC_STATIC_3,str);
}
else if(m_method_combo=="并联电抗"){
str.Format("电导:");
SetDlgItemText(IDC_STATIC_1,str);
str.Format("导纳:");
SetDlgItemText(IDC_STATIC_2,str);
str.Format("Ω");
SetDlgItemText(IDC_STATIC_3,str);
}
else {
str.Format("电阻/电导/传输线长度:");
SetDlgItemText(IDC_STATIC_1,str);
str.Format("电纳/导纳/传输线特性阻抗:");
SetDlgItemText(IDC_STATIC_2,str);
str.Format("λ/Ω");
SetDlgItemText(IDC_STATIC_3,str);
}
/* CClientDC clientDC(this);
CRect rect;
rect.top=476;
rect.left=348;
rect.bottom=665;
rect.right=882;
// clientDC.Rectangle(rect);
CPen pen(PS_SOLID,1,RGB(255,0,0));
CPen wpen(PS_SOLID,1,RGB(0,0,0));
clientDC.SelectObject(&pen);
CShowTrans trans;
double time;
int x,y;
trans.beta=1;
trans.omga=1;
trans.l=1;
trans.Zc=50;
trans.Zg=100;
trans.Zl=100;
trans.Umax=10;
trans.SetTl();
trans.SetTs();
time=0;
for(x=348;x<=882;x++){
y=long(trans.Umax/50*95*trans.GetY(time,(x-348)*trans.l/534)+571);
clientDC.SelectObject(&pen);
clientDC.MoveTo(x,y);
clientDC.LineTo(x,y);
Sleep(1000);
time++;
clientDC.SelectObject(&wpen);
clientDC.MoveTo(x,y);
clientDC.LineTo(x,y);
}
*/
CDialog::OnMouseMove(nFlags, point);
}
void CMySmithDlg::OnF()
{
// TODO: Add your control notification handler code here
smith.m_F=!smith.m_F;
}
void CMySmithDlg::OnMouse()
{
// TODO: Add your control notification handler code here
smith.m_mouse=!smith.m_mouse;
if(smith.m_mouse==false){
CClientDC clientdc(this);
CPen pen(PS_SOLID,1,RGB(255,255,255));
CPoint cpl(long(smith.m_dx-smith.m_r),(long) smith.m_dy);
CPoint cpr(long(smith.m_dx+smith.m_r),(long)smith.m_dy);
clientdc.SelectObject(pen);
if(smith.m_R){
clientdc.Arc(smith.DrawRCircle(&clientdc,smith.m_re),cpr,cpr);
}
if(smith.m_X){
if(smith.m_x>0) clientdc.Arc(smith.DrawXCircle(&clientdc,smith.m_x),smith.GetXCircleEnd(smith.m_x),cpr);
else if(smith.m_x<0) clientdc.Arc(smith.DrawXCircle(&clientdc,smith.m_x),cpr,smith.GetXCircleEnd(smith.m_x));
else {clientdc.MoveTo(cpl);clientdc.LineTo(cpr);}
}
if(smith.m_F){
clientdc.Arc(smith.DrawFCircle(&clientdc,smith.m_f*smith.m_r),smith.m_point,smith.m_point);
}
if(smith.m_Q){
if(smith.m_point.y<smith.m_dy) clientdc.Arc(smith.DrawQCircle(&clientdc,smith.m_ql,smith.m_point),cpr,cpl);
else if(smith.m_point.y>smith.m_dy) clientdc.Arc(smith.DrawQCircle(&clientdc,smith.m_ql,smith.m_point),cpl,cpr);
else {
clientdc.MoveTo(cpl);
clientdc.LineTo(cpr);
}
}
}
}
void CMySmithDlg::OnQ()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -