Email:   


Home
In This Issue
Email a Friend
EasyPrint
Click here for the RSS feed's XML code. This is not a browser URL.


PROGRAMMING POWER
Utility routines for programmers
By Alan Jay Weiner

We looked at resources last month, and started looking at forms and controls. This month, I'm going to skip ahead a bit and get some code into your hands. We can return to examine controls next month.

These are some of the routines from my personal library. They make working with buttons and text a bit easier.

Pointers to control objects
Many of the APIs require pointers to various control objects rather than simply the identification number you've assigned them. The GetObjectPtr routine in Listing A (see http://www.component-net.com/pp-extras/utility1.html) takes the ID number and determines the pointer. It assumes that the control is on the currently displayed form.

This routine is straight out of the Palm examples. Many of the following routines use it to reference control objects.

Hiding buttons
Sometimes we want to hide a button. For example, to make sure a particular feature isn't available until some other conditions occur. Or we want to make a button visible because those conditions have been met.

Making a control invisible when the form is displayed is easy. Simply mark it "not usable" when you design the form. Then, when the form is first displayed, the control won't be drawn.

Listing B (see http://www.component-net.com/pp-extras/utility2.html) shows two routines; MakeButtonInvisible hides a button. The other, MakeButtonVisible, unhides it.

Changing a button's text
Listing C (see http://www.component-net.com/pp-extras/utility3.html), ChangeButtonText, changes the text on a button. Use this to make a button mean different things under different circumstances. It's easier to change the text on a single button than to have multiple buttons in the same place.

Centering a line of text on the screen
This final routine, in Listing D (see http://www.component-net.com/pp-extras/utility4.html), centers a line of text. Actually, it's two routines; the first sets the font unless the new font is CURRENT_FONT, or the value -1. While this could be done in-line in the DisplayCentered routine, we'll see it in future text-display routines. It also updates the font value with the original font, so it can later be restored.

The regular fonts are defined in FONT.H; they are stdFont, boldFont, largeFont, symbolFont, symbol11Font, symbol7Font, and ledFont. The Palm III has added a new font called largeBoldFont.

DisplayCentered itself is fairly simple - it optionally changes to a new font, gets the width of the text string, and draws it in the right place.





[ Next ]

-- Advertisement --

NO HASSLE PHOTO PRINTING, SHARING, AND STORAGE -- AS LOW AS $2.54 PER MONTH
Discover an easier way to share, print and manage your photos online! Get your own online photo album site for sharing photos, as well as easy-to-use editing tools to make sure your photos look their very best. You can even order high quality prints directly from your album -- and have them delivered right to your door!

Best of all, you can also get login-free photo sharing at your personal domain name (if you have one), so your friends and family don't have to hassle with signing up or logging in just to view your pictures. It's the perfect solution for sharing, printing and storing all your favorite images!

And it's only from The Duck! Tap here to get started.

-- Advertisement --

Write for Computing Unplugged!
Share your experience and expertise with other handheld device users. There are new opportunities at ZATZ for contributing authors and editors.

Write about something you're an expert on and get your name in lights.

For Writers' Guidelines and to discuss topics, contact Staff Editor Steve Niles. This is your opportunity to shine in front of your peers, your clients, and friends.

Click for more info!

Copyright © 1998-2008, ZATZ Publishing. All rights reserved worldwide.