📄 elctricmachinedlg.cpp
字号:
// elctricmachineDlg.cpp : implementation file
//
#include "stdafx.h"
#include "elctricmachine.h"
#include "elctricmachineDlg.h"
#include"math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
CPen *oldPen;
CBrush *oldbrush;
int color1,color2;
#define xmax 200//200Nm
#define ymax 4000//2000rpm
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CElctricmachineDlg dialog
CElctricmachineDlg::CElctricmachineDlg(CWnd* pParent /*=NULL*/)
: CDialog(CElctricmachineDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CElctricmachineDlg)
m_r2 = 0.0f;
m_djn = 0;
m_TLBZ = 0.0f;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CElctricmachineDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CElctricmachineDlg)
DDX_Control(pDX, IDC_EDIT1, m_myedit);
DDX_Text(pDX, IDC_ZZDZ, m_r2);
DDV_MinMaxFloat(pDX, m_r2, 0.f, 1000.f);
DDX_Text(pDX, IDC_DJN, m_djn);
DDX_Text(pDX, IDC_TLBZ, m_TLBZ);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CElctricmachineDlg, CDialog)
//{{AFX_MSG_MAP(CElctricmachineDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_GYBXT, OnGybxt)
ON_BN_CLICKED(IDC_RRATED, OnRrated)
ON_BN_CLICKED(IDC_DRAW, OnDraw)
ON_BN_CLICKED(IDC_CLR, OnClr)
ON_WM_CREATE()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON1, OnStopFZ)
ON_WM_CLOSE()
ON_BN_CLICKED(IDC_NHZD, OnNhzd)
ON_BN_CLICKED(IDC_DYFJ, OnDyfj)
ON_BN_CLICKED(IDC_DLFZ, OnDlfz)
ON_BN_CLICKED(IDC_ZXDD, OnZxdd)
ON_BN_CLICKED(IDC_FXDD, OnFxdd)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CElctricmachineDlg message handlers
BOOL CElctricmachineDlg::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);
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
m_TLBZ=1;
UpdateData(FALSE);
UpdateData(TRUE);
m_myedit.GetRect(&rect);
KX=(float)rect.Width()/(float)xmax;
KY=(float)rect.Height()/(float)ymax;
//
return TRUE; // return TRUE unless you set the focus to a control
}
void CElctricmachineDlg::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 CElctricmachineDlg::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
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CElctricmachineDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CElctricmachineDlg::OnGybxt()
{
// TODO: Add your control notification handler code here
CAboutDlg btdlg;
btdlg.DoModal();
//this->UpdateWindow();
}
//回馈制动
void CElctricmachineDlg::OnRrated()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_r2=0;
yudrawFD();
m_TLBZ=-m_TLBZ;
drawFZ(-rect.Height()/2);// -400);
// drawFZ(340);
m_TLBZ=-m_TLBZ;
txbz=1;
s=1.0;
color1=125;
color2=0;
KillTimer(2);
SetTimer(2,10,NULL);
KillTimer(3);
SetTimer(3,10,NULL);
KillTimer(4);
SetTimer(4,10,NULL);
jsnT(m_r2);
// if(m_select==1){Tem=-Tem;n=-n;}//判断是否反转
// m_tem=Tem;
m_djn=n;
UpdateData(FALSE);
CString str;
str.Format("%f",Tem);
this->SetDlgItemText(IDC_TEM,str);
int cx,cy;
cx=Tem*KX;
cy=n*KY;
cy=-cy;//rect.Height()/2-cy;
cx0=cx;
cy0=cy;
}
//自然特性
void CElctricmachineDlg::OnDraw()
{
// TODO: Add your control notification handler code here
// m_tem=0;
// UpdateData(FALSE);
UpdateData(TRUE);
m_r2=0;
s=1.0;
yudraw();
drawFZ(-rect.Height()/2);// 400);
// m_tem=TL;
m_djn=(1-0.038666*m_TLBZ)*1500;
UpdateData(FALSE);
CString str;
str.Format("%f",TL);
this->SetDlgItemText(IDC_TEM,str);
}
void CElctricmachineDlg::OnClr()
{
// TODO: Add your control notification handler code here
drawZB();
m_djn=0.0;
UpdateData(FALSE);
CString str;
str.Format("%f",m_djn);
this->SetDlgItemText(IDC_TEM,str);
}
void CElctricmachineDlg::OnCancel()
{
// TODO: Add extra cleanup here
OnStopFZ();
if(MessageBox("是否退出本系统?","警告",MB_YESNO+MB_ICONWARNING)!=IDYES)
{
return;
}
CDialog::OnCancel();
}
void CElctricmachineDlg::SetDraw(CDC *pdc, CRect myrect, int x0, int y0)
{
CRgn myRgn;//设置绘图区域
myRgn.CreateRectRgnIndirect(myrect);
pdc->SelectObject(&myRgn);
DeleteObject(&myRgn);
CBrush myBrush(RGB(255,255,255));//清除绘图区域
CBrush *oldBrush;
oldBrush=pdc->SelectObject(&myBrush);
pdc->FillRgn(&myRgn,&myBrush);
pdc->SelectObject(oldBrush);
DeleteObject(&myBrush);
pdc->SelectObject(oldBrush);
pdc->SetMapMode(MM_LOMETRIC);//设置映射模式和原点
pdc->SetViewportOrg(x0,y0);
pdc->SetViewportExt(rect.Width(),rect.Height());
}
void CElctricmachineDlg::drawZB()
{
CClientDC dc(GetDlgItem(IDC_EDIT1));//获得编辑框句柄
int cy,cx;
int dy,dx;
cy=rect.Height();
cx=rect.Width();
dy=cy/10;
dx=cx/10;
CRgn myRgn;//设置绘图区域
myRgn.CreateRectRgnIndirect(rect);
dc.SelectObject(&myRgn);
DeleteObject(&myRgn);
CBrush myBrush(RGB(255,255,255));//清除绘图区域
CBrush *oldBrush;
oldBrush=dc.SelectObject(&myBrush);
dc.FillRgn(&myRgn,&myBrush);
dc.SelectObject(oldBrush);
DeleteObject(&myBrush);
dc.SelectObject(oldBrush);
dc.SetMapMode(MM_TEXT);//设置映射模式和原点
dc.SetViewportOrg(cx/2,cy/2);//cy);
dc.SetViewportExt(rect.Width(),rect.Height());
CPen zbpen;
zbpen.CreatePen(PS_SOLID,1,RGB(220,220,220));
oldPen=dc.SelectObject(&zbpen);
DeleteObject(&zbpen);
for(int y=-cy/2;y<cy/2;y=y+dy)//画横坐标
{
dc.MoveTo(-cx/2,y);
dc.LineTo(cx/2,y);
}
for(int x=-cx/2;x<cx/2;x=x+dx)//画横坐标
{
dc.MoveTo(x,-cy/2);
dc.LineTo(x,cy/2);
}
dc.SelectObject(oldPen);
CPen zbpen1;
zbpen1.CreatePen(PS_SOLID,4,RGB(0,0,0));
oldPen=dc.SelectObject(&zbpen1);
DeleteObject(&zbpen1);
dc.MoveTo(-cx/2,0);
dc.LineTo(cx/2,0);
// dc.LineTo(cx-25,-5);
// dc.MoveTo(cx-25,+5);
// dc.LineTo(cx,0);
dc.MoveTo(0,-cy/2);
dc.LineTo(0,cy/2);
// dc.LineTo(-5,cy-25);
// dc.MoveTo(+5,cy-25);
// dc.LineTo(0,cy);
dc.SelectObject(oldPen);
}
int CElctricmachineDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CDialog::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
KillTimer(1);
SetTimer(1,50,NULL);
return 0;
}
void CElctricmachineDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1)
{
drawZB();
KillTimer(1);
CDialog::OnTimer(nIDEvent);
return;
}
jsnT(m_r2);
// if(m_select==1){Tem=-Tem;n=-n;}//判断是否反转
if(txbz==3) {Tem=-Tem;n=-n;}
// m_tem=Tem;
m_djn=n;
UpdateData(FALSE);
CString str;
str.Format("%f",Tem);
this->SetDlgItemText(IDC_TEM,str);
CClientDC dc(GetDlgItem(IDC_EDIT1));//获得编辑框句柄
CPen drawpen;
if(((txbz==2)||(txbz==3))&&((Tem*n)<=0))
drawpen.CreatePen(PS_SOLID,8,RGB(255,0,255));
else drawpen.CreatePen(PS_SOLID,8,RGB(color1,color2,255));
oldPen=dc.SelectObject(&drawpen);
DeleteObject(&drawpen);
CBrush drawbrush;
drawbrush.CreateSolidBrush(RGB(color1,color2,255));
oldbrush=dc.SelectObject(&drawbrush);
DeleteObject(&drawbrush);
dc.SetMapMode(MM_TEXT);//设置映射模式和原点
dc.SetViewportOrg(rect.Width()/2 ,rect.Height()/2);
int cx,cy;
cx=Tem*KX;
cy=n*KY;
cy=-cy;//rect.Height()/2-cy;
// if((cx<480)&&(cy<420))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -