home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow / Players / CutScene / main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  3.3 KB  |  108 lines

  1. //------------------------------------------------------------------------------
  2. // File: Main.cpp
  3. //
  4. // Desc: DirectShow sample code - simple movie player console application.
  5. //
  6. // Copyright (c) 2000-2001 Microsoft Corporation.  All rights reserved.
  7. //------------------------------------------------------------------------------
  8.  
  9.  
  10. //
  11. //   This program uses the PlayCutscene() function provided in cutscene.cpp.  
  12. //   It is only necessary to provide the name of a file and the application's 
  13. //   instance handle.
  14. //
  15. //   If the file was played to the end, PlayCutscene returns S_OK.
  16. //   If the user interrupted playback, PlayCutscene returns S_FALSE.
  17. //   Otherwise, PlayCutscene will return an HRESULT error code.
  18. //
  19. //   Usage: cutscene <required file name>
  20. //
  21.  
  22. #include <windows.h>
  23.  
  24. #include "cutscene.h"
  25.  
  26. #define USAGE \
  27.         TEXT("Cutscene is a console application that demonstrates\r\n")      \
  28.         TEXT("playing a movie at the beginning of your game.\r\n\r\n")       \
  29.         TEXT("Please provide a valid filename on the command line.\r\n")     \
  30.         TEXT("\r\n            Usage: cutscene <filename>\r\n")               \
  31.  
  32.  
  33. //
  34. // Main program code
  35. //
  36. int APIENTRY
  37. WinMain (
  38.          HINSTANCE hInstance,
  39.          HINSTANCE hPrevInstance,
  40.          LPSTR lpszMovie,
  41.          int nCmdShow
  42.          )
  43. {
  44.     HRESULT hr;
  45.     TCHAR szMovieName[MAX_PATH];
  46.  
  47.     // Prevent C4100: unreferenced formal parameter
  48.     hPrevInstance = hPrevInstance;
  49.     nCmdShow = nCmdShow;
  50.  
  51. #ifdef UNICODE
  52.     TCHAR szCommandLine[MAX_PATH], *pstrCommandLine=NULL;
  53.     UNREFERENCED_PARAMETER(lpszMovie);
  54.  
  55.     // Get the UNICODE command line.  This is necessary for UNICODE apps
  56.     // because the standard WinMain only passes in an LPSTR for command line.
  57.     lstrcpy(szCommandLine, GetCommandLine());
  58.     pstrCommandLine = szCommandLine;
  59.  
  60.     // Skip the first part of the command line, which is the full path 
  61.     // to the exe.  If the path contains spaces, it will be contained in quotes,
  62.     // so the leading and trailing quotes need to be removed.
  63.     if (*pstrCommandLine == TEXT('\"'))
  64.     {
  65.         // Remove the leading quotes
  66.         pstrCommandLine++;
  67.  
  68.         // Skip characters until we reach the trailing quotes
  69.         while (*pstrCommandLine != TEXT('\0') && *pstrCommandLine != TEXT('\"'))
  70.             pstrCommandLine++;
  71.  
  72.         // Strip trailing quotes from executable name
  73.         if( *pstrCommandLine == TEXT('\"'))
  74.             pstrCommandLine++;
  75.     }
  76.     else
  77.     {
  78.         // Executable name isn't encased in quotes, so just search for the
  79.         // first space, which indicates the end of the executable name.
  80.         while (*pstrCommandLine != TEXT('\0') && *pstrCommandLine != TEXT(' '))
  81.             pstrCommandLine++;
  82.     }
  83.  
  84.     // Strip all leading spaces on file name
  85.     while( *pstrCommandLine == TEXT(' '))
  86.         pstrCommandLine++;
  87.  
  88.    lstrcpy(szMovieName, pstrCommandLine);
  89.  
  90. #else
  91.     lstrcpy(szMovieName, lpszMovie);
  92. #endif
  93.  
  94.     // If no filename is specified, show an error message and exit
  95.     if (szMovieName[0] == TEXT('\0'))
  96.     {
  97.         MessageBox(NULL, USAGE, TEXT("Cutscene Error"), MB_OK | MB_ICONERROR);
  98.         exit(1);
  99.     }
  100.  
  101.     // Play movie
  102.     hr = PlayCutscene(szMovieName, hInstance);
  103.  
  104.     return hr;
  105. }
  106.  
  107.  
  108.