📄 mousetestdlg.cpp
字号:
// MouseTestDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MouseTest.h"
#include "MouseTestDlg.h"
#include "Pkfuncs.h"
#include "Winbase.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
typedef struct {
UINT rADCCON;
UINT rADCTSC;
UINT rADCDLY;
UINT rADCDAT0;
UINT rADCDAT1;
UINT rADCUPDN; // fwood 030830
}ADCreg ;
volatile ADCreg * v_pADCPregs;
#define ADC_BASE 0xB1800000 // 0x58000000
volatile ADCreg *v_pADCregs;
BOOL AddressAlloc(void)
{
if(v_pADCregs == NULL) {
v_pADCregs = (volatile ADCreg *)
VirtualAlloc(0,sizeof(ADCreg),MEM_RESERVE, PAGE_NOACCESS);
if(v_pADCregs == NULL) {
// ERRORMSG(1,(TEXT("For ADCreg: VirtualAlloc failed!\r\n")));
return (FALSE);
}
else {
if(!VirtualCopy((PVOID)v_pADCregs,(PVOID)(ADC_BASE),sizeof(ADCreg),
PAGE_READWRITE | PAGE_NOCACHE )) {
// ERRORMSG(1,(TEXT("For pADCregs: VirtualCopy failed!\r\n")));
// PddpTouchPanelDeallocateVm();
return (FALSE);
}
}
}
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMouseTestDlg dialog
CMouseTestDlg::CMouseTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMouseTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMouseTestDlg)
m_strDown = _T("");
m_strUp = _T("");
m_CountDown = 0;
m_CountUp = 0;
m_AdcValue = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMouseTestDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMouseTestDlg)
DDX_Text(pDX, IDC_INFO_DOWN, m_strDown);
DDX_Text(pDX, IDC_INFO_UP, m_strUp);
DDX_Text(pDX, IDC_EDIT_DOWN, m_CountDown);
DDX_Text(pDX, IDC_EDIT_UP, m_CountUp);
DDX_Text(pDX, IDC_ADC_VALUE_1, m_AdcValue);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMouseTestDlg, CDialog)
//{{AFX_MSG_MAP(CMouseTestDlg)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
ON_WM_MOUSEMOVE()
ON_BN_CLICKED(IDC_INFO_DOWN, OnInfoDown)
ON_BN_CLICKED(IDC_INFO_UP, OnInfoUp)
ON_EN_CHANGE(IDC_EDIT_DOWN, OnChangeEditDown)
ON_EN_CHANGE(IDC_EDIT_UP, OnChangeEditUp)
// ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMouseTestDlg message handlers
BOOL CMouseTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
CenterWindow(GetDesktopWindow()); // center to the hpc screen
if (!AddressAlloc()) return FALSE;
// TODO: Add extra initialization here
CString filelog;
::GetModuleFileName(NULL,filelog.GetBufferSetLength(512),512);
filelog.MakeLower();
filelog.Replace(_T(".exe"),_T(".log"));
CFile f;
TRY{
if(f.Open(filelog,CFile::modeCreate))
{
f.Close();
}
}CATCH(CFileException ,e )
{
e->Delete();
f.Abort();
}
END_CATCH
return TRUE; // return TRUE unless you set the focus to a control
}
UINT m_CountADC =1;
void CMouseTestDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
UINT ybuf,xbuf;
ybuf = 0x3ff - (0x3ff & v_pADCregs->rADCDAT0);//ADCDAT0 读取的Y方向值.
xbuf = 0x3ff & v_pADCregs->rADCDAT1;
m_CountDown++;
m_MsCurrPt = point;
m_strDown.Format(_T("%.4d(%d,%d)"),m_CountDown,point.x,point.y);
m_AdcValue.Format(_T("(%d,%d)"),xbuf,ybuf);
SaveLog(_T("DN:")+m_strDown+_T(" "));
SaveLog(_T("ADC:")+m_AdcValue+_T(" "));
UpdateData(false);
CDialog::OnLButtonDown(nFlags, point);
}
void CMouseTestDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
UINT ybuf,xbuf;
ybuf = 0x3ff - (0x3ff & v_pADCregs->rADCDAT0);//ADCDAT0 读取的Y方向值.
xbuf = 0x3ff & v_pADCregs->rADCDAT1;
m_CountUp++;
m_MsCurrPt = point;
m_strUp.Format(_T("%.4d(%d,%d)"),m_CountUp,point.x,point.y);
m_AdcValue.Format(_T("%.4d(%d,%d)"),m_CountADC,xbuf,ybuf);
SaveLog(_T("UP:")+m_strUp+_T(" "));
SaveLog(_T("ADC:")+m_AdcValue+_T("\r\n"));
UpdateData(false);
CDialog::OnLButtonUp(nFlags, point);
}
void CMouseTestDlg::OnButton2()
{
// TODO: Add your control notification handler code here
CDialog::OnOK();
}
void CMouseTestDlg::SaveLog(CString &str)
{
CByteArray byte;
byte.SetSize(0);
#ifdef _UNICODE
int nLen = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
if (nLen == 0)
{
return ;
}
byte.SetSize(nLen);
if (nLen != WideCharToMultiByte(CP_ACP, 0, str, -1,
(char*)byte.GetData(), nLen, NULL, NULL))
{
byte.SetSize(0);
return ;
}
byte.SetSize(nLen - 1);
#else
byte.SetSize(str.GetLength());
memcpy(byte.GetData(), (LPCTSTR)str, str.GetLength());
#endif //_UNICODE
CString filelog;
::GetModuleFileName(NULL,filelog.GetBufferSetLength(512),512);
filelog.MakeLower();
filelog.Replace(_T(".exe"),_T(".log"));
CFile f;
TRY{
if(f.Open(filelog,CFile::modeNoTruncate|CFile::modeCreate|CFile::modeWrite))
{
f.SeekToEnd();
f.Write(byte.GetData(),byte.GetSize());
f.Close();
}
}CATCH(CFileException ,e )
{
e->Delete();
f.Abort();
}
END_CATCH
}
void CMouseTestDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnMouseMove(nFlags, point);
}
void CMouseTestDlg::OnInfoDown()
{
// TODO: Add your control notification handler code here
}
void CMouseTestDlg::OnInfoUp()
{
// TODO: Add your control notification handler code here
}
void CMouseTestDlg::OnChangeEditDown()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMouseTestDlg::OnChangeEditUp()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CMouseTestDlg::OnButton1()
{
// TODO: Add your control notification handler code here
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -