TweetFollow Us on Twitter

TCL and VA 2
Volume Number:11
Issue Number:11
Column Tag:Getting Started

TCL and Visual Architect, Part 2

By Dave Mark, MacTech Magazine Regular Contributing Author

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

In last month’s column, we took a look at Symantec’s latest development environment, including the Symantec Project Manager and Visual Architect. Following the example presented in Chapter 14 of the Symantec C++ User’s Guide, we used Visual Architect to generate source code to implement the single, default view named Main. We then returned to the Symantec Project Manager and compiled the code into a standalone application (See Figure 1).

Figure 1. The window that appeared when we ran last month’s program.

This month, we’re going to add a second view to our program. This second view will be a dialog that allows you to type a number into an editable text field. When you press the Beep button, the dialog will beep the specified number of times.

Adding a Second View

Go into the Button ƒ folder you created last month and double-click on the file Button.Π to launch the Symantec Project Manager. When the project window appears, double click on the file name Visual Architect.rsrc to bring up Visual Architect. This is where we’ll add the second view.

• Select New View from the View menu.

• When asked to name the new view, type BeeperDialog and make sure Modal Dialog is selected from the View Kind: popup menu (Figure 2), then press the OK button.

Figure 2. Naming the new view.

The name BeeperDialog will be used as the basis for a new class, called CBeeperDialog. The next time you select Generate from Visual Architect’s Symantec Project Manager menu, Visual Architect will generate the files CBeeperDialog.cp, CBeeperDialog.h, x_CBeeperDialog.cp, and x_CBeeperDialog.h. First, we’ll add a few items to this dialog and then add a button to our Main view that brings up the dialog.

Once you press the OK button, a view window will appear with the name BeeperDialog.

• Select View Info from the View menu.

A view info window titled Dialog Info will appear (Figure 3). The view info window, which looks a lot like a ResEdit or Resorcerer WIND templat, lets you customize the look of your new dialog window.

Figure 3. The view info window for the BeeperDialog view.

• Click on the movable modal dialog icon (the second from the right) or type “5” in the procID: field.

• Click on the OK button to dismiss the dialog.

Your next step is to add some items to the dialog.

• Click on the Tools menu and drag down until the tool palette outline appears.

When you release the mouse button, the Tools palette window will appear (Figure 4). Take a few minutes to play with the items in this palette. In the top row, you have the selection tool, the text tool, and the editable text tool. The second row features the pushbutton tool, the radio button tool, and the check box tool. The third row features the popup menu, icon, and PICT tools. We’ll get into the rest of the tools in a future column. For now, try creating items based on the tools in the first three rows. Click on a tool, then click and drag in the BeeperDialog view window. Once you get a feel for these tools, select the selection tool (the arrow), then click on each of the items you added and press the delete key. Keep on deleting until the BeeperDialog window is empty again.

Figure 4. The Tools palette.

Now let’s add the items that make up the Beeper dialog. We’ll add four items: an OK button, a Cancel button, a static text label, and an editable text field for entering the number of beeps. We’ll start with the OK and Cancel buttons.

• Click on the button tool in the palette window.

• Click on the BeeperDialog window and drag out an OK button.

As you drag, keep your eye on the lower left corner of the window. Notice that the two coordinates listed reflect the upper left and lower right corners of the button. I made my button 80 pixels wide and 20 pixels tall with an upper left corner of (200,42).

• Click on the BeeperDialog window and drag out a Cancel button.

My Cancel button was also 80 pixels wide and 20 pixels tall. This time, the upper left corner was (107,42). Notice that VA automatically filled in the text OK for the first button and Cancel for the second button. Nice feature! Let’s change the OK to say Beep.

• Double-click on the OK button (or click on it and select Pane Info... from the Pane menu) to bring up the Pane Info window.

• Click on the triangle to the left of the class name CControl, revealing the CControl data members.

• Change contrlTitle from OK to Beep and close the Pane Info window.

Notice that the button’s name changed from OK to Beep. Now let’s add the static text label.

• Click on the static text tool (the big letter A) in the palette window.

• Click in the BeeperDialog window and type the text Number of times to beep:

