加入收藏 | 设为首页 | 会员中心 | 我要投稿 北几岛 (https://www.beijidao.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

连动的数字编辑框

发布时间:2021-07-06 05:56:39 所属栏目:大数据 来源: https://www.jb51.cc
导读:因为项目需要,要做一个互相关联的连动数字编辑框。闹了我两天时间,终于做好了。主要的错误出在没有理解MFC的WM_EN_CHANGE这个消息发送的时机,所以每次再影射这个消息并使用时总会出现一个ASSERT,提示::IsWindow(m_hWnd),为false。错误的查找是很辛苦的

因为项目需要,要做一个互相关联的连动数字编辑框。闹了我两天时间,终于做好了。主要的错误出在没有理解MFC的WM_EN_CHANGE这个消息发送的时机,所以每次再影射这个消息并使用时总会出现一个ASSERT,提示::IsWindow(m_hWnd),为false。错误的查找是很辛苦的,一度怀疑是使用DDX影射的缘故,最终把很简单的代码全部修改为GetDlgItem()类的东东,还是由问题。

俺终于忍不住在这个消息里加上了如下代码,虽然看起来不那么顺眼,但总算解决了这个问题。

代码如下:

CButton* pButton=(CButton*)GetDlgItem(m_edt[0]);
?CEdit* pStartB=(CEdit*)GetDlgItem(m_edt[6]);
?CEdit* pEndB=(CEdit*)GetDlgItem(m_edt[7]);
?CEdit* pStartA=(CEdit*)GetDlgItem(m_edt[4]);
?CEdit* pEndA=(CEdit*)GetDlgItem(m_edt[5]);
?CEdit* pLines=(CEdit*)GetDlgItem(m_edt[10]);

?CString strText;
?int nLines=1;
?int nValue=1;
?//必须进行判断,否则会进入非窗口时事机
?if(pLines!=NULL && ::IsWindow(pLines->GetSafeHwnd())
?? && ::IsWindow(pStartA->GetSafeHwnd()) && ::IsWindow(pStartB->GetSafeHwnd())
?? && ::IsWindow(pEndA->GetSafeHwnd()) && ::IsWindow(pEndB->GetSafeHwnd()))
?{
??pLines->GetWindowText(strText);
??nLines=atoi(strText);
??pStartA->GetWindowText(strText);
??nValue=atoi(strText);
??if(nValue>m_nMaxLineNumber-nLines+1)
??{
???nValue=m_nMaxLineNumber-nLines+1;
???strText.Format("%d",nValue);
???pStartA->SetWindowText(strText);
??}
??strText.Format("%d",nValue+nLines-1);
??pEndA->SetWindowText(strText);??

??if(pButton->GetCheck()==BST_CHECKED)
??{
???pStartA->GetWindowText(strText);?
???pStartB->SetWindowText(strText);
???pEndA->GetWindowText(strText);
???pEndB->SetWindowText(strText);
??}
??else
??{
???pStartB->GetWindowText(strText);
???nValue=atoi(strText);
???if(nValue>m_nMaxLineNumber-nLines+1)
???{
????nValue=m_nMaxLineNumber-nLines+1;
????strText.Format("%d",nValue);
????pStartB->SetWindowText(strText);
???}
???strText.Format("%d",nValue+nLines-1);
???pEndB->SetWindowText(strText);?
???
??}
?}

?

(编辑:北几岛)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读