📄 cartestdlg.cpp
字号:
// cartestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "cartest.h"
#include "cartestDlg.h"
#include"Login.h"
#include "MESSAGEDIALOG.h"
#include "searchDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include <afxmt.h>
//事件对象
static CEvent g_end;
//辅助线程回调函数
static UINT ThreadProc(LPVOID pPar);
// 定义对话框的全局变量
static HWND hWnd;
CCartestDlg* pic;
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
typedef struct
{
CDC* dc;
CPowerSet* powerset;
}data;
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 void OnStart();
afx_msg void OnStart3();
afx_msg void OnStop();
virtual BOOL OnInitDialog();
afx_msg void OnJs();
afx_msg void OnJj();
//}}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)
ON_BN_CLICKED(IDC_Start, OnStart)
ON_BN_CLICKED(IDC_Start3, OnStart3)
ON_BN_CLICKED(IDC_Stop, OnStop)
ON_BN_CLICKED(IDC_JS, OnJs)
ON_BN_CLICKED(IDC_JJ, OnJj)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCartestDlg dialog
CCartestDlg::CCartestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCartestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCartestDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCartestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCartestDlg)
DDX_Control(pDX, IDC_G, m_GRAPH);
DDX_Control(pDX, IDC_Lr2, m_lr2);
DDX_Control(pDX, IDC_Lr, m_lr);
DDX_Control(pDX, IDC_Redit, m_redit);
DDX_Control(pDX, IDC_Ledit, m_ledit);
DDX_Control(pDX, IDC_LIST, m_list);
DDX_Control(pDX, IDC_Graph, m_graph);
DDX_Control(pDX, IDC_Title, m_title);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCartestDlg, CDialog)
//{{AFX_MSG_MAP(CCartestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_Button5, OnButton5)
ON_BN_CLICKED(IDC_Button6, OnButton6)
ON_BN_CLICKED(IDC_PRintG, OnPRintG)
ON_BN_CLICKED(IDC_BUTTONCON, OnButtoncon)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCartestDlg message handlers
_ConnectionPtr mpconnection;
BOOL CCartestDlg::OnInitDialog()
{
hWnd=GetSafeHwnd();
g_end.ResetEvent ();
AfxEnableControlContainer();
CLogin login;
SetDlgItemText(IDC_BUTTONCON,"车辆到位控制");
GetDlgItem(IDC_BUTTON3)->EnableWindow(false);
GetDlgItem(IDC_BUTTON4)->EnableWindow(false);
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
return TRUE; // return TRUE unless you set the focus to a control
}
void CCartestDlg::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 CCartestDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
SetDlgItemText(IDC_EDIT1,number[0]);
SetDlgItemText(IDC_EDIT2,number[1]);
SetDlgItemText(IDC_EDIT3,number[2]);
SetDlgItemText(IDC_EDIT7,number[3]);
SetDlgItemText(IDC_EDIT8,number[4]);
SetDlgItemText(IDC_EDIT5,number[5]);
SetDlgItemText(IDC_EDIT6,number[6]);
CBitmap bit;
CDC memDC;
CRect rect;
this->GetClientRect(&rect);
bit.LoadBitmap(IDB_BITMAP1);
memDC.CreateCompatibleDC(&dc);
memDC.SelectObject(&bit);
dc.BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);
memDC.DeleteDC();
::DeleteObject(&bit);
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 CCartestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
bool fbflag=1;
void CCartestDlg::OnButtoncon()
{
// TODO: Add your control notification handler code here
if(MessageBox("车辆是否到位","检测控制",MB_OKCANCEL)==IDOK)
{
GetDlgItem(IDC_BUTTON4)->EnableWindow(true);
GetDlgItem(IDC_BUTTON3)->EnableWindow(false);
}
else
{
GetDlgItem(IDC_BUTTON4)->EnableWindow(false);
GetDlgItem(IDC_BUTTON3)->EnableWindow(false);
}
}
void CCartestDlg::OnButton4()
{
if(powerset.IsOpen())
powerset.Close();
powerset.Open();
CFont font,newfont,*oldfont;
GetDlgItem(IDC_BUTTON4)->EnableWindow(false);
GetDlgItem(IDC_BUTTON3)->EnableWindow(false);
GetDlgItem(IDC_BUTTON1)->EnableWindow(false);
////////重绘画图区,使再次绘图时背景显白色
controldc=GetDlgItem(IDC_G)->GetDC();
CBrush brush;
brush.CreateSolidBrush (RGB(255,255,255));
controldc->SelectObject(&brush);
controldc->Rectangle(0,0,400,335);
SetDlgItemText(IDC_Title,"正在从机器读数,请稍候.......");
GetDlgItem(IDC_Title)->SetFont(&font);
controldc=GetDlgItem(IDC_EDITTITLE)->GetDC();
newfont.CreateFont(100,18,0,10,100,0,0,0,DEFAULT_CHARSET,OUT_CHARACTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH|FF_MODERN,"华文行楷");
controldc->SelectObject (&newfont);
controldc->SetBkColor(RGB(50,50,50));
controldc->SetTextColor(RGB(255,0,0));
if (MessageBox("未检测到设备,是否用现有数据库演示?","制动检测",MB_OKCANCEL)==IDOK)
{
if(MessageBox("检测前轴还是后轴","轴选择",MB_OKCANCEL)==IDOK)
{
fbflag=1;
}
else
{
fbflag=0;
}
searchDialog dlg;
dlg.DoModal ();
CString var1,var2;
mdc=GetDlgItem(IDC_Lr)->GetDC();
mdc0=GetDlgItem(IDC_Lr2)->GetDC();
dc=GetDlgItem(IDC_G)->GetDC();
dc->TextOut (-15,333,"原点");
dc->TextOut(2,-5,"100N");
dc->TextOut(410,333,"时间:0.1S");
dc->TextOut(2,10,"红线为左制动力,绿线为右制动力");
//画坐标轴
dc->MoveTo (2,0);
dc->LineTo (2,330);
dc->LineTo (400,330);
dc->MoveTo (0,4);
dc->LineTo (2,0);
dc->LineTo (4,4);
dc->MoveTo (396,328);
dc->LineTo (400,330);
dc->LineTo(396,332);
//画刻度
float arrar[200],leftpower[200],rightpower[200];
long i,j;
int k=0;
for (i=0;i<66;i++)
{
dc->MoveTo (2,330-5*i);
dc->LineTo (4,330-5*i);
}
for (j=0;j<79;j++)
{
dc->MoveTo (2+5*j,330);
dc->LineTo (2+5*j,328);
}
CPen *oldpen;
CPen pen1,pen2;
pen1.CreatePen (PS_DASH,2,RGB(255,0,0));
pen2.CreatePen (PS_DASH,2,RGB(0,255,0));
oldpen=dc->SelectObject (&pen1);
float left=0,right=0;
CString str1,str2,str3,str4,str5,str6;
i=2;
if(globaldata==1)
do
{
dc->SelectObject (&pen1);
dc->MoveTo(i,330-left);
dc->LineTo(i+2,330-powerset.m_column3);
dc->SelectObject (&pen2);
dc->MoveTo(i,330-right);
dc->LineTo(i+2,330-powerset.m_column4);
var1.Format ("%f",powerset.m_column3);
var2.Format ("%f",powerset.m_column4);
mdc->TextOut(20,20,var1);
mdc0->TextOut(20,20,var2);
left=powerset.m_column3;
right=powerset.m_column4;
::Sleep(50);
i+=2;
leftpower[k]=left;
rightpower[k]=right;
arrar[k]=left-right;
k++;
powerset.MoveNext();
}while(!powerset.IsEOF());
if(globaldata==2)
do
{
dc->SelectObject (&pen1);
dc->MoveTo(i,330-left);
dc->LineTo(i+2,330-powerset.m_left1);
dc->SelectObject (&pen2);
dc->MoveTo(i,330-right);
dc->LineTo(i+2,330-powerset.m_right1);
var1.Format ("%f",powerset.m_left1);
var2.Format ("%f",powerset.m_right1);
mdc->TextOut(20,20,var1);
mdc0->TextOut(20,20,var2);
left=powerset.m_left1;
right=powerset.m_right1;
::Sleep(50);
i+=2;
leftpower[k]=left;
rightpower[k]=right;
arrar[k]=left-right;
k++;
powerset.MoveNext();
}while(!powerset.IsEOF());
if(globaldata==3)
do
{
dc->SelectObject (&pen1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -