I was going over the editorial calendar for MacTutor a few weeks back. I was trying to schedule all the fine articles we have on file for future publication. In short, I was trying to do the impossible. But I do get a feeling of accomplishment if I come away without feeling terrible for not placing everyones article or without a headache.

To continue, I came across Paul Potts article, and scheduled it for April for our Dialog issue. I chided myself for not being as good with my modal dialogs. It was so easy to make them a little more friendlier to the user. I decided to come up with a set of useful dialog routines of my own.

When writing an application, there are many dialogs that are similar in nature. They usually have one to three buttons with a message similar to, Save changes to , You cannot do that!, or I am deleting all funds in your Swiss bank account. If youre like most people, you have a general dialog box and a general set of routines to put it up with your message in it. It is usually not as robust as it should be. I decided to write a few routines for a general message dialog, Messenger.

Messenger Structure

The heart of messenger is located in the global variable, MInfo. This structure contains the information needed to put up a dialog box with/without an icon and from 0 to 3 buttons. The structure is declared as follows:

defaultItem: Indicates the button considered the default, or the button which responds to return or enter key. It draws a bold, rounded rectangle around that button.

Buttons: The number of buttons in the dialog. Valid numbers are 0 through 3. If there are 0 buttons then a mouse click, return, or enter will exit the dialog.

dPlace: The dialog is placed in the center or top third of the screen.

dIcon: Specifies the resource ID of the icon or -1 if no icon. You may call the stop, note, or caution icons with their appropriate constant values.

IconRect, Button1Rect, Button2Rect, Button3Rect, TextRect, and dRect: These are the enclosing rectangles for the icon, buttons, text, and dialog. You need only set the top left point to (0,0) and the bottom right point to the width and height of the object. The dialog handler will take care of positioning them for you.

Button1, Button2, Button3: The titles of the buttons to display.

CharEquiv: The character equivalents for the buttons. Two characters may be specified for each button: the first two for button 1, the next two for button 2, and the last two for button 3.

Arrange: This flag has a valid value of HORIZONTAL or VERTICAL, depending on if you want your buttons across the bottom or down the right side.

AddFilter: In addition to the Messengers own filter proc which handles character equivalents, updates, and so forth, an additional filter may be designated for further processing. Just pass nil if none, or pass a filter proc of the form:

/* 2 */
pascal Boolean MyFilter(itemHit, theDialog);

itemHit is the item number of the dialog hit; theDialog is the dialog pointer, and you return true if you wish to exit the modal dialog loop and false if not.

Messenger Routines and Globals

menu_height: This is a global of the height in pixels the menu is. It is initialized in InitMessage().

InitMessage: This call is made to put valid values in the MInfo structure. You may modify them to your default dialog style. Call this at the beginning of your application and whenever you wish to reset the default values.

GetMInfo, SetMInfo: I like those calls to GetPort and SetPort, and so I have implemented similar calls. With GetMInfo, you store the old values of MInfo, and with SetMInfo, you set it to your values.

DoMessage: This is the main routine that does all the work. It takes the values in MInfo, creates the dialog, arranges the items, sets the ParamText with the strings you pass, and calls ModalDialog. It returns the number of the last item hit, or 0 if something went wrong.

Message: This is a standard, general dialog routine. It handles those dialogs with familiar button titles such as OK.

There are a few other routines, such as positioning a small rectangle in the center or the top third of a larger rectangle (such as screenBits.bounds). The routine will find the top third or center line of the larger rectangle and then centers the smaller rectangle on that line. BoldRect() is used for hiliting the default button. SaveChanges() allows you to pass the file name and a before closing/quitting string. AnOSError() is an error handler that returns FALSE if no error is passed to it; otherwise it puts up an appropriate dialog and returns TRUE.

The Code

Messenger.h: This is the header file for Messenger. Include this file in your main routine to call InitMessage, and also include it in every file that makes use of the Messenger routines.

Messenger.c: This is the code for Messenger. I would suggest, again, that you change InitMessage to the set up that you are most likely to use in your application.

About.c: In this file, there are a couple of examples of how to use Messenger. The D_About procedure puts up an About dialog. D_Example procedure shows the use of the additional filter procedure.

Messenger.r: This is the resource file for messenger. Be sure to include it in your resource file. Also, do not use the same IDs for the templates.

Where to go from here?

One direction to go is to improve on the routines. How about three character equivalents? Or get rid of the resource file and do everything in memory? Or add functionality to the positioning routines? Perhaps a few more general dialog routines could be added.

THINK C 4.0 have Estr resource types for their class library. These are string resources with English error messages whose IDs correspond to error numbers. For those who are still having difficulty with OOP, perhaps you could extend the error dialog to handle them.

Software Updates via MacUpdate

EtreCheck 3.1.5 - For troubleshooting yo...

EtreCheck is an app that displays the important details of your system configuration and allow you to copy that information to the Clipboard. It is meant to be used with Apple Support Communities to... Read more

WALTR 2 2.0.8 - $39.95

WALTR 2 helps you wirelessly drag-and-drop any music, ringtones, videos, PDF, and ePub files onto your iPhone, iPad, or iPod without iTunes. It is the second major version of Softorino's critically-... Read more

Carbon Copy Cloner 4.1.12 - Easy-to-use...

Carbon Copy Cloner backups are better than ordinary backups. Suppose the unthinkable happens while you're under deadline to finish a project: your Mac is unresponsive and all you hear is an ominous,... Read more

