#include "Stdafx.h" #include "Resource.h" #include "DlgCustomRule.h" ////////////////////////////////////////////////////////////////////////////////// BEGIN_MESSAGE_MAP(CDlgCustomRule, CDialog) END_MESSAGE_MAP() ////////////////////////////////////////////////////////////////////////////////// //构造函数 CDlgCustomRule::CDlgCustomRule() : CDialog(IDD_CUSTOM_RULE) { //设置变量 ZeroMemory(&m_CustomRule,sizeof(m_CustomRule)); m_CustomRule.bAutoBuildCard = false; m_CustomRule.wTimeOut = 40; m_CustomRule.wSendCardTime = 10; m_CustomRule.wCompareCardTime = 20; return; } //析构函数 CDlgCustomRule::~CDlgCustomRule() { } //配置函数 BOOL CDlgCustomRule::OnInitDialog() { __super::OnInitDialog(); //设置控件 ((CEdit *)GetDlgItem(IDC_EDIT_TIME_OUT))->LimitText(3); ((CEdit *)GetDlgItem(IDC_EDIT_SEND_CARD_TIME))->LimitText(3); ((CEdit *)GetDlgItem(IDC_EDIT_COMPARE_CARD_TIME))->LimitText(3); //更新参数 FillDataToControl(); return FALSE; } //确定函数 VOID CDlgCustomRule::OnOK() { //投递消息 GetParent()->PostMessage(WM_COMMAND,MAKELONG(IDOK,0),0); return; } //取消消息 VOID CDlgCustomRule::OnCancel() { //投递消息 GetParent()->PostMessage(WM_COMMAND,MAKELONG(IDCANCEL,0),0); return; } //更新控件 bool CDlgCustomRule::FillDataToControl() { //设置数据 SetDlgItemInt(IDC_EDIT_TIME_OUT, m_CustomRule.wTimeOut); ((CButton *)GetDlgItem(IDC_CHECK_AUTO_BUILD))->SetCheck((m_CustomRule.bAutoBuildCard == true) ? BST_CHECKED : BST_UNCHECKED); SetDlgItemInt(IDC_EDIT_SEND_CARD_TIME, m_CustomRule.wSendCardTime); SetDlgItemInt(IDC_EDIT_COMPARE_CARD_TIME, m_CustomRule.wCompareCardTime); return true; } //更新数据 bool CDlgCustomRule::FillControlToData() { //设置数据 m_CustomRule.wTimeOut = (WORD)GetDlgItemInt(IDC_EDIT_TIME_OUT); m_CustomRule.bAutoBuildCard = (((CButton *)GetDlgItem(IDC_CHECK_AUTO_BUILD))->GetCheck() == BST_CHECKED); //数据校验 if ((m_CustomRule.bAutoBuildCard)&&(m_CustomRule.wTimeOut==0)) { AfxMessageBox(TEXT("超时时间必须设置!"),MB_ICONSTOP); return false; } m_CustomRule.wSendCardTime = (WORD)GetDlgItemInt(IDC_EDIT_SEND_CARD_TIME); m_CustomRule.wCompareCardTime = (WORD)GetDlgItemInt(IDC_EDIT_COMPARE_CARD_TIME); return true; } //读取配置 bool CDlgCustomRule::GetCustomRule(tagCustomRule & CustomRule) { //读取参数 if (FillControlToData()==true) { CustomRule=m_CustomRule; return true; } return false; } //设置配置 bool CDlgCustomRule::SetCustomRule(tagCustomRule & CustomRule) { //设置变量 m_CustomRule=CustomRule; //更新参数 if (m_hWnd!=NULL) FillDataToControl(); return true; } //////////////////////////////////////////////////////////////////////////////////