TweetFollow Us on Twitter

Staged Alerts
Volume Number:2
Issue Number:7
Column Tag:Basic School

ResEdit Creates Staged Alerts for Basic

By Dave Kelly, Editorial Board

Alerts and MS Basic

Let's talk about how to set up your own Alerts. For any of you that are not sure what alerts are, just pull down the 'About' menu from just about any application. The dialog box in an 'About' menu item is a form of an alert that usually gives information about who wrote the application. For Macintosh programmers who are experienced in C or Pascal or other languages with Toolbox access, Alerts are probably old hat. MS BASIC programs have traditionally been using one of four regular windows for Alerts with the simulated Alert itself being controlled by programming within the BASIC program instead of by the Toolbox.

User Modified Programs

One feature not found on other computers is the ability to modify or customize the text, menus etc. after the program is written. This ability is only found in programs that use resources to store the menu, window, dialog or alert information. Therefore, since you must set up the information inside the BASIC program when using MS Basic, you must rewrite that section of BASIC code in order to change the information. For example, to change a menu from English to French would require that you translate each MENU command to French and modify each program line. That's not too hard to do, and not necessary very often, but still a disadvantage over other Mac languages.

How many times have you tried to figure out what size window you need in your program and have to guess at what the window coordinates are on the screen and then guess where the controls will be inside the window? What a pain. I tried to help out several issues of MacTutor back with the Rectangle Sizer program. That was ok, but you still had to use some trial and error till you got everything to look just right. The elegant solution is not to try to create your own custom windows in BASIC, but to create custom Alerts which may be used as often as desired, created much easier using ResEdit. (For a good discussion of Resource Editors, see Joel West's column in the May, 1986 MacTutor.)

CLR ToolLib Gives Access to Alert Resources

MS BASIC alone still has the limitation of having to set up Alerts as windows and simulate Alerts in the windows from Basic. Using the CLR ToolLib, Alerts are called as easily in BASIC as they are in other Toolbox Languages (C, Pascal, etc). Any language which has access to the Toolbox commands can use this column to help them understand Alerts better.

Alerts are probably one of the simplest routines to use. In most programs, you have to process the event in order to tell what selections are made. This is true when you set up your own dialogs (as you must do with MS BASIC). By using Alerts, you let the Toolbox ROM do part of the work for you. The toolbox automatically tracks the movement of the mouse for you and checks to see what controls or edit fields have been accessed.

There are three major kinds of Dialogs:

(1) Alerts

(2) Modal Dialogs

(3) Modeless Dialogs

The lowest level is Alerts, normally used to display error messages or other information. The Alert is always front-most on the screen and the only action which is allowed, takes place in the dialog box. The next level of dialogs are called 'modal dialogs'. In this 'mode', the dialog box will respond to the mouse and the keyboard. The modal dialog also remains frontmost on the screen and the user may dismiss the dialog with the keyboard or the mouse. 'Modeless dialogs' are dialogs which the user may move around on the screen, has a go-away box, and the user can activate other windows (bring to the front). This is the mode supported by MS BASIC except that MS BASIC can't save a set dialog as a resource for repeated use. Instead you have to dedicate one of MS BASIC's four windows (only four windows may be open at one time) to be the desired dialog. [Note: ResEdit is available on the Utilities Disk. See the MacTutor mail order store for information. -Ed.]

How to Use ResEdit

Before we get into how to call the Alerts using CLR Libraries and MS BASIC, let's set up our own custom Alert file using ResEdit. ResEdit is considered the easiest way to set up your own Alert resources. Here's what you do:

Start up ResEdit and either open a current file (the one you want to store your alert in) or open a new file. To open a new file, select NEW from the File menu.

Figure 1

When selecting a new file, you must supply a filename for your file (In the example, the filename is 'MacTutor Alerts'). Next select New to create a new resource in the newly created file. Enter the new Type Name which is the name of the type of resource to be created (see figure 1). In this case we will choose ALRT to create an Alert resource. ResEdit automatically assigns an unused ID number for the Alert. We will use the default in this case which is 2252 (your default ID number will probably be different). After selecting OK, then select NEW from the File menu. A window like that in figure 2 will appear and you can now graphically adjust the position of the Alert box by dragging it around in the window. You may want to wait till the Alert is complete to adjust the final position. The Alert box can be stretched by pointing the mouse about 1/8 inch from the bottom right corner (inside the Alert box) and dragging the corner out to the correct size.

Figure 2

Next toggle the graphics to text by selecting the ALRT menu. Figure 3 allows you to see the actual screen coordinates where the Alert will appear. You can edit these from here by changing top, bottom, left or right. ResID is the DITL (Dialog ITem List) id number. Every alert has an Dialog Item list associated with it which gives information about what is in the Alert. We will create our own DITL resource in a few moments.

Figure 3

The remainder of the window shown in Figure 3 involves staged Alerts. This means that your alerts can be staged to behave differently each time they occur. Up to 4 stages can be defined by selecting the ResEdit controls shown in figure 3. The '2 bold' button will cause item #2 to be the default item (the item shown in bold in the alert box which can be selected automatically with the return key). If not selected then item #1 will be the default (bold) item. The 'drawn' button indicates if the alert will be drawn. If the 'drawn' button is selected in stage 1 and not in stage 2, the alert will be drawn the first time it is called by the application program, but the second time called the alert would not be drawn. The sound is a number from 0 to 3 indicating the number of beeps to sound when the alert is selected. There is also a way to call your own sound routine, but that subject will not be covered here. You can experiment with values of sound (0-3) and run the demo program to see how it works (or write your own).

You can also find out what stage the last alert is currently up to by using the system global called ACount located at &HA9B. You may reset the alert to the first stage by using the system global ACount (use POKE &HA9B, &HFF:POKE &HA9A,&HFF to reset to 0 ). The resource ID of the last alert is found in the system variable ANumber. Use PEEK(&HA9A)*256)+PEEK(&HA9B) to display ANumber. It appears from the demo program included with this column that ANumber doesn't get incremented when the 4th stage is used. ANumber remains a three after the 3rd stage. That's ok, because all subsequent use of the alert will result in the 4th stage condition anyway.

