我用richedit实现文本编辑器,类似于记事本。但是我在实现查找替换功能时,想得到主窗体编辑框里的内容,但是这不是对话框,不能用GetDlgItem()->GetWindowText();得到。所以请高手帮帮忙,具体怎么实现。谢谢!!

解决方案 »

  1.   

    m_edit.GetWindowText();
    GetDlgItem()->GetWindowText();也可以用啊,GetDlgItem(IDC_RICHEDIT)->GetWindowText();
      

  2.   

    void CSearchDlg::OnBnClickedOk()
    {
    // TODO: Add your control notification handler code here

    CString str;     //Text from the edit box of the SearchDialog
    CString TextStr; //Text from the edit box of the Mainframe
    GetDlgItem(IDC_TEXTEDIT)->GetWindowText(str);
    AfxMessageBox(_T("!!"));//Get the text of the edit box of the SearchDialog
    m_RichEdit.GetWindowText(TextStr);//Get the text of the edit box of the Mainframe

    if(str.IsEmpty())
    {
             AfxMessageBox(_T("Please input the text you want to search!")); 
    }
    else
    {
    if(TextStr.Find(str)) //Find str in TextStr
    AfxMessageBox(_T("They can't be found!"));
    else
    {
            //(将选中的文本设置阴影效果)
                    }
                     

    }
    OnOK();
    }
    我在获取要查找的字符之后设置了一个断点,之后程序就蹦了,m_RichEdit是主窗体编辑框,麻烦帮我看看!谢谢!
      

  3.   

    应该很容易调试吧,Debug下打开call stack窗口,看看运行到哪个函数抛出异常
      

  4.   

    CRichEditCtrl *pmRichEdit;
    pmRichEdit=m_RichEdit;
    pmRichEdit->GetWindowText(TextStr);
    我想这样找到主窗体的文本内容,m_RichEdit是我在CMainFrame类里定义的CRichEditCtrl变量,但是在这里m_RichEdit却没有定义,我已经包含了MainFrm.h文件了,不知道错在哪里了。我觉得应该可以了的...
      

  5.   

    囧,你在对话框的类里竟然直接使用CMainFrame类的CRichEditCtrl对象
    你可以在你的CMainFrame类里定义一个public成员函数A,在该A函数中访问你的CRichEditCtrl对象,你的对话框类里也使用主框架类的这个成员函数A