Customizing the Common Find/Replace Dialog in RichEdit View

Introduction

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

// Dialog Data
 //{{AFX_DATA(CMyFindDlg)>
 enum { IDD = IDD_MYFINDDLG };
 // NOTE: the ClassWizard will add data members here
 //}}AFX_DATA


// Overrides
 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CMyFindDlg)
 protected:
 virtual void DoDataExchange(CDataExchange* pDX);    
 //}}AFX_VIRTUAL

// Implementation
protected:

 // Generated message map functions
 //{{AFX_MSG(CMyFindDlg)
 afx_msg void OnCheck1();
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};

Step 4

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

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

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 =
  MAKEINTRESOURCE(IDD_MYFINDDLG);

 m_pMyFindDialog->Create(TRUE,
                         NULL,
                         NULL,
                         FR_ENABLETEMPLATE | FR_HIDEUPDOWN,
                         this);
 m_pMyFindDialog->SetActiveWindow();
 m_pMyFindDialog->ShowWindow(TRUE);
 // 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 = 
 ::RegisterWindowMessage(FINDMSGSTRING);

ON_REGISTERED_MESSAGE(FindReplaceDialogMessage, 
                      OnFindReplaceMessage)

Here is the Find/Replace dialog message handler function:

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

 ASSERT(pFindReplace != NULL);

 if (pFindReplace->IsTerminating())
 {
  pFindReplace = NULL;
 }
 else if (pFindReplace->FindNext())
 {
  if(FindText(pFindReplace->GetFindString(),
              FALSE,
              FALSE))
   AdjustDialogPosition(pFindReplace);
  else
   TextNotFound(pFindReplace->GetFindString());
 }

 return 0;
}

Conclusion

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.

Downloads

Download source code and demo project - 32 Kb


Comments

  • The activities all the others does in relation to nike and those actions youhas to do completely different.

    Posted by icoppyapedcap on 04/06/2013 07:18am

    QerBgyLfcQwv [url=http://ナイキシューズ8.seesaa.net/]ナイキ[/url]WhuHcyXbjAaj [url=http://ナイキレディース.seesaa.net/]ナイキ レディース[/url]AzvFxlDzpWtn [url=http://nike16.webnode.jp/]ナイキシューズ[/url]MvfIyfWvsRor [url=http://nike-nike-running.webnode.jp/]nike running[/url]CtrIvlPgyWxp [url=http://アディダス8.seesaa.net/]adidas スニーカー[/url]GvkVttIftZcl [url=http://adidasxn--lck1a4c0kb.seesaa.net/]adidas[/url]LmnRrmHgmYkf [url=http://adidas-adidas8.seesaa.net/]アディダス[/url]BogLckZwpZgw [url=http://adidas-originals8.seesaa.net/]adidas オリジナル[/url]ThgFgcTmoMko [url=http://adidasshoes8.seesaa.net/]アディダス シューズ[/url] OxnKfoYizFve [url=http://adidas-shoes8.seesaa.net/]adidas[/url]SpzHrlAjiZzy [url=http://adidasoriginals11.seesaa.net/]adidas オリジナル[/url]OdaVeyDpuHvz QpiHooHycFfx [url=http://adidasxn--qcktc9dtbb.seesaa.net/]adidas ランニング[/url]VrsEuqPvqFzj [url=http://adidasshoes9.seesaa.net/]靴 アディダス[/url]QbhFsvHkeZwd [url=http://adidas-sneakers9.seesaa.net/]スニーカー adidas[/url]WaoEvaXnhScn [url=http://sneaker-adidas-9.seesaa.net/]adidas スニーカー[/url]JzzTyyEfuXhv [url=http://shoes-adidas9.seesaa.net/]adidas アディダス[/url]IkoHvuPlgThr [url=http://xn--nike9-qm4dob.seesaa.net/]nike air[/url]UtwQpgEhaRqm [url=http://nikeid9.seesaa.net/]nike id[/url]TerLmrRxkLbt [url=http://ナイキシューズ9.seesaa.net/]シューズナイキ[/url]WvaQnzHlwOae [url=http://xn--nike-om4c5f8h0cb.seesaa.net/]ナイキスニーカー[/url]FrsGbfCawWol

    Reply
  • memory leaks

    Posted by Legacy on 09/03/2003 12:00am

    Originally posted by: Parameter

    memory leaks because newed object isn't deleted
    

    Reply
  • BUG

    Posted by Legacy on 02/13/2003 12:00am

    Originally posted by: yong jin kwak

    To avoid multiple find-dialogbox.

    in constructor...
    m_pMyFindDialog = NULL;

    void CMyFindView::OnMyFind()
    {
    if( m_pMyFindDialog == NULL )
    {
    m_pMyFindDialog= new CMyFindDlg();
    m_pMyFindDialog->m_fr.lpTemplateName=MAKEINTRESOURCE(IDD_MYFINDDLG);
    m_pMyFindDialog->Create(TRUE,NULL,NULL,FR_ENABLETEMPLATE|FR_HIDEUPDOWN,this);
    m_pMyFindDialog->SetActiveWindow();
    m_pMyFindDialog->ShowWindow(SW_SHOW);
    // TODO: Add your command handler code here
    }
    else
    {
    m_pMyFindDialog->SetActiveWindow();
    m_pMyFindDialog->ShowWindow( SW_SHOW );
    }
    }

    LRESULT CMyFindView::OnFindReplaceMessage(WPARAM wParam, LPARAM lParam)
    {
    CFindReplaceDialog* pFindReplace = CFindReplaceDialog::GetNotifier(lParam);
    ASSERT(pFindReplace != NULL);

    if (pFindReplace->IsTerminating())
    {
    // pFindReplace = NULL;
    m_pMyFindDialog = NULL; // <- here
    }
    else if (pFindReplace->FindNext())
    {
    if(FindText(pFindReplace->GetFindString(),FALSE,FALSE))
    AdjustDialogPosition(pFindReplace);
    else
    TextNotFound(pFindReplace->GetFindString());
    }
    return 0;

    }


    thanks a lot :)

    Reply
  • Problem

    Posted by Legacy on 03/25/2002 12:00am

    Originally posted by: praveen

    I found your program as very handy to me. But, I am unable
    to execute the code if i just follow the steps which u have
    given in as a part of another new project.Please let me know
    how to get around this.

    Reply
  • Looking for Regular expressions

    Posted by Legacy on 09/13/2001 12:00am

    Originally posted by: Gavarraju

    Hi,
    This is very interesting. I want to do exactly same to include Regular expressions support. Do u have any idea?

    Thankx
    raju

    Reply
  • Nice

    Posted by Legacy on 03/13/2001 12:00am

    Originally posted by: Steve

    Yah very interesting

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Live Event Date: October 29, 2014 @ 1:00 p.m. ET / 10:00 a.m. PT It's well understood how critical version control is for code. However, its importance to DevOps isn't always recognized. The 2014 DevOps Survey of Practice shows that one of the key predictors of DevOps success is putting all production environment artifacts into version control. In this eSeminar, Gene Kim will discuss these survey findings and will share woeful tales of artifact management gone wrong! Gene will also share examples of how …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds