Retired Document
Important: This sample code may not represent best practices for current development. The project may use deprecated symbols and illustrate technologies and techniques that are no longer recommended.
Example2.c
/* |
File: Example2.c |
Contains: Compression of PICT Files |
The following sample code is similar to the previous example except |
that it requests files to compress until the user cancels and shows |
a slightly different use of the Standard Compression Dialog calls. |
This example is not a description of the "right" way to use these |
calls in an application. It should be used for comparison with the |
other examples. Example 3 is a better example of the "right" way to |
do things |
. |
Written by: |
Copyright: Copyright © 1992-1999 by Apple Computer, Inc., All Rights Reserved. |
You may incorporate this Apple sample source code into your program(s) without |
restriction. This Apple sample source code has been provided "AS IS" and the |
responsibility for its operation is yours. You are not permitted to redistribute |
this Apple sample source code as "Apple sample source code" after having made |
changes. If you're going to re-distribute the source, we require that you make |
it clear in the source that the code was descended from Apple sample source |
code, but that you've made changes. |
Change History (most recent first): |
8/17/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1 |
12/4/94 khs changed the format of the file to the new look and feel |
*/ |
// INCLUDE FILES |
#include <menus.h> |
#include <fonts.h> |
#include <osevents.h> |
#include <components.h> |
#include <quicktimecomponents.h> |
// FUNCTION PROTOTYPES |
void Example2(void); |
// FUNCTIONS |
void Example2(void) |
{ |
ComponentResult result; |
Point where; |
ComponentInstance ci; |
short sref; |
SFTypeList typeList; |
SFReply reply; |
// Open the Standard Compression Dialog component. |
ci = OpenDefaultComponent(StandardCompressionType, StandardCompressionSubType); |
if (ci) |
{ |
// Tell SFGetFilePreview to center on the best monitor. |
where.h = where.v = -2; |
// Show only 'PICT' files in the file list. |
typeList[0] = 'PICT'; |
// Keep asking the user for files until they cancel. |
reply.good = true; |
while (reply.good) |
{ |
// Ask user to select PICT file to be compressed. |
SFGetFilePreview(where, "\p", nil, 1, typeList, nil, &reply); |
if (reply.good) |
{ |
// If they selected a file, open that file. |
result = FSOpen(reply.fName, reply.vRefNum, &sref); |
if (!result) |
{ |
// If the file opened successfully, set the picture file to |
// be the test image shown in the dialog. Passing nil for srcRect |
// means use the entire image. Passing 0 for testFlags means |
// to use the default system method of displaying the test image |
// which is currently a combination of cropping and scaling. |
SCSetTestImagePictFile(ci, sref, nil, 0); |
// Because we may have already made default settings in a previous |
// pass through this loop, we need to set defaults specific to the |
// current picture file. This is particularly important because |
// defaults for the previous picture may include a color table |
// that is not appropriate for the current picture. |
// |
// There is a drawback to this approach. If the user wants to use |
// settings different from the defaults for several pictures, they |
// have to change the settings each time the compression dialog comes |
// up. The next example will show a better way of handling this problem |
// using the custom button. |
result = SCDefaultPictFileSettings(ci, sref, false); |
if (!result) |
{ |
// Now that we know there are current defaults settings, we must |
// explicitly request settings from the user. In the previous |
// example, SCCompressPictureFile requested settings from the user |
// for us because no default settings had been made. |
// |
// Note that the result code returned could include scUserCancelled. |
result = SCRequestImageSettings(ci); |
if (!result) |
{ |
// Compress the picture file with the settings chosen by the user. |
// The settings include any custom color table found in the source |
// picture if still appropriate for the depth chosen by the user. |
// |
// Again note that we are able to pass the source file ref for both the |
// source and destination picture files. In this case, the picture |
// file will be compressed in place. It would probably be better to |
// ask the user for a name to save the compressed file as, rather than |
// compressing it in place. |
result = SCCompressPictureFile(ci, sref, sref); |
// Another implementation would be to clear out the current settings |
// by calling SCSetInfo(ci,scSettingsStateType,nil) after calling |
// SCSetTestImagePictfile. We would then no longer need the calls |
// to SCDefaultPictFileSettings and SCRequestImageSettings because |
// SCCompressPictureFile would do that for us as it did in the first example. |
} |
} |
// Close the source picture file. |
FSClose(sref); |
} |
} |
} |
// Close the Standard Compression Dialog component. |
CloseComponent(ci); |
} |
} |
// MAIN FUNCTION |
void main(void) |
{ |
InitGraf(&qd.thePort); |
InitFonts(); |
FlushEvents(everyEvent, 0); |
InitWindows(); |
InitMenus(); |
InitDialogs(nil); |
InitCursor(); |
MaxApplZone(); |
Example2(); |
} |
Copyright © 2003 Apple Computer, Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2003-01-14