home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tolkit45.zip / os2tk45 / samples / mm / movie / movie.c < prev    next >
C/C++ Source or Header  |  1999-05-11  |  82KB  |  2,036 lines

  1. /*************************************************************************
  2.  * File Name    :  movie.c
  3.  *
  4.  * Description  :  This file contains the C source code required for the
  5.  *                 movie sample program.
  6.  *
  7.  * Concepts     :  The sample program illustrates how an application
  8.  *                 can play and edit a movie in a hardware independent manner.
  9.  *
  10.  *                 This sample application will demonstrate device control
  11.  *                 of a Software Motion Video device, playing and editing of
  12.  *                 a movie in an application specified window and in a window
  13.  *                 provided by the Softare Motion Video subsystem.
  14.  *
  15.  * MMPM/2 API's :  List of all MMPM/2 API's that are used in
  16.  *                 this module:
  17.  *
  18.  *                 mciSendCommand    MCI_OPEN
  19.  *                                   MCI_PLAY
  20.  *                                   MCI_PAUSE
  21.  *                                   MCI_RESUME
  22.  *                                   MCI_SEEK
  23.  *                                   MCI_CLOSE
  24.  *                                   MCI_SET
  25.  *                                   MCI_WINDOW
  26.  *                                   MCI_PUT
  27.  *                                   MCI_CUT
  28.  *                                   MCI_COPY
  29.  *                                   MCI_PASTE
  30.  *                  mmioGetHeader
  31.  *                  mmioSet
  32.  *                  mmioOpen
  33.  *                  mmioClose
  34.  *
  35.  * Required
  36.  *    Files     :  movie.c        Source Code.
  37.  *                 movie.h        Include file.
  38.  *                 movie.dlg      Dialog definition.
  39.  *                 movie.rc       Resources.
  40.  *                 movie.mak      Make file.
  41.  *                 movie.def      Linker definition file.
  42.  *                 movie.ico      Program icon.
  43.  *                 movie.wav      Program icon.
  44.  *
  45.  * Copyright (C) IBM 1993
  46.  *************************************************************************/
  47.  
  48. #define  INCL_WIN                   /* required to use Win APIs.           */
  49. #define  INCL_PM                    /* required to use PM APIs.            */
  50. #define  INCL_WINHELP               /* required to use IPF.                */
  51. #define  INCL_OS2MM                 /* required for MCI and MMIO headers   */
  52. #define  INCL_MMIOOS2               /* required for MMVIDEOHEADER          */
  53. #define  INCL_MMIO_CODEC            /* required for circular, secondary    */
  54. #define  INCL_SW                    /* required for circular, secondary    */
  55.                                     /* windows and graphic buttons         */
  56. #define  INCL_WINSTDFILE            /* required for open file dlg          */
  57. #define  INCL_WINSTDDLGS            /* required for open file dlg          */
  58.  
  59.  
  60. #include <os2.h>
  61. #include <os2me.h>
  62. #include <stdio.h>
  63. #include <stdlib.h>
  64. #include <string.h>
  65. #include <math.h>
  66. #include <dive.h>
  67.  
  68. #include <sw.h>
  69.  
  70.  
  71. #include "movie.h"
  72.  
  73. enum DeviceStates {ST_STOPPED, ST_PLAYING, ST_PAUSED, ST_REWIND};
  74. /*
  75.  * Procedure/Function Prototypes
  76.  */
  77.  
  78. MRESULT EXPENTRY MainDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  79.  
  80. BOOL    DoesFileExist( PSZ pszFileName );
  81. VOID    Finalize( VOID );
  82. BOOL    Initialize( VOID );
  83. VOID    InitializeHelp( VOID );
  84. USHORT  MessageBox( USHORT usMessageID, ULONG  ulStyle );
  85. BOOL    PlayTheAppFile( HWND hwnd );
  86. BOOL    PlayTheDefaultFile( HWND hwnd );
  87. BOOL    PlayTheMovie( HWND hwnd );
  88. VOID    SetMovieVolume( VOID );
  89. VOID    ShowMCIErrorMessage( ULONG ulError );
  90. VOID    StopTheDevice( VOID );
  91. VOID    ResumeTheMovie( HWND hwnd );
  92. VOID    PauseTheMovie( HWND hwnd );
  93. VOID    CloseTheDevice( VOID );
  94. BOOL    OpenTheDevice( HWND hwnd);
  95. VOID    EditTheMovie( HWND hwnd );
  96. BOOL    SendString( HWND hwnd, PCHAR pcMCIString, USHORT usUserParm );
  97. VOID    ResizeMovieWindow(HWND hwnd);
  98. VOID    InsertHelpMenuItem (PCHAR );
  99. BOOL    QueryDirectMode(VOID);
  100.  
  101. /*************** End of Procedure/Function Prototypes *************************/
  102.  
  103.   /********************/
  104.   /* Global Variables.*/
  105.   /********************/
  106. HAB    hab;
  107. HMQ    hmq;
  108. HWND   hwndFrame;                      /* Handle to the frame window.         */
  109. HWND   hwndClient;                     /* Handle to the client App window     */
  110. HWND   hwndAppFrame;                   /* Handle to the App frame window      */
  111. HWND   hwndHelpInstance;               /* Handle to Main Help window.         */
  112. HWND   hwndMainDialogBox;              /* Handle to the dialog window.        */
  113. HWND   hwndPlayPB;                     /* Handle to the play push button      */
  114. HWND   hwndRewindPB;                   /* Handle to the rewind push button    */
  115. HWND   hwndStopPB;                     /* Handle to the stop push button      */
  116. HWND   hwndPausePB;                    /* Handle to the pause push button     */
  117. HWND   hwndEditPB;                     /* Handle to the edit push button      */
  118. HWND   hwndApplication;                /* Handle to the Application RB        */
  119. HWND   hwndStandard;                   /* Handle to the Standard RB           */
  120. HWND   hwndVolumeSlider;               /* Handle to the Volume slider         */
  121. ULONG  ulMovieLength;                  /* Length of movie in mmtimeperframe   */
  122. ULONG  ulMovieWidth;                   /* Width of movie                      */
  123. ULONG  ulMovieHeight;                  /* Height of movie                     */
  124. SWP    swpAppFrame;
  125. HMMIO  hFile;                          /* handle to file                      */
  126.  
  127. enum   DeviceStates   eState = ST_STOPPED;      /* state of the device        */
  128.  
  129. SHORT  sVolumeLevel   = INIT_VOLUME;   /* desired volume level                */
  130. BOOL   fAudioOn       = FALSE;         /* Indicates that sound is supported   */
  131. BOOL   fPassedDevice  = FALSE;         /* for MCI_ACQUIRE to play the file    */
  132. BOOL   fDeviceOpen    = FALSE;         /* indicate we've opened for first time*/
  133. BOOL   fMovieLoaded   = FALSE;         /* indicate if we are loaded           */
  134. CHAR   achMsgBoxTitle[MAXNAMEL];       /* Error message box title             */
  135. CHAR   achTitle[MAXNAMEL];             /* buffer for window title text      */
  136.  
  137. CHAR   szReturn[CCHMAXPATH];           /* return value from mciSendString     */
  138. SHORT  sResizeWindow = 0;              /* flag set for resizing the widow     */
  139. SHORT  sKindOfPlay = 0;                /* flag set for which movie is playing */
  140. HPOINTER  hptrWait, hptrArrow;  /* Pointer handles for use during long waits. */
  141.  
  142. /************************** End of Global Variables ***************************/
  143.  
  144. /******************************************************************************
  145.  * Name         : main
  146.  *
  147.  * Description  : This function calls the Initialize procedure to prepare
  148.  *                everything for the program's operation, enters the
  149.  *                message loop, then calls Finalize to shut everything down
  150.  *                when the program is terminated.
  151.  *
  152.  * Concepts     : None.
  153.  *
  154.  * MMPM/2 API's : None.
  155.  *
  156.  * Parameters   : argc - Number of parameters passed into the program.
  157.  *                argv - Command line parameters.
  158.  *
  159.  * Return       : TRUE is returned to the operating system.
  160.  *
  161.  ******************************************************************************/
  162. INT main( VOID )
  163. {
  164.    QMSG    qmsg;
  165.  
  166.  
  167.  
  168.    if( !Initialize() )
  169.    {
  170.    while ( WinGetMsg( hab, (PQMSG) &qmsg, (HWND) NULL, 0, 0) )
  171.       WinDispatchMsg( hab, (PQMSG) &qmsg );
  172.  
  173.    Finalize();
  174.    }
  175.  
  176.    return( TRUE);
  177.  
  178. } /* End of main */
  179.  
  180. /******************************************************************************
  181.  * Name         : Initialize
  182.  *
  183.  * Description  : This function performs the necessary initializations and
  184.  *                setups that are required to show/run a secondary window
  185.  *                as a main window.  The message queue will be created, as will
  186.  *                the dialog box.
  187.  *
  188.  * Concepts     : Illustrates how to use secondary windows
  189.  *
  190.  * MMPM/2 API's : WinLoadSecondaryWindow
  191.  *
  192.  * Parameters   : None.
  193.  *
  194.  * Return       : BOOL, FALSE = success, TRUE = fail
  195.  *
  196.  ******************************************************************************/
  197. BOOL Initialize( VOID)
  198. {
  199.    CHAR     szHelp[CCHMAXPATH];          /* buffer for help menu text         */
  200.    CHAR     szDefaultSize[CCHMAXPATH];   /* buffer for default size menu text */
  201.    LONG     lmciSendStringRC;            /* return code from SendString       */
  202.    LONG     scrwidth,scrheight;          /* Width and height of screen        */
  203.    SWP      swpSEFrame;          /* struc containing information on Frame     */
  204.  
  205.  
  206.  
  207.    hab       = WinInitialize( 0);
  208.    hmq       = WinCreateMsgQueue( hab, 0);
  209.  
  210.  
  211.    /*****************************************************************/
  212.    /* Make sure that Direct Video is supported                      */
  213.    /*****************************************************************/
  214.  
  215.    if (!QueryDirectMode())
  216.    {
  217.       WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
  218.                     (PSZ)"Direct software motion video mode is not supported on this system.",
  219.                     (PSZ)"Ultieyes - Direct Mode Support Detection",
  220.                     0,
  221.                     MB_CANCEL | MB_ERROR | MB_MOVEABLE );
  222.  
  223.       return( TRUE );
  224.    }
  225.  
  226.  
  227.  
  228.  
  229.    hptrArrow = WinQuerySysPointer ( HWND_DESKTOP, SPTR_ARROW, FALSE );
  230.    hptrWait  = WinQuerySysPointer ( HWND_DESKTOP, SPTR_WAIT,  FALSE );
  231.  
  232.    /*****************************************************************/
  233.    /* Initialize the window. First, change pointer to a waiting     */
  234.    /* pointer, since this might take a couple of seconds.           */
  235.    /*****************************************************************/
  236.  
  237.    WinSetPointer ( HWND_DESKTOP, hptrWait );
  238.  
  239.    WinLoadString(
  240.       hab,                                  /* HAB for this window.           */
  241.       (HMODULE) NULL,                       /* Get the string from the .exe.  */
  242.       IDS_DEFAULTSIZE,                      /* Which string to get.           */
  243.       sizeof(szDefaultSize),                /* The size of the buffer.        */
  244.       szDefaultSize);                       /* The buffer to place the string.*/
  245.  
  246.    WinLoadString(
  247.       hab,                                  /* HAB for this window.           */
  248.       (HMODULE) NULL,                       /* Get the string from the .exe.  */
  249.       IDS_HELP,                             /* Which string to get.           */
  250.       sizeof(szHelp),                       /* The size of the buffer.        */
  251.       szHelp);                              /* The buffer to place the string.*/
  252.  
  253.    WinLoadString(
  254.       hab,                                  /* HAB for this dialog box.       */
  255.       (HMODULE) NULL,                       /* Get the string from the .exe.  */
  256.       IDS_MOVIE_ERROR,                      /* Which string to get.           */
  257.       (SHORT) sizeof( achMsgBoxTitle),      /* The size of the buffer.        */
  258.       achMsgBoxTitle);                      /* The buffer to place the string.*/
  259.  
  260.    hwndFrame =                    /* Returns the handle to the frame.         */
  261.        WinLoadSecondaryWindow(
  262.           HWND_DESKTOP,           /* Parent of the dialog box.                */
  263.           HWND_DESKTOP,           /* Owner of the dialog box.                 */
  264.           (PFNWP) MainDlgProc,    /* 'Window' procedure for the dialog box.   */
  265.           (HMODULE) NULL,         /* Where is the dialog.  Null is EXE file.  */
  266.           IDD_MAIN_WINDOW,        /* Dialog ID.                               */
  267.           (PVOID) NULL);          /* Creation Parameters for the dialog.      */
  268.  
  269.    /***************************************************************************/
  270.    /* Retrieve the handle to the dialog box by specifying the QS_DIALOG flag. */
  271.    /***************************************************************************/
  272.  
  273.    hwndMainDialogBox = WinQuerySecondaryHWND(hwndFrame, QS_DIALOG);
  274.  
  275.    /***************************************************************************/
  276.    /* Add Default Size menu item to system menu of the secondary window.      */
  277.    /***************************************************************************/
  278.  
  279.    WinInsertDefaultSize(hwndFrame, szDefaultSize);
  280.  
  281.    /***************************************************************************/
  282.    /* Add Help menu item to system menu of the secondary window.              */
  283.    /***************************************************************************/
  284.  
  285.    InsertHelpMenuItem(szHelp);
  286.  
  287.    /******************************************************************/
  288.    /* Get the window title string from the Resource string table     */
  289.    /* and set it as the window text for the dialog window.           */
  290.    /******************************************************************/
  291.    WinLoadString(
  292.       hab,                                  /* HAB for this dialog box.       */
  293.       (HMODULE) NULL,                       /* Get the string from the .exe.  */
  294.       IDS_PROGRAM_TITLE,                    /* Which string to get.           */
  295.       (SHORT) sizeof( achTitle),            /* The size of the buffer.        */
  296.       achTitle);                            /* The buffer to place the string.*/
  297.  
  298.    WinSetWindowText( hwndFrame, achTitle);
  299.  
  300.  
  301.    /******************************************************************/
  302.    /* Get the system values for screen width and height and then     */
  303.    /* place the main window appropriately(centered on the screen).   */
  304.    /******************************************************************/
  305.  
  306.    WinQueryWindowPos( HWND_DESKTOP, &swpSEFrame );
  307.    scrwidth  = swpSEFrame.cx;
  308.    scrheight = swpSEFrame.cy;
  309.  
  310.    WinQueryWindowPos( hwndFrame, &swpSEFrame );
  311.    scrwidth  = ceil((scrwidth - swpSEFrame.cx)/2);
  312.    scrheight = ceil((scrheight - swpSEFrame.cy)/2);
  313.  
  314.    WinSetWindowPos(hwndFrame,
  315.                    HWND_TOP,
  316.                    scrwidth,
  317.                    scrheight,
  318.                    swpSEFrame.cx,
  319.                    swpSEFrame.cy,
  320.                    SWP_SIZE | SWP_MOVE);
  321.  
  322.   /*************************************************************************/
  323.   /* Create a new window within our secondary window to play the movie.    */
  324.   /* When playing a movie in this window the Sendstring                    */
  325.   /* function will be passed this windows handle in order to know where    */
  326.   /* to put the movie before playing.                                      */
  327.   /*************************************************************************/
  328.  
  329.     WinRegisterClass(
  330.       hab,
  331.     "MovieWindow",
  332.     (PFNWP) NULL,
  333.     CS_SIZEREDRAW | CS_MOVENOTIFY,
  334.     0 );
  335.  
  336.   hwndAppFrame =  WinCreateWindow((HWND)hwndMainDialogBox,
  337.                                  "MovieWindow",
  338.                                   NULL,
  339.                                   WS_VISIBLE,
  340.                                   0,
  341.                                   0,
  342.                                   0,
  343.                                   0,
  344.                                   (HWND)hwndMainDialogBox,
  345.                                   HWND_TOP, ID_APPWINDOW, NULL, NULL );
  346.  
  347.    WinShowWindow( hwndFrame, TRUE );           /* Display the main window.    */
  348.  
  349.    InitializeHelp();                           /* Initialize the help.        */
  350.  
  351.    /*
  352.     * Now that we're done here, change the pointer back to the arrow.
  353.     */
  354.    WinSetPointer ( HWND_DESKTOP, hptrArrow );
  355.  
  356.    return( FALSE );
  357.  
  358. } /* end initialization */
  359.  
  360. /******************************************************************************
  361.  * Name         : Finalize
  362.  *
  363.  * Description  : This routine is called after the message dispatch loop
  364.  *                has ended because of a WM_QUIT message.  The code will
  365.  *                destroy the help instance, messages queue, and window.
  366.  *
  367.  * Concepts     : None.
  368.  *
  369.  * MMPM/2 API's : WinDestroySecondaryWindow
  370.  *
  371.  * Parameters   : None.
  372.  *
  373.  * Return       : None.
  374.  *
  375.  ******************************************************************************/
  376. VOID Finalize( VOID )
  377. {
  378.    /*
  379.     * Destroy the Help Instances.
  380.     */
  381.    if ( hwndHelpInstance != (HWND) NULL)
  382.    {
  383.       WinDestroyHelpInstance( hwndHelpInstance );
  384.    }
  385.  
  386.    WinDestroySecondaryWindow( hwndFrame );
  387.    WinDestroyMsgQueue( hmq );
  388.    WinTerminate( hab );
  389.  
  390. }  /* End of Finalize */
  391.  
  392. /******************************************************************************
  393.  * Name         : MainDlgProc
  394.  *
  395.  * Description  : This function controls the main dialog box.  It will handle
  396.  *                received messages such as pushbutton notifications, timing
  397.  *                events, etc.
  398.  *
  399.  * Concepts     : Illustrates:
  400.  *                  - How to participate in MMPM/2 device sharing scheme.
  401.  *                  - How to handle notification messages.
  402.  *                  - How to implement graphic pushbutton's
  403.  *                  - How to implement secondary windows.
  404.  *
  405.  * MMPM/2 API's : WinDefSecondaryWindowProc
  406.  *                mciSendString
  407.  *                   - acquire
  408.  *
  409.  * Parameters   : hwnd - Handle for the Main dialog box.
  410.  *                msg  - Message received by the dialog box.
  411.  *                mp1  - Parameter 1 for the just received message.
  412.  *                mp2  - Parameter 2 for the just received message.
  413.  *
  414.  * Return       : 0 or the result of default processing.
  415.  *
  416.  ******************************************************************************/
  417. MRESULT EXPENTRY MainDlgProc( HWND   hwnd,
  418.                               ULONG  msg,
  419.                               MPARAM mp1,
  420.                               MPARAM mp2 )
  421. {
  422.    LONG        lmciSendStringRC;      /* return value form mciSendString      */
  423.    HPOINTER    hpProgramIcon;         /* handle to program's icon             */
  424.    USHORT      usCommandMessage;      /* command message for notify           */
  425.    USHORT      usNotifyCode;          /* notification message code            */
  426.    SHORT       sWmControlID;          /* WM_CONTROL id                        */
  427.    ULONG       ulFrame;               /* video position in frames.            */
  428.    MRESULT     mresult;               /* return result                        */
  429.  
  430.    switch( msg )
  431.    {
  432.       case WM_INITDLG :
  433.          hpProgramIcon =
  434.             WinLoadPointer(
  435.                HWND_DESKTOP,
  436.                (HMODULE) NULL,              /* Resource is kept in .Exe file. */
  437.                ID_ICON );                   /* Which icon to use.             */
  438.  
  439.          WinDefSecondaryWindowProc(
  440.             hwnd,                    /* Dialog window handle.                 */
  441.             WM_SETICON,              /* Message to the dialog.  Set it's icon.*/
  442.             (MPARAM) hpProgramIcon,
  443.             (MPARAM) 0 );            /* mp2 no value.                         */
  444.  
  445.          /*********************************/
  446.          /* get all the required handles. */
  447.          /*********************************/
  448.                                                          /* volume slider     */
  449.          hwndVolumeSlider = WinWindowFromID( hwnd, IDC_VOLUME_SLIDER );
  450.  
  451.                                                          /* play push button  */
  452.  
  453.          hwndPlayPB      = WinWindowFromID( hwnd, IDC_GPB_PLAY );
  454.          hwndRewindPB    = WinWindowFromID( hwnd, IDC_GPB_REWIND );
  455.          hwndStopPB      = WinWindowFromID( hwnd, IDC_GPB_STOP);
  456.          hwndPausePB     = WinWindowFromID( hwnd, IDC_GPB_PAUSE );
  457.  
  458.          hwndEditPB      = WinWindowFromID( hwnd, IDC_GPB_EDIT );
  459.  
  460.                                                          /* application RB    */
  461.          hwndApplication = WinWindowFromID( hwnd, IDC_RADIO1 );
  462.  
  463.          if (!DoesFileExist( "movie.avi" ))
  464.           {
  465.              MessageBox( IDS_CANNOT_FIND_MOVIE_FILE,     /* ID of the message */
  466.                          MB_CANCEL | MB_ERROR  | MB_MOVEABLE);    /* style    */
  467.  
  468.              WinEnableWindow( hwndPlayPB, FALSE );
  469.              WinEnableWindow( hwndEditPB, FALSE );
  470.           }
  471.  
  472.  
  473.          /********************************************************************/
  474.          /*  Check to see if we have audio support                           */
  475.          /*                                                                  */
  476.          /********************************************************************/
  477.  
  478.          lmciSendStringRC =
  479.                SendString(hwnd, "sysinfo all name 1", 0);
  480.  
  481.          if ( strstr( szReturn, "Waveaudio" ) )
  482.          {
  483.             fAudioOn = TRUE;
  484.  
  485.             /********************************************************************/
  486.             /* The slider control cannot be completely set from the dialog      */
  487.             /* template so some aspects must be set here.  We will set the      */
  488.             /* volume range to 0-100, increment 1-10, and set the initial       */
  489.             /* volume level to 100.                                             */
  490.             /********************************************************************/
  491.             WinSendMsg( hwndVolumeSlider,
  492.                         CSM_SETRANGE,
  493.                         (MPARAM) 0L,
  494.                         (MPARAM) 100L);
  495.  
  496.             WinSendMsg( hwndVolumeSlider,
  497.                         CSM_SETINCREMENT,
  498.                         (MPARAM) 10L,
  499.                         (MPARAM) 1L);
  500.  
  501.             WinSendMsg( hwndVolumeSlider,
  502.                         CSM_SETVALUE,
  503.                         (MPARAM) sVolumeLevel,
  504.                         (MPARAM) NULL);
  505.          }
  506.  
  507.             /*****************/
  508.             /* Volume Slider */
  509.             /*****************/
  510.  
  511.             WinEnableWindow( hwndVolumeSlider, TRUE );
  512.  
  513.          /**********************************************/
  514.          /* Set the application window as the default  */
  515.          /**********************************************/
  516.          WinSendMsg(hwndApplication, BM_SETCHECK, MPFROMSHORT(1), NULL);
  517.  
  518.          return( (MRESULT) 0);
  519.  
  520.       case WM_CLOSE :
  521.  
  522.          /*********************************************/
  523.          /* If the device is opened, close the device */
  524.          /*********************************************/
  525.  
  526.          if (fDeviceOpen)
  527.             CloseTheDevice();
  528.  
  529.          return( WinDefSecondaryWindowProc( hwnd, msg, mp1, mp2 ) );
  530.  
  531.  
  532.       /*************************************************************/
  533.       /* This message is recieved when the user changes the volume */
  534.       /* or the radio buttons.                                     */
  535.       /*************************************************************/
  536.  
  537.       case WM_CONTROL:
  538.         sWmControlID  = SHORT1FROMMP(mp1);
  539.         usNotifyCode  = (USHORT) SHORT2FROMMP(mp1);
  540.  
  541.         switch ( sWmControlID )
  542.         {
  543.  
  544.            case IDC_VOLUME_SLIDER:
  545.               if ( ( usNotifyCode == CSN_CHANGED ) ||
  546.                    ( usNotifyCode == CSN_TRACKING ) )
  547.               {
  548.  
  549.                /**************************************************************/
  550.                /*  Every time the volume control setting is changed, save the*/
  551.                /*  new value in sVolumeLevel.                                */
  552.                /**************************************************************/
  553.  
  554.                  sVolumeLevel = SHORT1FROMMP (mp2);
  555.  
  556.                 /*****************************/
  557.                 /*  Set the new volume level */
  558.                 /*****************************/
  559.  
  560.                  SetMovieVolume();
  561.               }
  562.               break;
  563.  
  564.            case IDC_RADIO1:
  565.                     sKindOfPlay = 0;          /* play in application window */
  566.                 break;
  567.  
  568.            case IDC_RADIO2:
  569.                     sKindOfPlay = 1;          /* play in the default window */
  570.                     break;
  571.  
  572.  
  573.         }
  574.  
  575.         return( (MRESULT) 0);
  576.  
  577.       case WM_COMMAND :
  578.  
  579.         /**********************************************************************/
  580.         /* To get which pushbutton was pressed the SHORT1FROMMP macro is used.*/
  581.         /**********************************************************************/
  582.  
  583.          switch (SHORT1FROMMP(mp1))
  584.          {
  585.             case IDC_GPB_PLAY:               /* user selected "Play"        */
  586.  
  587.                switch ( eState )
  588.                {
  589.                   /**********************************************************/
  590.                   /* If the Movie is currently stopped, check to see if we  */
  591.                   /* were playing. if we were then resume.                  */
  592.                   /**********************************************************/
  593.                   case ST_STOPPED:
  594.  
  595.                     /****************************************************/
  596.                     /* Open the movie, resize the window if needed for  */
  597.                     /* the movie, then start playing.                   */
  598.                     /****************************************************/
  599.                      if (!fDeviceOpen)
  600.                        {
  601.                          OpenTheDevice ( hwnd );
  602.                        } /* if */
  603.                      if(sResizeWindow == 0 )
  604.                        {
  605.                          ResizeMovieWindow(hwnd);
  606.                          sResizeWindow = 1;
  607.                        }
  608.                      PlayTheMovie( hwnd );
  609.                      break;
  610.  
  611.                   /******************************************************/
  612.                   /* If the Movie is currently paused, resume the Movie */
  613.                   /******************************************************/
  614.                   case ST_PAUSED:
  615.                      ResumeTheMovie(hwnd);
  616.                      break;
  617.  
  618.                   case ST_REWIND:
  619.                      PlayTheMovie(hwnd);
  620.                      break;
  621.                }
  622.                break;
  623.  
  624.             case IDC_GPB_PAUSE:
  625.                switch ( eState )
  626.                {
  627.                  /************************************************/
  628.                  /* If the Movie is currently playing, pause it. */
  629.                  /************************************************/
  630.  
  631.                  case ST_PLAYING:
  632.                     PauseTheMovie(hwnd);
  633.                     break;
  634.  
  635.                  /***********************************************************/
  636.                  /* If the Movie is currently paused, resume the Movie play.*/
  637.                  /***********************************************************/
  638.  
  639.                  case ST_PAUSED:
  640.                     ResumeTheMovie(hwnd);
  641.                     break;
  642.                }
  643.               break;
  644.  
  645.             case IDC_GPB_REWIND:         /* User selected "Rewind" pushbutton */
  646.                if (fDeviceOpen)          /* If the device is opened.          */
  647.                  {
  648.                   eState = ST_REWIND;
  649.                   lmciSendStringRC =
  650.                             SendString(hwnd, "seek movie to start notify", 0);
  651.                  }
  652.                break;
  653.  
  654.             case IDC_GPB_EDIT:           /* User selected "Edit" pushbutton. */
  655.                  {
  656.                  MessageBox( IDS_EDIT_MOVIE,
  657.                              MB_OK | MB_INFORMATION  | MB_MOVEABLE);
  658.                  if (!fDeviceOpen)     /* check to see if the device is open.*/
  659.                    {
  660.                      OpenTheDevice ( hwnd );
  661.                    } /* if */
  662.                                        /* Stop the device if we are in a */
  663.                                        /* playing or paused state.       */
  664.                  if ((eState == ST_PLAYING) || (eState == ST_PAUSED))
  665.                    {
  666.                      StopTheDevice();
  667.                    } /* if */
  668.                   /*****************************************************/
  669.                   /* This function illustrates the cut, copy and paste */
  670.                   /* functionality.                                    */
  671.                   /*****************************************************/
  672.                   EditTheMovie(hwnd);
  673.  
  674.                  }
  675.                break;
  676.  
  677.             case IDC_GPB_STOP:         /* user selected "Stop" pushbutton */
  678.  
  679.                /***********************************************************/
  680.                /* If the Movie is not in stopped state, stop the device.  */
  681.                /***********************************************************/
  682.  
  683.                if (eState != ST_STOPPED)
  684.                  {
  685.                     StopTheDevice();
  686.                  }
  687.                break;
  688.  
  689.             case WM_HELP:      /* User selected "Help" from System menu   */
  690.  
  691.        /*********************************************************************/
  692.        /* The dialog window has received a request for help from the user.  */
  693.        /* Send the HM_DISPLAY_HELP message to the Help Instance with the IPF*/
  694.        /* resource identifier for the correct HM panel.  This will show the */
  695.        /* help panel for this sample program.                               */
  696.        /*********************************************************************/
  697.  
  698.          WinSendMsg( hwndHelpInstance,
  699.                      HM_DISPLAY_HELP,
  700.                      MPFROMSHORT(1),
  701.                      MPFROMSHORT(HM_RESOURCEID));
  702.  
  703.                break;
  704.  
  705.             default:
  706.                break;
  707.  
  708.          }  /* End of Command Switch */
  709.  
  710.          return( (MRESULT) 0);
  711.  
  712.       /**********************************************************************/
  713.       /* The next two messages are handled so that this application can     */
  714.       /* participate in device sharing.  Since it opens the device as a     */
  715.       /* shareable device, other applications can gain control of the       */
  716.       /* device.  When this happens, we will receive a MM_MCIPASSDEVICE     */
  717.       /* message.  We keep track of this device passing in the              */
  718.       /* fPassedDevice Boolean variable.                                    */
  719.       /*                                                                    */
  720.       /* We use the WM_ACTIVATE message to participate in device            */
  721.       /* sharing.  We first check to see if this is an activate             */
  722.       /* or a deactivate message (indicated by mp1).  Then,                 */
  723.       /* we check to see if we've passed control of the                     */
  724.       /* devices.  If these conditions are true, then                       */
  725.       /* we issue an acquire device command to regain control of            */
  726.       /* the device, since we're now the active window on the screen.       */
  727.       /*                                                                    */
  728.       /* This is one possible method that can be used to implement          */
  729.       /* device sharing. For applications that are more complex             */
  730.       /* than this sample program, developers may wish to take              */
  731.       /* advantage of a more robust method of device sharing.               */
  732.       /* This can be done by using the MCI_ACQUIRE_QUEUE flag on            */
  733.       /* the MCI_ACQUIREDEVICE command.  Please refer to the MMPM/2         */
  734.       /* documentation for more information on this flag.                   */
  735.       /**********************************************************************/
  736.  
  737.       case MM_MCIPASSDEVICE:
  738.          if (SHORT1FROMMP(mp2) == MCI_GAINING_USE)           /* GAINING USE */
  739.            {
  740.              fPassedDevice = FALSE;            /* Gaining control of device.*/
  741.            }
  742.          else                                               /* Losing use   */
  743.            {
  744.              fPassedDevice = TRUE;             /* Losing  control of device.*/
  745.            }
  746.          return( WinDefSecondaryWindowProc( hwnd, msg, mp1, mp2 ) );
  747.  
  748.       case WM_ACTIVATE:
  749.  
  750.        /*********************************************************************/
  751.        /* We use the WM_ACTIVATE message to participate in device sharing.  */
  752.        /* We first check to see if this is an activate or a deactivate      */
  753.        /* message (indicated by mp1).  Then, we check to see if we've passed*/
  754.        /* control of the Movie device.  If these conditions are true,       */
  755.        /* then we issue an acquire device command to regain control of      */
  756.        /* the device, since we're now the active window on the screen.      */
  757.        /*********************************************************************/
  758.          if ((BOOL)mp1 && fPassedDevice == TRUE)
  759.          {
  760.            /***********************************************************/
  761.            /* To acquire the device, we will issue MCI_ACQUIREDEVICE  */
  762.            /* command to the MCI.                                     */
  763.            /***********************************************************/
  764.  
  765.             SendString( hwnd, "acquire movie notify", 0 );
  766.          }
  767.          return( WinDefSecondaryWindowProc( hwnd, msg, mp1, mp2 ) );
  768.  
  769.       case MM_MCINOTIFY:
  770.  
  771.        /***********************************************************************/
  772.        /* This message is returned to an application when a device            */
  773.        /* successfully completes a command that was issued with a NOTIFY      */
  774.        /* flag, or when an error occurs with the command.                     */
  775.        /*                                                                     */
  776.        /* This message returns two values. A user parameter (mp1) and         */
  777.        /* the command message (mp2) that was issued. The low word of mp1      */
  778.        /* is the Notification Message Code which indicates the status of the  */
  779.        /* command like success or failure. The high word of mp2 is the        */
  780.        /* Command Message which indicates the source of the command.          */
  781.        /***********************************************************************/
  782.  
  783.          usNotifyCode    = (USHORT) SHORT1FROMMP( mp1);  /* low-word  */
  784.          usCommandMessage = (USHORT) SHORT2FROMMP( mp2); /* high-word */
  785.  
  786.          switch (usCommandMessage)
  787.          {
  788.             case MCI_PLAY:
  789.                switch (usNotifyCode)
  790.                {
  791.                   case MCI_NOTIFY_SUPERSEDED:
  792.                   case MCI_NOTIFY_ABORTED:
  793.  
  794.                      /* we don't need to handle these messages. */
  795.                      break;
  796.  
  797.                   /********************************************************/
  798.                   /* This case is used for either successful completion   */
  799.                   /* of a command or for an error.                        */
  800.                   /********************************************************/
  801.  
  802.                   default:
  803.                    if (eState != ST_STOPPED)
  804.                      {
  805.                         eState = ST_STOPPED;
  806.                         if ( usNotifyCode != MCI_NOTIFY_SUCCESSFUL)
  807.  
  808.                            /*************************************************/
  809.                            /* Notification error message. We need to display*/
  810.                            /* the error message to the user.                */
  811.                            /*************************************************/
  812.  
  813.                            ShowMCIErrorMessage( usNotifyCode);
  814.                            fMovieLoaded = FALSE;
  815.  
  816.                      }
  817.  
  818.                     break;
  819.                }
  820.                break;
  821.          }
  822.          return( (MRESULT) 0);
  823.  
  824.       default:
  825.          return( WinDefSecondaryWindowProc( hwnd, msg, mp1, mp2));
  826.  
  827.    }  /* End of msg Switch */
  828.  
  829. } /* End of MainDlgProc */
  830.  
  831. /******************************************************************************
  832.  * Name         :  PlayTheAppFile
  833.  *
  834.  * Description  :  This procedure will load a specific movie file into the
  835.  *                 application defined video window.
  836.  *
  837.  * Concepts     :  - Playing a movie in a application defined window.
  838.  *                   in a device independent manner.
  839.  *                 - Loading a file into an already open device.
  840.  *
  841.  * MMPM/2 API's :  mciSendString
  842.  *                    - load
  843.  *                    - put
  844.  *                    - window handle
  845.  *
  846.  * Parameters   :  hwnd  - Handle for the main window.
  847.  *
  848.  * Return       :  TRUE  -  if the operation was initiated without error.
  849.  *                 FALSE -  if an error occurred.
  850.  *
  851.  ******************************************************************************/
  852. BOOL PlayTheAppFile( HWND hwnd )
  853. {
  854.    LONG    lmciSendStringRC;         /* return code from SendString           */
  855.  
  856.    CHAR    szHandle[12] = "";        /* string used for window handle         */
  857.    CHAR    szx[5]       = "";        /* string used for x position of window  */
  858.    CHAR    szy[5]       = "";        /* string used for y position of window  */
  859.    CHAR    szcx[5]      = "";        /* string used for cx position of window */
  860.    CHAR    szcy[5]      = "";        /* string used for cy position of window */
  861.  
  862.    /*******************************************************************/
  863.    /* The szWindowString and szPutString are used as a foundation     */
  864.    /* for building a string command to send to sendstring             */
  865.    /*******************************************************************/
  866.  
  867.    CHAR    szWindowString[CCHMAXPATH] =
  868.              "window movie handle ";      /* string command to mciSendString */
  869.  
  870.    CHAR    szPutString[CCHMAXPATH] =
  871.             "put movie destination at ";  /* string command to mciSendString */
  872.  
  873.    /**********************************************************************/
  874.    /* Change pointer to a waiting pointer first, since this might take a */
  875.    /* couple of seconds.                                                 */
  876.    /**********************************************************************/
  877.  
  878.    WinSetPointer( HWND_DESKTOP, hptrWait );
  879.  
  880.    /******************************************************/
  881.    /* Convert the Frame window handle to a string so     */
  882.    /* we can use the mciSendStringCommand.               */
  883.    /******************************************************/
  884.  
  885.    hwndAppFrame    = WinWindowFromID( hwnd, ID_APPWINDOW );
  886.  
  887.    _ultoa(hwndAppFrame,szHandle,10);
  888.  
  889.  
  890.    /*****************************************/
  891.    /* Concatenate the converted handle to   */
  892.    /* the window string so we can issue the */
  893.    /* send string command.                  */
  894.    /*****************************************/
  895.    strcat (szWindowString, szHandle);
  896.    strcat (szWindowString, " ");
  897.    strcat (szWindowString, "wait");
  898.  
  899.    /* Send the window handle to the alias window */
  900.    lmciSendStringRC = SendString(hwnd, szWindowString, 0);
  901.  
  902.    /* Load the movie if it needs to be loaded */
  903.  
  904.    if (!fMovieLoaded)
  905.      {
  906.        lmciSendStringRC = SendString(hwnd, "load movie movie.avi wait", 0);
  907.        if ( lmciSendStringRC )
  908.          {
  909.            fMovieLoaded = TRUE;
  910.          }
  911.        else
  912.          {
  913.            MessageBox( IDS_CANNOT_LOAD_MOVIE_FILE,
  914.                        MB_CANCEL | MB_ERROR  | MB_MOVEABLE);
  915.            return( FALSE );
  916.          } /* else */
  917.  
  918.      } /* if */
  919.  
  920.    /******************************************************/
  921.    /* Convert the frame windows sizes to strings so      */
  922.    /* we can use the mciSendStringCommand to put the     */
  923.    /* video in our application frame window.             */
  924.    /******************************************************/
  925.  
  926.      WinQueryWindowPos (hwndAppFrame, &swpAppFrame);
  927.  
  928.        swpAppFrame.x = 0;
  929.        swpAppFrame.y = 0;
  930.  
  931.      /**********************************************************/
  932.      /* convert the application windows coordinates to strings */
  933.      /* so we can issue the the sendstring command             */
  934.      /**********************************************************/
  935.      _ultoa(swpAppFrame.x,szx,10);
  936.      _ultoa(swpAppFrame.y,szy,10);
  937.      _ultoa(swpAppFrame.cx,szcx,10);
  938.      _ultoa(swpAppFrame.cy,szcy,10);
  939.  
  940.      /**********************************************************/
  941.      /* concatenate the converted strings to the the put string*/
  942.      /* so we can issue the the sendstring command             */
  943.      /**********************************************************/
  944.  
  945.      strcat (szPutString, szx);
  946.      strcat (szPutString, " ");
  947.      strcat (szPutString, szy);
  948.      strcat (szPutString, " ");
  949.      strcat (szPutString, szcx);
  950.      strcat (szPutString, " ");
  951.      strcat (szPutString, szcy);
  952.      strcat (szPutString, " ");
  953.      strcat (szPutString, "wait");
  954.  
  955.    /* Send the put command along with the window coordinates. */
  956.  
  957.      lmciSendStringRC = SendString( hwnd, szPutString, 0 );
  958.  
  959.    /******************************************************************/
  960.    /* Now that we're done here, change the pointer back to the arrow.*/
  961.    /******************************************************************/
  962.    WinSetPointer ( HWND_DESKTOP, hptrArrow );
  963.  
  964.    return( TRUE );
  965.  
  966. }  /* end of PlayTheAppFile */
  967.  
  968. /******************************************************************************
  969.  * Name         :  PlayTheDefaultFile
  970.  *
  971.  * Description  :  This procedure will load a specific movie file into
  972.  *                 the applications default video window.  Default video
  973.  *                 window will appear in the lower left origin of the screen.
  974.  *
  975.  *
  976.  * Concepts     :  - Playing a movie in the default window in a device
  977.  *                   independent manner.
  978.  *                 - Loading a file into an already open device.
  979.  *
  980.  * MMPM/2 API's :  mciSendString
  981.  *                    - load
  982.  *
  983.  * Parameters   :  hwnd  - Handle for the Main dialog box.
  984.  *
  985.  * Return       :  TRUE  -  if the operation was initiated without error.
  986.  *                 FALSE -  if an error occurred.
  987.  *
  988.  ******************************************************************************/
  989. BOOL PlayTheDefaultFile( HWND hwnd )
  990. {
  991.    LONG    lmciSendStringRC;            /* return code from SendString   */
  992.  
  993.    /**********************************************************************/
  994.    /* Change pointer to a waiting pointer first, since this might take a */
  995.    /* couple of seconds.                                                 */
  996.    /**********************************************************************/
  997.  
  998.    WinSetPointer( HWND_DESKTOP, hptrWait );
  999.  
  1000.    if (!fMovieLoaded)
  1001.      {
  1002.        lmciSendStringRC = SendString(hwnd, "load movie movie.avi wait", 0);
  1003.        if (lmciSendStringRC)
  1004.          {
  1005.            fMovieLoaded = TRUE;
  1006.          }
  1007.        else
  1008.          {
  1009.            MessageBox( IDS_CANNOT_LOAD_MOVIE_FILE,
  1010.                        MB_CANCEL | MB_ERROR  | MB_MOVEABLE);
  1011.            return( FALSE );
  1012.          } /* else */
  1013.      } /* if */
  1014.  
  1015.  
  1016.    /* Send the window command to play the movie in the default window. */
  1017.    SendString(hwnd,"window movie handle default wait", 0 );
  1018.  
  1019.    /******************************************************************/
  1020.    /* Now that we're done here, change the pointer back to the arrow.*/
  1021.    /******************************************************************/
  1022.    WinSetPointer ( HWND_DESKTOP, hptrArrow );
  1023.  
  1024.    return( TRUE );
  1025.  
  1026. }  /* end of PlayTheDefaultFile */
  1027.  
  1028. /*************************************************************************
  1029.  * Name         :  PlayTheMovie
  1030.  *
  1031.  * Description  :  This procedure will begin playing a movie file.
  1032.  *                 It is invoked when the user selects the Play pushbutton
  1033.  *                 on the application's main window.  The movie will be
  1034.  *                 played in either a application defined window or in a
  1035.  *                 default window depending on the state of the radio buttons.
  1036.  *
  1037.  *
  1038.  * Concepts     :  Playing a movie file using the MCI interface.
  1039.  *
  1040.  * MMPM/2 API's :  mciSendString
  1041.  *                    - play
  1042.  *
  1043.  * Parameters   :  hwnd - Handle for the main dialog box.
  1044.  *
  1045.  * Return       :  TRUE  -  if the operation was initiated without error.
  1046.  *                 FALSE -  if an error occurred.
  1047.  *
  1048.  ******************************************************************************/
  1049. BOOL PlayTheMovie( HWND hwnd)
  1050. {
  1051.  
  1052.    /*******************************************/
  1053.    /* Check to see which window we want to    */
  1054.    /* play the movie in.                      */
  1055.    /*******************************************/
  1056.  
  1057.    if (WinSendMsg(hwndApplication, BM_QUERYCHECK, NULL,NULL ))
  1058.      {
  1059.        /* Play the movie in the application window */
  1060.        if (!PlayTheAppFile(hwnd))
  1061.          {
  1062.            return (FALSE);
  1063.          }
  1064.  
  1065.      } /* if */
  1066.    else
  1067.      {
  1068.        /* Play the movie in the default window */
  1069.        if (!PlayTheDefaultFile(hwnd))
  1070.          {
  1071.            return( FALSE );
  1072.          } /* if */
  1073.      }
  1074.  
  1075.    eState = ST_PLAYING;                      /* set state to PLAYING         */
  1076.  
  1077.    SetMovieVolume();                         /* set the starting volume      */
  1078.  
  1079.    /**************************************************************************/
  1080.    /* To play the movie, we will issue an MCI_PLAY command via mciSendString.*/
  1081.    /* A MM_MCINOTIFY message will be sent to the window specified in         */
  1082.    /* SendString when the operation is completed.                            */
  1083.    /**************************************************************************/
  1084.    SendString( hwnd,"play movie notify", 0 );
  1085.  
  1086.    return( TRUE );
  1087.  
  1088. }  /* end of PlayTheMovie */
  1089.  
  1090. /*************************************************************************
  1091.  * Name         :  ResumeTheMovie
  1092.  *
  1093.  * Description  :  This procedure will resume the playing of the movie
  1094.  *                 once it has been paused.
  1095.  *
  1096.  * Concepts     :  Resuming the movie using MCI interface.
  1097.  *
  1098.  * MMPM/2 API's :  mciSendString
  1099.  *                    - resume
  1100.  *
  1101.  * Parameters   :  hwnd - window handle
  1102.  *
  1103.  * Return       :  none.
  1104.  *
  1105.  *************************************************************************/
  1106. VOID ResumeTheMovie( HWND hwnd)
  1107. {
  1108.      /*********************************************/
  1109.      /* Check to see which pushbutton is selected.*/
  1110.      /*********************************************/
  1111.  
  1112.       if (!WinSendMsg(hwndApplication, BM_QUERYCHECK, NULL, NULL))
  1113.         {
  1114.           PlayTheDefaultFile(hwnd);
  1115.         } /* if */
  1116.       else
  1117.         {
  1118.           PlayTheAppFile(hwnd);
  1119.         } /* else */
  1120.  
  1121.    /*******************************************************************/
  1122.    /* To resume the movie, we will issue an MCI_RESUME command via    */
  1123.    /* MciSendString.                                                  */
  1124.    /*******************************************************************/
  1125.    if (SendString( (HWND)NULL, "resume movie wait", 0 ) )
  1126.      {
  1127.        eState = ST_PLAYING;
  1128.        SetMovieVolume();
  1129.      }
  1130.  
  1131.    return;
  1132. }  /* End of ResumeTheMovie */
  1133.  
  1134. /******************************************************************************
  1135.  * Name         :  PauseTheMovie
  1136.  *
  1137.  * Description  :  This procedure will pause the playing of the movie that
  1138.  *                 that is currently playing.
  1139.  *
  1140.  * Concepts     :  Pausing the movie using MCI interface.
  1141.  *
  1142.  * MMPM/2 API's :  mciSendString
  1143.  *                    - pause
  1144.  *
  1145.  * Parameters   :  hwnd - window handle
  1146.  *
  1147.  * Return       :  none.
  1148.  *
  1149.  ******************************************************************************/
  1150. VOID PauseTheMovie( HWND hwnd)
  1151. {
  1152.  
  1153.   USHORT sCheckState;
  1154.  
  1155.    /*******************************************************************/
  1156.    /* To pause the movie, we will issue an MCI_PAUSE command via      */
  1157.    /* MciSendString.                                                  */
  1158.    /*******************************************************************/
  1159.  
  1160.    if ( SendString( (HWND)NULL, "pause movie wait", 0 ) )
  1161.     {
  1162.        eState = ST_PAUSED;
  1163.     }
  1164.  
  1165.    return;
  1166. }  /* end of PauseTheMovie */
  1167.  
  1168. /******************************************************************************
  1169.  * Name         :  StopTheDevice
  1170.  *
  1171.  * Description  :  This procedure will stop the device that is playing.
  1172.  *
  1173.  * Concepts     :  Stopping a device using the MCI interface.
  1174.  *
  1175.  * MMPM/2 API's :  mciSendString
  1176.  *                    - stop
  1177.  *
  1178.  * Parameters   :  none
  1179.  *
  1180.  * Return       :  nothing.
  1181.  *
  1182.  *****************************************************************************/
  1183. VOID StopTheDevice( VOID )
  1184. {
  1185.  
  1186.  /****************************************************************************/
  1187.  /* To stop the device , we will issue an string command using mciSendString.*/
  1188.  /* This stop command is done for the alias.                                 */
  1189.  /****************************************************************************/
  1190.  
  1191.    if (SendString( (HWND)NULL, "stop movie wait", 0 ) )
  1192.    {
  1193.       if (eState == ST_PLAYING)
  1194.         {
  1195.           eState = ST_STOPPED;
  1196.         }
  1197.    }
  1198.  
  1199.    return;
  1200. }  /* end of StopTheDevice */
  1201.  
  1202.  
  1203. /*************************************************************************
  1204.  * Name         :  CloseTheDevice
  1205.  *
  1206.  * Description  :  This procedure will close the Movie device.
  1207.  *
  1208.  * Concepts     :  Closing a device using MCI interface.
  1209.  *
  1210.  * MMPM/2 API's :  mciSendString
  1211.  *                    - close
  1212.  *
  1213.  * Parameters   :  None.
  1214.  *
  1215.  * Return       :  nothing.
  1216.  *
  1217.  *****************************************************************************/
  1218. VOID CloseTheDevice( VOID)
  1219. {
  1220.  
  1221.  /****************************************************************************/
  1222.  /* To close the device , we will issue a string command using mciSendString.*/
  1223.  /* This close command is done for the alias.                                */
  1224.  /****************************************************************************/
  1225.  
  1226.    fDeviceOpen = FALSE;
  1227.    fMovieLoaded = FALSE;
  1228.    SendString((HWND)NULL, "close movie wait", 0 );
  1229.  
  1230.    return;
  1231.  
  1232. }  /* end of CloseTheDevice */
  1233.  
  1234. /*************************************************************************
  1235.  * Name         :  OpenTheDevice
  1236.  *
  1237.  * Description  :  This procedure will open the Movie device.
  1238.  *
  1239.  * Concepts     :  Opening a device using MCI interface.
  1240.  *
  1241.  * MMPM/2 API's :  mciSendString
  1242.  *                    - open
  1243.  *
  1244.  * Parameters   :  hwnd - window handle
  1245.  *
  1246.  * Return       :  None
  1247.  *
  1248.  *****************************************************************************/
  1249. BOOL OpenTheDevice( HWND hwnd)
  1250. {
  1251.   if (!fDeviceOpen )
  1252.  
  1253.   {
  1254.      /******************************************************************/
  1255.      /* To open the device, we will issue MCI_OPEN command to the MCI  */
  1256.      /* for digital video.                                             */
  1257.      /******************************************************************/
  1258.      if ( SendString( hwnd,
  1259.                       "open digitalvideo alias movie wait shareable",
  1260.                       0 ) )
  1261.  
  1262.      {
  1263.         /* Open success, set the flag and return true */
  1264.  
  1265.         fDeviceOpen = TRUE;
  1266.  
  1267.         return(TRUE);
  1268.      }
  1269.   }
  1270.  
  1271.   return( FALSE );
  1272.  
  1273. }  /* end of OpenTheDevice */
  1274.  
  1275. /*************************************************************************
  1276.  * Name         :  EditTheMovie
  1277.  *
  1278.  * Description  :  This procedure will edit the movie file in the following
  1279.  *                 manner:  first we will load the movie, then set the data
  1280.  *                 format to frames.  The next thing we do is copy the first
  1281.  *                 25 frames which places these frames into the clipboard.
  1282.  *                 Then paste the 25 frames 4 times, which actually duplicates
  1283.  *                 our first 25 frames 4 times.  The last step is to cut the
  1284.  *                 first 10 frames from the movie which places them in the
  1285.  *                 clipboard then seek to the end of the movie and paste them
  1286.  *                 to the end.  The cut API actually deletes the specified
  1287.  *                 number of frames from the position you specified the cut.
  1288.  *
  1289.  * Concepts     :  Editing a movie using the MCI string interface.
  1290.  *
  1291.  * MMPM/2 API's :  mciSendString
  1292.  *                    - cut
  1293.  *                    - copy
  1294.  *                    - paste
  1295.  *
  1296.  * Parameters   :  hwnd - window handle
  1297.  *
  1298.  * Return       :  nothing.
  1299.  *
  1300.  ******************************************************************************/
  1301. VOID EditTheMovie( HWND hwnd)
  1302. {
  1303.    LONG    lmciSendStringRC;            /* return code from SendString */
  1304.  
  1305.  /**********************************************************************/
  1306.  /* Change pointer to a waiting pointer first, since this might take a */
  1307.  /* couple of seconds.                                                 */
  1308.  /**********************************************************************/
  1309.    WinSetPointer ( HWND_DESKTOP, hptrWait );
  1310.  
  1311.    if (!fMovieLoaded)   /* If the movie is not loaded then load it */
  1312.      {
  1313.        lmciSendStringRC = SendString(hwnd, "load movie movie.avi wait", 0);
  1314.        if (lmciSendStringRC)
  1315.          {
  1316.            fMovieLoaded = TRUE;
  1317.          }
  1318.        else
  1319.          {
  1320.            MessageBox( IDS_CANNOT_LOAD_MOVIE_FILE,
  1321.                        MB_CANCEL | MB_ERROR  | MB_MOVEABLE);
  1322.            return;
  1323.          } /* else */
  1324.      } /* if */
  1325.  
  1326.    /* Seek to the beginning of the movie */
  1327.    lmciSendStringRC = SendString(hwnd, "seek movie to start notify", 0);
  1328.  
  1329.  /********************************************************************/
  1330.  /* Before we start editing, change the data format to frames. Frame */
  1331.  /* format is sometimes easier to work with.                         */
  1332.  /********************************************************************/
  1333.    lmciSendStringRC = SendString( hwnd, "set movie time format frames wait",
  1334.                                   0 );
  1335.  
  1336.  /***********************************************************/
  1337.  /* copy the first 25 frames. The copy will place the       */
  1338.  /* data into the clipboard.                                */
  1339.  /***********************************************************/
  1340.  
  1341.    lmciSendStringRC = SendString(hwnd,"copy movie from 1 to 25 wait", 0);
  1342.  
  1343.  /*******************************************************************/
  1344.  /* Paste our information we just copied.  We will paste the 25     */
  1345.  /* frames 4 times which will duplciate what we have just copied.   */
  1346.  /* The paste will start at the current frame of the movie.         */
  1347.  /*******************************************************************/
  1348.  
  1349.    lmciSendStringRC = SendString(hwnd, "paste movie from 25 wait", 0);
  1350.  
  1351.    lmciSendStringRC = SendString(hwnd, "paste movie from 25 wait", 0);
  1352.  
  1353.    lmciSendStringRC = SendString(hwnd, "paste movie from 25 wait", 0);
  1354.  
  1355.    lmciSendStringRC = SendString(hwnd, "paste movie from 25 wait", 0);
  1356.  
  1357.  /******************************************/
  1358.  /* Cut the first 10 frames from the movie.*/
  1359.  /* This will delete the first 10 frames.  */
  1360.  /******************************************/
  1361.  
  1362.    lmciSendStringRC = SendString(hwnd, "cut movie from 1 to 25 wait", 0);
  1363.  
  1364.  /******************************************/
  1365.  /* Seek to the end of the movie so we can */
  1366.  /* paste the first 25 frames to the end.  */
  1367.  /******************************************/
  1368.  
  1369.    lmciSendStringRC = SendString(hwnd, "seek movie to end wait", 0);
  1370.  
  1371.    lmciSendStringRC = SendString(hwnd, "paste movie wait",0);
  1372.  
  1373.  /*******************************************************************/
  1374.  /* Seek to the beginning of the file so we can be ready to play.   */
  1375.  /*******************************************************************/
  1376.  
  1377.    lmciSendStringRC = SendString(hwnd, "seek movie to start notify", 0);
  1378.  
  1379.  /******************************************************************/
  1380.  /* Now that we're done here, change the pointer back to the arrow.*/
  1381.  /******************************************************************/
  1382.  
  1383.    WinSetPointer ( HWND_DESKTOP, hptrArrow );
  1384.  
  1385. }  /* end of EditTheMovie */
  1386.  
  1387.  
  1388.  
  1389. /*************************************************************************
  1390.  * Name         :  SendString
  1391.  *
  1392.  * Description  :  This procedure will send string to MCI.
  1393.  *
  1394.  * Concepts     :  Sending a string command using the mciSendString interface.
  1395.  *
  1396.  * MMPM/2 API's :  mciSendString
  1397.  *
  1398.  * Parameters   :  hwnd        - window handle.
  1399.  *                 pcMCIString - string command.
  1400.  *                 usUserParm  - user parameter.
  1401.  *
  1402.  * Return       :  TRUE  - if the operation was initiated without error.
  1403.  *                 FALSE - if an error occurred.
  1404.  *
  1405.  ******************************************************************************/
  1406. BOOL  SendString( HWND hwnd, PCHAR pcMCIString, USHORT usUserParm )
  1407. {
  1408.    LONG           lmciSendStringRC;    /* return value fromm mciSendString    */
  1409.  
  1410.  
  1411.    lmciSendStringRC =
  1412.        mciSendString( (PSZ)pcMCIString,
  1413.                       (PSZ)szReturn,
  1414.                       (USHORT)CCHMAXPATH,
  1415.                       (HWND)hwnd,
  1416.                       (USHORT)usUserParm );
  1417.  
  1418.    if (lmciSendStringRC != 0)
  1419.    {
  1420.       ShowMCIErrorMessage(lmciSendStringRC);
  1421.       return( FALSE );
  1422.    }
  1423.  
  1424.    return( TRUE );
  1425. }
  1426.  
  1427.  
  1428. /******************************************************************************
  1429.  * Name         :  MessageBox
  1430.  *
  1431.  * Description  :  This procedure will display messages for the application
  1432.  *                 based upon string IDs passed in.  The actual text will be
  1433.  *                 loaded from the string table in the resource.
  1434.  *
  1435.  * Concepts     :  None.
  1436.  *
  1437.  * MMPM/2 API's :  None.
  1438.  *
  1439.  * Parameters   :  usMessageID - ID of the message string
  1440.  *                 ulStyle     - Style of the message box (WinMessageBox)
  1441.  *
  1442.  * Return       :  TRUE  -  if the operation was initiated without error.
  1443.  *                 FALSE -  if an error occurred.
  1444.  *
  1445.  ******************************************************************************/
  1446. USHORT MessageBox( USHORT usMessageID, ULONG  ulStyle)
  1447. {
  1448.    CHAR     achMessage[LEN_ERROR_MESSAGE];
  1449.    USHORT   usResult;
  1450.  
  1451.    /***************************************************************************/
  1452.    /* Get the string from the Resource defined string table and show it       */
  1453.    /* in the message box.                                                     */
  1454.    /***************************************************************************/
  1455.    WinLoadString(
  1456.       hab,                             /* HAB for this dialog box.            */
  1457.       (HMODULE) NULL,                  /* Get the string from the .exe file.  */
  1458.       usMessageID,                     /* Which string to get.                */
  1459.       (SHORT) sizeof( achMessage),     /* The size of the buffer.             */
  1460.       achMessage );                    /* The buffer to place the string.     */
  1461.  
  1462.    if ( !(ulStyle & MB_INFORMATION) )
  1463.       {
  1464.       usResult =
  1465.          WinMessageBox(
  1466.             HWND_DESKTOP,              /* Parent handle of the message box.   */
  1467.             hwndMainDialogBox,         /* Owner handle of the message box.    */
  1468.             achMessage,                /* String to show in the message box.  */
  1469.             achMsgBoxTitle,            /* Title to shown in the message box.  */
  1470.             (USHORT) ID_MESSAGEBOX,    /* Message Box Id.                     */
  1471.             ulStyle );                 /* The style of the message box.       */
  1472.       }
  1473.    else
  1474.       {
  1475.       usResult =
  1476.          WinMessageBox(
  1477.             HWND_DESKTOP,              /* Parent handle of the message box.   */
  1478.             hwndMainDialogBox,         /* Owner handle of the message box.    */
  1479.             achMessage,                /* String to show in the message box.  */
  1480.             achTitle,                  /* Title to shown in the message box.  */
  1481.             (USHORT) ID_MESSAGEBOX,    /* Message Box Id.                     */
  1482.             ulStyle );                 /* The style of the message box.       */
  1483.       }
  1484.  
  1485.    return( usResult );
  1486.  
  1487. }  /* End of MessageBox */
  1488.  
  1489.  
  1490. /******************************************************************************
  1491.  * Name         :  ShowMCIErrorMessage
  1492.  *
  1493.  * Description  :  This window procedure displays an MCI error message
  1494.  *                 based upon a ulError return code.  The MCI function
  1495.  *                 mciGetErrorString is used to convert the error code into
  1496.  *                 a text string and the title is pulled from the resource
  1497.  *                 based upon a string id.
  1498.  *
  1499.  * Concepts     :  Using mciGetErrorString to convert an error code into
  1500.  *                 a textual message.
  1501.  *
  1502.  * MMPM/2 API's :  mciGetErrorString
  1503.  *
  1504.  * Parameters   :  ulError  -  MCI error code.
  1505.  *
  1506.  * Return       :  nothing
  1507.  *
  1508.  ******************************************************************************/
  1509. VOID  ShowMCIErrorMessage( ULONG ulError)
  1510. {
  1511.    CHAR  achBuffer[LEN_ERROR_MESSAGE];
  1512.  
  1513.    switch(mciGetErrorString( ulError, (PSZ)achBuffer,   sizeof( achBuffer)))
  1514.    {
  1515.       case MCIERR_SUCCESS:
  1516.  
  1517.          /*******************************************************************/
  1518.          /* This is what we want.  We were able to use mciGetErrorString to */
  1519.          /* retrieve a textual error message we can show in a message box.  */
  1520.          /*******************************************************************/
  1521.          WinMessageBox( HWND_DESKTOP,
  1522.                         hwndMainDialogBox,
  1523.                         achBuffer,
  1524.                         achMsgBoxTitle,
  1525.                         (USHORT) ID_MESSAGEBOX,
  1526.                         MB_CANCEL | MB_HELP | MB_ERROR | MB_MOVEABLE);
  1527.          break;
  1528.  
  1529.       case MCIERR_INVALID_DEVICE_ID:
  1530.       case MCIERR_OUTOFRANGE:
  1531.       case MCIERR_INVALID_BUFFER:
  1532.       default:
  1533.          MessageBox( IDS_UNKNOWN,
  1534.                      MB_CANCEL | MB_HELP | MB_ERROR | MB_MOVEABLE);
  1535.          break;
  1536.    }
  1537.  
  1538.    return;
  1539.  
  1540. }  /* end of ShowMCIErrorMessage */
  1541.  
  1542.  
  1543. /******************************************************************************
  1544.  * Name         :  DoesFileExist
  1545.  *
  1546.  * Description  :  This helper function determines if a file with a given
  1547.  *                 file name exists. If it does, we want to attain specific
  1548.  *                 information for future use.  This information is attained
  1549.  *                 by getting the track ID of the movie.
  1550.  *
  1551.  * Concepts     :  Using MMIO interface to access a data file and header
  1552.  *                 information.
  1553.  *
  1554.  * MMPM/2 API's :  mmioOpen
  1555.  *                 mmioClose
  1556.  *                 mmioGetHeader
  1557.  *                 mmioSet
  1558.  *
  1559.  * Parameters   :  pszFileName - The file name to be tested.
  1560.  *
  1561.  * Return       :  TRUE  -  if the a file exists matching pszFilename
  1562.  *                          and there are no errors getting the movie file
  1563.  *                          header information.
  1564.  *                 FALSE -  if the file does not exist or problem getting
  1565.  *                          the movie file header information
  1566.  *
  1567.  *
  1568.  ******************************************************************************/
  1569. BOOL DoesFileExist( PSZ pszFileName )
  1570. {
  1571.    BOOL  bReturn = 0;                    /* Function return value       */
  1572.    HMMIO hFile;                          /* Handle to file              */
  1573.    LONG  lHeaderLengthMovie;             /* Header length of movie file */
  1574.    LONG  lHeaderLengthVideo;             /* Header length of movie file */
  1575.    ULONG ulTrackID;                      /* Track ID                    */
  1576.    LONG  lBytes;                         /* Number of bytes read        */
  1577.    LONG  lSize;                          /* Size of Header information  */
  1578.    PMMMOVIEHEADER pmmMovieHeader;        /* Std Movie Header            */
  1579.    MMVIDEOHEADER  mmVideoHeader;         /* Std Video Header            */
  1580.    MMEXTENDINFO   mmExtendinfo;          /* Std Extended Information    */
  1581.    MMIOINFO       mmioinfo;              /* Structure for mmio info     */
  1582.    PMMIOPROC      pIOProc;
  1583.    PMMIOPROC      pAnswer;
  1584.    HMODULE        hmod;
  1585.    FOURCC         fcc;
  1586.    CHAR           LoadError[100];
  1587.    ULONG          rc = MMIO_SUCCESS;
  1588.  
  1589.  
  1590.    /*********************************************************/
  1591.    /* Reset all my my mmio information structures           */
  1592.    /*********************************************************/
  1593.  
  1594.    memset(&mmioinfo, '\0', sizeof(MMIOINFO));
  1595.    memset(&mmExtendinfo, '\0', sizeof(MMEXTENDINFO));
  1596.    memset(&mmVideoHeader, '\0', sizeof(MMVIDEOHEADER));
  1597.  
  1598.    mmioinfo.ulTranslate =  MMIO_TRANSLATEHEADER;   /* Set to std translation */
  1599.  
  1600.                                     /* Set all operations on the active track*/
  1601.    mmExtendinfo.ulFlags = MMIO_TRACK;
  1602.  
  1603.    hFile = mmioOpen( pszFileName, &mmioinfo, MMIO_READ );
  1604.  
  1605.    if (hFile != (HMMIO) NULL)
  1606.     {
  1607.  
  1608.       mmExtendinfo.ulTrackID = -1;                     /* reset the track id */
  1609.  
  1610.      /*********************************************************/
  1611.      /* The mmioSet function associates an MMIO handle with   */
  1612.      /* the CODEC information.  The MMIO_SET_EXTENDEDINFO     */
  1613.      /* is set to associate the CODEC Procs with the file.    */
  1614.      /*********************************************************/
  1615.  
  1616.       bReturn = mmioSet(hFile, &mmExtendinfo, MMIO_SET_EXTENDEDINFO);
  1617.  
  1618.      /*********************************************************/
  1619.      /* The mmioQueryHeaderLength returns the length of the   */
  1620.      /* header in bytes.  This length is actually variable    */
  1621.      /* because a chunk of information gets added to each     */
  1622.      /* track or stream in the movie.                         */
  1623.      /*********************************************************/
  1624.       bReturn = mmioQueryHeaderLength(hFile, &lHeaderLengthMovie,0L, 0L);
  1625.  
  1626.       if (!bReturn)
  1627.         {
  1628.           pmmMovieHeader = malloc(lHeaderLengthMovie);
  1629.         } /* if */
  1630.  
  1631.      /*********************************************************/
  1632.      /* The mmioGetHeader function returns the header of the  */
  1633.      /* media structure of the file opened by mmioOpen.       */
  1634.      /* The header contains information about the media.      */
  1635.      /*********************************************************/
  1636.       if (!(bReturn = mmioGetHeader(hFile,
  1637.                                     pmmMovieHeader,
  1638.                                     lHeaderLengthMovie,
  1639.                                     &lBytes,
  1640.                                     0L,
  1641.                                     0L)))
  1642.        {
  1643.  
  1644.          /*********************************************************/
  1645.          /* Read the movie header informationn and get the track  */
  1646.          /* information.                                          */
  1647.          /*********************************************************/
  1648.  
  1649.           mmExtendinfo.ulTrackID = pmmMovieHeader->ulNextTrackID;
  1650.  
  1651.           /**************************************************************/
  1652.           /* Here we will use the mmioSet to set the extended info      */
  1653.           /* to the correct track after issuing the mmioGetHeader. Once */
  1654.           /* we have the correct track we can issue mmioGetHeader       */
  1655.           /* requesting the movie information we wish to have. In this  */
  1656.           /* sample we are asking for the height, width, length of the  */
  1657.           /* movie.                                                     */
  1658.           /**************************************************************/
  1659.  
  1660.           bReturn = mmioSet(hFile, &mmExtendinfo, MMIO_SET_EXTENDEDINFO);
  1661.  
  1662.           lHeaderLengthVideo = sizeof(MMVIDEOHEADER);
  1663.  
  1664.           /*******************************************************/
  1665.           /* Get the information we need from the video header   */
  1666.           /* height, width, length.                              */
  1667.           /*******************************************************/
  1668.  
  1669.           bReturn = mmioGetHeader(hFile,
  1670.                                   &mmVideoHeader,
  1671.                                   lHeaderLengthVideo,
  1672.                                   &lBytes,
  1673.                                   0L,
  1674.                                   0L);
  1675.  
  1676.           ulMovieWidth  = mmVideoHeader.ulWidth;
  1677.  
  1678.           ulMovieHeight = mmVideoHeader.ulHeight;
  1679.  
  1680.           ulMovieLength = mmVideoHeader.ulLength;
  1681.  
  1682.           /*****************************************************/
  1683.           /* Here we are using the mmioSet to reset the tracks */
  1684.           /* We do this just in case we would need to do some- */
  1685.           /* thing different with the movie file.              */
  1686.           /*****************************************************/
  1687.           mmExtendinfo.ulTrackID = MMIO_RESETTRACKS;
  1688.  
  1689.           bReturn = mmioSet(hFile, &mmExtendinfo,MMIO_SET_EXTENDEDINFO);
  1690.  
  1691.           mmioClose( hFile, 0);
  1692.  
  1693.           bReturn = TRUE;
  1694.           return (bReturn);
  1695.           free(pmmMovieHeader);
  1696.        }
  1697.     }
  1698.    bReturn = FALSE;
  1699.    return (bReturn);
  1700.  
  1701.  
  1702. }
  1703. /******************************************************************************
  1704.  * Name         :  SetMovieVolume
  1705.  *
  1706.  * Description  :  This helper function sets the Movie file volume based upon
  1707.  *                 the position of the volume slider.  The slider will be
  1708.  *                 queried and the Movie file volume will be set.
  1709.  *
  1710.  * Concepts     :  Setting the volume of a device.
  1711.  *
  1712.  * MMPM/2 API's :  mciSendString
  1713.  *                    - set
  1714.  *
  1715.  * Parameters   :  none.
  1716.  *
  1717.  * Return       :  none.
  1718.  *
  1719.  ******************************************************************************/
  1720. VOID SetMovieVolume( VOID )
  1721. {
  1722.    LONG      lmciSendStringRC;             /* return value form mciSendString */
  1723.    CHAR      szVolume[4] = "";             /* to hold the volume level        */
  1724.    CHAR      szCommandString[CCHMAXPATH] = /* string command to MCI           */
  1725.                "set movie audio volume ";
  1726.  
  1727.    if( !fAudioOn ) return;
  1728.  
  1729.    if ((!fPassedDevice) && (eState == ST_PLAYING ))
  1730.    {
  1731.       /*****************************************************************/
  1732.       /* To set the volume,  first, build the string command for the   */
  1733.       /* MCI.  Then an MCI_SET command should be issued to the device  */
  1734.       /* to perform the volume change.                                 */
  1735.       /*****************************************************************/
  1736.       _itoa(sVolumeLevel, szVolume, 10);
  1737.       strcat( szCommandString, szVolume);
  1738.       strcat( szCommandString, " ");
  1739.       strcat( szCommandString, "wait");
  1740.  
  1741.       lmciSendStringRC =
  1742.           mciSendString( (PSZ)szCommandString,
  1743.                          (PSZ)szReturn,
  1744.                          CCHMAXPATH,
  1745.                          (HWND)NULL,
  1746.                          (USHORT)NULL );
  1747.       if (lmciSendStringRC != 0)
  1748.          ShowMCIErrorMessage(lmciSendStringRC);
  1749.  
  1750.    }
  1751.    return;
  1752. }  /* end of SetMovieVolume */
  1753.  
  1754. /*************************************************************************
  1755.  * Name         : InitializeHelp
  1756.  *
  1757.  * Description  : This procedure will set up the initial values in the
  1758.  *                global help structure.  This help structure will then
  1759.  *                be passed on to the Help Manager when the Help Instance
  1760.  *                is created.  The handle to the Help Instance will be
  1761.  *                kept for later use.
  1762.  *
  1763.  * Concepts     : None.
  1764.  *
  1765.  * MMPM/2 API's : None.
  1766.  *
  1767.  * Parameters   : None.
  1768.  *
  1769.  * Return       : None.
  1770.  *
  1771.  *************************************************************************/
  1772. VOID InitializeHelp( VOID )
  1773. {
  1774.  
  1775.    HELPINIT helpInit;                 /* Help initialization structure. */
  1776.    CHAR     achHelpLibraryName[LEN_HELP_LIBRARY_NAME];
  1777.    CHAR     achHelpWindowTitle[LEN_HELP_WINDOW_TITLE];
  1778.  
  1779.    /*
  1780.     * Load the strings for the Help window title and library name.
  1781.     * Initialize the help structure and associate the help instance.
  1782.     */
  1783.    WinLoadString( hab,
  1784.                   (HMODULE) NULL,
  1785.                   IDS_HELP_WINDOW_TITLE,
  1786.                   (SHORT) sizeof( achHelpWindowTitle),
  1787.                   achHelpWindowTitle);
  1788.  
  1789.    WinLoadString( hab,
  1790.                   (HMODULE) NULL,
  1791.                   IDS_HELP_LIBRARY_NAME,
  1792.                   (SHORT) sizeof( achHelpLibraryName),
  1793.                   achHelpLibraryName);
  1794.  
  1795.    memset ( &helpInit, 0, sizeof(helpInit) );
  1796.    /*
  1797.     * Initialize the help structure.
  1798.     */
  1799.    helpInit.cb                 = sizeof( helpInit);  /* size of the help struc*/
  1800.    helpInit.ulReturnCode       = (ULONG) 0;          /* RC from HM init       */
  1801.    helpInit.pszTutorialName    = (PSZ) NULL;         /* No tutorial program   */
  1802.    helpInit.pszHelpWindowTitle = achHelpWindowTitle; /* The Help window title.*/
  1803.    helpInit.fShowPanelId       = (ULONG) 0;          /* help panel ID.        */
  1804.    helpInit.pszHelpLibraryName = achHelpLibraryName; /* library name          */
  1805.    helpInit.phtHelpTable       = (PVOID)(0xffff0000 | ID_MOVIE_HELPTABLE);
  1806.  
  1807.    /*
  1808.     * Create the Help Instance for IPF.
  1809.     * Give IPF the Anchor Block handle and address of the IPF initialization
  1810.     * structure, and check that creation of Help was a success.
  1811.     */
  1812.    hwndHelpInstance = WinCreateHelpInstance(
  1813.                          hab,                   /* Anchor Block Handle.       */
  1814.                          &helpInit );           /* Help Structure.            */
  1815.  
  1816.    if ( hwndHelpInstance == (HWND) NULL)
  1817.    {
  1818.       MessageBox( IDS_HELP_CREATION_FAILED,     /* ID of the message          */
  1819.                   MB_OK | MB_INFORMATION  | MB_MOVEABLE);    /* style         */
  1820.    }
  1821.    else
  1822.    {
  1823.       if ( helpInit.ulReturnCode)
  1824.       {
  1825.          WinDestroyHelpInstance( hwndHelpInstance);
  1826.          MessageBox( IDS_HELP_CREATION_FAILED,
  1827.                      MB_OK | MB_INFORMATION | MB_MOVEABLE);
  1828.       }
  1829.       else  /* help creation worked */
  1830.          WinAssociateHelpInstance(
  1831.             hwndHelpInstance,        /* The handle of the Help Instance.      */
  1832.             hwndFrame);              /* Associate to this dialog window.      */
  1833.    }  /* End of IF checking the creation of the Help Instance. */
  1834.  
  1835. }  /* End of InitializeHelp */
  1836.  
  1837. /*************************************************************************
  1838.  * Name         : InsertHelpMenuItem
  1839.  *
  1840.  * Description  : This procedure will set up "Help" menu item to
  1841.  *                the system menu.
  1842.  *
  1843.  * Concepts     : None.
  1844.  *
  1845.  * MMPM/2 API's : None.
  1846.  *
  1847.  * Parameters   : Pointer to the "Help" text data.
  1848.  *
  1849.  * Return       : None.
  1850.  *
  1851.  *************************************************************************/
  1852. VOID InsertHelpMenuItem( PCHAR szHelp )
  1853. {
  1854.    MENUITEM MenuItem;                     /* Menu-Item Structure           */
  1855.    HWND     hwndSysMenuPullDown;          /* window handle for pulldown    */
  1856.    USHORT   idSysMenu;                    /*                               */
  1857.    HWND     hwndSysMenu;                  /* window handle for system menu */
  1858.    USHORT   i;                            /*                               */
  1859.    USHORT   iDefaultSize = MIT_END;       /*                               */
  1860.    BOOL     fSearch = TRUE;               /*                               */
  1861.    LONG     cntSeparator = 0;             /*                               */
  1862.  
  1863.  
  1864.    /*
  1865.     *  Get the system pull down menu window handle.
  1866.     */
  1867.    hwndSysMenu = WinWindowFromID(hwndFrame,
  1868.                                    FID_SYSMENU);
  1869.    idSysMenu = SHORT1FROMMR (WinSendMsg (hwndSysMenu,
  1870.                                MM_ITEMIDFROMPOSITION, 0L, 0L));
  1871.    WinSendMsg (hwndSysMenu, MM_QUERYITEM,
  1872.                  MPFROM2SHORT (idSysMenu, FALSE), MPFROMP(&MenuItem));
  1873.    hwndSysMenuPullDown = MenuItem.hwndSubMenu;
  1874.  
  1875.    /*
  1876.     *  Find the position to insert "Help" item.
  1877.     */
  1878.    for (i=0; fSearch; i++)
  1879.    {
  1880.       idSysMenu = SHORT1FROMMR (WinSendMsg (hwndSysMenuPullDown,
  1881.                                 MM_ITEMIDFROMPOSITION, (MPARAM)i, 0L));
  1882.       fSearch = (BOOL)WinSendMsg (hwndSysMenuPullDown, MM_QUERYITEM,
  1883.                   MPFROM2SHORT (idSysMenu, FALSE), MPFROMP(&MenuItem));
  1884.  
  1885.       if (fSearch && MenuItem.afStyle & MIS_SEPARATOR)
  1886.       {
  1887.          cntSeparator ++;
  1888.          if (cntSeparator == 2)
  1889.          {
  1890.             cntSeparator ++;
  1891.             break;
  1892.          } /* endif */
  1893.       } /* endif */
  1894.  
  1895.    } /* endfor */
  1896.  
  1897.    if (fSearch)
  1898.    {
  1899.       if (i==0)
  1900.       {
  1901.          iDefaultSize = MIT_FIRST;
  1902.       }
  1903.       else
  1904.       {
  1905.          iDefaultSize = i;
  1906.       }
  1907.    }
  1908.  
  1909.    /*
  1910.     *  Insert separator first.
  1911.     */
  1912.    MenuItem.iPosition   = iDefaultSize;
  1913.    MenuItem.afStyle     = MIS_SEPARATOR;
  1914.    MenuItem.afAttribute = (ULONG)NULL;
  1915.    MenuItem.id          = (ULONG)NULL;
  1916.    MenuItem.hwndSubMenu = (HWND)NULL;
  1917.    MenuItem.hItem       = (ULONG)NULL;
  1918.    WinSendMsg (hwndSysMenuPullDown, MM_INSERTITEM,
  1919.                  (MPARAM)&MenuItem, (MPARAM)NULL);
  1920.    /*
  1921.     *  Insert "Help" text next.
  1922.     */
  1923.    MenuItem.iPosition   = ++iDefaultSize;
  1924.    MenuItem.afStyle     = (ULONG)NULL;
  1925.    MenuItem.afAttribute = (ULONG)NULL;
  1926.    MenuItem.id          = WM_HELP;
  1927.    MenuItem.hwndSubMenu = (HWND)NULL;
  1928.    MenuItem.hItem       = (ULONG)NULL;
  1929.    WinSendMsg (hwndSysMenuPullDown, MM_INSERTITEM,
  1930.                  (MPARAM)&MenuItem, (MPARAM)szHelp);
  1931.  
  1932. }  /* End of InsertHelpMenuItem */
  1933.  
  1934. /******************************************************************************
  1935.  * Name         : ResizeMovieWindow
  1936.  *
  1937.  * Description  : This function will resize the applications movie window
  1938.  *                according to the height and width of the movie file being
  1939.  *                opened.
  1940.  *
  1941.  * Parameters   : hwnd - Handle of the secondary window.
  1942.  *
  1943.  * Return       : none.
  1944.  *
  1945.  ******************************************************************************/
  1946. VOID ResizeMovieWindow (HWND hwnd)
  1947. {
  1948.  
  1949.    HWND hwndSEFrame;             /* handle for the Secondary Window Frame     */
  1950.    SWP  swpSEFrame;              /* struc containing information on Frame     */
  1951.    SWP  swpRewind;               /* struc containing information rewind button*/
  1952.    LONG cxWidthBorder = 0;
  1953.    LONG cyWidthBorder = 0;
  1954.    LONG cyTitleBar = 0;
  1955.  
  1956.   /*************************************************************/
  1957.   /* Query the position of the secondary window frame          */
  1958.   /* and the rewind button so we can postion our application   */
  1959.   /* frame for the movie.                                      */
  1960.   /*************************************************************/
  1961.  
  1962.    WinQueryWindowPos( hwndFrame, &swpSEFrame );
  1963.  
  1964.    WinQueryWindowPos( WinWindowFromID( hwnd, IDC_GPB_REWIND ),
  1965.                       &swpRewind );
  1966.  
  1967.    cxWidthBorder = (LONG) WinQuerySysValue(HWND_DESKTOP, SV_CXSIZEBORDER);
  1968.    cyWidthBorder = (LONG) WinQuerySysValue(HWND_DESKTOP, SV_CYSIZEBORDER);
  1969.    cyTitleBar =    (LONG) WinQuerySysValue(HWND_DESKTOP, SV_CYTITLEBAR);
  1970.  
  1971.   /*************************************************************/
  1972.   /* Check to see if our movie size is larger than our frame.  */
  1973.   /* If it is then resize our frame to fit the movie.          */
  1974.   /*************************************************************/
  1975.  
  1976.  if ((swpSEFrame.cx - (2 * cxWidthBorder)) <= ulMovieWidth)
  1977.   {
  1978.     swpSEFrame.cx = ulMovieWidth + (2 * cxWidthBorder);
  1979.   } /* if */
  1980.  if ((swpSEFrame.cy - swpRewind.cy - ulMovieHeight -
  1981.                                      cyTitleBar - (2 * cyWidthBorder)
  1982.                                       < ulMovieHeight ))
  1983.   {
  1984.     swpSEFrame.cy = ulMovieHeight + cyTitleBar + (2 * cyWidthBorder);
  1985.   } /* if */
  1986.  
  1987.   /*************************************************************/
  1988.   /* Set the position and size of the application window       */
  1989.   /* to the position and size of the movie.                    */
  1990.   /*************************************************************/
  1991.  
  1992.      WinSetWindowPos( hwndAppFrame, HWND_TOP,
  1993.                       (swpSEFrame.cx - ulMovieWidth - cxWidthBorder) / 2,
  1994.                       (cyWidthBorder + swpRewind.y + swpRewind.cy) + 5,
  1995.                       ulMovieWidth,
  1996.                       ulMovieHeight,
  1997.                       SWP_SIZE | SWP_MOVE);
  1998.  
  1999. }
  2000.  
  2001.  
  2002.  
  2003.  
  2004. /*****************************************************************
  2005.  * Name : QueryDirectMode
  2006.  *
  2007.  * Function: Determine if direct mode is supported.
  2008.  *
  2009.  ******************************************************************/
  2010.  
  2011. BOOL  QueryDirectMode(VOID)
  2012. {
  2013.     DIVE_CAPS    DiveCaps;             /* Dive Query Capabilities */
  2014.     ULONG        rc;                   /* API Return Code         */
  2015.     FOURCC       fccFormats[100] = {0};
  2016.  
  2017.     memset (&DiveCaps,0,sizeof(DiveCaps));
  2018.     DiveCaps.pFormatData = fccFormats;
  2019.     DiveCaps.ulFormatLength = 120;
  2020.     DiveCaps.ulStructLen = sizeof(DIVE_CAPS);
  2021.     rc = DiveQueryCaps( &DiveCaps, DIVE_BUFFER_SCREEN);
  2022.     if (!rc)
  2023.       {
  2024.         if (DiveCaps.fScreenDirect)
  2025.          {
  2026.            if (DiveCaps.ulDepth < 8)
  2027.               return (BOOL)(FALSE);
  2028.          }
  2029.          else
  2030.               return (BOOL)(FALSE);
  2031.  
  2032.       }
  2033.     return (BOOL)(TRUE);
  2034. }
  2035.  
  2036.