LRESULT CMyRichEditView::OnFindReplace(WPARAM wparam, LPARAM lparam) { UNREFERENCED_PARAMETER(wparam); CFindReplaceDialog *pDlg = CFindReplaceDialog::GetNotifier(lparam); if( NULL != pDlg ) { // Use pDlg as a pointer to the existing FindReplace dlg to // call CFindReplaceDialog member functions if(pDlg->IsTerminating()) { CString csFindString; CString csReplaceString; csFindString = pDlg->GetFindString(); csReplaceString = pDlg->GetReplaceString(); VERIFY(AfxGetApp()->WriteProfileString( AfxGetApp()->m_pszAppName, _T("FindString"), csFindString)); VERIFY(AfxGetApp()->WriteProfileString(AfxGetApp()->m_pszAppName, _T("ReplaceString"), csReplaceString)); VERIFY(pDlg->DestroyWindow()); } } return 0; }
LONG CJevView::FindReplaceHelper( UINT wParam, LONG lParam ) { BOOL bFindResult; CMainFrame* pMainFrame; pMainFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd; CFindReplaceDialog* pDialogBox = CFindReplaceDialog::GetNotifier(lParam); if( pDialogBox->IsTerminating() ) { sFindString = pDialogBox->GetFindString(); delete pFindReplaceDialog; pFindReplaceDialog = NULL; pMainFrame->SetStatusBarText( "Ready" ); return 0; } CJevDoc* pDoc = GetDocument(); if( pDialogBox->FindNext() ) { TRACE("FindReplaceHelper: FindString='%s'\n", pDialogBox->GetFindString() ); } bFindResult = pDoc->Find( pDialogBox->GetFindString(), pDialogBox->MatchCase(), pDialogBox->MatchWholeWord(), pDialogBox->SearchDown() ); if( bFindResult == FALSE ) MessageBeep(-1); return (LONG) bFindResult; }
LRESULT CScriptEditView::OnFindReplaceCmd( UINT, WPARAM, LPARAM lParam, BOOL& ) { CFindReplaceDialog* pDlg = CFindReplaceDialog::GetNotifier(lParam); if( pDlg == NULL ) { ::MessageBeep( (UINT)-1 ); return 1; } ATLASSERT( pDlg == m_pFindDlg ); if( pDlg->IsTerminating() ) { m_pFindDlg = NULL; return 0; } lstrcpyn( m_fro.StrToFind, pDlg->m_fr.lpstrFindWhat, DIMOF(m_fro.StrToFind) ); m_fro.bMatchCase = (pDlg->MatchCase() != FALSE); m_fro.bWholeWord = (pDlg->MatchWholeWord() != FALSE); if( pDlg->FindNext() ) { if( !DoFindText() ) ::MessageBeep( (UINT)-1 ); } else if( pDlg->ReplaceCurrent() ) { long nStart, nEnd; GetSel( nStart, nEnd ); if( nStart != nEnd ) { LPTSTR szFind = (LPTSTR)_alloca( (nEnd - nStart + 1) * sizeof(TCHAR) ); GetSelText( szFind ); int nRet; if( m_fro.bMatchCase ) nRet = lstrcmp( szFind, m_fro.StrToFind ); else nRet = lstrcmpi( szFind, m_fro.StrToFind ); if(nRet == 0) ReplaceSel( pDlg->GetReplaceString(), TRUE ); } if( !DoFindText() ) ::MessageBeep( (UINT)-1 ); } else if( pDlg->ReplaceAll() ) { SetRedraw(FALSE); CWaitCursor wait; while( DoFindText(false) ) ReplaceSel( pDlg->GetReplaceString(), TRUE ); SetRedraw( TRUE ); Invalidate(); UpdateWindow(); } return 0; }
LONG CMixereView::OnFindReplace(WPARAM wParam, LPARAM lParam) { CFindReplaceDialog *frd = CFindReplaceDialog::GetNotifier(lParam); if (frd->IsTerminating()) { m_FindStr = frd->GetFindString(); m_FindDlg = NULL; } else if (frd->FindNext() || frd->ReplaceCurrent()) { CString FindStr = frd->GetFindString(); if (!frd->MatchCase()) // if case-insensitive match FindStr.MakeLower(); // make find string lower case if (FindStr != m_FindStr) { // if find string changed m_FindStr = FindStr; // update member var m_NewFind = TRUE; // reset new find flag } m_FindMatchCase = frd->MatchCase() != 0; m_FindSearchDown = frd->SearchDown() != 0; FindNext(); } return(0); }
LRESULT CEditView::OnFindReplaceCmd(WPARAM, LPARAM lParam) { ASSERT_VALID(this); _AFX_EDIT_STATE* pEditState = _afxEditState; CFindReplaceDialog* pDialog = CFindReplaceDialog::GetNotifier(lParam); ASSERT(pDialog != NULL); ASSERT(pDialog == pEditState->pFindReplaceDlg); if (pDialog->IsTerminating()) { pEditState->pFindReplaceDlg = NULL; } else if (pDialog->FindNext()) { OnFindNext(pDialog->GetFindString(), pDialog->SearchDown(), pDialog->MatchCase()); } else if (pDialog->ReplaceCurrent()) { ASSERT(!pEditState->bFindOnly); OnReplaceSel(pDialog->GetFindString(), pDialog->SearchDown(), pDialog->MatchCase(), pDialog->GetReplaceString()); } else if (pDialog->ReplaceAll()) { ASSERT(!pEditState->bFindOnly); OnReplaceAll(pDialog->GetFindString(), pDialog->GetReplaceString(), pDialog->MatchCase()); } ASSERT_VALID(this); return 0; }
LRESULT CLogViewDlg::OnFindReplaceMsg(WPARAM wParam, LPARAM lParam) { CFindReplaceDialog* pFindDlg = CFindReplaceDialog::GetNotifier(lParam); // 正在关闭 if(pFindDlg->IsTerminating()) { delete[] pFindDlg->m_fr.lpstrFindWhat; pFindDlg->m_fr.lpstrFindWhat = NULL; pFindDlg->m_fr.wFindWhatLen = 0; m_pFindDlg = NULL; return 0; } int nItemCount = m_LogList.GetItemCount(); if(nItemCount < 2) return 0; m_bFindDown = pFindDlg->SearchDown(); m_bFindNext = pFindDlg->FindNext(); m_bMatchCase = pFindDlg->MatchCase(); m_bMatchWholeWord = pFindDlg->MatchWholeWord(); int nStart = m_LogList.GetNextItem(-1, LVNI_SELECTED); int nEnd = m_bFindDown ? nItemCount - 1 : 0; if(nStart == -1) nStart = m_bFindDown ? 0 : nItemCount - 1; else nStart = m_bFindDown ? nStart + 1 : nStart - 1; CString strFindWhat(pFindDlg->GetFindString()); m_strFindWhat = strFindWhat; int nNextItem = -1; int i = nStart; while(TRUE) { if(m_bFindDown) { if(i > nEnd) break; } else { if(i < nEnd) break; } CString strLog = GetItemText(i, Column_Log); if(m_bMatchCase) { // Case-Sensitive if(m_bMatchWholeWord) { if(strLog == strFindWhat) { nNextItem = i; break; } } else { if(strLog.Find(strFindWhat) != -1) { nNextItem = i; break; } } } else { // Non Case-Sensitive CharLower(strLog.GetBuffer(strLog.GetLength())); strLog.ReleaseBuffer(strLog.GetLength()); CharLower(strFindWhat.GetBuffer(strFindWhat.GetLength())); strFindWhat.ReleaseBuffer(strFindWhat.GetLength()); if(m_bMatchWholeWord) { if(strLog == strFindWhat) { nNextItem = i; break; } } else { if(strLog.Find(strFindWhat) != -1) { nNextItem = i; break; } } } i = m_bFindDown ? i + 1 : i - 1; } if(nNextItem != -1) { ClearLogListSelection(); m_LogList.SetItemState(nNextItem, LVIS_SELECTED, LVIS_SELECTED); m_LogList.EnsureVisible(nNextItem, FALSE); } else { AfxMessageBox(_T("No More Matched Items."), MB_OK | MB_ICONWARNING); } return 0; }
LRESULT CEditView::OnFindReplaceCmd( WPARAM wParam, LPARAM lParam ) /*****************************************************************/ { UNUSED_ALWAYS( wParam ); CFindReplaceDialog *pDlg = CFindReplaceDialog::GetNotifier( lParam ); ASSERT( pDlg == _afxEditState->pFindReplaceDlg ); if( pDlg->FindNext() ) { OnFindNext( pDlg->GetFindString(), pDlg->SearchDown(), pDlg->MatchCase() ); } else if( pDlg->ReplaceCurrent() ) { OnReplaceSel( pDlg->GetFindString(), pDlg->SearchDown(), pDlg->MatchCase(), pDlg->GetReplaceString() ); } else if( pDlg->ReplaceAll() ) { OnReplaceAll( pDlg->GetFindString(), pDlg->GetReplaceString(), pDlg->MatchCase() ); } else if( pDlg->IsTerminating() ) { _afxEditState->pFindReplaceDlg = NULL; } return( 0L ); }