我分别给两个编辑框做了ON_EN_CHANGE事件处理,本意是当其中一个编辑框内容发生变化时另一个编辑框内容相应变化,这个过程只需要出现一次就行了,可是结果这样会出现死循环,请高手指定!

解决方案 »

  1.   

    在消息循环中截取消息WM_CHAR,然后判断是哪个EDIT的,然后对另一个用SETWINDOWTEXT
      

  2.   

    在 ON_EN_CHANGE 消息里如果判断此edit控件是否有焦点 if ( GetFocus()==this ),如果有焦点就 调用SetWIndowText 设置 另外一个edit框 的字符。
    另外一个对话框此时也会收到 ON_EN_CHANGE ,但由于判断没有焦点,所以直接返回。
      

  3.   

    The EN_CHANGE notification is not sent when the ES_MULTILINE style is used and the text is sent through WM_SETTEXT. 你的两个编辑框都设置Multi-line属性void CXXDlg::OnChangeEdit1() 
    {
    // 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 static int i=0; m_text2.Format(_T("%d"), i++);
    GetDlgItem(IDC_EDIT2)->SetWindowText(m_text2);
    }void CXXDlg::OnChangeEdit2() 
    {
    // 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
    static int i=0; m_text.Format(_T("%d"), i++);
    UpdateData(FALSE);
    }
      

  4.   

    囧,第二个写错了,OnChangeEdit2里面的处理需要和第一个修改成一致即可,
    GetDlgItem(IDC_EDIT1)->SetWindowText(m_text1);
      

  5.   

    我试了不会啊~~
    你出现死循环的代码是???可以贴出来看看不void CTwoEditDataExchangeDlg::OnEnChangeEdit1()
    {
    // TODO:  如果该控件是 RICHEDIT 控件,则它将不会
    // 发送该通知,除非重写 CDialog::OnInitDialog()
    // 函数并调用 CRichEditCtrl().SetEventMask(),
    // 同时将 ENM_CHANGE 标志“或”运算到掩码中。 // TODO:  在此添加控件通知处理程序代码
    CString str;
    GetDlgItemText(IDC_EDIT1,str);
    SetDlgItemText(IDC_EDIT2,str);
    }