• Click outside the static text to stop entering text, then click on the static text to select it. Drag it to a satisfactory position in the BeeperDialog window.

I dragged my static text so its upper-left corner was at (23,13). You might want to use the arrow keys to move the static text around the window, 4 pixels at a time. Hold down the command (Apple) key to get the arrow keys to move 1 pixel at a time. Experiment with the Shift and option keys which let you resize an item by 1 or 4 pixels in any of 4 directions.

Finally, let’s add an editable text field.

• Click on the editable text tool (to the right of the static text tool) in the palette window.

• Click on the BeeperDialog window and drag out an editable text area.

Mine had and upper left corner of (205,13) and a lower right of (280,29). Once your items are in place, resize the dialog view so it comfortably encloses the dialog items. To do that, click on the handle in the lower-right corner of the grey rectangle embedded in the BeeperDialog window. Drag the handle to its new position. I dragged mine to (293,75). The finished Beeper dialog is shown in Figure 5.

Figure 5. The finished Beeper dialog with the Beep button selected.

If you like, you can try the dialog out by selecting Try Out from the View menu. Click on one of the buttons or select Close from the File menu to close the Try Out window once you are done admiring your handiwork.

Our next task is to tell VA that our edit-text field is designed to hold only integers (as opposed to any old text).

• Click on the editable text field.

• Select Class from the Pane menu, then select CIntegerText from the submenu that appears.

Next, we need to define a new command that will get sent when the Beep button is clicked. Right now the Beep button’s command is set to cmdOK. To see that, double-click on the Beep button to bring up the Pane Info window, then click on the CButton triangle. Take a look at the Command popup menu. If you click on it, you’ll find a whole bunch of commands, all of them built into the TCL. Since there is no Beep command, we’ll need to define it ourselves, then set the Beep button to send it when clicked.

• Close the Beep Pane Info window, if you opened it to look at the Command popup.

• With the BeeperDialog window frontmost, select Commands... from the Edit menu.

• When the Commands window appears, select New Command from the Edit menu.

• Type cmdBeep in the uppermost editable text field.

• Select CBeeperDialog from the In Class: popup menu.

This tells VA which class this command belongs to.

• Select Call from the Do: popup menu.

This tells VA what you want done in response to this command. You could do nothing, you could ask VA to call a function, or you could open another view. In our case, we’ve asked VA to call a CBeeperDialog member function. We’ll get to that function in a bit.

Notice that VA automatically generated the command number 512. This is not particularly important. You’ll use the constant cmdBeep instead of 512, so there’s no reason to memorize your command numbers.

• Click on the OK button to dismiss the Commands dialog.

As you’ve probably guessed, your next step is to associate the cmdBeep command with the Beep button.

• Double-click on the Beep button to bring up the Pane Info window.

• Click on the triangle to the left of the class CButton, revealing the Command popup menu.

• Select cmdBeep from the Command popup (Figure 6).

• Close the Pane Info window.

Figure 6. The Pane Info window associated with the Beep button.
Notice that the Command popup has been set to cmdBeep.

You may have noticed that the Beep button no longer has the bold, rounded rectangle around it, specifying it as the default button, the button pressed when the user hits return. This changed because VA specifies the cmdOK command as the default. Let’s fix that.

• Select Set Default Command from the View menu.

• Select cmdBeep from the Command popup menu, then press OK.

Notice that the bold, rounded rectangle is back around the Beep button (Figure 7).

Figure 7. The BeeperDialog window, once cmdBeep is set as the default command.

We are almost done! Now we have to add a button to the Main view that brings up the Beeper dialog.

• Close the BeeperDialog view window.

• Double-click on Main in the view list window to bring up the Main view window.

• Click on the grow box in the lower left corner of the Main view window and drag down about 50 pixels.

• Click on the handle in the lower right corner of the grey bounding rectangle inside the window and drag it down about 50 pixels.

You’ve just resized the Main view to be about 50 pixels taller, making room for a new pushbutton.

• Click on the pushbutton tool (under the arrow) in the palette window.

• Click in the Main view window and drag out a new button below the PICT.

• Before you click off the button, type the word Beeper...

The button will now bear the name Beeper....

• Double-click on the Beeper... button, bringing up the button’s Pane Info window.

• Click on the triangle next to the class name CButton to reveal the CButton data members.

• Choose Other... from the top of the Command popup menu.

• When the Commands dialog appears, choose New Command from the Edit menu.

• Enter the command name cmdBeeperDialog.

• Choose CMain from the In Class: popup menu to let VA know you want the new command associated with the CMain class.

• Choose Open from the Do: popup menu.

• Choose CBeeperDialog from the View: popup menu.

We’ve just told VA that we want this new command (cmdBeeperDialog) to open the CBeeperDialog view (See Figure 8).

Figure 8. The Commands window for the new cmdBeeperDialog command.

• Click on the OK button.

Now we’ve told VA to associate this command with the Beeper... button we just created.

• Close the button’s Pane Info window to return to the Main view window (Figure 9).

Figure 9. My Main view with my new Beeper... button.

If you like, select Try Out from the View menu and take your new version of Main for a spin. Note that we haven’t put the code in place that gets called when the Beeper... button is pressed, but the scrollbars should work and the button should highlight when clicked.

Our next step is to ask VA to regenerate our source code, reflecting the new panes and commands we’ve defined.

• Select Generate... from the Symantec Project Manager menu (diamond shaped menu to the right of the Windows menu).

• When prompted to save your changes, click OK.

VA will update your existing code base. If you selected Generate All..., VA would have replaced your existing code base. Be sure you understand this difference!

Adding the New Code

Our last step is to add a few lines of code to bring all our new interface elements together.

• Return to the Symantec Project Manager.

• In the project window, click on the triangle to the left of the folder labeled Source. Skip this step if the Source folder was already opened.

• Double click on the file name “CBeeperDialog.cp”.

• Add this code to the end of CBeeperDialog.cp:

void CBeeperDialog::DoCmdBeep()
 long n;
 n = fBeeperDialog_Edit15->GetIntValue();
 for ( long i=0; i<n; i++ )
 SysBeep( 20 );

This code references the data member fBeeperDialog_Edit15. When VA generates your code, it makes up a constant for each of your dialog items. You can find these definitions in the file BeeperDialogItems.h. Here’s the constants that were generated for my version of Beeper:

 kBeeperDialog_Butn12 = 1,
 kBeeperDialog_Butn12ID = 2049L,
 kBeeperDialog_Butn13 = 2,
 kBeeperDialog_Butn13ID = 2050L,
 kBeeperDialog_Stat14 = 3,
 kBeeperDialog_Stat14ID = 2051L,
 kBeeperDialog_Stat17 = 4,
 kBeeperDialog_Stat17ID = 2053L,
 kBeeperDialog_Edit15 = 5,
 kBeeperDialog_Edit15ID = 2052L,

The member function GetIntValue() retrieves the value from the field that calls it (in this case, the editable text field), translates the value into an integer, and returns it. The loop uses this value to beep the specified number of times.

• Go to the top of the file and remove the comment characters (//) at the beginning of the line:

// #include   “AppCommands.h”

You’ll need to do this last step whenever your view includes at least 1 command.

• Close CBeeperDialog.cp.

That’s it! When you run the program, the Main view should appear, featuring a brand new button (Figure 10).

Figure 10. The Main view, with the Beeper... button pressed.

Press the Beeper... button. The Beeper Dialog will appear.
Type a number in the text field and press the Beep button. Happy?

Figure 11. Pressing the Beep button.

Till Next Month...

Next month, we’ll go back to PowerPlant. I just got my copy of CW7, and I’m anxious to dig into it. Hope you got your upgrades, too. See you next month...


Community Search:
MacTech Search:

Software Updates via MacUpdate

Viber 6.8.6 - Send messages and make cal...
Viber lets you send free messages and make free calls to other Viber users, on any device and network, in any country! Viber syncs your contacts, messages and call history with your mobile device, so... Read more
Carbon Copy Cloner 4.1.17 - Easy-to-use...
Carbon Copy Cloner backups are better than ordinary backups. Suppose the unthinkable happens while you're under deadline to finish a project: your Mac is unresponsive and all you hear is an ominous,... Read more
EtreCheck 3.4.2 - For troubleshooting yo...
EtreCheck is an app that displays the important details of your system configuration and allow you to copy that information to the Clipboard. It is meant to be used with Apple Support Communities to... Read more
Hopper Disassembler 4.2.10- - Binary dis...
Hopper Disassembler is a binary disassembler, decompiler, and debugger for 32- and 64-bit executables. It will let you disassemble any binary you want, and provide you all the information about its... Read more
VueScan 9.5.81 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
iFFmpeg 6.4.2 - Convert multimedia files...
iFFmpeg is a comprehensive media tool to convert movie, audio and media files between formats. The FFmpeg command line instructions can be very hard to master/understand, so iFFmpeg does all the hard... Read more
Fantastical 2.4.1 - Create calendar even...
Fantastical 2 is the Mac calendar you'll actually enjoy using. Creating an event with Fantastical is quick, easy, and fun: Open Fantastical with a single click or keystroke Type in your event... Read more
Fantastical 2.4.1 - Create calendar even...
Fantastical 2 is the Mac calendar you'll actually enjoy using. Creating an event with Fantastical is quick, easy, and fun: Open Fantastical with a single click or keystroke Type in your event... Read more
Live Home 3D Pro 3.2.2 - $69.99
Live Home 3D Pro, a successor of Live Interior 3D, is the powerful yet intuitive home design software that lets you build the house of your dreams right on your Mac. It has every feature of Live Home... Read more
Live Home 3D Pro 3.2.2 - $69.99
Live Home 3D Pro, a successor of Live Interior 3D, is the powerful yet intuitive home design software that lets you build the house of your dreams right on your Mac. It has every feature of Live Home... Read more

Latest Forum Discussions

See All

Glyph Quest Chronicles guide - how to ma...
Glyph Quest returns with a new free-to-play game, Glyph Quest Chronicles. Chronicles offers up more of the light-hearted, good humored fantasy fun that previous games featured, but with a few more refined tricks up its sleeve. It's a clever mix of... | Read more »
Catch yourself a Lugia and Articuno in P...
Pokémon Go Fest may have been a bit of a disaster, with Niantic offering fans full refunds and $100 worth of in-game curency to apologize for the failed event, but that hasn't ruined trainers' chances of catching new legendary Pokémon. Lugia nad... | Read more »
The best deals on the App Store this wee...
There are quite a few truly superb games on sale on the App Store this week. If you haven't played some of these, many of which are true classics, now's the time to jump on the bandwagon. Here are the deals you need to know about. [Read more] | Read more »
Realpolitiks Mobile (Games)
Realpolitiks Mobile 1.0 Device: iOS Universal Category: Games Price: $5.99, Version: 1.0 (iTunes) Description: PLEASE NOTE: The game might not work properly on discontinued 1GB of RAM devices (iPhone 5s, iPhone 6, iPhone 6 Plus, iPad... | Read more »
Layton’s Mystery Journey (Games)
Layton’s Mystery Journey 1.0.0 Device: iOS Universal Category: Games Price: $15.99, Version: 1.0.0 (iTunes) Description: THE MUCH-LOVED LAYTON SERIES IS BACK WITH A 10TH ANNIVERSARY INSTALLMENT! Developed by LEVEL-5, LAYTON’S... | Read more »
Full Throttle Remastered (Games)
Full Throttle Remastered 1.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0 (iTunes) Description: Originally released by LucasArts in 1995, Full Throttle is a classic graphic adventure game from industry legend Tim... | Read more »
Stunning shooter Morphite gets a new tra...
Morphite is officially landing on iOS in September. The game looks like the space shooter we've been needing on mobile, and we're going to see if it fits the bill quite shortly. The game's a collaborative effort between Blowfish Studios, We're Five... | Read more »
Layton's Mystery Journey arrives to...
As you might recall, Layton's Mystery Journey is headed to iOS and Android -- tomorrow! To celebrate the impending launch, Level-5's released a new trailer, complete with an adorable hamster. [Read more] | Read more »
Sidewords (Games)
Sidewords 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Grab a cup of coffee and relax with Sidewords. Sidewords is part logic puzzle, part word game, all original. No timers. No... | Read more »
Noodlecake Games' 'Leap On!...
Noodlecake Games is always good for some light-hearted arcade fun, and its latest project, Leap On! could carry on that tradition. It's a bit like high stakes tetherball in a way. Your job is to guide a cute little blob around a series of floating... | Read more »

Price Scanner via

Apple Move Away from White Label Event Apps C...
DoubleDutch, Inc., a global provider of Live Engagement Marketing (LEM) solutions, has made a statement in the light of a game-changing announcement from Apple at this year’s WWDC conference.... Read more
70 Year Old Artist Creates Art Tools for the...
New Hampshire-based developer Pirate’s Moon has announced MyArtTools 1.1.3, the update to their precision drawing app, designed by artist Richard Hoeper exclusively for use with the 12.9-inch iPad... Read more
Sale! New 2017 13-inch 2.3GHz MacBook Pros fo...
Amazon has new 2017 13″ 2.3GHz/128GB MacBook Pros on sale today for $150 off MSRP including free shipping. Their prices are the lowest available for these models from any reseller: – 13″ 2.3GHz/128GB... Read more
13″ 2.3GHz/128GB Space Gray MacBook Pro on sa...
MacMall has the 13″ 2.3GHz/128GB Space Gray MacBook Pro (MPXQ2LL/A) on sale for $1219 including free shipping. Their price is $80 off MSRP. Read more
Clearance 2016 12-inch Retina MacBooks, Apple...
Apple recently dropped prices on Certified Refurbished 2016 12″ Retina MacBooks, with models now available starting at $1019. Apple will include a standard one-year warranty with each MacBook, and... Read more
Save or Share
FotoJet Designer, is a simple but powerful new graphic design apps available on both Mac and Windows. With FotoJet Designer’s 900+ templates, thousands of resources, and powerful editing tools you... Read more
Logo Maker Shop iOS App Lets Businesses Get C...
A newly released app is designed to help business owners to get creative with their branding by designing their own logos. With more than 1,000 editable templates, Logo Maker Shop 1.0 provides the... Read more
Sale! New 15-inch MacBook Pros for up to $150...
Amazon has the new 2017 15″ MacBook Pros on sale for up to $150 off MSRP including free shipping: – 15″ 2.8GHz MacBook Pro Space Gray: $2249 $150 off MSRP – 15″ 2.89Hz MacBook Pro Space Gray: $2779 $... Read more
DEVONthink To Go 2.1.7 For iOS Brings Usabili...
DEVONtechnologies has updated DEVONthink To Go, the iOS companion to DEVONthink for Mac, with enhancements and bug fixes. Version 2.1.7 adds an option to clear the Global Inbox and makes the grid... Read more
15-inch 2.2GHz Retina MacBook Pro, Apple refu...
Apple has Certified Refurbished 2015 15″ 2.2GHz Retina MacBook Pros available for $1699. That’s $300 off MSRP, and it’s the lowest price available for a 15″ MacBook Pro. An Apple one-year warranty is... Read more

Jobs Board

*Apple* Solutions Consultant (ASC) - Poole -...
Job Summary The people here at Apple don't just create products - they create the kind of wonder that's revolutionised entire industries. It's the diversity of those Read more
SW Engineer *Apple* TV - Apple Inc. (United...
Changing the world is all in a day's work at Apple . If you love innovation, here's your chance to make a career of it. You'll work hard. But the job comes with more Read more
Frameworks Engineering Manager, *Apple* Wat...
Frameworks Engineering Manager, Apple Watch Job Number: 41632321 Santa Clara Valley, California, United States Posted: Jun. 15, 2017 Weekly Hours: 40.00 Job Summary Read more
Product Manager - *Apple* Pay on the *Appl...
Job Summary Apple is looking for a talented product manager to drive the expansion of Apple Pay on the Apple Online Store. This position includes a unique Read more
*Apple* Retail - Multiple Positions - Apple...
SalesSpecialist - Retail Customer Service and SalesTransform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.