|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionThis 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 customizationCustomizing Find/Replace common dialog involves the following steps: Step 1Copy 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 2Make 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 3Use Classwizard to add a C++ class for our new Find/Replace template (say, /////////////////////////////////////////////////////////////////// // CMyFindDlg dialog class CMyFindDlg : public CFindReplaceDialog { // Construction public: CMyFindDlg(CWnd* pParent = NULL); // standard constructor // 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: // DDX/DDV support 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 4Change the constructor of //////////////////////////////////////////////////////////////////// // CMyFindDlg dialog CMyFindDlg::CMyFindDlg(CWnd* pParent /*=NULL*/) : CFindReplaceDialog() { //{{AFX_DATA_INIT(CMyFindDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } Step 5Create a new Menu item and a Toolbar button for our Find and add a handler function for command message (say, //////////////////////////////////////////////////////////////////// // 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 CMyFindDlg* m_pMyFindDialog; Step 6When 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 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;
}
ConclusionThe 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.
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||