⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdadlg.cpp

📁 wince系统,用EVC编写的串口读写程序,包括软键盘自动调用和隐藏,希望给大家个参考
💻 CPP
字号:
// testdaDlg.cpp : implementation file
//

#include "stdafx.h"
#include "testda.h"
#include "testdaDlg.h"
#include "Sipapi.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestdaDlg dialog

CTestdaDlg::CTestdaDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTestdaDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTestdaDlg)
	m_writereg = 0;
	m_writeval = 0;
	m_readreg = 0;
	m_readval = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CTestdaDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTestdaDlg)
	DDX_Text(pDX, IDC_WRITEREG_EDIT, m_writereg);
	DDV_MinMaxInt(pDX, m_writereg, 0, 255);
	DDX_Text(pDX, IDC_WRITEVAL_EDIT, m_writeval);
	DDV_MinMaxInt(pDX, m_writeval, 0, 255);
	DDX_Text(pDX, IDC_READREG_EDIT, m_readreg);
	DDV_MinMaxInt(pDX, m_readreg, 0, 255);
	DDX_Text(pDX, IDC_READVAL_EDIT, m_readval);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTestdaDlg, CDialog)
	//{{AFX_MSG_MAP(CTestdaDlg)
	ON_BN_CLICKED(IDC_WRITE_BUTTON, OnWriteButton)
	ON_EN_SETFOCUS(IDC_WRITEREG_EDIT, OnSetfocusWriteregEdit)
	ON_EN_SETFOCUS(IDC_WRITEVAL_EDIT, OnSetfocusWritevalEdit)
	ON_EN_KILLFOCUS(IDC_WRITEREG_EDIT, OnKillfocusWriteregEdit)
	ON_EN_KILLFOCUS(IDC_WRITEVAL_EDIT, OnKillfocusWritevalEdit)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_READ_BUTTON, OnReadButton)
	ON_EN_SETFOCUS(IDC_READREG_EDIT, OnSetfocusReadregEdit)
	ON_EN_KILLFOCUS(IDC_READREG_EDIT, OnKillfocusReadregEdit)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestdaDlg message handlers

BOOL CTestdaDlg::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
	m_hGpoFile = CreateFile(TEXT("GPO1:"),GENERIC_READ|GENERIC_WRITE,0,NULL,OPEN_EXISTING,0,NULL);
	if(m_hGpoFile==INVALID_HANDLE_VALUE ){ //判断是否打开成功
		MessageBox(TEXT("Can't Open GPO Driver"));
		SendMessage(WM_CLOSE); 
	}



	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}



void CTestdaDlg::OnWriteButton() 
{
	// TODO: Add your control notification handler code here
	DA_CONTROL writearg;  //定义一个DA_CONTROL变量

	UpdateData(TRUE);

	writearg.op = DA_WRITE;
	writearg.index= m_writereg;
	writearg.val= m_writeval;
	
/*	CString ss;
	ss.Format(_T(" %d:%d"),m_writereg,m_writeval);
	MessageBox(ss);
*/
  DWORD retlen;
	BOOL ret = DeviceIoControl(
						m_hGpoFile,
						IOCTL_DA_CONTROL,
						&writearg,
						sizeof(writearg),
						NULL,
						0,
						&retlen,
						NULL);
	if(!ret){
		MessageBox(TEXT("Write error!"));
	}
	

}

void CTestdaDlg::OnSetfocusWriteregEdit() 
{
	// TODO: Add your control notification handler code here
	SipShowIM(SIPF_ON);
	
}

void CTestdaDlg::OnSetfocusWritevalEdit() 
{
	// TODO: Add your control notification handler code here
	SipShowIM(SIPF_ON);
	
}

void CTestdaDlg::OnKillfocusWriteregEdit() 
{
	// TODO: Add your control notification handler code here
	SipShowIM(SIPF_OFF);
	
}

void CTestdaDlg::OnKillfocusWritevalEdit() 
{
	// TODO: Add your control notification handler code here
	SipShowIM(SIPF_OFF);
	
}

void CTestdaDlg::OnClose() 
{
	
	// TODO: Add your message handler code here and/or call default
	if(m_hGpoFile!=INVALID_HANDLE_VALUE ){
		CloseHandle(m_hGpoFile);
	}
	EndDialog(IDCANCEL);
}

void CTestdaDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	
//	CDialog::OnCancel();
}

void CTestdaDlg::OnOK() 
{
	// TODO: Add extra validation here
	
//	CDialog::OnOK();
}

void CTestdaDlg::OnReadButton() 
{
	// TODO: Add your control notification handler code here
	DA_CONTROL readarg;  //定义一个DA_CONTROL变量

	UpdateData(TRUE);

	readarg.op = DA_READ;
	readarg.index= m_readreg;
	
	DWORD retlen;
	BYTE regret;
	BOOL ret = DeviceIoControl(
						m_hGpoFile,
						IOCTL_DA_CONTROL,
						&readarg,
						sizeof(readarg),
						&regret,
						1,
						&retlen,
						NULL);
	if(!ret){
		MessageBox(TEXT("read error!"));
		m_readval = 0;
	}
	else{
		m_readval = regret;
	}
		
	
	UpdateData(FALSE);

	
}

void CTestdaDlg::OnSetfocusReadregEdit() 
{
	// TODO: Add your control notification handler code here
	SipShowIM(SIPF_ON);
	
}

void CTestdaDlg::OnKillfocusReadregEdit() 
{
	// TODO: Add your control notification handler code here
	SipShowIM(SIPF_OFF);
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -