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

Whitethorn Games combines two completely...
If you have ever gone fishing then you know that it is a lesson in patience, sitting around waiting for a bite that may never come. Well, that's because you have been doing it wrong, since as Whitehorn Games now demonstrates in new release Skate... | Read more »
Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »

Price Scanner via MacPrices.net

B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for up to $150 off Apple’s new MSRP, starting at only $849. Free 1-2 day delivery is available to most US... Read more
M2 Mac minis on sale for $100-$200 off MSRP,...
B&H Photo has Apple’s M2-powered Mac minis back in stock and on sale today for $100-$200 off MSRP. Free 1-2 day shipping is available for most US addresses: – Mac mini M2/256GB SSD: $499, save $... Read more
Mac Studios with M2 Max and M2 Ultra CPUs on...
B&H Photo has standard-configuration Mac Studios with Apple’s M2 Max & Ultra CPUs in stock today and on Easter sale for $200 off MSRP. Their prices are the lowest available for these models... Read more
Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more

Jobs Board

Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply 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
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
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
Business Analyst | *Apple* Pay - Banco Popu...
Business Analyst | Apple PayApply now " Apply now + Apply Now + Start applying with LinkedIn Start + Please wait Date:Mar 19, 2024 Location: San Juan-Cupey, PR Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.