Customizing the Common Find/Replace Dialog in RichEdit View

Thursday Jan 25th 2001 by Kalai Kandasamy

Explains how to customize the standard CRichEditView Find/Replace dialog


This article explains how to customize the standard Find/Replace Dialog in RichEdit view. The logic is same for Edit view or any other generic views with slight changes. Customizing the Find/Replace Dialog involves modifying windows common Find/Replace dialog template which allows you to add any new controls or remove the existing one. Please note, none of the controls in the original Find/Replace dialog template should be deleted instead, you can disable or hide those un wanted controls!

Find/Replace common Dialog customization

Customizing Find/Replace common dialog involves the following steps:

Step 1

Copy the Find/Replace dialog template from common dialog .RC to the application 's .RC file.This dialog template resides in the file "include\findtext.dlg"

Step 2

Make any necessary changes to the copied dialog template and note again none of the controls in the original Find/Replace dialog template should be deleted, instead you can disable or hide those un wanted controls.

The demo application which included with this article demonstrates the followings:

How to hide a contol?

o Directon(up/down) control is hidden

How to add an new control?

o New control "[ ] Auto wrap" is added

How to change it's properties?

o Dialog's default font has been changed

Step 3

Use Classwizard to add a C++ class for our new Find/Replace template (say, CMyFindDlg). Drive this new class from CDialog as the base class. Then change all reference from CDialog to CFindReplaceDialog in both header and implementation file of the newly created class.
// CMyFindDlg dialog

class CMyFindDlg : public CFindReplaceDialog
// Construction
 // standard constructor
 CMyFindDlg(CWnd* pParent = NULL);   

// Dialog Data
 enum { IDD = IDD_MYFINDDLG };
 // NOTE: the ClassWizard will add data members here

// Overrides
 // ClassWizard generated virtual function overrides
 virtual void DoDataExchange(CDataExchange* pDX);    

// Implementation

 // Generated message map functions
 afx_msg void OnCheck1();

Step 4

Change the constructor of CFindReplaceDialog which differs from the CDialog's constructor.
// CMyFindDlg dialog

CMyFindDlg::CMyFindDlg(CWnd* pParent /*=NULL*/)
 : CFindReplaceDialog()
  // NOTE: the ClassWizard will add member 
  // initialization here

Step 5

Create a new Menu item and a Toolbar button for our Find and add a handler function for command message (say, OnMyFind).While creating the Find dialog we can hide the unwanted controls.
// CMyFindView message handlers

void CMyFindView::OnMyFind() 
 m_pMyFindDialog= new CMyFindDlg();

 m_pMyFindDialog->m_fr.lpTemplateName =

                         FR_ENABLETEMPLATE | FR_HIDEUPDOWN,
 // TODO: Add your command handler code here

Where m_pMyFindDialog is defined in MyFindView.h

CMyFindDlg* m_pMyFindDialog;

Step 6

When Find/Replace dialog is opened the user can edit or type the search string, change the check marks of controls or press any buttons. So we should process those requests and necessary action to be taken. Actually CFindReplaceDialog sends a message to it's parent and you must specify the FINDMSGSTRING control in a call to the RegisterWindowMessage function to get the identifier to the message, sent by the FindReplace dialog box. Also add an ON_REGISTER_MESSAGE entry for message handler.
static UINT FindReplaceDialogMessage = 


Here is the Find/Replace dialog message handler function:

LRESULT CMyFindView::OnFindReplaceMessage(WPARAM wParam, 
                                          LPARAM lParam)
 CFindReplaceDialog* pFindReplace = 

 ASSERT(pFindReplace != NULL);

 if (pFindReplace->IsTerminating())
  pFindReplace = NULL;
 else if (pFindReplace->FindNext())

 return 0;


The purpose of this article is to demonstrate how to customize the standard Find/Replace dialog in a MFC application and how to handle the Find/Replace dialog box messages. A sample application with source files are also included with this article.


Download source code and demo project - 32 Kb
Mobile Site | Full Site
Copyright 2018 © QuinStreet Inc. All Rights Reserved