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
$108.00
Apple Inc.
+1.02
MSFT
$46.95
Microsoft Corpora
+0.90
GOOG
$559.08
Google Inc.
+8.77

MacTech Search:
Community Search:

Software Updates via MacUpdate

Vitamin-R 2.20b1 - Personal productivity...
Vitamin-R creates the optimal conditions for your brain to work at its best by structuring your work into short bursts of distraction-free, highly focused activity alternating with opportunities for... Read more
Dropbox 2.10.44 - Cloud synchronization...
Dropbox is an application that creates a special Finder folder that automatically syncs online and between your computers. It allows you to both backup files and keep them up-to-date between systems... Read more
Sandvox 2.9.2 - Easily build eye-catchin...
Sandvox is for Mac users who want to create a professional looking website quickly and easily. With Sandvox, you don't need to be a Web genius to build a stylish, feature-rich, standards-compliant... Read more
Cocktail 8.0.1 - General maintenance and...
Cocktail is a general purpose utility for OS X that lets you clean, repair and optimize your Mac. It is a powerful digital toolset that helps hundreds of thousands of Mac users around the world get... Read more
LibreOffice 4.3.3.2 - Free Open Source o...
LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more
VMware Fusion 7.0.1 - Run Windows apps a...
VMware Fusion allows you to create a Virtual Machine on your Mac and run Windows (including Windows 8.1) and Windows software on your Mac. Run your favorite Windows applications alongside Mac... Read more
OneNote 15.3.2 - Free digital notebook f...
OneNote is your very own digital notebook. With OneNote, you can capture that flash of genius, that moment of inspiration, or that list of errands that's too important to forget. Whether you're at... Read more
Audio Hijack Pro 2.11.4 - Record and enh...
Audio Hijack Pro drastically changes the way you use audio on your computer, giving you the freedom to listen to audio when you want and how you want. Record and enhance any audio with Audio Hijack... Read more
Iridient Developer 3.0.0 beta 3 - Powerf...
Iridient Developer (was RAW Developer) is a powerful image conversion application designed specifically for OS X. Iridient Developer gives advanced photographers total control over every aspect of... Read more
TextWrangler 4.5.11 - Free general purpo...
TextWrangler is the powerful general purpose text editor, and Unix and server administrator's tool. Oh, and also, like the best things in life, it's free. TextWrangler is the "little brother" to... Read more

Latest Forum Discussions

See All

Monster Flash Review
Monster Flash Review By Jordan Minor on October 31st, 2014 Our Rating: :: ALONE IN THE DARKUniversal App - Designed for iPhone and iPad Solid shooting and a surprising amount of spooky tension make Monster Flash a great portable... | Read more »
Retry Review
Retry Review By Rob Thomas on October 31st, 2014 Our Rating: :: SOARING HIGHUniversal App - Designed for iPhone and iPad Flappy who? Let Retry wash all those bad bird-related memories away on a cool retro-flavored flight… right... | Read more »
Dementia: Book of the Dead Review
Dementia: Book of the Dead Review By Lee Hamlet on October 31st, 2014 Our Rating: :: A TOUGH READUniversal App - Designed for iPhone and iPad A witch hunter is sent after a demonic book in the spooky but short-lived Dementia: Book... | Read more »
Card Dungeon, the Semi-Board Game Roguel...
Card Dungeon, the Semi-Board Game Roguelike, Has Been Renovated Posted by Jessica Fisher on October 31st, 2014 [ permalink ] | Read more »
Logitech Protection + Power iPhone5/5S C...
Made by: Logitech Price: $99.99 Hardware/iOS Integration Rating: 3 out of 5 stars Usability Rating: 0.5 out of 5 stars Reuse Value Rating: 0.75 out of 5 stars Build Quality Rating: 0.75 out of 5 stars Overall Rating: 1.25 out of 5 stars | Read more »
This Is Not a Test Goes Free, Permanentl...
This Is Not a Test Goes Free, Permanently Posted by Jessica Fisher on October 31st, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Swap Heroes Review
Swap Heroes Review By Campbell Bird on October 31st, 2014 Our Rating: :: STRATEGIC SWAPPINGUniversal App - Designed for iPhone and iPad Rotate a cast of heroes to fend of waves of monsters in this difficult, puzzle rpg.   | Read more »
Night Sky Pro™ (Reference)
Night Sky Pro™ 3.0.1 Device: iOS Universal Category: Reference Price: $2.99, Version: 3.0.1 (iTunes) Description: Night Sky Pro™Wonder No More™ Night Sky Pro™ is the ultimate stargazing experience. From the creators of the original... | Read more »
Audio Defence : Zombie Arena (Games)
Audio Defence : Zombie Arena 1.0 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0 (iTunes) Description: A zombie shooter audio game. Made from gut-wrenching 3D binaural sound, for a new kind of weird immersion. You... | Read more »
RPG Asdivine Hearts (Games)
RPG Asdivine Hearts 1.1.0 Device: iOS Universal Category: Games Price: $3.99, Version: 1.1.0 (iTunes) Description: SPECIAL PRICE50% OFF (USD 7.99 -> USD 3.99)!!! Travel alongside four companions and a cat in the adventure of a... | Read more »

