home *** CD-ROM | disk | FTP | other *** search
/ cyber.net 2 / cybernet2.ISO / qtw111 / samples / bigeight.c < prev    next >
C/C++ Source or Header  |  1992-10-22  |  16KB  |  530 lines

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // BigEight.c - Sample QuickTime for Windows Application
  5. //
  6. //              (c) 1988-1992 Apple Computer, Inc. All Rights Reserved.
  7. //
  8. // ---------------------------------------------------------------------
  9.  
  10. #include <windows.h>
  11. #include <stdlib.h>
  12. #include <qtw.h>
  13. #include "bigeight.h"
  14.  
  15. long FAR PASCAL __export WndProc (HWND, UINT, WPARAM, LPARAM);
  16.  
  17. MovieController mcController;
  18.  
  19. int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  20.    LPSTR lpszCmdParam, int nCmdShow)
  21.    {
  22.    static char szAppName[] = "BigEight";
  23.    HWND        hWnd;
  24.    MSG         msg;
  25.    WNDCLASS    wndclass;
  26.    Movie       mMovie;
  27.    RECT        rcMovie, rcMovieBox;
  28.    MovieFile   mfMovie;
  29.  
  30. // Establish links to QuickTime for Windows
  31.  
  32.    if (QTInitialize (NULL))
  33.       {
  34.       MessageBox (NULL, "QTInitialize failure", szAppName, MB_OK);
  35.       return 0;
  36.       }
  37.  
  38. // Allocate memory required for playing movies
  39.  
  40.    if (EnterMovies ())
  41.       {
  42.       MessageBox (NULL, "EnterMovies failure", szAppName, MB_OK);
  43.       return 0;
  44.       }
  45.  
  46. // Register and create main window
  47.  
  48.    if (!hPrevInstance)
  49.       {
  50.       wndclass.style         = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  51.       wndclass.lpfnWndProc   = WndProc;
  52.       wndclass.cbClsExtra    = 0;
  53.       wndclass.cbWndExtra    = 0;
  54.       wndclass.hInstance     = hInstance;
  55.       wndclass.hIcon         = LoadIcon (NULL,IDI_APPLICATION);
  56.       wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  57.       wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  58.       wndclass.lpszMenuName  = szAppName;
  59.       wndclass.lpszClassName = szAppName;
  60.  
  61.       if (!RegisterClass (&wndclass))
  62.          {
  63.          MessageBox (NULL, "RegisterClass failure", szAppName, MB_OK);
  64.          return 0;
  65.          }
  66.       }
  67.  
  68.    hWnd = CreateWindow (szAppName, szAppName, WS_OVERLAPPEDWINDOW |
  69.       WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  70.       CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
  71.  
  72.    if (hWnd == NULL)
  73.       {
  74.       MessageBox (NULL, "CreateWindow failure", szAppName, MB_OK);
  75.       return 0;
  76.       }
  77.  
  78. // Instantiate the movie
  79.  
  80.    if (OpenMovieFile ("SAMPLE.MOV", &mfMovie, OF_READ) != noErr)
  81.       {
  82.       MessageBox (NULL, "OpenMovieFile failure", szAppName, MB_OK);
  83.       return 0;
  84.       }
  85.  
  86.    NewMovieFromFile (&mMovie, mfMovie, NULL, NULL, 0, NULL);
  87.    CloseMovieFile (mfMovie);
  88.  
  89. // Instantiate the movie controller
  90.  
  91.    GetMovieBox (mMovie, &rcMovieBox);
  92.    OffsetRect(&rcMovieBox, -rcMovieBox.left, -rcMovieBox.top);
  93.  
  94.    GetClientRect (hWnd, &rcMovie);
  95.    rcMovie.top = (rcMovie.bottom / 2) - (rcMovieBox.bottom / 2);
  96.    rcMovie.bottom = rcMovie.top + rcMovieBox.bottom;
  97.    rcMovie.left = (rcMovie.right / 2) - (rcMovieBox.right / 2);
  98.    rcMovie.right = rcMovie.left + rcMovieBox.right;
  99.  
  100.    mcController = NewMovieController (mMovie, &rcMovie,
  101.       mcTopLeftMovie + mcScaleMovieToFit + mcWithBadge, hWnd);
  102.  
  103. // Make the movie paused initially
  104.  
  105.    MCDoAction (mcController, mcActionPlay, 0);
  106.  
  107. // Enable the keyboard interface
  108.  
  109.    MCDoAction (mcController, mcActionSetKeysEnabled, (LPVOID) TRUE);
  110.  
  111. // Make the movie active
  112.  
  113.    SetMovieActive (mMovie, TRUE);
  114.  
  115. // Make the main window visible
  116.  
  117.    ShowWindow (hWnd, nCmdShow);
  118.    UpdateWindow (hWnd);
  119.  
  120. // Play the movie
  121.  
  122.    while (GetMessage (&msg, NULL, 0, 0))
  123.       {
  124.       TranslateMessage (&msg);
  125.       DispatchMessage (&msg);
  126.       }
  127.  
  128. // Destroy the movie controller
  129.  
  130.    DisposeMovieController (mcController);
  131.  
  132. // Destroy the movie
  133.  
  134.    DisposeMovie (mMovie);
  135.  
  136. // Cut the connections to QuickTime for Windows
  137.  
  138.    ExitMovies ();
  139.    QTTerminate ();
  140.  
  141. // Return to Windows
  142.  
  143.    return msg.wParam;
  144.    }
  145.  
  146. long FAR PASCAL __export WndProc (HWND hWnd, UINT message, WPARAM wParam,
  147.    LPARAM lParam)
  148.    {
  149.    PAINTSTRUCT ps;
  150.    RECT        rcGrowBox;
  151.  
  152.    static BOOL bControllerVisible = TRUE;
  153.    static BOOL bGrowBoxVisible = TRUE;
  154.    static BOOL bKeysEnabled = TRUE;
  155.    static BOOL bLoopingEnabled = FALSE;
  156.    static BOOL bPalindromeEnabled = FALSE;
  157.    static BOOL bSoundEnabled = TRUE;
  158.    static BOOL bSpeakerVisible = TRUE;
  159.    static BOOL bSteppersVisible = TRUE;
  160.  
  161. // Drive the movie controller
  162.  
  163.    if (MCIsPlayerMessage (mcController, hWnd, message, wParam, lParam))
  164.       return 0;
  165.  
  166. // Process the windows message
  167.  
  168.    switch (message)
  169.       {
  170.       case WM_COMMAND:
  171.          {
  172.          HANDLE hMenu;
  173.  
  174.          hMenu= GetMenu (hWnd);
  175.  
  176.          switch (wParam)
  177.             {
  178.             case IDM_CONTROLLER:
  179.                {
  180.                if (bControllerVisible == FALSE)
  181.                   {
  182.  
  183.                // Change the controller menu item
  184.  
  185.                   ModifyMenu (hMenu, IDM_CONTROLLER, MF_BYCOMMAND |
  186.                      MF_STRING, IDM_CONTROLLER,
  187.                      (LPSTR) "Hide Controller");
  188.                   bControllerVisible = TRUE;
  189.  
  190.                // Show the controller
  191.  
  192.                   MCSetVisible (mcController, TRUE);
  193.  
  194.                // Ungray the other menu itmes
  195.  
  196.                   EnableMenuItem (hMenu, IDM_STEP_BUTTONS, MF_ENABLED);
  197.                   EnableMenuItem (hMenu, IDM_SPEAKER_BUTTON, MF_ENABLED);
  198.                   EnableMenuItem (hMenu, IDM_GROW_BOX, MF_ENABLED);
  199.                   EnableMenuItem (hMenu, IDM_KEYBOARD, MF_ENABLED);
  200.                   EnableMenuItem (hMenu, IDM_SOUND, MF_ENABLED);
  201.                   EnableMenuItem (hMenu, IDM_LOOPING, MF_ENABLED);
  202.                   EnableMenuItem (hMenu, IDM_PALINDROME, MF_ENABLED);
  203.                   }
  204.  
  205.                else
  206.                   {
  207.  
  208.                // Change the controller menu item
  209.  
  210.                   ModifyMenu (hMenu, IDM_CONTROLLER, MF_BYCOMMAND |
  211.                      MF_STRING, IDM_CONTROLLER,
  212.                      (LPSTR) "Show Controller");
  213.                   bControllerVisible = FALSE;
  214.  
  215.                // Hide the controller
  216.  
  217.                   MCSetVisible (mcController, FALSE);
  218.  
  219.                // Grey the rest of the menu items
  220.  
  221.                   EnableMenuItem (hMenu, IDM_STEP_BUTTONS, MF_GRAYED);
  222.                   EnableMenuItem (hMenu, IDM_SPEAKER_BUTTON, MF_GRAYED);
  223.                   EnableMenuItem (hMenu, IDM_GROW_BOX, MF_GRAYED);
  224.                   EnableMenuItem (hMenu, IDM_KEYBOARD, MF_GRAYED);
  225.                   EnableMenuItem (hMenu, IDM_SOUND, MF_GRAYED);
  226.                   EnableMenuItem (hMenu, IDM_LOOPING, MF_GRAYED);
  227.                   EnableMenuItem (hMenu, IDM_PALINDROME, MF_GRAYED);
  228.                   }
  229.                }
  230.                break;
  231.  
  232.             case IDM_STEP_BUTTONS:
  233.                {
  234.                LONG lFlags;
  235.  
  236.                if (bSteppersVisible == FALSE)
  237.                   {
  238.  
  239.                // Change the step button menu item
  240.  
  241.                   ModifyMenu (hMenu, IDM_STEP_BUTTONS, MF_BYCOMMAND |
  242.                      MF_STRING, IDM_STEP_BUTTONS,
  243.                      (LPSTR) "Hide Step Buttons");
  244.                   bSteppersVisible = TRUE;
  245.  
  246.                // Restore the step buttons
  247.  
  248.                   MCDoAction (mcController, mcActionGetFlags, &lFlags);
  249.                   lFlags &= ~mcFlagSuppressStepButtons;
  250.                   MCDoAction (mcController, mcActionSetFlags,
  251.                      (LPVOID) lFlags);
  252.                   }
  253.  
  254.                else
  255.                   {
  256.  
  257.                // Change the step button menu item
  258.  
  259.                   ModifyMenu (hMenu, IDM_STEP_BUTTONS, MF_BYCOMMAND |
  260.                      MF_STRING, IDM_STEP_BUTTONS,
  261.                      (LPSTR) "Show Step Buttons");
  262.                   bSteppersVisible = FALSE;
  263.  
  264.                // Hide the step buttons
  265.  
  266.                   MCDoAction (mcController, mcActionGetFlags, &lFlags);
  267.                   lFlags |= mcFlagSuppressStepButtons;
  268.                   MCDoAction (mcController, mcActionSetFlags,
  269.                      (LPVOID) lFlags);
  270.                   }
  271.                }
  272.                break;
  273.  
  274.             case IDM_SPEAKER_BUTTON:
  275.                {
  276.                LONG lFlags;
  277.  
  278.                if (bSpea