As we slowly bid farewell to the classic Mac OS, we'll take one last poke at the venerable Extension. This week we'll show you how to whip up a handy Extension with REALbasic.
Build the Interface and Add the Code
This week's project is drop dead simple to complete. Launch REALbasic and open Window1. To this window, add a Timer control (Mode = 2; Period = 10). By now, you interface might look like this:
Next, double clik the Timer control and enter this code:
This code continually checks for a user to press Option-a. If they do, it moves the mouse cursor to the upper left hand of the screen (hopefully in proximity to the Apple menu for easy clicking). Wait a second! REALbasic doesn't have a moveCursor command. To add the command to your project, download this XCMD resource and drag it into your project window.
Finally, we want to hide the window while this "application " runs. Normally extensions don't have interfaces and this is how we get around that problem with the interface-centric REALbasic. Add this command to the Open event of Window1 to hide the window:
me.top=-500That's it. Run the project to see how it works. Once you've tested it to your satisfaction, build the final application (Sorry, no Carbon allowed on this one.).
Convert an Application into an Extension
OK, now you've got an application staring at you. How do you make it into an Extension? Simple. Open the application with ResEdit and changes its type to 'appe'.
Then, open the 'SIZE' resource and click '1' for the Only background option.
Close the file and save it. Voila! It's an extension now. Drop the new extension in your Extensions Folder and reboot your Mac to check it out.
Conclusion
If you'd like to download this week's example instead of typing it in, you can download the completed project. See you next week!