The search and replace dialog box is also a non-Modal Dialog Box. Therefore, the creation process is similar to that of the create non-modal dialog box in MFC.
First create a window, set the relevant parameters, and then use it when it is displayed.
Create prototype: Virtual bool create (bool bfinddialogonly,
// True for find, false for findreplace
Lpctstr lpszfindwhat, // Default string to be searched
Lpctstr lpszreplacewith = NULL, // The default string to be searched and replaced
DWORD dwflags = fr_down, // Some attributes in the Setting dialog box are described below.
Cwnd * pparentwnd = NULL ); // The parent window of the dialog box
Description of dwflags ):
If fr_down is set, the "search down" radio button in the dialog box is selected. If no option is set, the "search up" radio button is selected;
Fr_hideupdown does not display the find direction radio button;
Fr_hidematchcase does not show case-sensitive check buttons;
Fr_hidewholeword does not display the "full match" Check button;
Fr_matchcase: Enable the case-sensitive check button to be selected;
Fr_wholeword: make the "match all" Check button selected;
Fr_nomatchcase: Enable the case-sensitive check button to be disabled (grayed out;
Fr_noupdown: the single-choice button in the search direction is disabled (grayed out;
Fr_nowholeword: make the check button of Full-character match disabled (dimmed;
Fr_showhelp displays a Help button in the dialog box.
Create an instance of the search window as follows:
Cfindreplacedialog * pfinddlg =
New cfindreplacedialog;
// Because the non-modal dialog box is displayed, use the new command to allocate memory.
If (! Pfinddlg-> Create (true, _ T ("Hyp's knowledge base"), null, fr_down | fr_matchcase | fr_wholeword, this) // as described above
{
Return;
}
Pfinddlg-> showwindow (sw_show );
// Display the window after it is created
Pfinddlg-> setactivewindow ();
// Set as the activity window
Create an instance of the find and replace window as follows:
Cfindreplacedialog * preplacedlg = new cfindreplacedialog;
If (! Preplacedlg-> Create (false, _ T ("Hyp"), _ T ("Hyp's knowledge base"), fr_down, this ))
{
Return;
}
Preplacedlg-> showwindow (sw_show );
Preplacedlg-> setactivewindow ();
In the displayed dialog box, you still need to add some response functions. I found that there is no ready-made message response.
The general steps are as follows:
Add the following under # pragma once in the header file of the "search and replace" dialog box
Const
Int wm_findreplace =: registerwindowmessage (findmsgstring); // register findmsgstring as a wm_findreplace message
And the message ing function generated in the header file
Afx_msg long onfindreplace (wparam, lparam );
Associate the message ing function with the wm_findreplace message in the source file.
Begin_message_map (...)
...
On_registered_message (wm_findreplace, onfindreplace)
...
End_message_map ()
Next, write the onfindreplace function.
Long chypdlg: onfindreplace (wparam, lparam)
{
// Todo: add the control notification handler code here
Cfindreplacedialog * pdlg = cfindreplacedialog: getnotifier (lparam );
// Write your own code for specific search and replacement
// Pdlg-> getfindstring (); This function returns a query string.
// Pdlg-> getreplacestring (); this function returns a replacement string.
// Pdlg-> searchdown (); This function can be used to determine whether to search up or down, true is down, and ooxx
// Pdlg-> matchcase (); This function can determine whether it is case sensitive.
// Pdlg-> matchwholeword (); this function can be used to determine whether a full-character match exists.
If (pdlg! =
Null)
{
If (pdlg-> findnext ())
{
MessageBox ("findnext! ",
"Hyp's knowledge base", mb_ OK );
}
Else
If (pdlg-> replaceall ())
{
MessageBox ("replaceall! ",
"Hyp's knowledge base", mb_ OK );
}
Else
If (pdlg-> replacecurrent ()){
MessageBox ("replacecurrent! ",
"Hyp's knowledge base", mb_ OK );
}
}
Delete pdlg;
// The dialog box is automatically destroyed after the click is added.
Return
1;
}
The specific search and replacement functions are added to the onfindreplace function.