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

  1. /******************************************************************************
  2.  * File Name    :  OPTIONS.C
  3.  *
  4.  * Description  :  This file contains the C source code required for the
  5.  *                 Recorder sample program.
  6.  *
  7.  * MMPM/2 API's :  List of all MMPM/2 API's that are used in
  8.  *                 this module
  9.  *
  10.  *                 mmioOpen
  11.  *                 mmioGetHeader
  12.  *                 mmioClose
  13.  *
  14.  * Copyright (C) IBM 1993
  15.  ******************************************************************************/
  16.  
  17. #define  INCL_WIN                      /* required to use Win APIs.           */
  18. #define  INCL_PM                       /* required to use PM APIs.            */
  19. #define  INCL_OS2MM                    /* required for MCI and MMIO headers   */
  20. #define  INCL_SW                       /* required for secondary window       */
  21.  
  22. #include <os2.h>
  23. #include <os2me.h>
  24. #include <stdio.h>
  25. #include <string.h>
  26.  
  27. #include "recorder.h"
  28.  
  29. /*
  30.  * Procedure/Function Prototypes
  31.  */
  32. VOID    EnableTheOption( USHORT idOption );
  33. VOID    DisableTheOption( HWND hwndMenu, USHORT idOption );
  34.  
  35. extern  USHORT MessageBox( USHORT usMessageID, ULONG  ulStyle );
  36.  
  37. extern  HWND hwndMenu;
  38. extern  HWND hwndFrame;
  39. extern  HAB  hab;
  40. /******************************************************************************
  41.  * Name         : SelectTheOption
  42.  *
  43.  * Description  : This procedure will select the menu pulldown option.
  44.  *
  45.  * Concepts     : None.
  46.  *
  47.  * MMPM/2 API's : None.
  48.  *
  49.  * Parameters   : idOption - Id for the selected menu pulldown option.
  50.  *
  51.  * Return       : None.
  52.  *
  53.  ******************************************************************************/
  54. VOID  SelectTheOption( USHORT idOption )
  55. {
  56.    USHORT   usAttrib;
  57.  
  58.    /*
  59.     * Query the selected menu pulldown to get their current state...
  60.     */
  61.    usAttrib = (USHORT) WinSendMsg( hwndMenu,
  62.                                    MM_QUERYITEMATTR,
  63.                                    MPFROM2SHORT(idOption, TRUE),
  64.                                    MPFROMSHORT(MIA_CHECKED));
  65.    if (!(usAttrib & MIA_CHECKED))
  66.    {
  67.       /*
  68.        * Selected option was not in selected state, set the attribute and
  69.        * select it.
  70.        */
  71.       usAttrib ^= MIA_CHECKED;
  72.       WinSendMsg( hwndMenu,
  73.                   MM_SETITEMATTR,
  74.                   MPFROM2SHORT( idOption, TRUE),
  75.                   MPFROM2SHORT( MIA_CHECKED, usAttrib ) );
  76.    }
  77.    return;
  78. }
  79.  
  80. /******************************************************************************
  81.  * Name         : DeselectTheOption
  82.  *
  83.  * Description  : This procedure will deselect the menu pulldown option.
  84.  *
  85.  * Concepts     : None.
  86.  *
  87.  * MMPM/2 API's : None.
  88.  *
  89.  * Parameters   : idOption - Id for the selected menu pulldown option.
  90.  *
  91.  * Return       : None.
  92.  *
  93.  ******************************************************************************/
  94. VOID  DeselectTheOption( USHORT idOption )
  95. {
  96.    USHORT   usAttrib;
  97.  
  98.    /*
  99.     * Query the selected menu pulldown to get their current state...
  100.     */
  101.    usAttrib = (USHORT) WinSendMsg( hwndMenu,
  102.                                    MM_QUERYITEMATTR,
  103.                                    MPFROM2SHORT(idOption, TRUE),
  104.                                    MPFROMSHORT(MIA_CHECKED));
  105.    if (usAttrib & MIA_CHECKED)
  106.    {
  107.       /*
  108.        * Selected option was in selected state, set the attribute and
  109.        * deselect it.
  110.        */
  111.       usAttrib ^= MIA_CHECKED;
  112.       WinSendMsg( hwndMenu,
  113.                   MM_SETITEMATTR,
  114.                   MPFROM2SHORT( idOption, TRUE),
  115.                   MPFROM2SHORT( MIA_CHECKED, usAttrib ) );
  116.    }
  117.    return;
  118. }
  119.  
  120.  
  121. /******************************************************************************
  122.  * Name         : DisableTheOption
  123.  *
  124.  * Description  : This procedure will disable the menu pulldown option.
  125.  *
  126.  * Concepts     : None.
  127.  *
  128.  * MMPM/2 API's : None.
  129.  *
  130.  * Parameters   : hwndMenu - handle for the menu.
  131.  *                idOption - Id for the selected menu pulldown option.
  132.  *
  133.  * Return       : None.
  134.  *
  135.  ******************************************************************************/
  136. VOID  DisableTheOption( HWND hwndMenu, USHORT idOption )
  137. {
  138.    USHORT   usAttrib;
  139.  
  140.    /*
  141.     * Query the selected menu pulldown to get their current state...
  142.     */
  143.    usAttrib = (USHORT) WinSendMsg( hwndMenu,
  144.                                    MM_QUERYITEMATTR,
  145.                                    MPFROM2SHORT(idOption, TRUE),
  146.                                    MPFROMSHORT(MIA_DISABLED));
  147.    if (!(usAttrib & MIA_DISABLED))
  148.    {
  149.       /*
  150.        * Selected option was in enable state, set the attribute and
  151.        * disable it.
  152.        */
  153.       usAttrib ^= MIA_DISABLED;
  154.       WinSendMsg( hwndMenu,
  155.                   MM_SETITEMATTR,
  156.                   MPFROM2SHORT( idOption, TRUE ),
  157.                   MPFROM2SHORT( MIA_DISABLED, usAttrib));
  158.    }
  159.    return;
  160. }
  161.  
  162.  
  163. /******************************************************************************
  164.  * Name         : EnableTheOption
  165.  *
  166.  * Description  : This procedure will enable the menu pulldown option.
  167.  *
  168.  * Concepts     : None.
  169.  *
  170.  * MMPM/2 API's : None.
  171.  *
  172.  * Parameters   : idOption - Id for the selected menu pulldown option.
  173.  *
  174.  * Return       : None.
  175.  *
  176.  ******************************************************************************/
  177. VOID  EnableTheOption( USHORT idOption )
  178. {
  179.    USHORT   usAttrib;
  180.  
  181.    /*
  182.     * Query the selected menu pulldown to get their current state...
  183.     */
  184.    usAttrib = (USHORT) WinSendMsg( hwndMenu,
  185.                                    MM_QUERYITEMATTR,
  186.                                    MPFROM2SHORT(idOption, TRUE),
  187.                                    MPFROMSHORT(MIA_DISABLED));
  188.    if (usAttrib & MIA_DISABLED)
  189.    {
  190.       /*
  191.        * Selected option was in disable state, set the attribute and
  192.        * enable it.
  193.        */
  194.       usAttrib ^= MIA_DISABLED;
  195.       WinSendMsg( hwndMenu,
  196.                   MM_SETITEMATTR,
  197.                   MPFROM2SHORT( idOption, TRUE ),
  198.                   MPFROM2SHORT( MIA_DISABLED, usAttrib));
  199.    }
  200.    return;
  201. }
  202.  
  203.  
  204. /******************************************************************************
  205.  *  Name          : SetTheOptions
  206.  *
  207.  *  Description   : If the user selected an existing file, this procedure
  208.  *                  will do the following:
  209.  *                    -  get the file header information.
  210.  *                    -  sets checkmarks on the appropriate type menu options.
  211.  *                    -  disable the other type menu options.
  212.  *
  213.  *                  If the user selected a new file, this procedure will do
  214.  *                  the following:
  215.  *                    -  Enable the disabled type menu options.
  216.  *                    -  Deselect the selected type menu options.
  217.  *                    -  Select the default type menu options.
  218.  *
  219.  *  MMPM/2 API's : mmioOpen
  220.  *                 mmioGetHeader
  221.  *
  222.  *  Parameters   : fSelectedFileType :  Selected file type - new/existing.
  223.  *
  224.  * Return        :  TRUE  -  if there is no error
  225.  *                  FALSE -  if there is an error
  226.  *
  227. \******************************************************************************/
  228. BOOL SetTheOptions( BOOL fSelectedFileType )
  229. {
  230.     ULONG         rc;                   /* for return code                    */
  231.     HMMIO         hmmio;                /* Handle to the currently loaded file*/
  232.     ULONG         lHeaderLength;        /* for header length                  */
  233.     LONG          lBytes;               /* used for mmioGetheader api         */
  234.     MMAUDIOHEADER mmAudioHeader;        /* WAVE header structure              */
  235.  
  236.     extern CHAR szFileName[FILE_NAME_SIZE];/* for fully qualified file name   */
  237.     extern BOOL    fMonoSupported;                /* Dev supports mono files   */
  238.     extern BOOL    fStereoSupported;              /* Dev supports stereo files */
  239.     extern BOOL    fVoiceSupported;               /* Dev supports 11 kHz files */
  240.     extern BOOL    fMusicSupported;               /* Dev supports 22 kHz files */
  241.     extern BOOL    fHiFiSupported;                /* Dev supports 44 kHz files */
  242.     extern BOOL    fHighQualitySupported;         /* Dev supports 16 bps files */
  243.     extern BOOL    fLoQualitySupported;           /* Dev supports 8 bps files  */
  244.  
  245.  
  246.     if (fSelectedFileType != NEW_FILE)
  247.     {
  248.        /*
  249.         * Selected file is an EXISTING file. Open the file get the header
  250.         * information.
  251.         */
  252.        hmmio = mmioOpen( szFileName, (PMMIOINFO)NULL, MMIO_READWRITE );
  253.        if (!hmmio)
  254.        {
  255.           MessageBox( IDS_CANNOT_OPEN_INPUT_FILE,   /* ID of the message          */
  256.                       MB_OK | MB_INFORMATION  | MB_MOVEABLE);    /* style         */
  257.           return( FALSE );
  258.        }
  259.  
  260.        /*
  261.         * Get the header information from the selected file.
  262.         */
  263.        lHeaderLength = sizeof(MMAUDIOHEADER);
  264.        rc = mmioGetHeader( hmmio,
  265.                            (PVOID)&mmAudioHeader,
  266.                            lHeaderLength,
  267.                            (PLONG)&lBytes,
  268.                            (ULONG) NULL,
  269.                            (ULONG) NULL );
  270.        if (rc)
  271.        {
  272.           MessageBox( IDS_MMIO_GET_HEADER_FAIL,     /* ID of the message          */
  273.                       MB_OK | MB_INFORMATION  | MB_MOVEABLE);    /* style         */
  274.           return( FALSE );
  275.        }
  276.     }
  277.  
  278.     /*
  279.      * Before setting the correct selctions, enable the disbled items
  280.      * in the menu pulldown and deselect the selected items.
  281.      */
  282.     if (fMonoSupported)           EnableTheOption( IDM_MONO );
  283.     if (fStereoSupported)         EnableTheOption( IDM_STEREO );
  284.     if (fVoiceSupported)          EnableTheOption( IDM_VOICE );
  285.     if (fMusicSupported)          EnableTheOption( IDM_MUSIC );
  286.     if (fHiFiSupported)           EnableTheOption( IDM_HIGH_FIDELITY );
  287.     if (fLoQualitySupported)      EnableTheOption( IDM_LOW_QUALITY );
  288.     if (fHighQualitySupported)    EnableTheOption( IDM_HIGH_QUALITY );
  289.     DeselectTheOption( IDM_MONO );
  290.     DeselectTheOption( IDM_VOICE );
  291.     DeselectTheOption( IDM_MUSIC );
  292.     DeselectTheOption( IDM_HIGH_FIDELITY );
  293.     DeselectTheOption( IDM_LOW_QUALITY );
  294.     DeselectTheOption( IDM_STEREO );
  295.     DeselectTheOption( IDM_HIGH_QUALITY );
  296.  
  297.     if (fSelectedFileType != NEW_FILE)
  298.     {
  299.        /*
  300.         * Selected file is an EXISTING file. Check the header information
  301.         * and check the appropriate item.
  302.         */
  303.        if ( mmAudioHeader.mmXWAVHeader.WAVEHeader.usChannels == 1 )
  304.        {
  305.           /*
  306.            * Selected file is using only channel. Select the "Mono" menu option.
  307.            * Disable the "Stereo" menu option.
  308.            */
  309.           SelectTheOption( IDM_MONO );
  310.           DisableTheOption( hwndMenu, IDM_STEREO );
  311.        }
  312.        else
  313.        if ( mmAudioHeader.mmXWAVHeader.WAVEHeader.usChannels == 2 )
  314.        {
  315.           /*
  316.            * Selected file is using both the channel. Select the "Stereo" menu
  317.            * option. Disable the "Mono" menu option.
  318.            */
  319.           SelectTheOption( IDM_STEREO );
  320.           DisableTheOption( hwndMenu, IDM_MONO );
  321.        }
  322.  
  323.        if (mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec == 11025)
  324.        {
  325.           /*
  326.            * Selected file sampling rate is 11.025 kHz. Select "Voice (11 khz)"
  327.            * menu option. Disable the "Music (22 khz)" and
  328.            * "High fidelity (44 khz)" menu options.
  329.            */
  330.           SelectTheOption( IDM_VOICE );
  331.           DisableTheOption( hwndMenu, IDM_MUSIC );
  332.           DisableTheOption( hwndMenu, IDM_HIGH_FIDELITY );
  333.        }
  334.        else
  335.        if (mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec == 22050)
  336.        {
  337.           /*
  338.            * Selected file sampling rate is 22.050 kHz. Select "Music (22 khz)"
  339.            * menu option. Disable the "Voice (11 khz)" and
  340.            * "High fidelity (44 khz)" menu options.
  341.            */
  342.           SelectTheOption( IDM_MUSIC );
  343.           DisableTheOption( hwndMenu, IDM_VOICE );
  344.           DisableTheOption( hwndMenu, IDM_HIGH_FIDELITY );
  345.        }
  346.        else
  347.        if (mmAudioHeader.mmXWAVHeader.WAVEHeader.ulSamplesPerSec == 44100)
  348.        {
  349.           /*
  350.            * Selected file sampling rate is 44.100 kHz. Select "High fidelity
  351.            * 44 khz" menu option. Disable the "Voice (11 khz)" and
  352.            * "Music (22 khz)" menu options.
  353.            */
  354.           SelectTheOption( IDM_HIGH_FIDELITY );
  355.           DisableTheOption( hwndMenu, IDM_VOICE );
  356.           DisableTheOption( hwndMenu, IDM_MUSIC );
  357.        }
  358.  
  359.        if (mmAudioHeader.mmXWAVHeader.WAVEHeader.usBitsPerSample == 8)
  360.        {
  361.           /*
  362.            * Selected file bits per sample is 8. Select "Low quality (8-bit)"
  363.            * menu option. Disable the "High quality (16-bit)" menu option.
  364.            */
  365.           SelectTheOption( IDM_LOW_QUALITY );
  366.           DisableTheOption( hwndMenu, IDM_HIGH_QUALITY );
  367.        }
  368.        else
  369.        if (mmAudioHeader.mmXWAVHeader.WAVEHeader.usBitsPerSample == 16)
  370.        {
  371.           /*
  372.            * Selected file bits per sample is 16. Select "High quality (16-bit)"
  373.            * menu option. Disable the "Low quality (8-bit)" menu option.
  374.            */
  375.           SelectTheOption( IDM_HIGH_QUALITY );
  376.           DisableTheOption( hwndMenu, IDM_LOW_QUALITY );
  377.        }
  378.     }
  379.     else
  380.     {
  381.        /*
  382.         * Selected file is a NEW file. Select all the default menu options.
  383.         */
  384.        SelectTheOption( IDM_STEREO );
  385.        SelectTheOption( IDM_MUSIC );
  386.        SelectTheOption( IDM_LOW_QUALITY );
  387.     }
  388.     mmioClose( hmmio, 0 );
  389.     return( TRUE );
  390.  
  391. }   /* end GetHeader() */
  392.  
  393. /******************************************************************************
  394.  * Name         :  AdjustTheDlg
  395.  *
  396.  * Description  :  This fuction adjusts the main dialog window whenever the
  397.  *                 status line is added or deleted.
  398.  *
  399.  * Concepts     :
  400.  *
  401.  * MMPM/2 API's :  none
  402.  *
  403.  * Parameters   :  fShow - flag for selection/deselection of the Status line.
  404.  *
  405.  * Return       :  none
  406.  *
  407.  ******************************************************************************/
  408. VOID AdjustTheDlg( HWND hwnd, BOOL fShow )
  409. {
  410.    SWP    swpFrame;                /* frame window positioning.               */
  411.    SWP    swpDefault;              /* default window positioning.             */
  412.    SWP    swpDialog;               /* dialog window positioning.              */
  413.    SWP    swpStatus;               /* status line window positioning.         */
  414.    static ULONG ulcyDialog = 0 ;   /* height of the dialog window.            */
  415.    BOOL   fAtDefaultSize = FALSE ; /* flag to determine the size of the window*/
  416.  
  417.  
  418.    /*
  419.     * Get the current frame window and the default frame window sizes.
  420.     */
  421.    WinQueryWindowPos( hwndFrame, &swpFrame ) ;
  422.    WinQueryDefaultSize( hwndFrame, &swpDefault ) ;
  423.  
  424.    /*
  425.     * Set the flag to determine whether we were at the default size.
  426.     */
  427.    if (swpFrame.cx==swpDefault.cx && swpFrame.cy==swpDefault.cy)
  428.    {
  429.       fAtDefaultSize = TRUE ;
  430.    }
  431.  
  432.    /*
  433.     * Query the window size and position of the Dialog window.
  434.     */
  435.    WinQueryWindowPos( hwnd, &swpDialog ) ;
  436.  
  437.    /*
  438.     * Save the current height of the Dialog window for further use.
  439.     */
  440.    if (!ulcyDialog)
  441.    {
  442.       ulcyDialog = swpDialog.cy ;
  443.    }
  444.  
  445.    /*
  446.     * Check to see the user selecting or deselecting the "Show status line"
  447.     * option.
  448.     */
  449.    if (fShow)
  450.    {
  451.       /*
  452.        * Status line is desired, raise dialog window height to ensure status
  453.        * is visible
  454.        */
  455.       swpDialog.cy = ulcyDialog ;
  456.    }
  457.    else
  458.    {
  459.       /*
  460.        * Status line is not desired, query the size and position of the
  461.        * "status text line" and lower dialog height to hide status line.
  462.        */
  463.       WinQueryWindowPos(
  464.          WinWindowFromID(
  465.             hwnd,                                 /* Dialog window handle     */
  466.             ID_STATUSTXT),                        /* Status text ID           */
  467.          &swpStatus );                            /* Return status text data  */
  468.       swpDialog.cy = swpStatus.y ;
  469.    }
  470.    /*
  471.     * Set the positioning of the Dialog window.
  472.     */
  473.    WinSetWindowPos(
  474.          hwnd,                           /* Dialog window handle              */
  475.          0L,                             /* Place hwnd on top of all siblings */
  476.          0L,                             /* Window position, x coordinate     */
  477.          0L,                             /* Window position, y coordinate     */
  478.          swpDialog.cx,                   /* New window size                   */
  479.          swpDialog.cy,                   /* New window size                   */
  480.          SWP_SIZE ) ;                    /* Window positioning options        */
  481.  
  482.    if (fAtDefaultSize)
  483.    {
  484.       /*
  485.        * Current window is at default size. Repaint the window with new
  486.        * window size.
  487.        */
  488.       WinDefaultSize(hwnd) ;
  489.    }
  490.    else
  491.    {
  492.       /*
  493.        * Current window is NOT at default size. Just update the window to
  494.        * hide the status line.
  495.        */
  496.       WinUpdateWindow(hwnd);
  497.    }
  498. }  /* End AdjustTheDlg() */
  499.  
  500. /******************************************************************************
  501.  * Name         :  UpdateTheStatusLine
  502.  *
  503.  * Description  :  This function update the status line text.
  504.  *
  505.  * Concepts     :  none
  506.  *
  507.  * MMPM/2 API's :  none
  508.  *
  509.  * Parameters   :  hwnd     -  Handle for the dialog window.
  510.  *                 usStatus -  Status line text to display.
  511.  *
  512.  * Return       :  none
  513.  *
  514.  ******************************************************************************/
  515. VOID UpdateTheStatusLine( HWND hwnd, USHORT usStatus )
  516. {
  517.    CHAR szStatus[50];                   /* to store string from the resource. */
  518.    CHAR szTemp[50];                     /* to store string from the resource. */
  519.    extern BOOL fPassedDevice;           /* for MCI_ACQUIRE to play the file.  */
  520.  
  521.    /*
  522.     * Get the appropriate string from the Resource string table.
  523.     */
  524.    WinLoadString( hab, (HMODULE)NULL, usStatus, sizeof(szStatus), szStatus );
  525.  
  526.    /*
  527.     * If lost the device, inform the user by appending "Suspended" to the
  528.     * current string.
  529.     */
  530.    if ( fPassedDevice )
  531.    {
  532.       /*
  533.        * Get the "Suspended" string from the Resource string table.
  534.        */
  535.       WinLoadString( hab, (HMODULE)NULL, IDS_PASSED, sizeof(szTemp), szTemp );
  536.  
  537.       strcat( szStatus, ", ");              /* append ", " to the status      */
  538.       strcat( szStatus, szTemp );           /* Append "Suspended" at the end. */
  539.    }
  540.    /*
  541.     * Update the status line.
  542.     */
  543.    WinSetWindowText (WinWindowFromID (hwnd, ID_STATUSTXT), szStatus);
  544.  
  545. }  /* End if status line should be shown */
  546.