Click here to Skip to main content
13,800,303 members
Click here to Skip to main content
Add your own
alternative version


31 bookmarked
Posted 6 Jan 2001
Licenced GPL3

Customizing the Common Find/Replace Dialog in RichEdit View

, 1 Apr 2001
Rate this:
Please Sign up or sign in to vote.
This article explains how to customize the standard Find/Replace Dialog in RichEdit view.

Sample Image - CustomFind.gif


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 unwanted 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 unwanted controls.

The demo application which is included with this article demonstrates the following:

How to hide a control?

Direction (up/down) control is hidden

How to add a new control?

New control "[ ] Wrap around" is added

How to change its properties?

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
    CMyFindDlg(CWnd* pParent = NULL);   // standard constructor

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

// Overrides
    // ClassWizard generated virtual function overrides
    // DDX/DDV support
    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();
    // 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 its 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 = 

ON_REGISTERED_MESSAGE(FindReplaceDialogMessage, OnFindReplaceMessage)

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 is also included with this article.


This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


About the Author

Kalai Kandasamy
United States United States
Working as an Senoir Engineering Manager in a California/USA based company and having 15 years of design and development experience on UNIX/Windows based platforms. Proficient in C, C++, Visual C++, MFC, Web based development and networking.

You may also be interested in...

Comments and Discussions

GeneralUsage from within a DDL Pin
Sebaestschjin15-Jun-17 4:47
memberSebaestschjin15-Jun-17 4:47 
QuestionCustomize dialog ? Pin
Viet Duy25-Nov-07 5:37
memberViet Duy25-Nov-07 5:37 
Questionform template Pin
ngwaikeong26-Sep-07 3:33
memberngwaikeong26-Sep-07 3:33 
QuestionFind and Replace Pin
Jaanviragu18-Sep-07 22:22
memberJaanviragu18-Sep-07 22:22 
QuestionOperator delete Pin
crisoc29-Jun-07 5:57
membercrisoc29-Jun-07 5:57 
GeneralIt's missing the most essential part... Pin
Anonymous5-Feb-03 16:03
memberAnonymous5-Feb-03 16:03 
GeneralRe: It's missing the most essential part... Pin
Waylandbill23-Mar-04 4:05
memberWaylandbill23-Mar-04 4:05 
GeneralCopying Find/Replace dialog template Pin
5-Mar-02 23:14
suss5-Mar-02 23:14 
GeneralRe: Copying Find/Replace dialog template Pin
31-May-02 3:57
suss31-May-02 3:57 
QuestionITextServices? Pin
M. Ashokkumar7-Feb-02 19:25
memberM. Ashokkumar7-Feb-02 19:25 
GeneralCool this is what I am looking for Pin
14-Feb-01 15:27
suss14-Feb-01 15:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web02 | 2.8.181214.1 | Last Updated 2 Apr 2001
Article Copyright 2001 by Kalai Kandasamy
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid