![]() 3D 3D Photo Gallery (Part 1) 3D Photo Gallery (Part 2) Audio Poor Man's MIDI Make A Metronome iPod Tricks (Part 1) iPod Tricks (Part 2) iPod Tricks (Part 3) Laugh Track Machine Audio Player with Reverb Shepard Melody RB Phone Home Build a Drum Machine Custom Controls and Windows Double Click Listbox Draggable Metal Window Double Click Canvas Custom Buttons Custom Buttons Part II iTunes-style Listboxes Custom Controls General RB Scrolling Windows Using Mesage Dialogs Case-Sensitive Word Finder Introduction to Stacks Wiggle Window JPEG in PDF Listbox Checkboxes Background Applications Listbox Auto-Find Virtual Volumes Time Tracker Software Distribution (Part 1) Software Distribution (Part 2) Software Distribution (Part 3) Software Distribution (Part 4) Exceptions Tips and Tricks Text Clippings Made Easy Graphics Drawing a Simple Gradient The SpriteSurface: Space Game Image Spinner Cropping Graphics (Part 1) Cropping Graphics (Part 2) Cropping Graphics (Part 3) Cropping Graphics (Part 4) Shimmer Graphics Lissajous Figures Simple Screen Capture Vector Graphics Kaleidoscope Images Stegonography Spirals! Image Table RB Magnifying Lens Screen Capture Color Picker Tutorial Hacks Ghost Grab Speedy Mouse Extension iTunes Plugins iTunes Skinner Mac OS X Global Hot Key Event (Carbon Events) Login Welcomer (Carbon Events) Add/Remove Buttons Resizable Sheets Mac OS X Preferences Window Using Sheets in REALbasic Build a Bundle (Part 1) Build a Bundle (Part 2) Dock Your Passwords Mac OS X Debugging REALbasic Mac OS X Icon Tutorial Animate Your Dock RB and the Command Line Menus Window Menu Templates Menu Listbox Menu Novelty Guessing Game Calendar Trivia Tile Mixer Zip Code Finder Happy Valentine's Day Merlin Simulator (Part 1) Merlin Simulator (Part 2) Merlin Simulator (Part 3) Buzzword Machine AppleSoft BASIC Printing Print to PDF Registration Registration Code Validation Network Registration Codes Resources Picture Extractor (Part 1) Picture Extractor (Part 2) Serial Caller ID (Part 1) Caller ID (Part 2) Caller ID (Part 3) Speech Speech Recognition Socket Communication Easy Peer-to-Peer File Sharing MacPAD Version Checking Display Web Image In Canvas HTML IMG Tags Version Tracking Even Smarter Instant Messaging Web Tiler JavaScript and REALbasic Stock Ticker (Part I) Stock Ticker (Part 2) AIM Mate XML Manipulation Simple XML Introduction Video Big Brother Video Capture Note: All articles without a byline were written by Erick Tejkowski. When cleaning the site I removed them because the code differed from page to page, and I have yet to put them back in.
Tell us about a bad link. |
MessageDialogs
(TextEdit in Mac OS X showing a Standard Alert)
In the past, REALbasic developers either had to create their own dialogs from scratch or use a plugin or declare statements to call into the OS's API. However, in REALbasic 5.5, there's no need for this, as a simple MessageDialog class is built-in and fully cross platform! In today's tutorial, we're going to use an instance of the MessageDialog class to confirm that the user wishes to close the window without saving the changes.
The Interface
(This tutorial's interface)
Keeping Track of The Window's State
(Mac OS X's fancy darkened dot)
Now seeing how this is a Mac site, I've used two declares to allow us to get this fancy dot in Mac OS X. Add these two methods to the document window in your REALbasic project:
(Returns true or false based on whether the window has been modified or not)
(Sets whether the window has been modified or not using Window.Modified = Boolean)
As you can see, the function calls to SetWindowModified and IsWindowModified in the Window Manager are very straightforward.
The Carbon Constant
(Creates a constant to the Carbon library or framework)
Now if we wanted to support Mac OS 9, we could add another platform constant variation for Mac (Classic) with a value of "InterfaceLib", but since Mac OS 9 is officially dead and Mac OS X offers so many absolutely cool features for developers and users alike, I don't bother even thinking about Mac OS 9 compatability.
Tracking the Modifications
(Keeing track of the window's changes)
Displaying The MessageDialog The ActionButton property is the button which preforms the default action. It's the default button, and by default it has a Caption value of "OK". The CancelButton is obviously the button which cancels the action and has a default Caption value of "Cancel". The AlternateActionButton is a third button which you can use to offer a third choice. In our case this would be the "Don't Save" button. Note that the CancelButton and AlternateActionButtons by default are not visible while the ActionButton is. Now let's put this to some use:
(Displays a confirmation dialog before closing the window)
As you can see, the code only does something if the window has been modified. If it has, we first create the dialog we're going to display and set the Message and Explaination properties as well as set the button captions and visibility for our three buttons. The reason ActionButton and AlternateActionButton have an ampersand as the first character in their captions, is because it's your way of letting REALbasic know that the keyboard commands Command-S and Command-D should map to those two buttons. On Windows and Linux this would map to Control-S and Control-D. The CancelButton however does not use this feature since by default, Command-. or Control-. on Windows and Linux, is the keyboard command for the cancel button. After creating the dialog we then display it by calling the ShowModal method of the MessageDialog instance, which then returns a MessageDialogButton pointing to which of the three buttons was clicked. The easiest way to determine which button was clicked is by using a Select Case statement with the button's caption. Make a note that if the caption included an ampersand when you created it, you'll need to include that ampersand in the Select statement.
Final Notes As always, you can download the project for this tutorial. |
|||||
|
Please support ResExcellence by Visiting our Sponsors. One click makes a difference. |
||||||
|
|