📄 serialdlg.cpp
字号:
m_uMesneData = m_uValue;
m_ucValue = m_uValue;
m_uTimer = SetTimer(1,m_uPul,NULL);
m_gValue.EnableClick(FALSE);
((CWnd *)GetDlgItem(IDC_EDITBITS))->EnableWindow(FALSE);
((CWnd *)GetDlgItem(IDC_EDITVALUE))->EnableWindow(FALSE);
((CWnd *)GetDlgItem(IDC_EDITPATH))->EnableWindow(FALSE);
((CWnd *)GetDlgItem(IDC_EDIT_PUL))->EnableWindow(FALSE);
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(FALSE);
((CWnd *)GetDlgItem(IDC_PAUSE))->EnableWindow(TRUE);
((CWnd *)GetDlgItem(IDC_STOP))->EnableWindow(TRUE);
//SetGridsByUInt(&m_gStatus,0,0,m_ucValue);
m_strOut = _T("");
m_strPeriod = _T("");
m_nPLength = 0;
InvalidateRect(&m_valueRct);
}
void CSerialDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int nH,nV;
UINT uHWidth,uVWidth;
if(m_bIsRunning || m_bIsPause)
return;
m_gValue.GetLTTWidth(&uHWidth,&uVWidth);
m_gValue.GetClickPosition(point,uHWidth,uVWidth,&nH,&nV);
m_uValue = m_gValue.GridsStatusToUInt(0);
UpdateData(FALSE);
InvalidateRect(&m_valueRct);
CString str(_T(""));
double max_value = 0;
str.LoadString(IDS_STRING_VALUEINFO);
SetDlgItemText(IDC_STATICINFO,str);
max_value = ldexp(1.0,m_uBits) - 1;
//CClientDC dc((CWnd *)GetDlgItem(IDC_STATICINFO));
if(m_uValue <= 0 || (double)m_uValue > max_value)
{
m_bVCorrect = FALSE;
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(FALSE);
str.Format(_T(" 不合法的初值输入!请输入一个在“1”到“%d”之间正确的数值,")\
_T("或者用下面的方法输入一个二进制式的值!"),(int)max_value);
SetDlgItemText(IDC_STATICINFO,str);
m_uValue = 0;
UpdateData(FALSE);
return ;
}
m_bVCorrect = TRUE;
if(m_bBCorrect && m_bVCorrect && m_bPCorrect)
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(TRUE);
else
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(FALSE);
CDialog::OnLButtonDown(nFlags, point);
}
/*
* // UINT *pOut [out] 移位输出值。
* // 返回值为每移位一次后的中间产值
*/
UINT CSerialDlg::OnExeCalculation(UINT *pOut)
{
unsigned int tmp_path = 0;
unsigned int sum = 0;
// 得到反馈路径位值
tmp_path = (m_ucValue >> m_uPath) & 0x00000001;
// 得到输出位(最低(右)位)值
*pOut = m_ucValue & 0x00000001;
// 移出最右一位
m_ucValue = m_ucValue >> 1;
// 路径位和输出位作模 2 相加,得到反馈位值
sum = (tmp_path + *pOut) % 2;
sum = sum << (m_uBits - 1);
m_ucValue |= sum; // 设置反馈位值到最高(左)位
return m_ucValue; // 返回移位后的值
}
void CSerialDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
//int strLength = 0;
CString strTmp(_T(""));
m_uMesneData = OnExeCalculation(&m_uOut);
strTmp.Format("0x%.3X",m_uMesneData);
m_strStatusHex = strTmp;
// hex number out
strTmp.Format("%X",m_uOut);
m_strOut += strTmp;
if(m_uMesneData == m_uValue)
{
// set the period string
m_strPeriod = m_strOut.Left(m_nPLength + 1);
// add the separator to the output string
// while circulating finish
m_strOut += _T(" ");
}
// get and set length of a period
m_nPLength = m_strOut.Find(_T(" "));
if(m_nPLength == -1)
{
m_strPeriod = m_strOut;
m_nPLength = m_strOut.GetLength();
}
else
{
// for 5 periods
if(m_strOut.GetLength() > 5 * (m_nPLength + (int)_tcslen(_T(" "))))
m_strOut = strTmp;
}
InvalidateRect(&m_valueRct);
CDialog::OnTimer(nIDEvent);
}
void CSerialDlg::OnStop()
{
// TODO: Add your control notification handler code here
if(m_uTimer)
KillTimer(m_uTimer);
m_bIsPause = FALSE;
m_gValue.EnableClick(TRUE);
m_bIsRunning = FALSE;
((CWnd *)GetDlgItem(IDC_EDITBITS))->EnableWindow(TRUE);
((CWnd *)GetDlgItem(IDC_EDITVALUE))->EnableWindow(TRUE);
((CWnd *)GetDlgItem(IDC_EDITPATH))->EnableWindow(TRUE);
((CWnd *)GetDlgItem(IDC_EDIT_PUL))->EnableWindow(TRUE);
((CWnd *)GetDlgItem(IDC_STOP))->EnableWindow(FALSE);
((CWnd *)GetDlgItem(IDC_PAUSE))->EnableWindow(FALSE);
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(TRUE);
CString str(_T(""));
str.LoadString(IDS_STRING_STOP);
SetDlgItemText(IDC_STATICINFO,str);
InvalidateRect(&m_statusRct);
}
void CSerialDlg::OnPause()
{
// TODO: Add your control notification handler code here
if(m_uTimer)
KillTimer(m_uTimer);
m_bIsRunning = FALSE;
m_bIsPause = TRUE;
m_gValue.EnableClick(FALSE);
((CWnd *)GetDlgItem(IDC_PAUSE))->EnableWindow(FALSE);
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(TRUE);
CString str(_T(""));
str.LoadString(IDS_STRING_PAUSE);
SetDlgItemText(IDC_STATICINFO,str);
}
BOOL CSerialDlg::SetGridsByUInt(CGrids *pG, int nH, int nV, UINT value)
{
BOOL ret = TRUE;
UINT temp = 0;
for(int i = 0; i < 8*sizeof(int); i++)
{
temp = (value >> i) & 0x00000001;
ret = pG->SetSelectBox((BOOL)temp,nH,nV + i);
if(!ret)
break;
}
return TRUE;
}
void CSerialDlg::OnChangeEditbits()
{
// 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
UpdateData();
CString str(_T(""));
str.LoadString(IDS_STRING_BITSINFO);
SetDlgItemText(IDC_STATICINFO,str);
if(m_uBits < 3 || m_uBits > 9)
{
m_bBCorrect = FALSE;
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(FALSE);
str.Format(_T(" 不合法的位数输入!请输入一个在“3”到“9”之间的数值,"));
SetDlgItemText(IDC_STATICINFO,str);
m_uBits = 0;
UpdateData(FALSE);
//((CWnd *)GetDlgItem(IDC_EDITBITS))->SetFocus();
InvalidateRect(&m_valueRct);
return ;
}
m_bBCorrect = TRUE;
if(m_bBCorrect && m_bVCorrect && m_bPCorrect)
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(TRUE);
else
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(FALSE);
InvalidateRect(&m_valueRct);
}
void CSerialDlg::OnChangeEditvalue()
{
// 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
UpdateData();
CString str(_T(""));
double max_value = 0;
str.LoadString(IDS_STRING_VALUEINFO);
SetDlgItemText(IDC_STATICINFO,str);
max_value = ldexp(1.0,m_uBits) - 1;
//CClientDC dc((CWnd *)GetDlgItem(IDC_STATICINFO));
if(m_uValue <= 0 || (double)m_uValue > max_value)
{
m_bVCorrect = FALSE;
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(FALSE);
str.Format(_T(" 不合法的初值输入!请输入一个在“1”到“%d”之间正确的数值,")\
_T("或者用下面的方法输入一个二进制式的值!"),(int)max_value);
SetDlgItemText(IDC_STATICINFO,str);
m_uValue = 0;
UpdateData(FALSE);
SetGridsByUInt(&m_gValue,0,0,m_uValue);
InvalidateRect(&m_valueRct);
return ;
}
m_bVCorrect = TRUE;
if(m_bBCorrect && m_bVCorrect && m_bPCorrect)
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(TRUE);
else
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(FALSE);
SetGridsByUInt(&m_gValue,0,0,m_uValue);
InvalidateRect(&m_valueRct);
}
void CSerialDlg::OnChangeEditpath()
{
// 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
UpdateData();
CString str(_T(""));
double max_value = 0;
str.LoadString(IDS_STRING_PATHINFO);
SetDlgItemText(IDC_STATICINFO,str);
if(m_uPath < 1 || m_uPath >= m_uBits)
{
m_bPCorrect = FALSE;
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(FALSE);
str.Format(_T(" 不合法的反馈路径输入!请输入一个在“1”到“%d”之间的反馈路径"),\
(int)m_uBits-1);
SetDlgItemText(IDC_STATICINFO,str);
m_uPath = 0;
UpdateData(FALSE);
return ;
}
m_bPCorrect = TRUE;
max_value = ldexp(1.0,m_uBits) - 1;
//CClientDC dc((CWnd *)GetDlgItem(IDC_STATICINFO));
if(m_uValue <= 0 || (double)m_uValue > max_value)
{
m_bVCorrect = FALSE;
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(FALSE);
str.Format(_T(" 不合法的初值输入!请输入一个在“1”到“%d”之间正确的数值,")\
_T("或者用下面的方法输入一个二进制式的值!"),(int)max_value);
SetDlgItemText(IDC_STATICINFO,str);
m_uValue = 0;
UpdateData(FALSE);
return ;
}
else
m_bVCorrect = TRUE;
if(m_bBCorrect && m_bVCorrect && m_bPCorrect)
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(TRUE);
else
((CWnd *)GetDlgItem(IDC_EXEC))->EnableWindow(FALSE);
InvalidateRect(&m_valueRct);
}
void CSerialDlg::OnSetfocusEditbits()
{
// TODO: Add your control notification handler code here
CString str(_T(""));
str.LoadString(IDS_STRING_BITSINFO);
SetDlgItemText(IDC_STATICINFO,str);
}
void CSerialDlg::OnSetfocusEditvalue()
{
// TODO: Add your control notification handler code here
CString str(_T(""));
str.LoadString(IDS_STRING_VALUEINFO);
SetDlgItemText(IDC_STATICINFO,str);
}
void CSerialDlg::OnSetfocusEditpath()
{
// TODO: Add your control notification handler code here
CString str(_T(""));
str.LoadString(IDS_STRING_PATHINFO);
SetDlgItemText(IDC_STATICINFO,str);
}
void CSerialDlg::OnSetfocusEditPul()
{
// TODO: Add your control notification handler code here
CString str(_T(""));
str.LoadString(IDS_STRING_SETTIME);
SetDlgItemText(IDC_STATICINFO,str);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -