?? pushtestdlg.cpp
字號:
// PushTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "PushTest.h"
#include "PushTestDlg.h"
#include "Push.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
UINT ValidateThrd(PVOID pParam);
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()
/////////////////////////////////////////////////////////////////////////////
// CPushTestDlg dialog
CPushTestDlg::CPushTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPushTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPushTestDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CPushTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPushTestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPushTestDlg, CDialog)
//{{AFX_MSG_MAP(CPushTestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
ON_BN_CLICKED(IDC_BUTTON7, OnButton7)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_BN_CLICKED(IDC_BUTTON9, OnButton9)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPushTestDlg message handlers
BOOL CPushTestDlg::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_ExitFlag = TRUE;
return TRUE; // return TRUE unless you set the focus to a control
}
void CPushTestDlg::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 CPushTestDlg::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 CPushTestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//顯示信息
void CPushTestDlg::AlertInfo(char * str)
{
GetDlgItem(IDC_info)->SetWindowText(str);
}
void CPushTestDlg::AlertInfo(int code)
{
CString str;
switch(code)
{
case -99:
str = "Negative response(Communication problem/Equipment not connected)";
break;
case -31:
str = "Open port failed!";
break;
case -32:
str = "Close port failed!";
break;
case -41:
str = "Open the Door failed!";
break;
case -42:
str = "Close the Door failed!";
break;
case -43:
str = "Parcel Pushing Failure";
break;
case 10:
str = "Parcel Being";
break;
case 11:
str = "No Parcel";
break;
case 12:
str = "Getting light Sensor1 Failure";
break;
case 20:
str = "Parcel Falling into Parcel Box";
break;
case 21:
str = "Parcel did not Fall into Parcel Box";
break;
case 22:
str = "Getting light Sensor2 Failure";
break;
case 30:
str = "Parcel Box Full";
break;
case 31:
str = "Parcel Box not Full";
break;
case 32:
str = "Getting light Sensor3 Failure";
break;
default:
str = "unknown error";
break;
}
GetDlgItem(IDC_info)->SetWindowText(str);
}
void CPushTestDlg::OnButton1()
{
// TODO: Add your control notification handler code here
int iret = P_OpenPort();
if(iret == 0)
{
AlertInfo("Open Port Success!");
}
else
AlertInfo(iret);
}
void CPushTestDlg::OnButton2()
{
// TODO: Add your control notification handler code here
m_ExitFlag = FALSE;
Sleep(200);
int iret = P_ClosePort();
if(iret == 0)
AlertInfo("Close Port Success!");
else
AlertInfo(iret);
}
void CPushTestDlg::OnButton3()
{
// TODO: Add your control notification handler code here
int iret = P_OpenDoor();
if(iret == 0)
AlertInfo("Open the Door Success!");
else
AlertInfo(iret);
}
void CPushTestDlg::OnButton8()
{
// TODO: Add your control notification handler code here
int iret = P_PushParcel();
if(iret == 0)
AlertInfo("Successful delivery");
else
AlertInfo(iret);
}
void CPushTestDlg::OnButton5()
{
// TODO: Add your control notification handler code here
int iret = P_GetSensor1();
AlertInfo(iret);
}
void CPushTestDlg::OnButton6()
{
// TODO: Add your control notification handler code here
int iret = P_GetSensor2();
AlertInfo(iret);
}
void CPushTestDlg::OnButton7()
{
// TODO: Add your control notification handler code here
int iret = P_GetSensor3();
AlertInfo(iret);
}
void CPushTestDlg::OnButton4()
{
// TODO: Add your control notification handler code here
int iret = P_CloseDoor();
if(iret == 0)
AlertInfo("Close the Door Success!");
else
AlertInfo(iret);
}
UINT ValidateThrd(PVOID pParam)
{
CPushTestDlg *pDlg = (CPushTestDlg *)AfxGetApp()->m_pMainWnd;
MSG msg;
int stat1,stat2,stat3;
while(pDlg->m_ExitFlag)
{
if( ::PeekMessage(&msg,NULL,0,0,PM_REMOVE) )
{
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
stat1 = P_GetSensor1();
if(stat1 == 10)
pDlg->GetDlgItem(IDC_S1)->SetWindowText("Parcel Being");
else if(stat1 == 11)
pDlg->GetDlgItem(IDC_S1)->SetWindowText("No Parcel");
else if(stat1 == 12)
pDlg->GetDlgItem(IDC_S1)->SetWindowText("Getting light Sensor1 Failure");
stat2 = P_GetSensor2();
if(stat2 == 20)
pDlg->GetDlgItem(IDC_S2)->SetWindowText("Parcel Falling into Parcel Box");
else if(stat2 == 21)
pDlg->GetDlgItem(IDC_S2)->SetWindowText("Parcel did not Fall into Parcel Box");
else if(stat2 == 22)
pDlg->GetDlgItem(IDC_S2)->SetWindowText("Getting Sensor2 Failure");
stat3 = P_GetSensor3();
if(stat3 == 30)
pDlg->GetDlgItem(IDC_S3)->SetWindowText("Parcel Box Full");
else if(stat3 == 31)
pDlg->GetDlgItem(IDC_S3)->SetWindowText("arcel Box not Full");
else if(stat3 == 32)
pDlg->GetDlgItem(IDC_S3)->SetWindowText("Getting light Sensor3 Failure");
}
return 1;
}
void CPushTestDlg::OnButton9()
{
// TODO: Add your control notification handler code here
AfxBeginThread(ValidateThrd,NULL);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -