lucent2000
asked on
How To Change the String in CRichEditCtrl
RE is a CRichEditCtrl object. What I have is a spell checker. There are four choices for the user 1st Ignore,Ignore All, Change, and Change All.
so basically I have this options in a switch statement.
Since I already have the Change working how do I implement the ChangeAll. These are push buttons.If the spell checker detects a mispelled word. It list the suggestion in the list box.
switch (idAction)
{
case IDIGNORE:
// skip this instance of pToken
break;
case IDIGNOREALL:
// skip every instance of pToken - add to ignore list
break;
case IDCHANGE:
// change this instance of pToken to dlg.m_strChange
RE.ReplaceSel(LPCTSTR(dlg. m_strChang e), true);
nNew = dlg.m_strChange.GetLength( );
int dxChars += (nNew - nOld);
break;
case IDCHANGEALL:
// change every instance of pToken to dlg.m_strChange
break;
default:
break;
so basically I have this options in a switch statement.
Since I already have the Change working how do I implement the ChangeAll. These are push buttons.If the spell checker detects a mispelled word. It list the suggestion in the list box.
switch (idAction)
{
case IDIGNORE:
// skip this instance of pToken
break;
case IDIGNOREALL:
// skip every instance of pToken - add to ignore list
break;
case IDCHANGE:
// change this instance of pToken to dlg.m_strChange
RE.ReplaceSel(LPCTSTR(dlg.
nNew = dlg.m_strChange.GetLength(
int dxChars += (nNew - nOld);
break;
case IDCHANGEALL:
// change every instance of pToken to dlg.m_strChange
break;
default:
break;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
void CNarrativeView::CheckSpell ing(bool bAll)
{
CString strText = _T("");
if (bAll)
{
//check all word
strText = GetNarrative();
if(!strText.IsEmpty())
{
int dxChars = 0;
int n = strText.GetLength();
PSTR pszBuf = new char[n+1];
if (!pszBuf)
{
return;
}
//copies string to the buffer
strcpy(pszBuf,LPCTSTR(strT ext));
char seps[] = " ,\t\r\n";
PSTR pToken = NULL;
//check spelling suggestion
_ApplicationPtr pWord = reinterpret_cast<CNarrativ eApp*>(Afx GetApp())- >GetWordPt r();
if (pWord)
{
pToken = strtok(pszBuf,seps);
CStringArray strSugs;
bool bCheck = false;
while( pToken != NULL )
{
bCheck = true;
if (m_Options.m_bIgnoreNumber s)
{
CString strWord = pToken;
if (strWord.FindOneOf("012345 6789") != -1)
{
bCheck = false;
}
}
if (bCheck && m_Options.m_bIgnoreUpper)
{
CString strWord = pToken;
if (strWord.FindOneOf("abcedf ghijklmnop qrstuvwxyz ") == -1)
{
bCheck = false;
}
}
if (bCheck)
{
_bstr_t bstrWord(pToken);
VARIANT_BOOL vtBool = pWord->CheckSpelling(bstrW ord);
if (vtBool == VARIANT_FALSE)
{
if (m_Options.m_bSuggestions)
{
SpellingSuggestionsPtr pSugs = NULL;
pSugs = pWord->GetSpellingSuggesti ons(bstrWo rd);
int iCount = pSugs->GetCount();
strSugs.RemoveAll();
for (int i =1; i <= iCount; i++)
{
SpellingSuggestionPtr pSugWord = pSugs->Item(i);
if (pSugWord)
{
// Build list
CString strSug = (LPCTSTR)pSugWord->GetName ();
TRACE("Suggestion: <%s>\r\n", strSug);
strSugs.Add(strSug);
}
}
}
CDlgSpelling dlg;
// copy array elements
int nSugs = strSugs.GetSize();
for (int i = 0; i < nSugs; i++)
{
dlg.m_astrSugs.Add(strSugs [i]);
}
int nNew = 0;
int nOld = strlen(pToken);
int iStart = pToken - pszBuf;
iStart += dxChars;
int iEnd = iStart + nOld;
CRichEditCtrl& RE = GetRichEditCtrl();
RE.SetSel(iStart, iEnd);
dlg.m_strWrong = pToken;
int idAction = dlg.DoModal();
switch (idAction)
{
case IDIGNORE:
// skip this instance of pToken
break;
case IDIGNOREALL:
// skip every instance of pToken - add to ignore list
break;
case IDCHANGE:
//change this instance of pToken to dlg.m_strChange
RE.ReplaceSel(LPCTSTR(dlg. m_strChang e), true);
nNew = dlg.m_strChange.GetLength( );
dxChars += (nNew - nOld);
break;
case IDCHANGEALL:
//change every instance of pToken to dlg.m_strChange
/*Use the FindText member of CRichEditCtrl and
use a while loop to find every instance of the word
by using the WHOLEWORD attribute for FindText.
Using the found position of the word execute a SetSel call
to set the selection to the found word.
Then use the same ReplaceSel in the IDCHANGE code.*/
CHARRANGE chrg; // range to search
LPSTR lpstrText; // null-terminated string to find
CHARRANGE chrgText; // range in which text is found
FINDTEXTEX ft;
long nFind = RE.FindText(FR_WHOLEWORD,F INDTEXTEX) ;
long nMinPos = RE.SetSel(chrgText.cpMin);
long nMaxPos = RE.SetSel(chrgText.cpMax);
break;
default:
break;
}
}
}
pToken = strtok( NULL, seps );
}
}
delete pszBuf;
}
}
else
{
CRichEditCtrl& RE = GetRichEditCtrl();
strText = RE.GetSelText();
if (!strText.IsEmpty())
{
_ApplicationPtr pWord = reinterpret_cast<CNarrativ eApp*>(Afx GetApp())- >GetWordPt r();
if (pWord)
{
_bstr_t bstrWord(strText);
VARIANT_BOOL vtBool = pWord->CheckSpelling(bstrW ord);
if (vtBool == VARIANT_FALSE)
{
SpellingSuggestionsPtr pSugs = NULL;
pSugs = pWord->GetSpellingSuggesti ons(bstrWo rd);
int iCount = pSugs->GetCount();
for (int i = 1; i <= iCount; i++)
{
SpellingSuggestionPtr pSugWord = pSugs->Item(i);
if (pSugWord)
{
CString strWord = (LPCTSTR)pSugWord->GetName ();
TRACE("Suggestion: <%s>\r\n", strWord);
}
}
//dlg
CDlgSpelling dlg;
dlg.DoModal();
}
}
}
}
}
{
CString strText = _T("");
if (bAll)
{
//check all word
strText = GetNarrative();
if(!strText.IsEmpty())
{
int dxChars = 0;
int n = strText.GetLength();
PSTR pszBuf = new char[n+1];
if (!pszBuf)
{
return;
}
//copies string to the buffer
strcpy(pszBuf,LPCTSTR(strT
char seps[] = " ,\t\r\n";
PSTR pToken = NULL;
//check spelling suggestion
_ApplicationPtr pWord = reinterpret_cast<CNarrativ
if (pWord)
{
pToken = strtok(pszBuf,seps);
CStringArray strSugs;
bool bCheck = false;
while( pToken != NULL )
{
bCheck = true;
if (m_Options.m_bIgnoreNumber
{
CString strWord = pToken;
if (strWord.FindOneOf("012345
{
bCheck = false;
}
}
if (bCheck && m_Options.m_bIgnoreUpper)
{
CString strWord = pToken;
if (strWord.FindOneOf("abcedf
{
bCheck = false;
}
}
if (bCheck)
{
_bstr_t bstrWord(pToken);
VARIANT_BOOL vtBool = pWord->CheckSpelling(bstrW
if (vtBool == VARIANT_FALSE)
{
if (m_Options.m_bSuggestions)
{
SpellingSuggestionsPtr pSugs = NULL;
pSugs = pWord->GetSpellingSuggesti
int iCount = pSugs->GetCount();
strSugs.RemoveAll();
for (int i =1; i <= iCount; i++)
{
SpellingSuggestionPtr pSugWord = pSugs->Item(i);
if (pSugWord)
{
// Build list
CString strSug = (LPCTSTR)pSugWord->GetName
TRACE("Suggestion: <%s>\r\n", strSug);
strSugs.Add(strSug);
}
}
}
CDlgSpelling dlg;
// copy array elements
int nSugs = strSugs.GetSize();
for (int i = 0; i < nSugs; i++)
{
dlg.m_astrSugs.Add(strSugs
}
int nNew = 0;
int nOld = strlen(pToken);
int iStart = pToken - pszBuf;
iStart += dxChars;
int iEnd = iStart + nOld;
CRichEditCtrl& RE = GetRichEditCtrl();
RE.SetSel(iStart, iEnd);
dlg.m_strWrong = pToken;
int idAction = dlg.DoModal();
switch (idAction)
{
case IDIGNORE:
// skip this instance of pToken
break;
case IDIGNOREALL:
// skip every instance of pToken - add to ignore list
break;
case IDCHANGE:
//change this instance of pToken to dlg.m_strChange
RE.ReplaceSel(LPCTSTR(dlg.
nNew = dlg.m_strChange.GetLength(
dxChars += (nNew - nOld);
break;
case IDCHANGEALL:
//change every instance of pToken to dlg.m_strChange
/*Use the FindText member of CRichEditCtrl and
use a while loop to find every instance of the word
by using the WHOLEWORD attribute for FindText.
Using the found position of the word execute a SetSel call
to set the selection to the found word.
Then use the same ReplaceSel in the IDCHANGE code.*/
CHARRANGE chrg; // range to search
LPSTR lpstrText; // null-terminated string to find
CHARRANGE chrgText; // range in which text is found
FINDTEXTEX ft;
long nFind = RE.FindText(FR_WHOLEWORD,F
long nMinPos = RE.SetSel(chrgText.cpMin);
long nMaxPos = RE.SetSel(chrgText.cpMax);
break;
default:
break;
}
}
}
pToken = strtok( NULL, seps );
}
}
delete pszBuf;
}
}
else
{
CRichEditCtrl& RE = GetRichEditCtrl();
strText = RE.GetSelText();
if (!strText.IsEmpty())
{
_ApplicationPtr pWord = reinterpret_cast<CNarrativ
if (pWord)
{
_bstr_t bstrWord(strText);
VARIANT_BOOL vtBool = pWord->CheckSpelling(bstrW
if (vtBool == VARIANT_FALSE)
{
SpellingSuggestionsPtr pSugs = NULL;
pSugs = pWord->GetSpellingSuggesti
int iCount = pSugs->GetCount();
for (int i = 1; i <= iCount; i++)
{
SpellingSuggestionPtr pSugWord = pSugs->Item(i);
if (pSugWord)
{
CString strWord = (LPCTSTR)pSugWord->GetName
TRACE("Suggestion: <%s>\r\n", strWord);
}
}
//dlg
CDlgSpelling dlg;
dlg.DoModal();
}
}
}
}
}
ASKER