TweetFollow Us on Twitter

Summer 91 - PRINT HINTS FROM LUKE & ZZ

PRINT HINTS FROM LUKE & ZZ

HELP FOR YOUR DIALOG APPENDAGES

PETE "LUKE" ALEXANDER and Zz

[IMAGE Luke+Zz.GIF]

Zz speaks

OK, so you're cruising your source like a madman trying to get all those little System 7.0 changes in before that target ship date (whatever it is this week), and you notice that the items you've added to the Page Setup/Print dialogs don't have any Balloon HelpTM--you know, those items like Reverse Pages, Print Hidden Text, or even Use Fractional Font Widths. (Coming up with meaningful names for these items, in four words or less, was a little tricky.) But now there's help, literally, in System 7.0. Great! Then you remember that there wasn't a simple Printing Manager call to add those items to the dialogs. You had to resort to the technique described in Technical Note #95, How to Add Items to the Print Dialogs. As you remember, it used a set of procedures that modified the Printing Manager's (that is, the selected print driver's) dialog item list (DITL) resource.

Remembering the actual code in Tech Note #95, you consider that the Standard File package shipped with 7.0 has a new call that allows you to append things to its dialog, including Help Manager resources. Feeling relieved, you think, "Ah, there must be a similar call in the new Pri . . ." But no, the new printing architecture has been delayed. A quick scan shows that there isn't even a Printing Manager chapter inInside Macintosh Volume VI! Help!!! It's not as bad as you might expect. If you consult Tech Note #95, you'll see the rather husky AppendDITL procedure. This procedure is called to append the items that you want to add to the dialog item list being used by the particular dialog (Page Setup or Print).

The sample code from Tech Note #95 calls some Printing Manager routines that let you get in after the DITL resource has been loaded, but before the dialog has been displayed. You add your items to the resource in memorywithout calling either ChangedResource or WriteResource. The driver then uses this DITL and displays your items. Once the dialog is dismissed, the resource is purged, and the driver doesn't even know you were there. Life is good.

As you've probably guessed by now, you're going to have to append to the Help Manager dialog item help ('hdlg') resource in the same way that you appended to the DITL resource. You simply scan the list to the end, and then append the appropriate items. The 'hdlg' resource is purged in the same way as the DITL resource, so once again you make no permanent changes.

On the next page is the definition of the Append2hdlg procedure. We start by getting both 'hdlg' resources into memory. It's safe to assume the source 'hdlg' resource hasn't been loaded yet, but we use the SetResLoad trick on the destination in case it has already been loaded. (The SetResLoad trick is a method for determining whether a resource has already been loaded. This trick is important, since in cases where the resource has already been loaded by the system, you don't want to unload it or permanently change any of its resource attributes.) The trick works like this: You SetResLoad to false so that the Resource Manager doesn't load the resource data; instead, it just creates an empty resource handle that can be passed to routines like GetResInfo. You then call GetResource on the resource you're looking for. If the handle returned is empty (that is, points to nil), you know the resource isn't already in memory. If the handle returned is not empty, something else (like the system) has already loaded it before you called GetResource. In this example, since we use HGetState and HSetState to preserve the resource attributes, and we want the resource to be left in memory when we're done, we don't really need to know if it was already loaded. The SetResLoad code is included for anyone who is planning on modifying this code to do more.

Next we initialize our locals. We want to point srcPtr to the place in the source resource that we want to start copying from. To do this, we need to point past the "missing item." The size of the item is stored in the resource just after the resource header. We first use srcPtr to get the size (in bytes) of the missing item. Using that size, we can calculate the starting location for the copy. We don't actually initialize srcPtr yet, since resizing the destination handle could move memory. Next we initialize dstPtr and dstLength. In the process, we resize dstHdl to make room for the items we're going to append. Once SetHandleSize has been called, we also initialize srcPtr. Now that srcPtr and dstPtr are set up, we use BlockMove to copy the new items into the destination resource. After unlocking the resource handles, we update the numItems field of the destination resource so that the Help Manager will know how many items we added. Finally, we release the source resource. We don't want to release the destination, since our changes would then be lost.

void Append2hdlg(srcResID, dstResID)
short   srcResID, dstResID;
{
    Handle              srcHdl, dstHdl;
    Ptr                 srcPtr, dstPtr;
    short               srcLength, dstLength;
    short               missingItmSz;
    SignedByte      dstHState;
    
    srcHdl = GetResource('hdlg', srcResID); 
    if (srcHdl != nil) {
        SetResLoad(false);  /* System resource, make sure it's not */
        dstHdl = GetResource('hdlg', dstResID); /* already loaded. */
        SetResLoad(true);
        if (*dstHdl == 0)
            dstHdl = GetResource('hdlg', dstResID);
        dstHState = HGetState(dstHdl);
        
        if (dstHdl != nil) {
            srcPtr = (Ptr)*srcHdl + sizeof(hdlgHeader);
            missingItmSz = *((IntPtr)srcPtr);
            srcLength = GetHandleSize(srcHdl) - (sizeof(hdlgHeader)
                - missingItmSz);

            dstLength = GetHandleSize(dstHdl);
            SetHandleSize(dstHdl, dstLength + srcLength);
            if (MemError() != noErr) {
                DebugStr("\pMemError");
                            /* Use this error handler, go to jail. */
                ExitToShell();              /* It's the law! */
            }
            dstPtr = (Ptr)*dstHdl + dstLength;
            srcPtr = (Ptr)*srcHdl + sizeof(hdlgHeader) +
                missingItmSz;

            HLock(srcHdl);
            HLock(dstHdl);

            BlockMove(srcPtr, dstPtr, srcLength);

            HUnlock(srcHdl);
            HSetState(dstHdl, dstHState);

            ((hdlgHeaderPtr)*dstHdl)->hdlgNumItems +=
                ((hdlgHeaderPtr)*srcHdl)->hdlgNumItems;
        }
    }
    ReleaseResource(srcHdl);
}

So that's about it. Append2hdlg is a lot smaller than AppendDITL because we don't actually need to parse the contents of the 'hdlg' resource. Although it's another piece of code to be added to your application, this should be quite painless, unlike other Printing Manager exercises. Don't forget to read the Help Manager chapter of Inside Macintosh Volume VI for guidelines on the contents of your Help Manager balloons. See ya next time . . .


SCOTT "ZZ" ZIMMERMAN loves Disneyland--we think it's because he's really a cartoon character at heart. When asked, he admitted to wanting to be Captain Hook when he grew up. His favorite ride is Peter Pan because it's romantic, cool, dark, and the main character is a kid who never grew up. Except for the romantic, cool, and dark parts, it reminds him a lot of life at Apple. When he's at Apple he makes sure he drinks at least 15 gallons of Mountain Dew a day--he says it powers the mechanism for his retractable Barbie Doll hair. In closing, we'll leave you with his favorite question, "How can I miss you if you won't leave?"*

For more information on the format and use of the "missing item" in an 'hdlg' resource, and much more about Balloon Help, see the Help Manager chapter in Inside Macintosh Volume VI. *

 
AAPL
$103.30
Apple Inc.
+0.80
MSFT
$45.09
Microsoft Corpora
-0.34
GOOG
$577.33
Google Inc.
+5.73

MacTech Search:
Community Search:

Software Updates via MacUpdate

TextSoap 7.4.0 - Flexible text editing u...
TextSoap is for people who work with text. TextSoap effortlessly cleans up text from endlessly different formats. Wash away unwanted characters, spaces, tabs. Fix paragraphs with hard returns at the... Read more
NetShade 6.0.2 - Browse privately using...
NetShade is an Internet security tool that conceals your IP address on the web. NetShade routes your Web connection through either a public anonymous proxy server, or one of NetShade's own dedicated... Read more
Mac DVDRipper Pro 5.0 - Copy, backup, an...
Mac DVDRipper Pro is the DVD backup solution that lets you protect your DVDs from scratches, save your batteries by reading your movies from your hard disk, manage your collection with just a few... Read more
pwSafe 3.1 - Secure password management...
pwSafe provides simple and secure password management across devices and computers. pwSafe uses iCloud to keep your password databases backed-up and synced between Macs and iOS devices. It is... Read more
StatsBar 1.8 - Monitor system processes...
StatsBar gives you a comprehensive and detailed analysis of the following areas of your Mac: CPU usage Memory usage Disk usage Network and bandwidth usage Battery power and health (MacBooks only)... Read more
Path Finder 6.5.5 - Powerful, award-winn...
Path Finder is a file browser that combines the familiar Finder interface with the powerful utilities and innovative features. Just a small selection of the Path Finder 6 feature set: Dual pane... Read more
QuarkXPress 10.2.1 - Desktop publishing...
With QuarkXPress, you can communicate in all the ways you need to -- and always look professional -- in print and digital media, all in a single tool. Features include: Easy to Use -- QuarkXPress is... Read more
Skype 6.19.0.450 - Voice-over-internet p...
Skype allows you to talk to friends, family and co-workers across the Internet without the inconvenience of long distance telephone charges. Using peer-to-peer data transmission technology, Skype... Read more
Capo 3.1.2 - Slow down and learn to play...
Capo lets you slow down your favorite songs so you can hear the notes and learn how they are played. With Capo, you can quickly tab out your songs atop a highly-detailed OpenCL-powered spectrogram... Read more
VueScan 9.4.41 - 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

Latest Forum Discussions

See All

Modern Combat 5 Gets a Major Multiplayer...
Modern Combat 5 Gets a Major Multiplayer Update Posted by Jessica Fisher on September 2nd, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Alien Creeps TD Review
Alien Creeps TD Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: EXPENSIVE DEFENSESUniversal App - Designed for iPhone and iPad Alien Creeps TD would be a fun if unremarkable Tower Defense game, but its heavy focus on... | Read more »
The Journey Down: Chapter Two Review
The Journey Down: Chapter Two Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: DARK YET ENTICINGUniversal App - Designed for iPhone and iPad It’s a little dark, in every sense of the word, but The Journey Down:... | Read more »
Function Space, a Social Network App for...
Function Space, a Social Network App for Science, Launches on iOS Posted by Ellis Spice on September 2nd, 2014 [ permalink ] | Read more »
Stupidfast – How Taylor Martinez Switche...
How do you make an Endless Running game more than just another Endless Running game? By adding real life prizes to it, of course! That’s the thinking behind StupidFast: a game designed for football enthusiasts, and the brainchild of former college... | Read more »
Little Raiders: Robin’s Revenge Review
Little Raiders: Robin’s Revenge Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: CASUAL RAIDINGUniversal App - Designed for iPhone and iPad Combining simple combat with village building is a potent combination for... | Read more »
Treasure Tombs: Ra Deal Coming from Bulk...
Treasure Tombs: Ra Deal Coming from Bulkypix and Dark Tonic This Fall Posted by Jessica Fisher on September 2nd, 2014 [ permalink ] Dark Tonic and | Read more »
Pirate Bash Review
Pirate Bash Review By Nadia Oxford on September 2nd, 2014 Our Rating: :: BAD PIRATES, GOOD TIMESUniversal App - Designed for iPhone and iPad Pirate Bash’s turn-based battles add an intriguing twist to a typical physics game.   | Read more »
Tiny Tower Vegas Review
Tiny Tower Vegas Review By Jennifer Allen on September 2nd, 2014 Our Rating: :: STEADY DEVELOPMENTUniversal App - Designed for iPhone and iPad Build a huge tower again but Vegas-style in Tiny Tower Vegas.   | Read more »
The Manhattan Project Review
The Manhattan Project Review By Andrew Fisher on September 2nd, 2014 Our Rating: :: ROCKET SCIENCEUniversal App - Designed for iPhone and iPad The Manhattan Project offers a great Euro-style gameplay experience, but it is totally... | Read more »

Price Scanner via MacPrices.net

Apple Cuts iPad mini Prices; Non-apple Vendor...
Digitimes’ Max Wang and Joseph Tsai report that Apple is cooperating with US-based retailers including Best Buy and Amazon to cut iPad mini prices, and that channel retailers believe other brand... Read more
Apple refurbished iPads available for up to $...
Apple is offering Certified Refurbished iPad Airs for up to $140 off MSRP. Apple’s one-year warranty is included with each model, and shipping is free. Stock tends to come and go with some of these... Read more
Are We Now In The Post-Post-PC Era?
A longtime and thoroughgoing laptop aficionado, I was more than a little dismayed by Steve Jobs’s declaration back in 2010 when he sprang the iPad on an unsuspecting world. that we’d entered a “post-... Read more
PC Outlook Improves, But 2014 Shipments Still...
According to the International Data Corporation (IDC) Worldwide Quarterly PC Tracker, worldwide PC shipments are expected to fall by -3.7 percent in 2014. To hat’s actually an improvement from the... Read more
IDC Lowers Tablet Sales Projections for 2014...
Following a second consecutive quarter of softer than expected demand, International Data Corporation (IDC) has lowered its worldwide tablet plus 2-in-1 forecast for 2014 to 233.1 million units. The... Read more
Apple now offering refurbished 21-inch 1.4GHz...
The Apple Store is now offering Apple Certified Refurbished 21″ 1.4GHz iMacs for $929 including free shipping plus Apple’s standard one-year warranty. Their price is $170 off the cost of new models,... Read more
Save $50 on the 2.5GHz Mac mini, on sale for...
B&H Photo has the 2.5GHz Mac mini on sale for $549.99 including free shipping. That’s $50 off MSRP, and B&H will also include a free copy of Parallels Desktop software. NY sales tax only. Read more
Save up to $300 on an iMac with Apple refurbi...
The Apple Store has Apple Certified Refurbished iMacs available for up to $300 off the cost of new models. Apple’s one-year warranty is standard, and shipping is free. These are the best prices on... Read more
The Rise of Phablets
Carlisle & Gallagher Consulting Group, a businesses and technology consulting firm focused solely on the financial services industry, has released an infographic depicting the convergence of... Read more
Bad Driver Database App Allows Good Drivers t...
Bad Driver Database 1.4 by Facile Group is a new iOS and Android app that lets users instantly input and see how many times a careless, reckless or just plain stupid driver has been added to the... Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.