home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 …ember: Reference Library / Apple Developer Reference Library (December 1999) (Disk 1).iso / pc / what's new / sample code / quicktime / qteffects explode / main.c next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  4.4 KB  |  310 lines

  1. /*
  2.     File:        main.c
  3.     
  4.     Contains:    Code to generate a QuickTime movie with a QuickTime video effect in it.
  5.     
  6.     Written by:    Scott Kuechle
  7.                 (based heavily on QuickTime SDK QTShowEffect sample code by Tim Monroe)
  8.  
  9.     Copyright:    © 1999 by Apple Computer, Inc. All rights reserved
  10.     
  11.     Change History (most recent first)
  12.     
  13.         <1>        9/25/99        srk        first file
  14.         <2>        10/19/99    srk        changed cross fade effect to explode effect
  15.  
  16.  
  17. */
  18.  
  19.  
  20. #if TARGET_OS_WIN32
  21.         // Windows headers
  22.     #define    STRICT
  23.     #include <windows.h>
  24.         // QTML stuff
  25.     #include "QTML.h"
  26. #endif
  27.  
  28. #ifndef __FONTS__
  29. #include <Fonts.h>
  30. #endif
  31.  
  32. #ifndef __IMAGECODEC__
  33. #include <ImageCodec.h>
  34. #endif
  35.  
  36. #ifndef __MOVIES__
  37. #include <Movies.h>
  38. #endif
  39.  
  40. #ifndef __MOVIESFORMAT__
  41. #include <MoviesFormat.h>
  42. #endif
  43.  
  44. #ifndef __MEDIAHANDLERS__
  45. #include <MediaHandlers.h>
  46. #endif
  47.  
  48. #ifndef __NUMBERFORMATTING__
  49. #include <NumberFormatting.h>
  50. #endif
  51.  
  52. #ifndef __QUICKTIMECOMPONENTS__
  53. #include <QuickTimeComponents.h>
  54. #endif
  55.  
  56. #ifndef __ENDIAN__
  57. #include <Endian.h>
  58. #endif
  59.  
  60. #ifndef __GESTALT__
  61. #include <Gestalt.h>
  62. #endif
  63.  
  64. #ifndef __FIXMATH__
  65. #include <FixMath.h>
  66. #endif
  67.  
  68. #ifndef __MACWINDOWS__
  69. #include <MacWindows.h>
  70. #endif
  71.  
  72. #ifndef __PRINTING__
  73. #include <Printing.h>
  74. #endif
  75.  
  76. #ifndef __SCRIPT__
  77. #include <Script.h>
  78. #endif
  79.  
  80. #ifndef __SOUND__
  81. #include <Sound.h>
  82. #endif
  83.  
  84. #ifndef _STRING_H
  85. #include <string.h>
  86. #endif
  87.  
  88. #ifndef _STDLIB_H
  89. #include <stdlib.h>
  90. #endif
  91.  
  92. #ifndef __TEXTUTILS__
  93. #include <TextUtils.h>
  94. #endif
  95.  
  96. #ifndef __TRAPS__
  97. #include <Traps.h>
  98. #endif
  99.  
  100. #ifndef __RESOURCES__
  101. #include <Resources.h>
  102. #endif
  103.  
  104. #ifndef __FILETYPESANDCREATORS__
  105. #include <FileTypesAndCreators.h>
  106. #endif
  107.  
  108.  
  109.  
  110. #include "Main.h"
  111. #include "QTEffects.h"
  112.  
  113.  
  114. // miscellaneous constants
  115. #define kMsgDialogRsrcID                129
  116. #define kMsgItemID                        3    
  117.  
  118.  
  119.  
  120. #if TARGET_OS_WIN32
  121.  
  122.     short  gAppResID;
  123.  
  124. #endif
  125.  
  126. #if TARGET_OS_MAC
  127.  
  128.  
  129.  
  130. ////////////////////
  131. //
  132. // Main (Mac)
  133. //
  134. ////////////////////
  135.  
  136. void main( void )
  137. {
  138.     Movie movie;
  139.  
  140.  
  141.     InitMacToolbox ();
  142.     QuickTimeInit();
  143.         /* Create our effects movie */
  144.     movie = QTEffects_CreateEffectsMovie ();
  145. }
  146.  
  147. #else if TARGET_OS_WIN32
  148.  
  149.  
  150. ////////////////////
  151. //
  152. // Main (Windows)
  153. //
  154. ////////////////////
  155.  
  156. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  157.                     LPSTR lpszCmdLine, int nCmdShow)
  158.  
  159. {
  160.     Movie movie;
  161.  
  162.  
  163.     QuickTimeInit();
  164.  
  165.         /* Create our effects movie */
  166.     movie = QTEffects_CreateEffectsMovie ();
  167.  
  168.     #if TARGET_OS_WIN32
  169.  
  170.         if (gAppResID != -1)
  171.             CloseResFile(gAppResID);
  172.  
  173.     #endif
  174.  
  175.  
  176.     return 0;
  177. }
  178.  
  179. #endif
  180.  
  181.  
  182. #if TARGET_OS_MAC
  183.  
  184. ////////////////////
  185. //
  186. // InitMacToolbox
  187. // Standard Macintosh Toolbox Initialization
  188. //
  189. ////////////////////
  190.  
  191. static void InitMacToolbox (void)
  192. {
  193.     InitGraf (&qd.thePort);
  194.     InitFonts ();
  195.     InitWindows ();
  196.     InitMenus ();
  197.     TEInit ();
  198.     InitDialogs (nil);
  199. }
  200.  
  201. #endif
  202.  
  203. ////////////////////
  204. //
  205. // QuickTimeInit
  206. // Initialize QuickTime here
  207. //
  208. ////////////////////
  209.  
  210. static void QuickTimeInit (void)
  211. {
  212.     OSErr err;
  213.  
  214.     #if TARGET_OS_WIN32
  215.  
  216.     char   szAppPathName[256];
  217.  
  218.     FSSpec resFSSpec;
  219.  
  220.  
  221.     err = InitializeQTML(0L);
  222.     CheckError (err, "InitializeQTML error" );
  223.     
  224.     GetModuleFileName(0, szAppPathName, 256);
  225.     NativePathNameToFSSpec(szAppPathName, &resFSSpec, kFullNativePath);
  226.     gAppResID = FSpOpenResFile(&resFSSpec, fsRdWrPerm);
  227.  
  228.     #endif
  229.  
  230.     err = EnterMovies ();
  231.     CheckError (err, "EnterMovies error" );
  232. }
  233.  
  234. ////////////////////
  235. //
  236. // Utils_Macintosh_DisplayMsg
  237. // Displays error messages for Macintosh sample code.
  238. //
  239. ////////////////////
  240.  
  241. #if TARGET_OS_MAC
  242. static void Macintosh_DisplayMsg(char *msg)
  243. {
  244.     DialogPtr theDlog;
  245.     Handle item = NULL;
  246.     Rect box;
  247.  
  248.         theDlog = GetNewDialog(kMsgDialogRsrcID, NULL, (WindowPtr)-1);
  249.         if (theDlog != NULL)
  250.         {
  251.             short itemType;
  252.             
  253.                 GetDialogItem(theDlog, kMsgItemID, &itemType, &item, &box);
  254.                 if (item != NULL)
  255.                 {
  256.                     short itemHit;
  257.                     
  258.                         SetDialogItemText(item, c2pstr(msg));
  259.                         ModalDialog(NULL, &itemHit);
  260.                         DisposeDialog(theDlog);
  261.                         p2cstr((StringPtr)msg);    /* restore C-string */
  262.                 }
  263.         }
  264.  
  265. }
  266. #endif
  267.  
  268. ////////////////////
  269. //
  270. // Utils_Win32_DisplayMsg
  271. // Displays error messages for Win95/NT sample code.
  272. //
  273. ////////////////////
  274.  
  275. #if TARGET_OS_WIN32
  276. static void Win32_DisplayMsg(char *msg)
  277. {
  278.  
  279.     MessageBox(NULL, msg, "", MB_OK);
  280. }
  281. #endif
  282.  
  283.  
  284. ////////////////////
  285. //
  286. // CheckError
  287. // Displays error message if an error occurred
  288. //
  289. ////////////////////
  290.  
  291. void CheckError(OSErr error, char *msg)
  292. {
  293.     if (error == noErr)
  294.     {
  295.         return;
  296.     }
  297.     if (strlen(msg) > 0)
  298.     {
  299.         #if TARGET_OS_MAC
  300.             Macintosh_DisplayMsg(msg);
  301.         #else if TARGET_OS_WIN32
  302.             Win32_DisplayMsg(msg);
  303.         #endif
  304.         
  305.  
  306.         ExitToShell();
  307.  
  308.     }
  309. }
  310.