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

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for $500-$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to $600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at $2969 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to $480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
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
Apple is offering a $50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for $249, Certified Refurbished. That’s $50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to $400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $150-$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering $170-$200 discounts on new...
Amazon is offering a $170-$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
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
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and 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.