Modal Filter
Volume Number: 9
Issue Number: 7
Column Tag: Getting Started
The Modal Dialog Filter 
Preprocessing events for a modal dialog
By Dave Mark, MacTech Magazine Regular Contributing Author
Note: Source code files accompanying article are located on MacTech CD-ROM orsource code disks.
This month has sure been a busy one. I’ve been putting the finishing touches on
Learn C++ on the Macintosh (looks like a July release), while Daniel (now 9 months
old) makes interesting changes to my source code by pounding on my keyboard with his
tiny little fists. Sigh. Despite Daniel’s best efforts, I’ve managed to complete this
month’s program, DLOGFilter. DLOGFilter shows you how to write a filter procedure
for a modal dialog. As usual, we’ll create and run the project this month, then walk
through the source code next month.
Let’s get started...
Creating the DLOGFilter Resources
Create a folder named DLOGFilter in your Development folder. Next, jump into
ResEdit and create a new file named DLOGFilter.π.rsrc inside the DLOGFilter folder.
Create an MBAR resource using the specifications in Figure 1. Be sure that the
MBAR’s resource ID is set to 128.
Next, create three MENU resources using the specifications in Figure 2 as a
guide. Be sure to include a separator line as the second item in all three MENUs.
Remember to type in the appropriate command key equivalents (two for the File menu
and four for the Edit menu).
Figure 1. Specifications for the MBAR resource.
Figure 2. Specifications for the three MENU resources.
Next, create a DLOG resource according to the specifications in Figure 3. Be sure
that the modal dialog window icon (8th from the left) is selected, that the DITL ID is
set to 128 and the Initially visible and Close box check boxes are unchecked, and that
the Top, Left, Height, and Width fields are filled in as noted. Remember, if your DLOG
editor uses Bottom and Right instead of Height and Width, select Show Height & Width
from the DLOG menu.
Figure 3. Specifications for the DLOG resource.
Next, select Auto Position... from the DLOG menu. When the Auto Position... dialog
appears, use the pop-up menus to direct System 7 to automatically center our dialog
on the main screen.
Figure 4. Proper settings for our DLOG’s auto-position dialog.
Next, double-click on the blank dialog box in the middle of the DLOG editing
window to create a new DITL resource with an id of 128. The DITL contains six items.
Create an OK button (Figure 5) and then a Cancel button (Figure 6).
Figure 5. Specifications for the OK button.
Figure 6. Specifications for the Cancel button.
Next, create a static text label (Figure 7) and its corresponding edit text field
(Figure 8). Our dialog filter procedure will limit the number of characters entered in
this field to 10.