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 { //(将选中的文本设置阴影效果) }
GetDlgItem()->GetWindowText();也可以用啊,GetDlgItem(IDC_RICHEDIT)->GetWindowText();
{
// 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是主窗体编辑框,麻烦帮我看看!谢谢!
pmRichEdit=m_RichEdit;
pmRichEdit->GetWindowText(TextStr);
我想这样找到主窗体的文本内容,m_RichEdit是我在CMainFrame类里定义的CRichEditCtrl变量,但是在这里m_RichEdit却没有定义,我已经包含了MainFrm.h文件了,不知道错在哪里了。我觉得应该可以了的...
你可以在你的CMainFrame类里定义一个public成员函数A,在该A函数中访问你的CRichEditCtrl对象,你的对话框类里也使用主框架类的这个成员函数A