The DITL Resource

To create the DITL resource, close the Alert resource windows back to the MacTutor Alerts window (i. e. leave your file open, but you may want to save what you have done so far by closing the file window also). Now with the MacTutor Alerts window open we again select a new resource by selecting NEW from the File menu. You should see the window of figure 4. Just like the way we created the ALRT resource, select the New Type Name of DITL and select OK.

Figure 4

Now you are ready to create each item of the Dialog ITem List (DITL) resource. Select New to create a new dialog item. An Edit Item window will appear similar to the one in figure 5 (figure 5 is for item #4, our first item will be item #1). Item #1 will be the item to be used as the default (shown in bold when the Alert is displayed) unless Item #2 is selected when setting up the Alert stages, in which case Item #2 will be displayed in bold. Items can be buttons, icons, or pictures. They could also be a special User item which I won't discuss here. Enabled and Disabled refers to whether or not you will be able to dismiss the Alert box by selecting the indicated item. You can change the item location from this window, but by simply closing the window you will see the item appear with grabbers for resizing the item. Note that you may choose to have a picture default to its original picture size to maintain the integrity of the picture from the menu.

Figure 5

Using Pictures or Icons

To use pictures or icons you should enter the Resource ID (as in figure 5) for the Picture or Icon resource to be used. It is common to use the same ID for the picture as for the alert, but you don't have to. Just in case you don't have a picture resource available, one can be created very easily. CLR ToolLib comes with a Scrapbook mover utility which will convert pictures stored in the Scrapbook to PICT files. To use it you may use an existing file or you can create one. You may create one by selecting (similar to what we did back in figure 4) the PICT file type as shown in figure 6.

Figure 6

At this point you can use the Scrapbook Mover (from CLR) to move a picture into the PICT resource. You may already have a PICT resource already that you wish to use. After you have set up your PICT resource with the picture you will use, choose Get Info and change the PICT ID# to the same as the alert we will be using as in figure 7. The important thing is that the ID# in the DITL resource cooresponds to the ID# of the PICT resource to be used. In our demo program we have two of our favorite PICTures in our PICT resource. You will have to provide your own or else use the MacTutor source code disk to use our own PICT resource. Be sure to change the ID numbers in the basic program to match your resources.

Back to the DITL resource for a moment. ResEdit provides the ability to customize your Alerts graphically. You can move each item around to suit the application you are programming. Figure 8 shows the Dialog item list for one of our sample Alerts (used in the demo basic program).

Another item worth mentioning is that in Alerts that contain only a picture, the picture should be the 2nd item or it will be set in bold as the default item. You can either create a dummy unselectable text field as item #1 or you can set the default item to item#2 by changing the staging setup (as in figure 3). You could hide a dialog item by moving it outside of the dialog window range. In figure 9 the cursor is pointing at item #1 which can be hidden from view by going to the Dialog Item List (DITL) and enlarging the window and then dragging the item to a location outside of the dialog window size. Figure 10 shows the Alert box with item#1 hidden outside of the window.

Figure 12 shows the final Alert resource as displayed graphically with ResEdit (See next page). Your custom dialog will be different than this of course.

Figure 7

Figure 8

Figure 9

Figure 10

One more thing in conclusion: Select Get Info for the ALRT resource and set the Preload and Purgeable buttons. Preload forces the entire Alert (PICT / ICON, DITL and ALRT resources to allocate memory and be loaded into the heap. The purgeable button lets the alert occupy memory until some other resource needs the memory. The Alert will be copied from the disk when it is first needed and as long as memory is not required for something else, it may be reused if desired. Resources are accessed from MSBASIC with the CLR command: Alert fileRefNum%,type%,id%,item%. Instructions for its use are clearly identified on page 40 of the CLR libraries manual. [Note: The CLR ToolLib is available from the MacTutor Mail Order Store. -Ed.] Setting the Preload and Purgeable buttons is shown below in figure 11.

Figure 11

Figure 12

Alert Demo Program

The following MS Basic program demonstrates how Basic, using the CLR ToolLib library, can access a resource file and display an alert. This program opens the ToolLib library file, and the 'MacTutor Alerts' file of resources that we just created using the ResEdit program. Both the ToolLib file and the resource file 'MacTutor Alerts' must be in the same folder as MS Basic as the program below is written. If you want either file in another folder, you must specify the complete path file name so the files can be found. Otherwise, Basic defaults the path name to the folder where it found the Basic interpreter.

The first alert is the MacTutor icon box with the three choices about reading MacTutor. The ID number for this alert is 2252. When we start this alert by calling the subroutine 'doalert', that subroutine actually calls the alert four times. This gives the user an opportunity to click on all three boxes. After each alert, we print the information on the staging status and which button was pressed.

The second alert, ID 12696, displays the MacTutor magazine header, and again, through our 'doalert' subroutine, gets called four times. Each time, the stage of the alert increases, as does the number of beeps. After the fourth call, the alert is finished and the program ends.

' Staged Alerts
'©MacTutor 1986
' by Dave Kelly

WINDOW1,"Alert Staging Demo",(2,40)-(510,340)
LIBRARY "ToolLib"
fileRefNum%=0:item%=0
OpenResFile "MacTutor Alerts",fileRefNum%
' Here comes the first Alert
id%=2252
POKE &HA9B,&HFF:POKE &HA9A,&HFF  'Set stage to 0
GOSUB doalert
' Here comes the second Alert
id%=12696
POKE &HA9B,&HFF:POKE &HA9A,&HFF  'Set stage to 0
GOSUB doalert
' All done with this alert business!
CloseResFile fileRefNum%
LIBRARY CLOSE
END

doalert:
Alert fileRefNum%,0,id%,item%
GOSUB printit
Alert fileRefNum%,0,id%,item%
GOSUB printit
Alert fileRefNum%,0,id%,item%
GOSUB printit
Alert fileRefNum%,0,id%,item%
GOSUB printit
RETURN

printit:
TEXTFONT (4):TEXTSIZE (12) 
LOCATE 15,1
PRINT "Alert ID#";(PEEK(&HA98)*256)+PEEK(&HA99)
PRINT "ITEM#";item%;" was selected."
PRINT "Stage #";(PEEK(&HA9A)*256)+PEEK(&HA9B)
RETURN

REdit Decompiles Resources

The following file is a partial disassembly of 'MacTutor Alerts' file using REdit, the European resource editor. REdit can decompile resource files created by ResEdit into a text file for documentation purposes. Unfortunately, it is not complete as the PICT resources are not de-compiled. [REdit is also available on the Utilities Disk. -Ed.]

MacTutor Alerts.rsrc
Type PICT

     ,2252
*   No format specification available.

     ,12696
*   No format specification available.

     ,15941
*   No format specification available.

     ,17658
*   No format specification available.

Type DITL

     ,2252
5
*   1
BtnItem Enabled
16 184 40 264
Yup!

*   2
BtnItem Enabled
56 184 80 264
Yes

*   3
BtnItem Enabled
96 184 120 264
Absolutely

*   4
PicItem Disabled
40 56 116 120
2252

*   5
StatText Disabled
16 8 32 168
Do you read MacTutor?

     ,12696
2
*   1
BtnItem Enabled
208 225 222 263

*   2
PicItem Enabled
25 27 139 443
12696


Type ALRT

     ,2252 (36)
72 126 210 410
2252
F6D4

     ,12696 (36)
68 20 234 490
12696
7654
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »

Price Scanner via MacPrices.net

Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more

Jobs Board

Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.