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

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 »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
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 below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »
Explore some of BBCs' most iconic s...
Despite your personal opinion on the BBC at a managerial level, it is undeniable that it has overseen some fantastic British shows in the past, and now thanks to a partnership with Roblox, players will be able to interact with some of these... | Read more »

Price Scanner via MacPrices.net

You can save $300-$480 on a 14-inch M3 Pro/Ma...
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
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer 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 MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more
Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices... Read more
Roundup of Verizon’s April Apple iPhone Promo...
Verizon is offering a number of iPhone deals for the month of April. Switch, and open a new of service, and you can qualify for a free iPhone 15 or heavy monthly discounts on other models: – 128GB... Read more

Jobs Board

IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
Top Secret *Apple* System Admin - Insight G...
Job Description Day to Day: * Configure and maintain the client's Apple Device Management (ADM) solution. The current solution is JAMF supporting 250-500 end points, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.