4.5.1 Displaying the Find Dialog Box

The Find dialog box contains controls that make it possible for a user to specify the following

The string that the application should find

Whether the string specifies a complete word or part of a word

Whether the application should match the case of the specified string

The direction in which the application should search (preceding or following the current cursor location)

Whether the application should resume the search, searching for the next occurrence of the string

Following is a Find dialog box.

To display the Find dialog box, you need to initialize a FINDREPLACE structure and call the FindText function. Members of the FINDREPLACE structure contain information about such items as the following:

Which window owns the dialog box

How the application should perform the search

A character buffer that is to receive the string

To initialize the FINDREPLACE structure, you need to perform the following tasks:

1.Set the lStructSize member by using the sizeof operator.

2.Set the hwndOwner member by using the handle that identifies the owner window of the dialog box.

3.If you are customizing the Find dialog box, set the hInstance member to identify the instance of the module that contains your custom dialog box template.

4.Set the Flags member to indicate the selection state of the dialog box options. (For example, setting the FR_NOUPDOWN flag disables the Up and Down buttons, setting the FR_NOWHOLEWORD flag disables the Match Whole Word Only check box, and setting the FR_NOMATCHCASE flag disables the Match Case check box).

5.If you are supplying a custom dialog box template or hook function, set additional flags in the Flags member.

6.Set the lpstrFindWhat member to point to the buffer that will receive the string to be found.

7.Set the wFindWhatLen member to specify the size, in bytes, of the buffer to which lpstrFindWhat points.

8.Set the lCustData member with any custom data your application may need to access.

9.If your application customizes the Find dialog box, set the lpfnHook member to point to your hook function.

10.If your application uses a custom dialog box template, set the lpTemplateName member to point to the string that identifies the template.

The following example initializes the FINDREPLACE structure and then calls the FindText function. This structure should be global or declared as a static variable.

FINDREPLACE fr;

/* Set all structure fields to zero. */

memset(&fr, 0, sizeof(FINDREPLACE));

fr.lStructSize = sizeof(FINDREPLACE);
fr.hwndOwner = hwnd;
fr.lpstrFindWhat = szFindWhat;
fr.wFindWhatLen = sizeof(szFindWhat);

hDlg = FindText(&fr);

break;