📄 buzz_testdlg.cpp
字号:
// Buzz_TestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "Buzz_Test.h"
#include "Buzz_TestDlg.h"
#include "DBT.h" // Added by ClassView
#include <MMSystem.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
const int Buzz_Button_Dia = 50;
const int Led_Dia = 15;
const int Row_Dis = 110;
const int Col_Dis = 48;
const CSize Center = CSize(125,85);
const AnswerWidth = 33;
const AnswerHeight = 74;
const Pressing = 2;
const Pressed = 1;
const NeverPressed = 0;
BOOL ButtonResult = 0;
const AllLedMode = 1;
const SingleLedMode = 2;
const ButtonMode = 3;
#define Circle 1
#define Rect 2
#define Red RGB(255,0,0)
#define Green RGB(0,255,0)
#define Blue RGB(0,0,255)
#define Yellow RGB(255,255,0)
#define Black RGB(0,0,0)
#define Orange RGB(255,128,0)
#define White RGB(255,255,255)
#define Brown RGB(128,0,0)
#define LedOn 0xff
#define LedOff 0x00
UCHAR BuzzSendData[8]={0,0,0,0,0,0,0,0};
UCHAR BReceiveData[8]={0,0,0,0,0,0,0,0};
LPVOID lpMsgBuf;
UINT TimerID; //定义定时器句柄
int TimerAccuracy;
CBuzz_TestDlg* pDLG;
//BuzzerButton Led[4];
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CBuzz_TestDlg dialog
CBuzz_TestDlg::CBuzz_TestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBuzz_TestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBuzz_TestDlg)
// 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 CBuzz_TestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBuzz_TestDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBuzz_TestDlg, CDialog)
//{{AFX_MSG_MAP(CBuzz_TestDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_RETEST, OnRetest)
ON_BN_CLICKED(IDC_FINISH, OnFinish)
ON_WM_LBUTTONDOWN()
ON_BN_CLICKED(IDC_TEST_LED, OnTestLed)
ON_MESSAGE(WM_DEVICECHANGE,OnDeviceChange)
ON_BN_CLICKED(IDC_ALL_LED, OnAllLed)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_TestButton, OnTestButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBuzz_TestDlg message handlers
BOOL CBuzz_TestDlg::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
BuzzReceiveRun = 0; //初始化
Prompt = _T("");
bConnect = 0;
SetButton(); // Set the state of all the button
for(int i=0;i<4;i++)
Led[i].Passed = 0; // Led show right four small circle
ResetButton();
ResetBCDEButton();
Connect();
OnTestButton(); // TRACE0
GetDlgItem(IDC_NUM4)->SetWindowText("0");
GetDlgItem(IDC_NUM5)->SetWindowText("0");
GetDlgItem(IDC_NUM6)->SetWindowText("0");
GetDlgItem(IDC_NUM7)->SetWindowText("0");
//Buzz.RegisterNotificationInterface(GetSafeHwnd());
return TRUE; // return TRUE unless you set the focus to a control
// The function OnPaint() is called every time
}
void CBuzz_TestDlg::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 CBuzz_TestDlg::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); // device context for painting
DrawButton(&dc);
// dc.TextOut (100,150,(LPCTSTR)lpMsgBuf);
if(ButtonResult == 1 && iTestMode == ButtonMode) //显示BUTTON OK
{
/* dc.SetBkMode(TRANSPARENT);
LOGFONT lf;
dc.GetCurrentFont()->GetLogFont(&lf);
CFont font1;
CFont *pOldFont;
lf.lfCharSet=800;
lf.lfHeight=-105;
lf.lfWidth=0;
strcpy(lf.lfFaceName, "宋体");
font1.CreateFontIndirect(&lf);
pOldFont=dc.SelectObject(&font1);
dc.TextOut (70,200,_T("按钮OK"));
dc.SelectObject(pOldFont);
font1.DeleteObject ();
Prompt = _T("测试完成 ");
*/ }
dc.TextOut (80,480,_T("提示:")+Prompt);
// dc.TextOut (80,480,_T("Prompt:")+Prompt);
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CBuzz_TestDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
//===========================================================
// 功能说明: 按钮数据接收线程。
// 函数原形: BuzzReceive(void * pParam)
// 输入参数: 线程上下文指针
// 输出参数: 无
// 备 注:
//===========================================================
static int firstNum4 = 0;
static int firstNum5 = 0;
static int firstNum6 = 0;
static int firstNum7 = 0;
UINT BuzzReceive(void * pParam)
{
CBuzz_TestDlg* Dlg = (CBuzz_TestDlg*) pParam;
DWORD dResult = 0,temp = 0, OldReceiveData = 0;;
Dlg->Led[0].Passed = Dlg->Led[1].Passed = Dlg->Led[2].Passed = Dlg->Led[3].Passed = 0;
BuzzSendData[2] = BuzzSendData[3] = BuzzSendData[4] = BuzzSendData[5] = 0x00;
//Dlg->Buzz.SendData(BuzzSendData);
while( Dlg->BuzzReceiveRun )
{
dResult = Dlg->Buzz.ReceiveData (BReceiveData);
//if(dResult == WAIT_OBJECT_0 )
//{
//BuzzSendData[2] = BuzzSendData[3] = BuzzSendData[4] = BuzzSendData[5] = 0xff;
TRACE("wait object !\r\n");
int Resulttemp = 0;
int TempBuzzReceiveData = 0;
int BuzzReceiveData = ((BReceiveData[5] & 0x0f)<<16) + (BReceiveData[4]<<8) +BReceiveData[3];
TempBuzzReceiveData = BuzzReceiveData;
if( Dlg->iTestMode == ButtonMode )
{
int mutibutton = 0;
for( int i=0; i<4; i++)
{
if( (TempBuzzReceiveData & (0x001e<<(5*i))) == (0x001e<<(5*i)))
Dlg->BCDEButton[i].Passed = Pressing;
else if(Dlg->BCDEButton[i].Passed == Pressing)
Dlg->BCDEButton[i].Passed = Pressed;
if(Dlg->BCDEButton[i].Passed == 1)
Resulttemp++;
}
/*增加的测试次数的代码*///-------->
CString str;
CString strFirst4;
CString strFirst5;
CString strFirst6;
CString strFirst7;
HWND hDlg;
HWND hWndFile4;
HWND hWndFile5;
HWND hWndFile6;
HWND hWndFile7;
hDlg = AfxGetMainWnd()->m_hWnd;
hWndFile4 = GetDlgItem(hDlg,IDC_NUM4);
hWndFile5 = GetDlgItem(hDlg,IDC_NUM5);
hWndFile6 = GetDlgItem(hDlg,IDC_NUM6);
hWndFile7 = GetDlgItem(hDlg,IDC_NUM7);
for(int k=0; k<20; k++)
{
// str.Format("%d",i);
if( TempBuzzReceiveData & (0x01 << k) )
{
mutibutton++;
// AfxMessageBox(str);
if(k==1&&firstNum4==0)
{
firstNum4 = 1;
strFirst4.Format("%d",firstNum4);
SetWindowText(hWndFile4,strFirst4);
}
else if(k==1&&Dlg->Button[k].Passed == Pressed)
{
//k++;
//AfxMessageBox("start");
firstNum4++;
strFirst4.Format("%d",firstNum4);
SetWindowText(hWndFile4,strFirst4);
Dlg->Button[k].Passed = NeverPressed;
}
if(k==6&&firstNum5==0)
{
firstNum5 = 1;
strFirst5.Format("%d",firstNum5);
SetWindowText(hWndFile5,strFirst5);
}
else if(k==6&&Dlg->Button[k].Passed == Pressed)
{
//k++;
//AfxMessageBox("start");
firstNum5++;
strFirst5.Format("%d",firstNum5);
SetWindowText(hWndFile5,strFirst5);
Dlg->Button[k].Passed = NeverPressed;
}
if(k==11&&firstNum6==0)
{
firstNum6 = 1;
strFirst6.Format("%d",firstNum6);
SetWindowText(hWndFile6,strFirst6);
}
else if(k==11&&Dlg->Button[k].Passed == Pressed)
{
//k++;
//AfxMessageBox("start");
firstNum6++;
strFirst6.Format("%d",firstNum6);
SetWindowText(hWndFile6,strFirst6);
Dlg->Button[k].Passed = NeverPressed;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -