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

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

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