ReplaceText

  HWND ReplaceText(lpfr)    
  LPFINDREPLACE lpfr; /* pointer to structure with initialization data */

The ReplaceText function creates a system-defined modeless dialog box that makes it possible for the user to find and replace text within a document. The application must perform the actual find and replace operations.

Parameters

lpfr

Points to a FINDREPLACE structure that contains information used to initialize the dialog box. When the user makes a selection in the dialog box, the system fills this structure with information about the user's selection and then sends a message to the application. This message contains a pointer to the FINDREPLACE structure. The FINDREPLACE structure has the following form:

#include <commdlg.h>

typedef struct tagFINDREPLACE { /* fr */

DWORD lStructSize;

HWND hwndOwner;

HINSTANCE hInstance;

DWORD Flags;

LPSTR lpstrFindWhat;

LPSTR lpstrReplaceWith;

UINT wFindWhatLen;

UINT wReplaceWithLen;

LPARAM lCustData;

UINT (CALLBACK* lpfnHook)(HWND, UINT, WPARAM, LPARAM);

LPCSTR lpTemplateName;

} FINDREPLACE;

Return Value

The return value is the window handle of the dialog box, or it is NULL if an error occurs. An application can use this handle to communicate with or to close the dialog box.

Errors

Use the CommDlgExtendedError function to retrieve the error value, which may be one of the following:

CDERR_FINDRESFAILURE
CDERR_INITIALIZATION
CDERR_LOADRESFAILURE
CDERR_LOADSTRFAILURE
CDERR_LOCKRESFAILURE
CDERR_MEMALLOCFAILURE
CDERR_MEMLOCKFAILURE
CDERR_NOHINSTANCE
CDERR_NOHOOK
CDERR_NOTEMPLATE
CDERR_STRUCTSIZE
FRERR_BUFFERLENGTHZERO

Comments

The dialog box procedure for the ReplaceText function passes user requests to the application through special messages. The lParam parameter of each of these messages contains a pointer to a FINDREPLACE structure. The procedure sends the messages to the window identified by the hwndOwner member of the FINDREPLACE structure. An application can register the identifier for these messages by specifying the commdlg_FindReplace string in a call to the RegisterWindowMessage function.

For the TAB key to function correctly, any application that calls the ReplaceText function must also call the IsDialogMessage function in its main message loop. (The IsDialogMessage function returns a value that indicates whether messages are intended for the Replace dialog box.)