Price Scanner via MacPrices.net

Tablets Ascendent Again; Global Tablet Market...
The worldwide tablet grew 11.5% year over year in the third quarter of 2014 (3Q14) with shipments reaching 53.8 million units according to preliminary data from the International Data Corporation (... Read more
Apple now offering refurbished 2014 13-inch R...
The Apple Store is now offering Apple Certified Refurbished 2014 13″ Retina MacBook Pros for up to $270 off the cost of new models. An Apple one-year warranty is included with each model, and... Read more
Apple Regains Momentum As Windows Stutters An...
The latest smartphone sales data from Kantar Worldpanel ComTech, for the three months to March 2014, shows Apple performing strongly in the first quarter of the year, with sales bouncing back in... Read more
Worldwide Smartphone Shipments Increase 25.2%...
New smartphone releases and an increased emphasis on emerging markets drove global smartphone shipments above 300 million units for the second consecutive quarter, according to preliminary data from... Read more
Apple now offering refurbished 2014 15-inch M...
The Apple Store is now offering Apple Certified Refurbished 2014 15″ Retina MacBook Pros for up to $400 off the cost of new models. An Apple one-year warranty is included with each model, and... Read more
Apple drops prices on refurbished 2013 Retina...
The Apple Store has dropped prices on 2013 Apple Certified Refurbished 13″ and 15″ Retina MacBook Pros, with Retina models now available starting at $999. Apple’s one-year warranty is standard, and... Read more
New 2.8GHz Mac mini on sale for $949, save $5...
Abt Electronics has the new 2.8GHz Mac mini in stock and on sale for $949.05 including free shipping. Their price is $50 off MSRP, and it’s the lowest price available for this model from any reseller... Read more
Sale! 3.7GHz Quad Core Mac Pro available for...
 B&H Photo has the 3.7GHz Quad Core Mac Pro on sale for $2649 including free shipping plus NY sales tax only. Their price is $350 off MSRP, and it’s the lowest price for this model from any... Read more
Mujjo Steps Up The Game With Refined Touchscr...
Netherlands based Mujjo have just launched their Refined Touchscreen Gloves, stepping up their game. The gloves feature a updated elegant design that takes these knitted gloves to the next level. A... Read more
Sale! Preorder the new 27-inch 5K iMac for $2...
 Abt Electronics has the new 27″ 3.5GHz 5K iMac on sale and available for preorder for $2374.05 including free shipping. Their price is $125 off MSRP, and it’s the lowest price available for this... Read more

Jobs Board

Position Opening at *Apple* - Apple (United...
…Summary** As a Specialist, you help create the energy and excitement around Apple products, providing the right solutions and getting products into customers' hands. You Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** Being a Business Manager at an Apple Store means you're the catalyst for businesses to discover and leverage the power, ease, and flexibility of Apple Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** As more and more people discover Apple , they visit our stores seeking ways to incorporate our products into their lives. It's your job, as a Store Read more
Position Opening at *Apple* - Apple (United...
**Job Summary** At the Apple Store, you connect business professionals and entrepreneurs with the tools they need in order to put Apple solutions to work in their Read more
Solutions Specialist with *Apple* Knowledge...
Company Description: We are an Apple Authorized Sales and Service Provider. We have been selling and servicing Apple computers in the Fairfield County area for over Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.