Flex Alert
Volume Number: 7
Issue Number: 1
Column Tag: C Workshop
FlexAlert 
By Ken Earle, Toronto, Canada
Alert Shrink Wrapping
How do you avoid having ugly alerts without running the risk of having your
message clipped off at the bottom? If your alert messages vary a fair bit in length, or if
they are to be translated into other languages, then one size alert doesn’t fit all. The
point of an alert is to guide and if appropriate reassure the user when the going gets
tough: ugly-looking or vague-sounding messages just don’t cut the mustard.
FlexAlert() takes a pointer to the message you wish to show, and “shrinkwraps”
the alert window around the text by finding the smallest text box that looks good around
the text. You may also choose from a selection of buttons and icons to be included with
the alert. Positioning of the alert on the screen is automatic, but you can control the
vertical placement of alerts by changing the definition or value of ALRTTOP below (two
reasonable definitions are provided).
Three ALRT and DITL resources are required, corresponding to the three possible
button combinations. Here’s how to whip them up with ResEdit--note that positions and
sizes of all items and windows are entirely unimportant, but the item numbers are
important. If you use different resource ID’s be sure to update the defined constants
JUST_OKALERTID, OK_CANALERTID, and CAN_OKALERTID near the top of FlexAlert.c.
ALRT and DITL 274:
item 1; button, enabled, “OK”
item 2; static text, disabled, “^0^1^2^3”
ALRT and DITL 272:
item 1; button, enabled, “OK”
item 2; button, enabled, “Cancel”
item 3; static text, disabled, “^0^1^2^3”
ALRT and DITL 273:
item 1; button, enabled, “Cancel”
item 2; button, enabled, “OK”
item 3; static text, disabled, “^0^1^2^3”
Use the “display as text” menu item in ResEdit while viewing the alerts to set
the characteristics of the alerts the way you want (but leave the ‘2 bold’ boxes