description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CFindReplaceDialog Class |
CFindReplaceDialog Class |
11/04/2016 |
|
|
610f0b5d-b398-4ef6-8c05-e9d6641e50a8 |
Allows you to implement standard string Find/Replace dialog boxes in your application.
class CFindReplaceDialog : public CCommonDialog
Name | Description |
---|---|
CFindReplaceDialog::CFindReplaceDialog | Call this function to construct a CFindReplaceDialog object. |
Name | Description |
---|---|
CFindReplaceDialog::Create | Creates and displays a CFindReplaceDialog dialog box. |
CFindReplaceDialog::FindNext | Call this function to determine whether the user wants to find the next occurrence of the find string. |
CFindReplaceDialog::GetFindString | Call this function to retrieve the current find string. |
CFindReplaceDialog::GetNotifier | Call this function to retrieve the FINDREPLACE structure in your registered message handler. |
CFindReplaceDialog::GetReplaceString | Call this function to retrieve the current replace string. |
CFindReplaceDialog::IsTerminating | Call this function to determine whether the dialog box is terminating. |
CFindReplaceDialog::MatchCase | Call this function to determine whether the user wants to match the case of the find string exactly. |
CFindReplaceDialog::MatchWholeWord | Call this function to determine whether the user wants to match entire words only. |
CFindReplaceDialog::ReplaceAll | Call this function to determine whether the user wants all occurrences of the string to be replaced. |
CFindReplaceDialog::ReplaceCurrent | Call this function to determine whether the user wants the current word to be replaced. |
CFindReplaceDialog::SearchDown | Call this function to determine whether the user wants the search to proceed in a downward direction. |
Name | Description |
---|---|
CFindReplaceDialog::m_fr | A structure used to customize a CFindReplaceDialog object. |
Unlike the other Windows common dialog boxes, CFindReplaceDialog
objects are modeless, allowing users to interact with other windows while they are on screen. There are two kinds of CFindReplaceDialog
objects: Find dialog boxes and Find/Replace dialog boxes. Although the dialog boxes allow the user to input search and search/replace strings, they do not perform any of the searching or replacing functions. You must add these to the application.
To construct a CFindReplaceDialog
object, use the provided constructor (which has no arguments). Since this is a modeless dialog box, allocate the object on the heap using the new
operator, rather than on the stack.
Once a CFindReplaceDialog
object has been constructed, you must call the Create member function to create and display the dialog box.
Use the m_fr structure to initialize the dialog box before calling Create
. The m_fr
structure is of type FINDREPLACE. For more information on this structure, see the Windows SDK.
In order for the parent window to be notified of find/replace requests, you must use the Windows RegisterWindowMessage function and use the ON_REGISTERED_MESSAGE message-map macro in your frame window that handles this registered message.
You can determine whether the user has decided to terminate the dialog box with the IsTerminating
member function.
CFindReplaceDialog
relies on the COMMDLG.DLL file that ships with Windows versions 3.1 and later.
To customize the dialog box, derive a class from CFindReplaceDialog
, provide a custom dialog template, and add a message map to process the notification messages from the extended controls. Any unprocessed messages should be passed to the base class.
Customizing the hook function is not required.
For more information on using CFindReplaceDialog
, see Common Dialog Classes.
CFindReplaceDialog
Header: afxdlgs.h
Constructs a CFindReplaceDialog
object.
CFindReplaceDialog();
Because the CFindReplaceDialog
object is a modeless dialog box, you must construct it on the heap by using the new
operator.
During destruction, the framework tries to perform a delete this;
on the pointer to the dialog box. If you created the dialog box on the stack, the this
pointer does not exist and undefined behavior may result.
For more information on the construction of CFindReplaceDialog
objects, see the CFindReplaceDialog overview. Use the CFindReplaceDialog::Create member function to display the dialog box.
[!code-cppNVC_MFCDocView#170]
Creates and displays either a Find or Find/Replace dialog box object, depending on the value of bFindDialogOnly
.
virtual BOOL Create(
BOOL bFindDialogOnly,
LPCTSTR lpszFindWhat,
LPCTSTR lpszReplaceWith = NULL,
DWORD dwFlags = FR_DOWN,
CWnd* pParentWnd = NULL);
bFindDialogOnly
Set this parameter to TRUE to display a Find dialog box. Set it to FALSE to display a Find/Replace dialog box.
lpszFindWhat
Pointer to the default search string when the dialog box appears. If NULL, the dialog box does not contain a default search string.
lpszReplaceWith
Pointer to the default replacement string when the dialog box appears. If NULL, the dialog box does not contain a default replacement string.
dwFlags
One or more flags you can use to customize the settings of the dialog box, combined using the bitwise OR operator. The default value is FR_DOWN, which specifies that the search is to proceed in a downward direction. See the FINDREPLACE structure in the Windows SDK for more information on these flags.
pParentWnd
A pointer to the dialog box's parent or owner window. This is the window that will receive the special message indicating that a find/replace action is requested. If NULL, the main window of the application is used.
Nonzero if the dialog box object was successfully created; otherwise 0.
In order for the parent window to be notified of find/replace requests, you must use the Windows RegisterWindowMessage function whose return value is a message number unique to the application's instance. Your frame window should have a message map entry that declares the callback function ( OnFindReplace
in the example that follows) that handles this registered message. The following code fragment is an example of how to do this for a frame window class named CMyRichEditView
:
[!code-cppNVC_MFCDocView#171] [!code-cppNVC_MFCDocView#172] [!code-cppNVC_MFCDocView#173]
Within your OnFindReplace
function, you interpret the intentions of the user by using the CFindReplaceDialog::FindNext and CFindReplaceDialog::IsTerminating methods and you create the code for the find/replace operations.
See the example for CFindReplaceDialog::CFindReplaceDialog.
Call this function from your callback function to determine whether the user wants to find the next occurrence of the search string.
BOOL FindNext() const;
Nonzero if the user wants to find the next occurrence of the search string; otherwise 0.
Call this function from your callback function to retrieve the default string to find.
CString GetFindString() const;
The default string to find.
[!code-cppNVC_MFCDocView#69]
Call this function to retrieve a pointer to the current Find Replace dialog box.
static CFindReplaceDialog* PASCAL GetNotifier(LPARAM lParam);
lParam
The lparam value passed to the frame window's OnFindReplace
member function.
A pointer to the current dialog box.
It should be used within your callback function to access the current dialog box, call its member functions, and access the m_fr
structure.
See CFindReplaceDialog::Create for an example of how to register the OnFindReplace handler to receive notifications from the Find Replace dialog box.
[!code-cppNVC_MFCDocView#69]
Call this function to retrieve the current replace string.
CString GetReplaceString() const;
The default string with which to replace found strings.
See the example for CFindReplaceDialog::GetFindString.
Call this function within your callback function to determine whether the user has decided to terminate the dialog box.
BOOL IsTerminating() const;
Nonzero if the user has decided to terminate the dialog box; otherwise 0.
See the example for CFindReplaceDialog::GetFindString.
Used to customize a CFindReplaceDialog
object.
FINDREPLACE m_fr;
m_fr
is a structure of type FINDREPLACE. Its members store the characteristics of the dialog-box object. After constructing a CFindReplaceDialog
object, you can use m_fr
to modify various values in the dialog box.
For more information on this structure, see the FINDREPLACE
structure in the Windows SDK.
See the example for CFindReplaceDialog::CFindReplaceDialog.
Call this function to determine whether the user wants to match the case of the find string exactly.
BOOL MatchCase() const;
Nonzero if the user wants to find occurrences of the search string that exactly match the case of the search string; otherwise 0.
Call this function to determine whether the user wants to match entire words only.
BOOL MatchWholeWord() const;
Nonzero if the user wants to match only the entire words of the search string; otherwise 0.
Call this function to determine whether the user wants all occurrences of the string to be replaced.
BOOL ReplaceAll() const;
Nonzero if the user has requested that all strings matching the replace string be replaced; otherwise 0.
Call this function to determine whether the user wants the current word to be replaced.
BOOL ReplaceCurrent() const;
Nonzero if the user has requested that the currently selected string be replaced with the replace string; otherwise 0.
Call this function to determine whether the user wants the search to proceed in a downward direction.
BOOL SearchDown() const;
Nonzero if the user wants the search to proceed in a downward direction; 0 if the user wants the search to proceed in an upward direction.