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

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // Filters.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 <qtw.h>
  12.  
  13. long FAR PASCAL __export WndProc  (HWND, UINT, WPARAM, LPARAM);
  14. BOOL CALLBACK __export TestFilter (MovieController, UINT,
  15.    LPVOID, LONG);
  16.  
  17. MovieController mcController;
  18. RECT rcNorm;
  19. short sMCHeight;
  20.  
  21. int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  22.    LPSTR lpszCmdParam, int nCmdShow)
  23.    {
  24.    static char szAppName[] = "Filters";
  25.    HWND        hWnd;
  26.    MSG         msg;
  27.    WNDCLASS    wndclass;
  28.    MovieFile   mfMovie;
  29.    RECT        rcMovie;
  30.    Movie       mMovie;
  31.  
  32. // Establish links to QuickTime for Windows
  33.  
  34.    if (QTInitialize (NULL))
  35.       {
  36.       MessageBox (NULL, "QTInitialize failure", szAppName, MB_OK);
  37.       return 0;
  38.       }
  39.  
  40. // Allocate memory required for playing movies
  41.  
  42.    if (EnterMovies ())
  43.       {
  44.       MessageBox (NULL, "EnterMovies failure", szAppName, MB_OK);
  45.       return 0;
  46.       }
  47.  
  48. // Register and create main window
  49.  
  50.    if (!hPrevInstance)
  51.       {
  52.       wndclass.style         = CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  53.       wndclass.lpfnWndProc   = WndProc;
  54.       wndclass.cbClsExtra    = 0;
  55.       wndclass.cbWndExtra    = 0;
  56.       wndclass.hInstance     = hInstance;
  57.       wndclass.hIcon         = LoadIcon (NULL,IDI_APPLICATION);
  58.       wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  59.       wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1);
  60.       wndclass.lpszMenuName  = NULL;
  61.       wndclass.lpszClassName = szAppName;
  62.  
  63.       if (!RegisterClass (&wndclass))
  64.          {
  65.          MessageBox (NULL, "RegisterClass failure", szAppName, MB_OK);
  66.          return 0;
  67.          }
  68.       }
  69.  
  70.    hWnd = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW |
  71.       WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
  72.       CW_USEDEFAULT, NULL, NULL, hInstance, NULL);
  73.  
  74.    if (hWnd == NULL)
  75.       {
  76.       MessageBox (NULL, "CreateWindow failure", szAppName, MB_OK);
  77.       return 0;
  78.       }
  79.  
  80. // Instantiate the movie
  81.  
  82.    if (OpenMovieFile ("SAMPLE.MOV", &mfMovie, OF_READ) != noErr)
  83.       {
  84.       MessageBox (NULL, "OpenMovieFile failure", szAppName, MB_OK);
  85.       return 0;
  86.       }
  87.  
  88.    NewMovieFromFile (&mMovie, mfMovie, NULL, NULL, 0, NULL);
  89.    CloseMovieFile (mfMovie);
  90.  
  91. // Get the normal movie dimensions. We'll use these as the
  92. // movie aspect ratio in the filter
  93.  
  94.    GetMovieBox (mMovie, &rcNorm);
  95.    OffsetRect (&rcNorm, -rcNorm.left, -rcNorm.top);
  96.  
  97. // Build the movie rectangle
  98.  
  99.    GetClientRect (hWnd, &rcMovie);
  100.    rcMovie.top = (rcMovie.bottom / 3) - (rcNorm.bottom / 2);
  101.    rcMovie.bottom = rcMovie.top + rcNorm.bottom;
  102.    rcMovie.left = (rcMovie.right / 3) - (rcNorm.right / 2);
  103.    rcMovie.right = rcMovie.left + rcNorm.right;
  104.  
  105. // Instantiate the movie controller
  106.  
  107.    mcController = NewMovieController (mMovie, &rcMovie,
  108.       mcTopLeftMovie + mcScaleMovieToFit + mcWithBadge, hWnd);
  109.  
  110. // Make the movie paused initially
  111.  
  112.    MCDoAction (mcController, mcActionPlay, 0);
  113.  
  114. // Calculate the controller height for use in filter
  115.  
  116.    MCGetControllerBoundsRect (mcController, &rcMovie);
  117.    OffsetRect (&rcMovie, -rcMovie.left, -rcMovie.top);
  118.    sMCHeight = rcMovie.bottom - rcNorm.bottom;
  119.  
  120. // Set an action filter, passing in the parent window handle
  121.  
  122.    MCSetActionFilter (mcController, TestFilter, (LONG) ((LPVOID) hWnd));
  123.  
  124. // Enable the keyboard interface
  125.  
  126.    MCDoAction (mcController, mcActionSetKeysEnabled, (LPVOID) TRUE);
  127.  
  128. // Make the movie active
  129.  
  130.    SetMovieActive (mMovie, TRUE);
  131.  
  132. // Make the movie visible
  133.  
  134.    ShowWindow (hWnd, nCmdShow);
  135.    UpdateWindow (hWnd);
  136.  
  137. // Play the movie
  138.  
  139.    while (GetMessage (&msg, NULL, 0, 0))
  140.       {
  141.       TranslateMessage (&msg);
  142.       DispatchMessage (&msg);
  143.       }
  144.  
  145. // Destroy the movie controller
  146.  
  147.    DisposeMovieController (mcController);
  148.  
  149. // Destroy the movie
  150.  
  151.    DisposeMovie (mMovie);
  152.  
  153. // Cut the connections to QuickTime for Windows
  154.  
  155.    ExitMovies ();
  156.    QTTerminate ();
  157.  
  158. // Return to Windows
  159.  
  160.    return msg.wParam;
  161.    }
  162.  
  163.  
  164. long FAR PASCAL WndProc (HWND hWnd, UINT message, WPARAM wParam,
  165.    LPARAM lParam)
  166.    {
  167.    PAINTSTRUCT ps;
  168.  
  169. // Drive the movie controller
  170.  
  171.    if (MCIsPlayerMessage (mcController, hWnd, message, wParam, lParam))
  172.       return 0;
  173.  
  174. // Process the windows message
  175.  
  176.    switch (message)
  177.       {
  178.       case WM_PAINT:
  179.  
  180.          if (!BeginPaint (hWnd, &ps))
  181.             return 0;
  182.          EndPaint (hWnd, &ps);
  183.          return 0;
  184.  
  185.       case WM_DESTROY:
  186.  
  187.          PostQuitMessage (0);
  188.          return 0;
  189.       }
  190.  
  191. // Return to Windows
  192.  
  193.    return DefWindowProc (hWnd, message, wParam, lParam);
  194.    }
  195.  
  196.  
  197. BOOL CALLBACK __export TestFilter (MovieController mcCaller,
  198.    UINT uAction, LPVOID lpParam, LONG refcon)
  199.    {
  200.    RECT rcBounds;
  201.    static BOOL bBlock;
  202.  
  203. // Don't want to recursively call ourselves
  204.  
  205.    if (bBlock)
  206.       return FALSE;
  207.  
  208. // Respond to mcAction
  209.  
  210.    switch (uAction)
  211.       {
  212.       case mcActionControllerSizeChanged:
  213.  
  214.       // Force a paint of the old client rectangle
  215.  
  216.          InvalidateRect ((HWND) refcon, NULL, TRUE);
  217.  
  218.          MCGetControllerBoundsRect (mcCaller, &rcBounds);
  219.  
  220.       // Calculate new bounds rect bottom
  221.  
  222.          rcBounds.bottom =
  223.             rcBounds.top + MulDiv (rcBounds.right - rcBounds.left,
  224.                rcNorm.bottom, rcNorm.right);
  225.  
  226.       // Add the controller height back in
  227.  
  228.          rcBounds.bottom += sMCHeight;
  229.  
  230.          bBlock = TRUE;
  231.          MCSetControllerBoundsRect (mcCaller, &rcBounds);
  232.          bBlock = FALSE;
  233.  
  234.          return TRUE;
  235.  
  236.       default:
  237.  
  238.          return FALSE;
  239.       }
  240.    }
  241.  
  242.