The Find and Replace dialog boxes differ from the other common dialogs in two respects: First, they are modeless; and second, their respective dialog box procedures send messages to the application that calls the FindText or ReplaceText function. These messages contain data specified by the user in the dialog box controls, such as the direction in which the application should search for a string, whether the application should match the case of the specified string, and whether the application should match the entire string.
To process messages from a Find or Replace dialog box, an application must register the dialog box's unique message, FINDMSGSTRING.
The application registers this message with the RegisterWindowMessage function. Once the application registers the message, it uses the function's return value to identify messages from the Find or Replace dialog box. The following example registers the message with the RegisterWindowMessage function:
UINT uFindReplaceMsg;
/* Register the FindReplace message. */
uFindReplaceMsg = RegisterWindowMessage(FINDMSGSTRING);
After the application registers this message, it can process messages for the Find or Replace dialog box by using the RegisterWindowMessage return value. The following example processes messages for the Find dialog box and then calls its own SearchFile function to locate the string of text. If the user is closing the dialog box (that is, if the Flags member of FINDREPLACE is FR_DIALOGTERM), the handle should be invalidated and the procedure should return zero.
LRESULT CALLBACK MainWndProc(HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam)
{
FINDREPLACE FAR* lpfr;
if (msg == uFindReplaceMsg) {
lpfr = (FINDREPLACE FAR*) lParam;
SearchFile((BOOL) (lpfr->Flags & FR_DOWN),
(BOOL) (lpfr->Flags & FR_MATCHCASE));
return 0;
}