FINDTEXT Structure
The FINDTEXT structure contains the parameters that enable an application to search for a string of text within a Rich Edit control.
Syntax
typedef struct _findtext {
CHARRANGE cp; // Range to search
LPSTR lpstrText; // Pointer to the search string (ANSI)
} FINDTEXT, *LPFINDTEXT;
Members
| Member | Type | Description |
|---|---|---|
cp |
CHARRANGE |
The character range to be searched. The start and end positions are specified in character indices. |
lpstrText |
LPSTR |
Pointer to a null‑terminated ANSI string that contains the text to locate. |
Remarks
- The
FINDTEXTstructure is used with theEM_FINDTEXTmessage (orEM_FINDTEXTEXfor Unicode). - To search using Unicode text, use the
FINDTEXTEXstructure and theEM_FINDTEXTEXmessage. - The
cprange can be set to{0, -1}to search the entire document.
Example
#include <windows.h>
#include <richedit.h>
void FindString(HWND hEdit, LPCSTR szFind) {
FINDTEXT ft;
ft.lpstrText = (LPSTR)szFind;
ft.cp.cpMin = 0;
ft.cp.cpMax = -1; // Search whole text
LONG index = SendMessage(hEdit, EM_FINDTEXT, 0, (LPARAM)&ft);
if (index != -1) {
// Highlight the found text
CHARRANGE cr = { index, index + lstrlen(szFind) };
SendMessage(hEdit, EM_EXSETSEL, 0, (LPARAM)&cr);
}
}