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