Dropbox 16.3.27 - Cloud backup and synch...

Dropbox is an application that creates a special Finder folder that automatically syncs online and between your computers. It allows you to both backup files and keep them up-to-date between systems... Read more

Microsoft OneNote 15.29 - Free digital n...

OneNote is your very own digital notebook. With OneNote, you can capture that flash of genius, that moment of inspiration, or that list of errands that's too important to forget. Whether you're at... Read more

Spotify 1.0.44.100. - Stream music, crea...

Spotify is a streaming music service that gives you on-demand access to millions of songs. Whether you like driving rock, silky R&B, or grandiose classical music, Spotify's massive catalogue puts... Read more

SpamSieve 2.9.27 - Robust spam filter fo...

SpamSieve is a robust spam filter for major email clients that uses powerful Bayesian spam filtering.
SpamSieve understands what your spam looks like in order to block it all, but also learns what... Read more

VueScan 9.5.62 - Scanner software with a...

VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more

Fantastical 2.3.2 - Create calendar even...

Fantastical 2 is the Mac calendar you'll actually enjoy using. Creating an event with Fantastical is quick, easy, and fun:
Open Fantastical with a single click or keystroke
Type in your event... Read more

PCalc 4.4.4 - Full-featured scientific c...

PCalc is a full-featured, scriptable scientific calculator with support for hexadecimal, octal, and binary calculations, as well as an RPN mode, programmable functions, and an extensive set of unit... Read more

Latest Forum Discussions

Christmas is fast approaching and that means it's time to prepare for Santa's yearly pilgrimage around the globe. Christmas Eve is an exciting time as parents help their kids get ready to welcome Santa. You've got the cookies and milk all planned... | Read more »

Galaxy on Fire 3 and four other fantasti...

Galaxy on Fire 3 - Manticore brings the series back for another round of daring space battles. It's familiar territory for folks who are familiar with the franchise. If you've beaten the game and are looking to broaden your horizons, might we... | Read more »

The best apps for your holiday gift exch...

What's that, you say? You still haven't started your holiday shopping? Don't beat yourself up over it -- a lot of people have been putting it off, too. It's become easier and easier to procrastinate gift shopping thanks to a number of apps that... | Read more »

MyTona, based in the chilly Siberian city of Yakutsk, has brought a little festive fun to its hidden object game Seekers Notes: Hidden Mystery. The Christmas update introduces some new inhabitants to players, and with them a chance to win plenty of... | Read more »

PINE GROVE 1.0
Device: iOS Universal
Category: Games
Price: $1.99, Version: 1.0 (iTunes)
Description:
A pine grove where there are no footsteps of people due to continuous missing cases. The case is still unsolved and nothing has... | Read more »

Niantic teases new Pokémon announcement...

After rumors started swirling yesterday, it turns out there is an official Pokémon GO update on its way. We’ll find out what’s in store for us and our growing Pokémon collections tomorrow during the Starbucks event, but Niantic will be revealing... | Read more »

3 reasons why Nicki Minaj: The Empire is...

Nicki Minaj is as business-savvy as she is musically talented and she’s proved that by launching her own game. Designed by Glu, purveyors of other fine celebrity games like cult favorite Kim Kardashian: Hollywood, Nicki Minaj: The Empire launched... | Read more »

Clash of Clans is getting its own animat...

Riding on its unending wave of fame and success, Clash of Clans is getting an animated web series based on its Clash-A-Rama animated shorts.As opposed to the current shorts' 60 second run time, the new and improved Clash-A-Rama will be comprised of... | Read more »

Price Scanner via MacPrices.net

Never Settle for Low Performing Wifi With iOS...

AppYogi Software has announced the release of WiFi Signal Strength Status App 1.0, the company’s new utility developed exclusively for macOS. WiFi Signal Strength Status App features a unique, single... Read more

DietSensor, Inc., a developer of smart food and nutrition applications designed to fight diabetes and obesity and help improve overall fitness, has announced the launch of its DietSensor app for... Read more

Best Buy has dropped their price on the 64GB Apple TV to $159.99 including free shipping. That’s $40 off MSRP.
32GB Apple TVs are on sale right now for $98 on Sams Club’s online store. That’s $51 off... Read more

12-inch Retina MacBooks, Apple refurbished, n...

Apple has restocked a full line of Certified Refurbished 2016 12″ Retina MacBooks, now available for $200-$260 off MSRP. Refurbished 2015 models are available starting at $929. Apple will include a... Read more

Apple has Certified Refurbished 13″ MacBook Airs available starting at $849. An Apple one-year warranty is included with each MacBook, and shipping is free:
- 13″ 1.6GHz/8GB/128GB MacBook Air: $849 $... Read more

Apple refurbished iMacs available for up to $...

Apple has Certified Refurbished 2015 21″ & 27″ iMacs available for up to $350 off MSRP. Apple’s one-year warranty is standard, and shipping is free. The following models are available:
- 21″ 3.... Read more

MacTech is a registered trademark of Xplain Corporation. Xplain, "The journal of Apple technology", Apple Expo, Explain It, MacDev, MacDev-1, THINK Reference, NetProfessional, Apple Expo, MacTech Central, MacTech Domains, MacNews, MacForge, and the MacTutorMan are trademarks or service marks of Xplain Corporation. Sprocket is a registered trademark of eSprocket Corporation. Other trademarks and copyrights appearing in this printing or software remain the property of their respective holders. Not responsible for typographical errors.

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.