home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectShow_WinXP / VMR / VMRXcl / commands.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  4.1 KB  |  143 lines

  1. //----------------------------------------------------------------------------
  2. //  File:   commands.cpp
  3. //
  4. //  Desc:   DirectShow sample code
  5. //          Processes commands from the user.
  6. //
  7. //  Copyright (c) 2000-2001 Microsoft Corporation. All rights reserved.
  8. //----------------------------------------------------------------------------
  9. #include "project.h"
  10. #include <mmreg.h>
  11. #include <commctrl.h>
  12.  
  13. #include <stdio.h>
  14. #include <io.h>
  15. #include "resrc1.h"
  16.  
  17. // Function prototypes
  18. void RepositionMovie(HWND hwnd);
  19. bool FindMediaFile(TCHAR * achFileName, TCHAR * achFoundFile);
  20.  
  21. // External data
  22. extern TCHAR       g_achFileName[];
  23. extern CMpegMovie  * pMpegMovie;
  24.  
  25.  
  26. //----------------------------------------------------------------------------
  27. //  ProcessOpen
  28. // 
  29. //  Creates instance of CMpegMovie and plays it. Called from user UI functions.
  30. //
  31. //  Parameters:
  32. //          achFileName - path to the file to play
  33. //          bPlay       - start demonstration if true
  34. //----------------------------------------------------------------------------
  35. BOOL
  36. ProcessOpen(
  37.     TCHAR *achFileName,
  38.     BOOL bPlay
  39.     )
  40. {
  41.     TCHAR achFoundFile[MAX_PATH];
  42.  
  43.     if( !FindMediaFile(achFileName, achFoundFile) )
  44.     {
  45.         InvalidateRect( hwndApp, NULL, FALSE );
  46.         UpdateWindow( hwndApp );
  47.         return false;
  48.     }
  49.  
  50.     lstrcpy(g_achFileName, achFoundFile);
  51.     pMpegMovie = new CMpegMovie(hwndApp);
  52.  
  53.     if (pMpegMovie) {
  54.  
  55.         HRESULT hr = pMpegMovie->OpenMovie(g_achFileName);
  56.         if (SUCCEEDED(hr)) {
  57.  
  58.             TCHAR achTmp[MAX_PATH];
  59.  
  60.             wsprintf(achTmp, IdStr(STR_APP_TITLE_LOADED), g_achFileName );
  61.             g_State = (VCD_LOADED | VCD_STOPPED);
  62.  
  63.             RepositionMovie(hwndApp);
  64.             InvalidateRect(hwndApp, NULL, TRUE);
  65.  
  66.             if (bPlay) {
  67.                 pMpegMovie->PlayMovie();
  68.             }
  69.         }
  70.         else {
  71.             MessageBox(hwndApp,
  72.                        TEXT("Failed to open the movie; "),
  73.                        IdStr(STR_APP_TITLE), MB_OK );
  74.  
  75.             pMpegMovie->CloseMovie();
  76.             delete pMpegMovie;
  77.             pMpegMovie = NULL;
  78.         }
  79.     }
  80.  
  81.     InvalidateRect( hwndApp, NULL, FALSE );
  82.     UpdateWindow( hwndApp );
  83.     return TRUE;
  84. }
  85.  
  86. //----------------------------------------------------------------------------
  87. //  FindMediaFile
  88. // 
  89. //  Provides FileOpen dialog to select media file or processes command line
  90. //
  91. //  Parameters:
  92. //          achFileName     - command line
  93. //          achFoundFile    - path to the file to play
  94. //
  95. //  Return: true if success 
  96. //----------------------------------------------------------------------------
  97. bool FindMediaFile(TCHAR * achFileName, TCHAR * achFoundFile)
  98. {
  99.     long lFindRes;
  100.     struct _finddata_t fileinfo;
  101.  
  102.     lFindRes = _findfirst( achFileName, &fileinfo );
  103.     if( -1 != lFindRes )
  104.     {
  105.         lstrcpy(achFoundFile, achFileName);
  106.         return true;
  107.     }
  108.  
  109.     OPENFILENAME ofn;
  110.     TCHAR  szBuffer[MAX_PATH];
  111.  
  112.     lstrcpy(szBuffer, TEXT(""));
  113.     static char szFilter[]  = "Video Files (.MOV, .AVI, .MPG, .VOB, .QT)\0*.AVI;*.MOV;*.MPG;*.VOB;*.QT\0" \
  114.                               "All Files (*.*)\0*.*\0\0";
  115.     ofn.lStructSize         = sizeof(OPENFILENAME);
  116.     ofn.hwndOwner           = NULL;
  117.     ofn.hInstance           = NULL;
  118.     ofn.lpstrFilter         = szFilter;
  119.     ofn.nFilterIndex        = 1;
  120.     ofn.lpstrCustomFilter   = NULL;
  121.     ofn.nMaxCustFilter      = 0;
  122.     ofn.lpstrFile           = szBuffer;
  123.     ofn.nMaxFile            = _MAX_PATH;
  124.     ofn.lpstrFileTitle      = NULL;
  125.     ofn.nMaxFileTitle       = 0;
  126.     ofn.lpstrInitialDir     = NULL;
  127.     ofn.lpstrTitle          = "VMRXCL: Select a video file to play...";
  128.     ofn.Flags               = OFN_HIDEREADONLY;
  129.     ofn.nFileOffset         = 0;
  130.     ofn.nFileExtension      = 0;
  131.     ofn.lpstrDefExt         = "mov";
  132.     ofn.lCustData           = 0L;
  133.     ofn.lpfnHook            = NULL;
  134.     ofn.lpTemplateName  = NULL; 
  135.     
  136.     if (GetOpenFileName (&ofn))  // user specified a file
  137.     {
  138.         lstrcpy(achFoundFile, ofn.lpstrFile);
  139.         return true;
  140.     }// if
  141.  
  142.     return false;
  143. }