An application uses the MLM_SEARCH message and the MLE_SEARCHDATA data structure to search for strings in MLE text. The first parameter of the MLM_SEARCH message is an array of flags that specify the style of the search. The application can set the MLFSEARCH_CASESENSITIVE flag if a case-sensitive search is required. If the application sets the MLFSEARCH_SELECTMATCH flag, the MLE field control highlights a matching string and, if necessary, scrolls the string into view. An application can use the MLFSEARCH_CHANGEALL flag to replace every occurrence of the string with the string specified in the pchReplace member of the MLE_SEARCHDATA data structure.
The second parameter of the MLM_SEARCH message is a pointer to an MLE_SEARCHDATA data structure that contains information required to perform the search operation. This data structure includes a pointer to the string and, if the MLFSEARCH_CHANGEALL flag is set in the MLM_SEARCH message, a pointer to the replacement string. The iptStart and iptStop members specify the starting and ending positions of the search. These positions are specified as offsets from the beginning of the MLE field. A value of -1 in the iptStart member causes the search to start at the current cursor position. A negative value in the iptStop member causes the search to end at the end of the MLE field. If a matching string is found, the MLE field control returns the length of the string in the cchFound member.
The following code fragment uses an entry field to obtain a search string from the user, then searches an MLE field for an occurrence of the string. The search begins at the current cursor position and ends at the end of the MLE text. When the MLFSEARCH_SELECTMATCH flag is specified, the MLE field control highlights a matching string and scrolls it into view.
The following code fragment shows how to search MLE text:
#define IDD_SEARCHFIELD 101 HWND hwnd; HWND hwndEntryFld; HWND hwndMle; MLE_SEARCHDATA mlesrch; CHAR szSearchString[64]; /* Obtain the handle of the entry field containing the search string */ hwndEntryFld = WinWindowFromID(hwnd, IDD_SEARCHFIELD); /* Obtain the search string from the entry field */ WinQueryWindowText(hwndEntryFld, sizeof(szSearchString), szSearchString); /* Fill the MLE_SEARCHDATA data structure */ mlesrch.cb = sizeof(mlesrch); /* Structure size */ mlesrch.pchFind = szSearchString; /* Search string */ mlesrch.pchReplace = NULL; /* No replacement string */ mlesrch.cchFind = 0; /* Not used */ mlesrch.cchReplace = 0; /* Not used */ mlesrch.iptStart = -1; /* Start at cursor position */ mlesrch.iptStop = -1; /* Stop at end of file */ /* Start the search operation */ WinSendMsg(hwndMle, MLM_SEARCH, MPFROMLONG(MLFSEARCH_SELECTMATCH), MPFROMP(&mlesrch));