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

  1. /**************************************************************************
  2.  * File Name   : MCISTRNG.C
  3.  *
  4.  * Description : This file contains the C source code required for the
  5.  *               MCISTRNG sample program.  This program can be run in three ways.
  6.  *
  7.  *               1. The user enters MCI String commands from a combination box
  8.  *               and presses the Send pushbutton.
  9.  *               2. The user can enter a batch file which has a series of valid
  10.  *               commands (one command per line) at the command prompt.
  11.  *               3. The user can open a batch file by selecting "Batch file"
  12.  *               push button.
  13.  *
  14.  *               The command is sent to the MCD and the string is placed in the
  15.  *               combination box's list box.
  16.  *
  17.  *               The MCD will take the MCI String Command and process it into
  18.  *               the correct MCI Commands.  Depending on the MCI String
  19.  *               Command the MCD will sent MCI Notification messages back to
  20.  *               the application.  These messages will be filtered as per the
  21.  *               user's instructions so that only certain messages will be
  22.  *               shown.
  23.  *
  24.  * Concepts    : This sample program will show how the MCI String interface
  25.  *               is used.  Basically, the use of the interface involves
  26.  *               sending MCI String Commands to the MCD, and handling the
  27.  *               MCI Notification messages that are received by the Call
  28.  *               Back window.
  29.  *
  30.  * MMPM/2 API's: List of all MMPM/2 API's that are used in
  31.  *               this module
  32.  *
  33.  *                mciSendString
  34.  *                mciGetErrorString
  35.  *
  36.  * Required
  37.  *    Files    : mcistrng.c         Source Code.
  38.  *               mcistrng.h         Include file.
  39.  *               mcistrng.dlg       Dialog definition.
  40.  *               mcistrng.rc        Resources.
  41.  *               mcistrng.ipf       Help text for the Main Dialog.
  42.  *               makefile           Make file.
  43.  *               mcistrng.def       Linker definition file.
  44.  *               mcistrng.ico       MCI String Icon.
  45.  *
  46.  * Copyright (C) IBM 1991, 1993
  47.  ******************************************************************************/
  48.  
  49. #define  INCL_OS2MM                      /* required for MCI and MMIO headers */
  50. #define  INCL_WIN                        /* Required to use Win APIs.         */
  51. #define  INCL_PM                         /* Required to use PM APIs.          */
  52. #define  INCL_GPIPRIMATIVES              /* Required to use GPI OS/2 APIs.    */
  53. #define  INCL_DOSDATETIME                /* Required for get date time info.  */
  54. #define  INCL_DOSPROCESS                 /* Required for OS/2 process APIs.   */
  55. #define  INCL_WINHELP                    /* Required to use IPF.              */
  56. #define  INCL_SECONDARYWINDOW            /* required for secondary window     */
  57. #define  INCL_WINSTDFILE                 /* required for open file dlg        */
  58. #define  INCL_WINSTDDLGS                 /* required for open file dlg        */
  59.  
  60. #include <os2.h>
  61. #include <os2me.h>
  62. #include <stdio.h>
  63. #include <stdlib.h>
  64. #include <string.h>
  65.  
  66. #include <sw.h>
  67.  
  68. #include "mcistrng.h"
  69.  
  70.  
  71. /*********************** Procedure/Function Prototypes ************************/
  72. /*
  73.  * This definition is required to use the sample program with the IBM
  74.  * C compiler.
  75.  */
  76. #pragma linkage( MainDialogProc, system )
  77. #pragma linkage( IncludeDialogProc, system )
  78. #pragma linkage( DisplayDialogProc, system )
  79. #pragma linkage( DisplayListBoxProc, system )
  80.  
  81.  
  82. MRESULT EXPENTRY MainDialogProc( HWND   hwnd,
  83.                                  ULONG  msg,
  84.                                  MPARAM mp1,
  85.                                  MPARAM mp2 );
  86. MRESULT EXPENTRY IncludeDialogProc( HWND   hwnd,
  87.                                     ULONG  msg,
  88.                                     MPARAM mp1,
  89.                                     MPARAM mp2 );
  90. MRESULT EXPENTRY DisplayDialogProc( HWND   hwnd,
  91.                                     ULONG  msg,
  92.                                     MPARAM mp1,
  93.                                     MPARAM mp2 );
  94. MRESULT EXPENTRY DisplayListBoxProc( HWND   hwnd,
  95.                                      ULONG  msg,
  96.                                      MPARAM mp1,
  97.                                      MPARAM mp2 );
  98. MRESULT EXPENTRY FileDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  99.  
  100. BOOL        GetStringFromComboBox( HWND hwndStringComboBox, PSZ  pszMCIString );
  101. BOOL        IsMCIStringValid( PSZ pszMCIString );
  102. USHORT      ShowAMessage( HWND   hwndOwnerWindow,
  103.                           CHAR   *pcMessageTitle,
  104.                           USHORT usMessageId,
  105.                           ULONG  ulMessageBoxStyle );
  106. VOID        InitializeHelp( VOID );
  107. VOID        SendStringToMCD( HWND hwndComboBox );
  108. VOID        InitializeDialog( VOID );
  109. VOID        TerminateDialog( VOID );
  110. VOID        RunTheBatchFile( HWND hwnd );
  111. VOID        SetSystemMenu( HWND hwndDialogWindow );
  112. VOID        SendScrollBarMessage( HWND  hwndDialogBox,
  113.                                   SHORT sScrollBarMessage );
  114. VOID        SaveMSTInfo( VOID );
  115. BOOL        OpenBatchFile( CHAR szBatchFileName[] );
  116. BOOL        GetBatchFileAndOpenIt( VOID );
  117. VOID        Restore( HWND hwnd );
  118.  
  119. /******************** End of Procedure/Function Prototypes ********************/
  120.  
  121.  
  122. /**************************** Global Variables. *******************************/
  123.  
  124. /*
  125.  * This array holds the ID's that are used to retrieve the the strings from
  126.  * the string table and placed into the global double array acStringBuffer.
  127.  * The defines that are used for the string table is used to create the index
  128.  * into the global buffer.  Since the string table starts at 1 and the global
  129.  * buffer starts at 0, the index is decremented by 1 when used.  This means
  130.  * when the acStringBuffer is accessed after the strings have been loaded into
  131.  * the buffer, all indexes will be n-1, i.e., IDS_MAIN_HELP_WINDOW_TITLE - 1,
  132.  * to get the proper string.  This is done simply to keep down the number of
  133.  * #defines.
  134.  */
  135. USHORT ausMessageId[] = { IDS_MAIN_WINDOW_TITLE,
  136.                           IDS_MAIN_HELP_WINDOW_TITLE,
  137.                           IDS_NORMAL_ERROR_MESSAGE_BOX_TEXT,
  138.                           IDS_MAIN_HELP_LIBRARY_FILE,
  139.                           IDS_RETURN_STRING,
  140.                           IDS_UNKNOWN,
  141.                           IDS_CONTINUE_BATCHFILE};
  142.  
  143. HELPINIT hmiHelpStructure;         /* Help initialization structures.     */
  144.  
  145. /*
  146.  * This variable will hold the address of the window procedure that controls
  147.  * the List Box that is in the Display Messages dialog.  This is required
  148.  * since we subclass the List Box to handle certain user actions.
  149.  */
  150. PFNWP pfnwpDisplayListBoxProc;
  151.  
  152. /*
  153.  * This array has the ID values for each of the check boxes used in the
  154.  * Include Dialog Box.  These values are used to get the check box window
  155.  * handles.
  156.  */
  157. USHORT ausCheckBoxIDs[] = { ID_NOTIFY_CB,
  158.                             ID_PASSDEVICE_CB,
  159.                             ID_POSITION_CHANGE_PB,
  160.                             ID_EVENT_CB,
  161.                             ID_CUEPOINT_CB,
  162.                             ID_PLAYLIST_CB
  163.                           };
  164.  
  165. /*
  166.  * This array holds the 'check' state of the check boxes.  TRUE indicates
  167.  * that the check box is 'checked off'.
  168.  */
  169. BOOL afCheckBoxState[] = { TRUE,    /* MM_MCINOTIFY is set.                   */
  170.                            TRUE,    /* MM_MCIPASSDEVICE is set.               */
  171.                            TRUE,    /* MM_MCIPOSITIONCHANGE is set.           */
  172.                            TRUE,    /* MM_MCIEVENT is set.                    */
  173.                            TRUE,    /* MM_MCICUEPOINT is set.                 */
  174.                            TRUE     /* MM_MCIPLAYLISTMESSAGE is set.          */
  175.                          };
  176.  
  177. BOOL   fDisplayMsgWindowIsUp;       /* for  display message window.           */
  178. BOOL   fNotify = FALSE;             /* flag needed if notify in the string.   */
  179. BOOL   fStringFromBatchFile;        /* source of the string command source    */
  180. USHORT usCountOfMCIStringSent = 1;  /* Number of sent cmds                    */
  181. USHORT usUserParameter;
  182. /*
  183.  * Holds the string result that is returned by the sending of a MCI String
  184.  * Command.
  185.  */
  186. CHAR   acMCIReturnString[ MCI_RETURN_STRING_LENTGH ];
  187.  
  188. CHAR   acMCIString[ MCI_STRING_LENGTH ];             /* MCI String Command.   */
  189. CHAR   acBatchFileName[CCHMAXPATH] = "";  /* Batch file name.                 */
  190. FILE   *hFile;                           /* Batch file handle.                */
  191. CHAR   szAppName[FILE_NAME_SIZE];        /* buffer for window title text      */
  192. CHAR   szKeyName[] = "SWP";              /* for key name in the os2.ini file  */
  193.  
  194. /*
  195.  * This array holds program required text that is pulled from the string
  196.  * table.
  197.  */
  198. CHAR   acStringBuffer[ NUMBER_OF_PROGRAM_STRINGS ][ STRING_SIZE ];
  199.  
  200. HWND   hwndMainDialogBox,              /* Handle to the Main Dialog window.   */
  201.        hwndIncludeDialogBox,           /* Handle to the Include Dialog box.   */
  202.        hwndDisplayDialogBox,           /* Handle to the Display Dialog box.   */
  203.        hwndHelpInstance,               /* Handle to the Help window.          */
  204.        hwndDisplayListBox,             /* Handle to the Display List Box.     */
  205.        hwndFrame,                      /* Handle to the frame window.         */
  206.        hwndSendPB,                     /* Send PB handle.                     */
  207.        hwndComboBox,                   /* Combo Box handle.                   */
  208.        hwndBatchFilePB;                /* Batch file PB handle.               */
  209.  
  210. HAB    hab;          /* Handle to the Anchor Block for the program.           */
  211. QMSG   qmsg;         /* Structure to hold a message on the message queue.     */
  212. HMQ    hmq;          /* Handle to the message queue.                          */
  213. SWPRESTORE  Save;    /* Structure for the Save and Restore                    */
  214.  
  215. /*
  216.  * This structure holds text representations for the string commands.  It's
  217.  * used during processing of the MM_MCINOTIFY message in the DisplayDialogProc.
  218.  *
  219.  * These strings are not in the resource file because they should not be
  220.  * translated.  They are string commands, and string commands are not
  221.  * translated.  These strings correspond to command message identifiers
  222.  * listed in mmsystem.h.
  223.  */
  224.  
  225. char  *szMessage[55] = {
  226.       "",
  227.       "OPEN",
  228.       "CLOSE",
  229.       "ESCAPE",
  230.       "PLAY",
  231.       "SEEK",
  232.       "STOP",
  233.       "PAUSE",
  234.       "INFO",
  235.       "CAPABILITY",
  236.       "STATUS",
  237.       "SPIN",
  238.       "SET",
  239.       "STEP",
  240.       "RECORD",
  241.       "SYSINFO",
  242.       "SAVE",
  243.       "CUE",
  244.       "UPDATE",
  245.       "CUEPOINT",
  246.       "POS_ADVISE",
  247.       "SYNC_OFFSET",
  248.       "LOAD",
  249.       "ACQUIRE",
  250.       "RELEASE",
  251.       "MASTERAUDIO",
  252.       "GETTOC",
  253.       "DEVICESETTINGS",
  254.       "CONNECTOR",
  255.       "RESUME",
  256.       "NOT_DEFINED",
  257.       "CONNECTORINFO",
  258.       "DEFAULT_CONNECTION",
  259.       "CONNECTION",
  260.       "NOT_DEFINED",
  261.       "NOT_DEFINED",
  262.       "NOT_DEFINED",
  263.       "NOT_DEFINED",
  264.       "NOT_DEFINED",
  265.       "NOT_DEFINED",
  266.       "CAPTURE",
  267.       "FREEZE",
  268.       "GETIMAGEBUFFER",
  269.       "GETIMAGEPALETTE",
  270.       "PUT",
  271.       "REALIZE",
  272.       "REWIND",
  273.       "RESTORE",
  274.       "SETIMAGEBUFFER",
  275.       "SETIMAGEPALETTE",
  276.       "UNFREEZE",
  277.       "WHERE",
  278.       "WINDOW"};
  279.  
  280. /************************** End of Globle Variables ***************************/
  281.  
  282.  
  283. /******************************************************************************
  284.  * Name        : main
  285.  *
  286.  * Description : This function calls the InitializeDialog procedure to create
  287.  *               the dialog box, starts up the message loop, and finally calls
  288.  *               TerminateDialog when the program is to end.
  289.  *
  290.  * Concepts    : None.
  291.  *
  292.  * MMPM/2 API's: None.
  293.  *
  294.  * Parameters  : None.
  295.  *
  296.  * Return      : TRUE is returned to the operating system.
  297.  *
  298.  ******************************************************************************/
  299. INT main( argc, argv )
  300. int    argc;
  301. char   *argv[];
  302. {
  303.    /*
  304.     * If using batch file copy. The file will be opened to process in
  305.     * WM_INITDLG of main dialog proc.
  306.     */
  307.    if (argc == 2)
  308.    {
  309.      strcpy(acBatchFileName,argv[1]);
  310.    }
  311.  
  312.    InitializeDialog();
  313.  
  314.    WinUpdateWindow( hwndFrame );              /* Force window to paint.       */
  315.    WinSetFocus( HWND_DESKTOP, hwndComboBox);  /* Set focus on the entry field */
  316.  
  317.    while ( WinGetMsg( hab, (PQMSG) &qmsg, (HWND) NULL, 0, 0) )
  318.       WinDispatchMsg( hab, (PQMSG) &qmsg );
  319.  
  320.    TerminateDialog();
  321.  
  322.    return( TRUE );
  323.  
  324. } /* End of main */
  325.  
  326.  
  327. /******************************************************************************
  328.  * Name        : InitializeDialog
  329.  *
  330.  * Description : This function performs the necessary initializations and
  331.  *               setups that are required to show/run a dialog box as a
  332.  *               main window.  The message queue will be created, as will
  333.  *               the dialog box.  Finally the message passing loop will be
  334.  *               started to give messages to the dialog box.
  335.  *
  336.  * Concepts    : None.
  337.  *
  338.  * MMPM/2 API's: None.
  339.  *
  340.  * Parameters  : None.
  341.  *
  342.  * Return      : None.
  343.  *
  344.  ******************************************************************************/
  345. VOID InitializeDialog( VOID )
  346. {
  347.  
  348.    USHORT   usI;                         /* Generic Counter.                  */
  349.    CHAR     szDefaultSize[CCHMAXPATH];   /* buffer for default size menu text */
  350.  
  351.    /*
  352.     * Setup and initialize the dialog window.
  353.     */
  354.    hab = WinInitialize( (USHORT) 0 );
  355.  
  356.    /*
  357.     * Load the various strings that are required by the program.
  358.     */
  359.    for( usI=0; usI<NUMBER_OF_PROGRAM_STRINGS; usI++)
  360.    {
  361.       WinLoadString(
  362.          hab,                            /* HAB for this dialog box.          */
  363.          (HMODULE) NULL,                 /* Get string from .exe file.        */
  364.          ausMessageId[ usI ],            /* Which string to get.              */
  365.          (SHORT) STRING_SIZE,            /* The size of the buffer.           */
  366.          (PSZ) &acStringBuffer[ usI ] ); /* Buffer to place string.           */
  367.    }
  368.  
  369.    hmq = WinCreateMsgQueue( hab, 0 );
  370.  
  371.    WinLoadString(
  372.       WinQueryAnchorBlock (HWND_DESKTOP),
  373.       (HMODULE) NULL,
  374.       IDS_DEFAULTSIZE,
  375.       sizeof(szDefaultSize),
  376.       szDefaultSize);
  377.  
  378.  
  379.    hwndFrame =                  /* Returns the handle to the frame.           */
  380.       WinLoadSecondaryWindow(
  381.          HWND_DESKTOP,          /* Parent of the dialog box.                  */
  382.          HWND_DESKTOP,          /* Owner of the dialog box.                   */
  383.          (PFNWP) MainDialogProc,/* 'Window' procedure for the dialog box.     */
  384.          (HMODULE) NULL,        /* Where is the dialog.  Null is EXE file..   */
  385.          ID_MAIN_DIALOG_BOX,    /* Dialog ID.                                 */
  386.          (PVOID) NULL );        /* Creation Parameters for the dialog.        */
  387.  
  388.    /*
  389.     * Retrieve the handle to the dialog box by specifying the QS_DIALOG flag.
  390.     */
  391.    hwndMainDialogBox = WinQuerySecondaryHWND(hwndFrame, QS_DIALOG);
  392.  
  393.    /*
  394.     * Add Default Size menu item to system menu of the secondary window.
  395.     */
  396.    WinInsertDefaultSize(hwndFrame, szDefaultSize);
  397.  
  398.    /*
  399.     * Set the name of the sample program in the title bar of the dialog
  400.     * window.  This is done so that the program name will show up in the
  401.     * Task List window, via the FCF_TASKLIST flag AND will NOT show the
  402.     * .exe file name of the program.  If the FCF_TASKLIST flag is used the
  403.     * .exe file name AND the dialog title will show up in the title bar.
  404.     * This is not wanted.
  405.     */
  406.    WinSetWindowText(
  407.       hwndFrame,
  408.       acStringBuffer[ IDS_MAIN_WINDOW_TITLE - 1 ] );
  409.  
  410.    /*
  411.     * This window is initially loaded but is NOT visible.  Only by pressing
  412.     * the Display Messages Pushbutton on the main window will this dialog
  413.     * box be displayed.  This is a non-modal dialog window.
  414.     */
  415.    hwndDisplayDialogBox =
  416.       WinLoadDlg(
  417.          HWND_DESKTOP,              /* Parent of the dialog box.              */
  418.          (HWND) NULL,               /* Owner of the dialog box.               */
  419.          (PFNWP) DisplayDialogProc, /* 'Window' procedure for the dialog box. */
  420.          (HMODULE) NULL,            /* Where is the dialog.  Null is EXE file.*/
  421.          ID_DISPLAY_DIALOG_BOX,     /* Dialog ID.                             */
  422.          (PVOID) NULL );            /* Creation Parameters for the dialog.    */
  423.  
  424.    /*
  425.     * Get the restored windows position information from the os2.ini
  426.     * file before displaying.
  427.     */
  428.    Restore( hwndFrame );
  429.  
  430.    /*
  431.     * Initialize the help structure and associate the help instance.
  432.     */
  433.    InitializeHelp();
  434.  
  435.    /*
  436.     * If the Dispay Message Box was up at the time of destroying the
  437.     * main window display it.
  438.     */
  439.    if (Save.fDisplayMsgWindowStatus == TRUE)
  440.         WinShowWindow(
  441.         hwndDisplayDialogBox,
  442.         TRUE );
  443.  
  444. } /* End of InitializeDialog */
  445.  
  446.  
  447. /******************************************************************************
  448.  * Name        : TerminateDialog
  449.  *
  450.  * Description : This routine is called after the message dispatch loop
  451.  *               has ended because of a WM_QUIT message.  The code will
  452.  *               destroy the help instance, messages queue and window.
  453.  *
  454.  * Concepts    : None.
  455.  *
  456.  * MMPM/2 API's: None.
  457.  *
  458.  * Parameters  : None.
  459.  *
  460.  * Return      : None.
  461.  *
  462.  ******************************************************************************/
  463. VOID TerminateDialog( VOID )
  464. {
  465.  
  466.    /*
  467.     * Save latest windows position to INI.
  468.     */
  469.    SaveMSTInfo();
  470.  
  471.    /*
  472.     * Destroy the Help Instance for this dialog window.
  473.     */
  474.    if ( hwndHelpInstance != (HWND) NULL )
  475.    {
  476.       WinDestroyHelpInstance( hwndHelpInstance );
  477.    }
  478.  
  479.    WinDestroySecondaryWindow( hwndFrame );
  480.    WinDestroyWindow( hwndDisplayDialogBox );
  481.    WinDestroyMsgQueue( hmq );
  482.    WinTerminate( hab );
  483.  
  484. }  /* End of TerminateDialog */
  485.  
  486.  
  487. /******************************************************************************
  488.  * Name        : MainDialogProc
  489.  *
  490.  * Description : This function controls the main dialog box.  It will handle
  491.  *               received messages such as pushbutton notifications, timing
  492.  *               events, etc.
  493.  *
  494.  * Concepts    : None.
  495.  *
  496.  * MMPM/2 API's: None.
  497.  *
  498.  * Parameters  : hwnd - Handle for the Main dialog box.
  499.  *               msg  - Message received by the dialog box.
  500.  *               mp1  - Parameter 1 for the just received message.
  501.  *               mp2  - Parameter 2 for the just received message.
  502.  *
  503.  * Return      : 0 or the result of default processing.
  504.  *
  505.  ******************************************************************************/
  506. MRESULT EXPENTRY MainDialogProc( HWND   hwnd,
  507.                                  ULONG  msg,
  508.                                  MPARAM mp1,
  509.                                  MPARAM mp2 )
  510. {
  511.    static PSWP  pswpWindowActionMP    = (PSWP) NULL; /* Action of Window.     */
  512.    static BOOL  fIsTheWindowMinimized = FALSE;       /* State of Window.      */
  513.  
  514.    HPOINTER hpProgramIcon;                           /* Pointer to Icon.      */
  515.    CHAR szFileNameBuffer[ FILE_NAME_SIZE ];
  516.  
  517.    switch( msg )
  518.    {
  519.       /*
  520.        * Since the dialog was just started, setup various objects.
  521.        */
  522.       case WM_INITDLG :
  523.          /*
  524.           * Set the sample programs minimize icon.
  525.           */
  526.          hpProgramIcon =
  527.             WinLoadPointer(
  528.                HWND_DESKTOP,
  529.                (HMODULE) NULL, /* Where the resource is kept. (Exe file)      */
  530.                ID_ICON );      /* Which icon to use.                          */
  531.  
  532.          WinDefSecondaryWindowProc(
  533.             hwnd,              /* Dialog window handle.                       */
  534.             WM_SETICON,        /* Message to the dialog.  Set it's icon.      */
  535.             (MPARAM) hpProgramIcon,
  536.             (MPARAM) 0 );      /* mp2 no value.                               */
  537.  
  538.          /*
  539.           * Get the handle of the Combination box so that it can be reused
  540.           * in future processing.
  541.           */
  542.          hwndComboBox =
  543.             WinWindowFromID(
  544.                hwnd,
  545.                ID_STRING_COMBO_BOX );
  546.  
  547.          /*
  548.           * Get the handle of the Send push button.
  549.           */
  550.          hwndSendPB =
  551.             WinWindowFromID(
  552.                hwnd,                   /* Handle of this dialog window.       */
  553.                ID_MAIN_SEND_PB );      /* ID of the left most PM control.     */
  554.  
  555.          /*
  556.           * Get the handle of the Batch file push button.
  557.           */
  558.          hwndBatchFilePB =
  559.             WinWindowFromID(
  560.                hwnd,                   /* Handle of this dialog window.       */
  561.                ID_BATCH_FILE_PB );      /* ID of the left most PM control.     */
  562.  
  563.          /*
  564.           * Disable the Send push button until valid text has been placed
  565.           * into the entry field.
  566.           */
  567.          WinEnableWindow(
  568.                hwndSendPB,             /* Handle of this dialog window.       */
  569.                FALSE );                /* ID of the left most PM control.     */
  570.  
  571.          /*
  572.           * Set the String limit size for the Combo Box's Entry Field.
  573.           */
  574.          WinSendMsg(
  575.             hwndComboBox,
  576.             EM_SETTEXTLIMIT,
  577.             MPFROMLONG( MCI_STRING_LENGTH ),
  578.             0L );
  579.  
  580.          /*
  581.           * If there is batch file, load the file and post a message to execute.
  582.           */
  583.          if ( strlen(acBatchFileName) > 0)
  584.          {
  585.             if (OpenBatchFile(acBatchFileName))
  586.             {
  587.                /*
  588.                 * Disable the Batch file push button until the batch file is
  589.                 * processed.
  590.                 */
  591.                WinEnableWindow(
  592.                   hwndBatchFilePB,        /* Handle of this dialog window.    */
  593.                   FALSE );                /* ID of the left most PM control.  */
  594.                WinPostMsg( hwnd, WM_BATCHFILE, NULL, NULL );
  595.             }
  596.          }
  597.          return( 0 );
  598.  
  599.       case WM_CLOSE :
  600.          /*
  601.           * The call to the WinDefSecondaryWindowProc is required so that the
  602.           * dialog box will be closed.  This is needed since the WM_QUIT is
  603.           * not processed in the same manner for dialog boxes and windows.
  604.           * But first cause the Display Messages Dialog to shutdown.
  605.           */
  606.          WinSendMsg(
  607.             hwndDisplayDialogBox,
  608.             WM_QUIT,
  609.             0L,
  610.             0L );
  611.  
  612.          return( WinDefSecondaryWindowProc( hwnd, msg, mp1, mp2 ) );
  613.  
  614.       case WM_HELP :
  615.          /*
  616.           * The dialog window has received a request for help from the user,
  617.           * i.e., the Help pushbutton was pressed.  Send the HM_DISPLAY_HELP
  618.           * message to the Help Instance with the IPF resource identifier
  619.           * for the correct HM panel.  This will show the help panel for this
  620.           * sample program.
  621.           */
  622.          WinSendMsg(
  623.             hwndHelpInstance,
  624.             HM_DISPLAY_HELP,
  625.             MPFROMSHORT( 1 ),
  626.             MPFROMSHORT( HM_RESOURCEID ) );
  627.          return( 0 );
  628.  
  629.       case WM_CONTROL :
  630.          switch( SHORT1FROMMP( mp1 ))
  631.          {
  632.             case ID_STRING_COMBO_BOX :
  633.             {
  634.                if ( SHORT2FROMMP( mp1 ) == CBN_EFCHANGE )
  635.                {
  636.                  /*
  637.                   * See if the text in the entry field is greater than zero.
  638.                   */
  639.                  if ( WinQueryWindowText(
  640.                          hwndComboBox,
  641.                          FILE_NAME_SIZE,
  642.                          szFileNameBuffer ) > 0 )
  643.                  {
  644.                     /*
  645.                      * If greater than zero enable the Send push button,
  646.                      */
  647.                     WinEnableWindow(
  648.                        hwndSendPB,
  649.                        TRUE );
  650.                  }
  651.                  else
  652.                  {
  653.                     /*
  654.                      *  Else disable the Send push button.
  655.                      */
  656.                     WinEnableWindow(
  657.                        hwndSendPB,
  658.                        FALSE );
  659.                  }
  660.                }
  661.             } /* endif */
  662.           return( 0 );
  663.         }
  664.  
  665.       case WM_BATCHFILE :
  666.  
  667.         RunTheBatchFile(hwnd);
  668.         break;
  669.  
  670.       case WM_TIMER :
  671.  
  672.         WinStopTimer( hab, hwnd, 1);
  673.         WinPostMsg( hwnd, WM_BATCHFILE, NULL, NULL );
  674.         break;
  675.  
  676.       case WM_COMMAND :
  677.          /*
  678.           * To get which pushbutton was pressed the SHORT1FROMMP macro
  679.           * is used.
  680.           */
  681.          switch( SHORT1FROMMP( mp1 ) )
  682.          {
  683.             /*
  684.              * The Send Push Button was pressed on the main dialog window.
  685.              */
  686.             case ID_MAIN_SEND_PB :
  687.  
  688.                fStringFromBatchFile = FALSE;  /* User typed the string command */
  689.                SendStringToMCD( hwndComboBox );
  690.  
  691.                return( 0 );
  692.  
  693.             /*
  694.              * The Display Messages Push Button was pressed on the main
  695.              * dialog window.
  696.              */
  697.             case ID_DISPLAY_MESSAGES_PB :
  698.  
  699.                /*
  700.                 * Show the Display Messages dialog box.  This dialog is always
  701.                 * running but is initially made invisible.  Therefore we will
  702.                 * make it visible at this point.
  703.                 */
  704.                WinShowWindow(
  705.                   hwndDisplayDialogBox,   /* Handle to the window.            */
  706.                   TRUE );                 /* Make the window visible.         */
  707.  
  708.                fDisplayMsgWindowIsUp = TRUE; /* Visible, set the flag.    */
  709.  
  710.                WinSetFocus(
  711.                   HWND_DESKTOP,           /* Window is in Desk top.           */
  712.                   hwndDisplayDialogBox ); /* Make the Display dialog in focus.*/
  713.  
  714.                return( 0 );
  715.  
  716.             case ID_BATCH_FILE_PB :
  717.                if ( GetBatchFileAndOpenIt() )
  718.                {
  719.                   /*
  720.                    * Disable the Batch file push button until the batch
  721.                    * file is processed.
  722.                    */
  723.                   WinEnableWindow(
  724.                      hwndBatchFilePB,  /* Handle of this dialog window.    */
  725.                      FALSE );          /* ID of the left most PM control.  */
  726.                   WinStartTimer( hab, hwndMainDialogBox, 1, 1000UL);
  727.                }
  728.                return( 0 );
  729.  
  730.             /*
  731.              * The Cancel Push Button was pressed on the main dialog window.
  732.              * Or the ESC key was pressed.
  733.              */
  734.             case DID_CANCEL:
  735.             case ID_MAIN_CANCEL_PB :
  736.                /*
  737.                 * Send a WM_CLOSE message to the sample program so that it
  738.                 * closes itself.
  739.                 */
  740.                WinSendMsg(
  741.                   hwnd,                   /* Window handle.                   */
  742.                   WM_CLOSE,               /* The message that is sent.        */
  743.                   (MPARAM) NULL,          /* No MP1 parameter.                */
  744.                   (MPARAM) NULL );        /* No MP2 parameter.                */
  745.  
  746.                return( 0 );
  747.  
  748.          }  /* End of Command Switch */
  749.  
  750.          return( 0 );
  751.  
  752.       case WM_MINMAXFRAME :
  753.       {
  754.          /*
  755.           * The code for this message is required since this sample program
  756.           * is using a dialog box as the main window.  There is a feature
  757.           * of PM that some controls may have to be hidden if an icon is
  758.           * desired when the program is minimized.  If the control is not
  759.           * hidden then it or a piece of it may show up in place of the icon.
  760.           *
  761.           * Therefore we use the handle to the left most control and if the
  762.           * message indicates that the program is to be minimized then we
  763.           * will hide the control.  When the program is Restored the control
  764.           * will be shown.
  765.           */
  766.  
  767.          pswpWindowActionMP = (PSWP) LONGFROMMP( mp1 );
  768.  
  769.          if ( pswpWindowActionMP->fl & SWP_MINIMIZE )
  770.          {
  771.             WinShowWindow(
  772.                hwndSendPB,             /* Handle to the control.              */
  773.                FALSE );                /* Hide the control window.            */
  774.  
  775.            /*
  776.             * If Display Message Window is visible, hide it.
  777.             */
  778.            if (fDisplayMsgWindowIsUp == TRUE)
  779.               WinShowWindow(
  780.                  hwndDisplayDialogBox,
  781.                  FALSE );
  782.          }
  783.          else
  784.          {
  785.             WinShowWindow(
  786.                hwndSendPB,             /* Handle to the control.              */
  787.                TRUE );                 /* Show the control window.            */
  788.  
  789.            /*
  790.             * If Display Message Window was visible at the time of minimizing
  791.             * the main window, make it visible.
  792.             */
  793.  
  794.            if (fDisplayMsgWindowIsUp == TRUE)
  795.               WinShowWindow(
  796.                  hwndDisplayDialogBox,
  797.                  TRUE );
  798.          }
  799.  
  800.          return( WinDefSecondaryWindowProc( hwnd, msg, mp1, mp2 ) );
  801.       }  /* End of MINMAXFRAM */
  802.  
  803.       default:
  804.           return( WinDefSecondaryWindowProc( hwnd, msg, mp1, mp2 ) );
  805.  
  806.    }  /* End of Switch */
  807.  
  808.    return( (MRESULT) FALSE );
  809.  
  810. } /* End of MainDialogProc */
  811.  
  812.  
  813. /******************************************************************************
  814.  * Name        : DisplayDialogProc
  815.  *
  816.  * Description : This function controls the Display dialog box.  It will
  817.  *               handle received messages such as pushbutton notifications,
  818.  *               timing events, etc.  This dialog is created with the Main
  819.  *               dialog box and is not destroyed until the termination of the
  820.  *               Main window.  The window is kept alive so that it can
  821.  *               process arriving MCI Notification messages.
  822.  *
  823.  *               The following messages are handled specifically by this
  824.  *               routine.
  825.  *
  826.  *                  WM_INITDLG
  827.  *                  WM_CLOSE
  828.  *                  WM_HELP
  829.  *                  WM_COMMAND
  830.  *                  WM_MINMAXFRAME
  831.  *
  832.  * Concepts    : Handling of arriving MCI Notification messages.
  833.  *
  834.  * MMPM/2 API's: MM_MCINOTIFY
  835.  *               MM_MCIPASSDEVICE
  836.  *               MM_MCIPOSITIONCHANGE
  837.  *               MM_MCIEVENT
  838.  *               MM_MCICUEPOINT
  839.  *               MM_MCIPLAYLISTMESSAGE
  840.  *
  841.  * Parameters  : hwnd - Handle for the Display dialog box.
  842.  *               msg  - Message received by the dialog box.
  843.  *               mp1  - Parameter 1 for the just received message.
  844.  *               mp2  - Parameter 2 for the just received message.
  845.  *
  846.  * Return      : 0 or the result of default processing.
  847.  *
  848.  ******************************************************************************/
  849. MRESULT EXPENTRY DisplayDialogProc( HWND   hwnd,
  850.                                     ULONG  msg,
  851.                                     MPARAM mp1,
  852.                                     MPARAM mp2 )
  853. {
  854.  
  855.    /*
  856.     * This array will hold the text that is used for the MCI Notification
  857.     * messages.
  858.     */
  859.    static CHAR acMCINotMessage[ NUMBER_OF_NOTIFICATION_MESSAGES ]
  860.                                        [ STRING_SIZE ];
  861.  
  862.    USHORT usI = 0,                             /* Generic Counter.            */
  863.           usJ = 0;                             /* Generic Counter.            */
  864.    CHAR   acTempString[ STRING_SIZE ];         /* Temp string buffer.         */
  865.    CHAR   acErrorBuf[20];                      /* Another temp buffer.        */
  866.    CHAR   acIDBuf[20];                         /* Another temp buffer.        */
  867.    CHAR   acUserParmBuf[20];                   /* Another temp buffer.        */
  868.    CHAR   acTimeBuf[20];                       /* Another temp buffer.        */
  869.  
  870.    switch( msg )
  871.    {
  872.  
  873.       case WM_INITDLG :
  874.          /*
  875.           * Hide the window until it is called.
  876.           */
  877.          WinShowWindow(
  878.             hwnd,
  879.             FALSE );
  880.  
  881.          /*
  882.           * Set the Child Dialog window's System Menu.
  883.           */
  884.          SetSystemMenu( hwnd );
  885.  
  886.          /*
  887.           * Load the text for the MCI Notification Messages.  This text
  888.           * will be shown in the Display Dialog Box's list box.
  889.           */
  890.          for( usI=STARTING_IDS_VALUE_FOR_MCI_NOTIFICATION_MESSAGES,usJ = 0;
  891.               usI<STARTING_IDS_VALUE_FOR_MCI_NOTIFICATION_MESSAGES +
  892.                      NUMBER_OF_NOTIFICATION_MESSAGES;
  893.               usI++)
  894.          {
  895.             /*
  896.              * Get the string from the Resource defined string table and
  897.              * show it in the message box.
  898.              */
  899.              WinLoadString(
  900.                 hab,                     /* HAB for this dialog box.      */
  901.                 (HMODULE) NULL,          /* The string is in the exe file.*/
  902.                 usI,                     /* Which string to get.          */
  903.                 (SHORT) STRING_SIZE,     /* The size of the buffer.       */
  904.                 acMCINotMessage[ usJ ]); /* String Buffer                 */
  905.             usJ++;
  906.          }  /* End of For that loads the MCI message text. */
  907.  
  908.          /*
  909.           * Get the handle to the list box that is in the Display Dialog.
  910.           */
  911.          hwndDisplayListBox =
  912.             WinWindowFromID(
  913.                hwnd,
  914.                ID_DISPLAY_CONTROL );
  915.  
  916.          /*
  917.           * Subclass the Display Dialog's list box so that certain actions
  918.           * can be ignored.  Some user interactions with this List Box, i.e.,
  919.           * selection of items, etc. will be trapped and ignored by the
  920.           * the sample program to meet CUA requirements.
  921.           */
  922.          pfnwpDisplayListBoxProc =
  923.             WinSubclassWindow(
  924.                hwndDisplayListBox,
  925.                (PFNWP)DisplayListBoxProc );
  926.  
  927.          return( 0 );
  928.  
  929.       case WM_CLOSE :
  930.          /*
  931.           * Since this window is not destroyed until the main dialog box
  932.           * closes, this WM_CLOSE message will simply hide the window.
  933.           */
  934.          WinShowWindow(
  935.             hwnd,                     /* Handle of the window to hide.        */
  936.             FALSE );                  /* Hide the window.                     */
  937.  
  938.          fDisplayMsgWindowIsUp = FALSE;     /* Not visible, set the flag. */
  939.  
  940.          /*
  941.           * Set the focus to the Main Dialog window.
  942.           */
  943.          WinSetFocus(
  944.             HWND_DESKTOP,             /* Use window in DESKTOP.               */
  945.             hwndMainDialogBox );      /* Set focus on the Main Dialog.        */
  946.  
  947.          WinSetFocus( HWND_DESKTOP, hwndComboBox);
  948.  
  949.          return( 0 );
  950.  
  951.       case WM_HELP :
  952.          /*
  953.           * The dialog window has received a request for help from the user,
  954.           * i.e., the Help pushbutton was pressed.  Send the HM_DISPLAY_HELP
  955.           * message to the Help Instance with the IPF resource identifier
  956.           * for the correct HM panel.  This will show the help panel for this
  957.           * sample program.
  958.           */
  959.          WinSendMsg(
  960.             hwndHelpInstance,
  961.             HM_DISPLAY_HELP,
  962.             MPFROMSHORT( 2 ),
  963.             MPFROMSHORT( HM_RESOURCEID ) );
  964.          return( 0 );
  965.  
  966.       case WM_COMMAND :
  967.          /*
  968.           * To get which pushbutton was pressed the SHORT1FROMMP macro
  969.           * is used.
  970.           */
  971.          switch( SHORT1FROMMP( mp1 ) )
  972.          {
  973.             /*
  974.              * The Include pushbutton was pressed.  If the Include dialog
  975.              * window is NOT currently in view then show it.  However if is
  976.              * already shown then this message will be ignored.
  977.              */
  978.             case ID_DISPLAY_INCLUDE_PB :
  979.  
  980.                /*
  981.                 * Call the Include dialog window.  This call will disable
  982.                 * the Display dialog until the Include dialog is closed.
  983.                 */
  984.                WinDlgBox(
  985.                   HWND_DESKTOP,                /* Parent of the dialog box.   */
  986.                   hwndDisplayDialogBox,        /* Owner of the dialog box.    */
  987.                   (PFNWP) IncludeDialogProc,   /* Dialog box procedure.       */
  988.                   (HMODULE) NULL,              /* Dialog is where, EXE file.  */
  989.                   ID_INCLUDE_DIALOG_BOX,       /* Dialog ID.                  */
  990.                   (PVOID) NULL );              /* Dialog Creation Parameters. */
  991.  
  992.                hwndIncludeDialogBox =
  993.                   WinWindowFromID(
  994.                      hwnd,                      /* Parent of the dialog box.  */
  995.                      ID_INCLUDE_DIALOG_BOX );   /* Dialog ID.                 */
  996.  
  997.                return( 0 );
  998.  
  999.             /*
  1000.              * The Cancel pushbutton was pressed, or the ESC key was pressed.
  1001.              * This will just cause the window to be hidden while the focus
  1002.              * is given back to the Main dialog box.
  1003.              */
  1004.             case DID_CANCEL:
  1005.             case ID_DISPLAY_CANCEL_PB :
  1006.                /*
  1007.                 * Hide the Display Messages Dialog Box.
  1008.                 */
  1009.                WinShowWindow(
  1010.                   hwnd,                     /* Handle of the window to hide.  */
  1011.                   FALSE );                  /* Hide the window.               */
  1012.  
  1013.                fDisplayMsgWindowIsUp = FALSE; /* Not visible, set the flag.*/
  1014.  
  1015.                WinSetFocus(
  1016.                   HWND_DESKTOP,             /* Use window in DESKTOP.         */
  1017.                   hwndMainDialogBox );      /* Set focus on the Main Dialog.  */
  1018.  
  1019.                WinSetFocus( HWND_DESKTOP, hwndComboBox);
  1020.  
  1021.                return( 0 );
  1022.  
  1023.          }  /* End of Command Switch */
  1024.  
  1025.          return( 0 );
  1026.  
  1027.       /*
  1028.        * The following MCI Notification messages will be caused by the sending
  1029.        * of MCI String Commands from the Main Dialog window.  ALL of the MCI
  1030.        * messages perform a check to see if the user wishes to see the arrival
  1031.        * of the MCI messages.  This is filtered through the Include Dialog box.
  1032.        * If the user has indicated that the messages are to be viewed, the
  1033.        * MCI Notification Messages are placed into the List Box of this window.
  1034.        */
  1035.       case MM_MCINOTIFY :
  1036.  
  1037.          /*
  1038.           * Check to see if the user has filtered out this message.
  1039.           */
  1040.  
  1041.          if ( afCheckBoxState[ ID_MM_MCINOTIFY ] == TRUE )
  1042.          {
  1043.             /*
  1044.              * If the user has not filtered out this message, then display
  1045.              * the message in the list box of the Display Messages window.
  1046.              */
  1047.  
  1048.             WinSendMsg( hwndDisplayListBox,             /* Handle to the lb  */
  1049.                         LM_INSERTITEM,                  /* Action for the lb */
  1050.                         MPFROMSHORT( LIT_END ),         /* Order             */
  1051.                         MPFROMP( acMCINotMessage[ ID_MM_MCINOTIFY ] ));
  1052.  
  1053.             /* Not only do we want to display the type of message received,
  1054.              * we also want to display the information received with the
  1055.              * message, because it can be very helpful in debugging media
  1056.              * drivers.
  1057.              *
  1058.              * First display the command message in the list box.
  1059.              */
  1060.  
  1061.              strcpy ( acTempString, acMCINotMessage[ ID_CMD_MSG ] );
  1062.  
  1063.              /*
  1064.               * If the command message string is in the szMessage array
  1065.               * display it, else display UNKNOWN.
  1066.               */
  1067.              if ( HIUSHORT(mp2) <= 55 )
  1068.                 strcat ( acTempString, szMessage[ HIUSHORT(mp2) ] );
  1069.              else
  1070.                 strcat ( acTempString, acStringBuffer[ IDS_UNKNOWN - 1 ] );
  1071.  
  1072.              WinSendMsg( hwndDisplayListBox,
  1073.                          LM_INSERTITEM,
  1074.                          MPFROMSHORT( LIT_END ),
  1075.                          MPFROMP( acTempString ));
  1076.  
  1077.             /*
  1078.              * Next display the notify code.
  1079.              */
  1080.  
  1081.             if (LOUSHORT(mp1) == MCI_NOTIFY_SUPERSEDED)
  1082.                WinSendMsg( hwndDisplayListBox,
  1083.                            LM_INSERTITEM,
  1084.                            MPFROMSHORT( LIT_END ),
  1085.                            MPFROMP(acMCINotMessage[ID_MCI_NOTIFY_SUPERSEDED]));
  1086.  
  1087.             else if (LOUSHORT(mp1) == MCI_NOTIFY_ABORTED)
  1088.                WinSendMsg( hwndDisplayListBox,
  1089.                            LM_INSERTITEM,
  1090.                            MPFROMSHORT( LIT_END ),
  1091.                            MPFROMP(acMCINotMessage[ID_MCI_NOTIFY_ABORTED]));
  1092.  
  1093.             else if (LOUSHORT(mp1) == MCI_NOTIFY_SUCCESSFUL)
  1094.                WinSendMsg( hwndDisplayListBox,
  1095.                            LM_INSERTITEM,
  1096.                            MPFROMSHORT( LIT_END ),
  1097.                            MPFROMP(acMCINotMessage[ID_MCI_NOTIFY_SUCCESSFUL]));
  1098.  
  1099.             else /* it's MCI_NOTIFY_ERROR */
  1100.                {
  1101.                   strcpy(acTempString,acMCINotMessage[ID_MCI_NOTIFY_ERROR] );
  1102.                   _itoa(LOUSHORT(mp1), acErrorBuf, 10);
  1103.                   strcat(acTempString, acErrorBuf);
  1104.                   WinSendMsg( hwndDisplayListBox,
  1105.                               LM_INSERTITEM,
  1106.                               MPFROMSHORT( LIT_END ),
  1107.                               MPFROMP( acTempString ));
  1108.                }
  1109.  
  1110.             /*
  1111.              * Next, display the device ID.
  1112.              */
  1113.  
  1114.             strcpy (acTempString, acMCINotMessage[ID_DEVICE_ID]);
  1115.             _itoa(LOUSHORT(mp2), acIDBuf, 10);
  1116.             strcat (acTempString, acIDBuf);
  1117.             WinSendMsg( hwndDisplayListBox,
  1118.                         LM_INSERTITEM,
  1119.                         MPFROMSHORT( LIT_END ),
  1120.                         MPFROMP( acTempString ));
  1121.  
  1122.             /*
  1123.              * Finally, display the user parameter.
  1124.              */
  1125.  
  1126.             strcpy (acTempString, acMCINotMessage[ID_USER_PARM]);
  1127.             _itoa(HIUSHORT(mp1), acUserParmBuf, 10);
  1128.             strcat (acTempString, acUserParmBuf);
  1129.             WinSendMsg( hwndDisplayListBox,
  1130.                         LM_INSERTITEM,
  1131.                         MPFROMSHORT( LIT_END ),
  1132.                         MPFROMP( acTempString ));
  1133.          }
  1134.  
  1135.          /*
  1136.           * When processing a command (with notify flag) from a batch file,
  1137.           * we don't want to process the next command until the current
  1138.           * one completes. These tests check to see if this notification
  1139.           * message is a result of one of the string commands from a batch
  1140.           * file. If it is, then, we can go on to process the next string
  1141.           * command from the batch file.
  1142.           *
  1143.           * Check to see the fNotify flag is true. Then check to see the
  1144.           * variable usUserParameter equals to the User Parameter returned.
  1145.           * If the both conditions are met post a message to read the next
  1146.           * string command from the batch file.
  1147.           */
  1148.          if ((fNotify) && ( usUserParameter == HIUSHORT(mp1)))
  1149.          {
  1150.             fNotify = FALSE;
  1151.             WinStartTimer( hab, hwndMainDialogBox, 1, 1000UL);
  1152.          }
  1153.          return( 0 );
  1154.  
  1155.       case MM_MCIPASSDEVICE :
  1156.  
  1157.          /*
  1158.           * Check to see if the user has filtered out this message.
  1159.           */
  1160.          if ( afCheckBoxState[ ID_MM_MCIPASSDEVICE] == TRUE )
  1161.          {
  1162.             /*
  1163.              * If the user has not filtered out this message, then display
  1164.              * the message in the list box of the Display Messages window.
  1165.              */
  1166.  
  1167.             WinSendMsg( hwndDisplayListBox,             /* Handle to the lb  */
  1168.                         LM_INSERTITEM,                  /* Action for the lb */
  1169.                         MPFROMSHORT( LIT_END ),         /* Order             */
  1170.                         MPFROMP( acMCINotMessage[ ID_MM_MCIPASSDEVICE ] ));
  1171.  
  1172.             /* Not only do we want to display the type of message received,
  1173.              * we also want to display the information received with the
  1174.              * message, because it can be very helpful in debugging media
  1175.              * drivers.
  1176.              *
  1177.              * First display the ID of the device.
  1178.              */
  1179.             strcpy (acTempString, acMCINotMessage[ID_DEVICE_ID]);
  1180.             _itoa(LOUSHORT(mp1), acIDBuf, 10);
  1181.             strcat (acTempString, acIDBuf);
  1182.             WinSendMsg( hwndDisplayListBox,
  1183.                         LM_INSERTITEM,
  1184.                         MPFROMSHORT( LIT_END ),
  1185.                         MPFROMP( acTempString ));
  1186.  
  1187.             /*
  1188.              * Next, determine if we're gaining use, or losing use.
  1189.              */
  1190.             if ((ULONG)mp2 == MCI_LOSING_USE)
  1191.                WinSendMsg( hwndDisplayListBox,
  1192.                            LM_INSERTITEM,
  1193.                            MPFROMSHORT( LIT_END ),
  1194.                            MPFROMP(acMCINotMessage[ID_LOSING_USE]));
  1195.             else
  1196.                WinSendMsg( hwndDisplayListBox,
  1197.                            LM_INSERTITEM,
  1198.                            MPFROMSHORT( LIT_END ),
  1199.                            MPFROMP(acMCINotMessage[ID_GAINING_USE]));
  1200.          }
  1201.  
  1202.          return( 0 );
  1203.  
  1204.       case MM_MCIPOSITIONCHANGE :
  1205.  
  1206.          /*
  1207.           * Check to see if the user has filtered out this message.
  1208.           */
  1209.          if ( afCheckBoxState[ ID_MM_MCIPOSITIONCHANGE ] == TRUE )
  1210.          {
  1211.             /*
  1212.              * If the user has not filtered out this message, then display
  1213.              * the message in the list box of the Display Messages window.
  1214.              */
  1215.  
  1216.             WinSendMsg( hwndDisplayListBox,            /* Handle to the lb  */
  1217.                         LM_INSERTITEM,                 /* Action for the lb */
  1218.                         MPFROMSHORT( LIT_END ),        /* Order             */
  1219.                         MPFROMP( acMCINotMessage[ID_MM_MCIPOSITIONCHANGE] ));
  1220.  
  1221.             /* Not only do we want to display the type of message received,
  1222.              * we also want to display the information received with the
  1223.              * message, because it can be very helpful in debugging media
  1224.              * drivers.
  1225.              *
  1226.              * First display the ID of the device.
  1227.              */
  1228.  
  1229.             strcpy (acTempString, acMCINotMessage[ID_DEVICE_ID]);
  1230.             _itoa(HIUSHORT(mp1), acIDBuf, 10);
  1231.             strcat (acTempString, acIDBuf);
  1232.             WinSendMsg( hwndDisplayListBox,
  1233.                         LM_INSERTITEM,
  1234.                         MPFROMSHORT( LIT_END ),
  1235.                         MPFROMP( acTempString ));
  1236.  
  1237.             /*
  1238.              * Next, display the media position (time).
  1239.              */
  1240.             strcpy (acTempString, acMCINotMessage[ID_TIME]);
  1241.             _itoa((ULONG)mp2, acTimeBuf, 10);
  1242.             strcat (acTempString, acTimeBuf);
  1243.             WinSendMsg( hwndDisplayListBox,
  1244.                         LM_INSERTITEM,
  1245.                         MPFROMSHORT( LIT_END ),
  1246.                         MPFROMP( acTempString ));
  1247.  
  1248.             /*
  1249.              * Finally, display the user parameter.
  1250.              */
  1251.             strcpy (acTempString, acMCINotMessage[ID_USER_PARM]);
  1252.             _itoa(LOUSHORT(mp1), acUserParmBuf, 10);
  1253.             strcat (acTempString, acUserParmBuf);
  1254.             WinSendMsg( hwndDisplayListBox,
  1255.                         LM_INSERTITEM,
  1256.                         MPFROMSHORT( LIT_END ),
  1257.                         MPFROMP( acTempString ));
  1258.          }
  1259.          return( 0 );
  1260.  
  1261.       case MM_MCICUEPOINT :
  1262.  
  1263.          /*
  1264.           * Check to see if the user has filtered out this message.
  1265.           */
  1266.          if ( afCheckBoxState[ ID_MM_MCICUEPOINT ] == TRUE )
  1267.          {
  1268.             /*
  1269.              * If the user has not filtered out this message, then display
  1270.              * the message in the list box of the Display Messages window.
  1271.              */
  1272.             WinSendMsg( hwndDisplayListBox,            /* Handle to the lb  */
  1273.                         LM_INSERTITEM,                 /* Action for the lb */
  1274.                         MPFROMSHORT( LIT_END ),        /* Order             */
  1275.                         MPFROMP( acMCINotMessage[ID_MM_MCICUEPOINT] ));
  1276.  
  1277.             /* Not only do we want to display the type of message received,
  1278.              * we also want to display the information received with the
  1279.              * message, because it can be very helpful in debugging media
  1280.              * drivers.
  1281.              *
  1282.              * First display the ID of the device.
  1283.              */
  1284.             strcpy (acTempString, acMCINotMessage[ID_DEVICE_ID]);
  1285.             _itoa(HIUSHORT(mp1), acIDBuf, 10);
  1286.             strcat (acTempString, acIDBuf);
  1287.             WinSendMsg( hwndDisplayListBox,
  1288.                         LM_INSERTITEM,
  1289.                         MPFROMSHORT( LIT_END ),
  1290.                         MPFROMP( acTempString ));
  1291.  
  1292.             /*
  1293.              * Next, display the media position (time).
  1294.              */
  1295.             strcpy (acTempString, acMCINotMessage[ID_TIME]);
  1296.             _itoa((ULONG)mp2, acTimeBuf, 10);
  1297.             strcat (acTempString, acTimeBuf);
  1298.             WinSendMsg( hwndDisplayListBox,
  1299.                         LM_INSERTITEM,
  1300.                         MPFROMSHORT( LIT_END ),
  1301.                         MPFROMP( acTempString ));
  1302.  
  1303.             /*
  1304.              * Finally, display the user parameter.
  1305.              */
  1306.             strcpy (acTempString, acMCINotMessage[ID_USER_PARM]);
  1307.             _itoa(LOUSHORT(mp1), acUserParmBuf, 10);
  1308.             strcat (acTempString, acUserParmBuf);
  1309.             WinSendMsg( hwndDisplayListBox,
  1310.                         LM_INSERTITEM,
  1311.                         MPFROMSHORT( LIT_END ),
  1312.                         MPFROMP( acTempString ));
  1313.          }
  1314.          return( 0 );
  1315.  
  1316.       case MM_MCIEVENT :
  1317.  
  1318.          /*
  1319.           * Check to see if the user has filtered out this message.
  1320.           */
  1321.          if ( afCheckBoxState[ ID_MM_MCIEVENT ] == TRUE )
  1322.          {
  1323.             /*
  1324.              * If the user has not filtered out this message, then display
  1325.              * the message in the list box of the Display Messages window.
  1326.              *
  1327.              */
  1328.             WinSendMsg( hwndDisplayListBox,            /* Handle to the lb  */
  1329.                         LM_INSERTITEM,                 /* Action for the lb */
  1330.                         MPFROMSHORT( LIT_END ),        /* Order             */
  1331.                         MPFROMP( acMCINotMessage[ID_MM_MCIEVENT] ));
  1332.          }
  1333.          return( 0 );
  1334.  
  1335.       case MM_MCIPLAYLISTMESSAGE :
  1336.          /*
  1337.           * Check to see if the user has filtered out this message.
  1338.           */
  1339.          if ( afCheckBoxState[ ID_MM_MCIPLAYLISTMESSAGE ] == TRUE )
  1340.          {
  1341.             /*
  1342.              * If the user has not filtered out this message, then
  1343.              * display the message in the list box of the Display
  1344.              * Messages window.
  1345.              */
  1346.             WinSendMsg( hwndDisplayListBox,            /* Handle to the lb  */
  1347.                         LM_INSERTITEM,                 /* Action for the lb */
  1348.                         MPFROMSHORT( LIT_END ),        /* Order             */
  1349.                         MPFROMP( acMCINotMessage[ID_MM_MCIPLAYLISTMESSAGE] ));
  1350.          }
  1351.          return( 0 );
  1352.  
  1353.       default:
  1354.           return( WinDefDlgProc( hwnd, msg, mp1, mp2 ) );
  1355.  
  1356.    }  /* End of Switch */
  1357.  
  1358.    return( (MRESULT) FALSE );
  1359.  
  1360. } /* End of DisplayDialogProc */
  1361.  
  1362.  
  1363. /******************************************************************************
  1364.  * Name        : DisplayListBoxProc
  1365.  *
  1366.  * Description : This function controls the Display Messages dialog box's
  1367.  *               list box. The list box window has been subclassed when the
  1368.  *               Display Dialog box was created.  This is required since the
  1369.  *               user is not allowed to select any text displayed in the list
  1370.  *               box via the keyboard or the mouse.  Therefore this window
  1371.  *               procedure will trap all appropriate keyboard and mouse
  1372.  *               actions so that no selections can be made.  All other
  1373.  *               messages received by this function that do not involve
  1374.  *               the relevant mouse or keyboard actions are passed back to
  1375.  *               the original List Box window procedure for processing.
  1376.  *
  1377.  *               The following messages are handled specifically by this
  1378.  *               routine.
  1379.  *               WM_BUTTON1DBLCLK
  1380.  *               WM_BUTTON1DOWN
  1381.  *               WM_CHAR
  1382.  *
  1383.  * Concepts    : None.
  1384.  *
  1385.  * MMPM/2 API's: None.
  1386.  *
  1387.  * Parameters  : hwnd - Handle for the Display dialog box.
  1388.  *               msg  - Message received by the dialog box.
  1389.  *               mp1  - Parameter 1 for the just received message.
  1390.  *               mp2  - Parameter 2 for the just received message.
  1391.  *
  1392.  * Return      : 0 or the result of default processing.
  1393.  *
  1394.  ******************************************************************************/
  1395. MRESULT EXPENTRY DisplayListBoxProc( HWND   hwnd,
  1396.                                      ULONG  msg,
  1397.                                      MPARAM mp1,
  1398.                                      MPARAM mp2 )
  1399. {
  1400.    static RECTL    rctListBox,                  /* Placement of the List Box. */
  1401.                    rctForbiddenMouseArea;       /* Area where mouse is forbid.*/
  1402.    static BOOL     fHasThisBeenDoneYet = FALSE; /* Indicates that first time  */
  1403.                                                 /* into this routine.         */
  1404.  
  1405.    SHORT sMouseXPosition,                       /* Mouse X position.          */
  1406.          sMouseYPosition;                       /* Mouse Y position.          */
  1407.  
  1408.    switch( msg )
  1409.    {
  1410.  
  1411.       /*
  1412.        * If the message indicates a mouse action that tries to select
  1413.        * text that is in the list box, reject the action.
  1414.        */
  1415.       case WM_BUTTON1DBLCLK :
  1416.       case WM_BUTTON1DOWN :
  1417.       {
  1418.          /*
  1419.           * The first time into this routine some initialization will be
  1420.           * performed.  Basically get the area in which the list box resides
  1421.           * so that any mouse actions in that region can be rejected.  Since
  1422.           * the control has already been created, the WM_INITDLG message
  1423.           * will not be received by this routine.  Therefore the first time
  1424.           * in this procedure we must do some initial processing.
  1425.           */
  1426.          if ( fHasThisBeenDoneYet == FALSE )
  1427.          {
  1428.             fHasThisBeenDoneYet = TRUE;
  1429.  
  1430.             WinQueryWindowRect(
  1431.                hwnd,                               /* Handle to the window.   */
  1432.                (PRECTL) &rctListBox );             /* Size of the window.     */
  1433.  
  1434.             /*
  1435.              * Calculate the area in which mouse/cursor selections are not
  1436.              * going to be allowed.
  1437.              */
  1438.             rctForbiddenMouseArea.xLeft   =
  1439.                rctListBox.xLeft + DISPLAY_CONTROL_X_POSITION;
  1440.  
  1441.             rctForbiddenMouseArea.yBottom =
  1442.                rctListBox.yBottom + DISPLAY_CONTROL_Y_POSITION;
  1443.  
  1444.             rctForbiddenMouseArea.xRight  =
  1445.                rctListBox.xRight + DISPLAY_CONTROL_X_POSITION;
  1446.  
  1447.             rctForbiddenMouseArea.yTop    =
  1448.                rctListBox.yTop + DISPLAY_CONTROL_Y_POSITION;
  1449.  
  1450.          }  /* End of the initial setup for this window procedure. */
  1451.  
  1452.          /*
  1453.           * Set the focus on the Display Messages dialog.
  1454.           */
  1455.          WinSetFocus(
  1456.             HWND_DESKTOP,
  1457.             hwndDisplayDialogBox );
  1458.  
  1459.          /*
  1460.           * Get the position of the mouse in the window.
  1461.           */
  1462.          sMouseXPosition = SHORT1FROMMP( mp1 );
  1463.          sMouseYPosition = SHORT2FROMMP( mp1 );
  1464.  
  1465.          /*
  1466.           * See if the mouse is in the forbidden.  If it is, ignore the
  1467.           * mouse action.
  1468.           */
  1469.          if ( sMouseXPosition < (SHORT) rctForbiddenMouseArea.xRight  ||
  1470.               sMouseXPosition > (SHORT) rctForbiddenMouseArea.xLeft   ||
  1471.               sMouseYPosition < (SHORT) rctForbiddenMouseArea.yTop    ||
  1472.               sMouseYPosition > (SHORT) rctForbiddenMouseArea.yBottom  )
  1473.          {
  1474.             return( 0 );
  1475.          }
  1476.  
  1477.          return( (pfnwpDisplayListBoxProc( hwnd, msg, mp1, mp2 )) );
  1478.  
  1479.       }  /* End of Mouse Button catches. */
  1480.  
  1481.       /*
  1482.        * A keyboard key has been pressed by the user.  We need to check
  1483.        * to see if the key(s) are up/down cursor keys, space bar,  AND if
  1484.        * the focus of the window is the List Box within the Display Dialog.
  1485.        */
  1486.       case WM_CHAR :
  1487.       {
  1488.          /*
  1489.           * Find out which key was pressed.  We only care about cursor keys
  1490.           * AND the Space Bar.  The space bar is to be ignored since if it
  1491.           * was passed into the default window procedure it would be used
  1492.           * and a List Box item would be selected.
  1493.           */
  1494.          switch( SHORT2FROMMP( mp2 ) )
  1495.          {
  1496.             case VK_SPACE :
  1497.             {
  1498.                return( 0 );
  1499.             }
  1500.  
  1501.             case VK_UP :
  1502.             {
  1503.                SendScrollBarMessage(
  1504.                   hwnd,
  1505.                   SB_LINEUP );
  1506.  
  1507.                   return( 0 );
  1508.             }  /* End of VK_UP */
  1509.  
  1510.             case VK_DOWN :
  1511.             {
  1512.                SendScrollBarMessage(
  1513.                   hwnd,
  1514.                   SB_LINEDOWN );
  1515.  
  1516.                   return( 0 );
  1517.             }  /* End of VK_DOWN. */
  1518.  
  1519.             case VK_PAGEUP   :
  1520.             {
  1521.                SendScrollBarMessage(
  1522.                   hwnd,
  1523.                   SB_PAGEUP );
  1524.  
  1525.                return( 0 );
  1526.  
  1527.             }  /* End of VK_PAGEUP. */
  1528.  
  1529.             case VK_PAGEDOWN :
  1530.             {
  1531.                SendScrollBarMessage(
  1532.                   hwnd,
  1533.                   SB_PAGEDOWN );
  1534.  
  1535.                   return( 0 );
  1536.  
  1537.             }  /* End of VK_PAGEDOWN. */
  1538.  
  1539.          }  /* End of CHAR switch. */
  1540.  
  1541.       }  /* End of WM_CHAR processing. */
  1542.  
  1543.       default:
  1544.           return( (pfnwpDisplayListBoxProc( hwnd, msg, mp1, mp2 )) );
  1545.  
  1546.    }  /* End of Switch */
  1547.  
  1548.    return( (pfnwpDisplayListBoxProc( hwnd, msg, mp1, mp2 )) );
  1549.  
  1550. }  /* End of DisplayListBoxProc. */
  1551.  
  1552.  
  1553. /*******************************************************************************
  1554.  * Name        : IncludeDialogProc
  1555.  *
  1556.  * Description : This function controls the Include dialog box.  It will
  1557.  *               allow, filter, MCI Notification messages to received by
  1558.  *               the Display Messages dialog.  The dialog window is
  1559.  *               application modal.
  1560.  *
  1561.  *               The following messages are handled specifically by this
  1562.  *               routine.
  1563.  *
  1564.  *                  WM_INITDLG
  1565.  *                  WM_CLOSE
  1566.  *                  WM_HELP
  1567.  *                  WM_COMMAND
  1568.  *
  1569.  * Concepts    : None.
  1570.  *
  1571.  * MMPM/2 API's: None.
  1572.  *
  1573.  * Parameters  : hwnd - Handle for the Include dialog box.
  1574.  *               msg  - Message received by the dialog box.
  1575.  *               mp1  - Parameter 1 for the just received message.
  1576.  *               mp2  - Parameter 2 for the just received message.
  1577.  *
  1578.  * Return      : 0 or the result of default processing.
  1579.  *
  1580.  ******************************************************************************/
  1581. MRESULT EXPENTRY IncludeDialogProc( HWND   hwnd,
  1582.                                     ULONG  msg,
  1583.                                     MPARAM mp1,
  1584.                                     MPARAM mp2 )
  1585. {
  1586.    /*
  1587.     * Holds the status of the checkboxes.
  1588.     */
  1589.    static HWND hwndCheckBoxes[ INCLUDE_NUMBER_OF_CHECKBOXES ];
  1590.  
  1591.    USHORT usI,                            /* Generic Counter.                 */
  1592.           usRC;                           /* Generic Return Code variable.    */
  1593.  
  1594.    BOOL   fOneCheckBoxWasChecked = FALSE; /* Indicates if a checkbox is used. */
  1595.    BOOL   afTempCheckBoxState[
  1596.              INCLUDE_NUMBER_OF_CHECKBOXES ]; /* Temp buffer for CB state.     */
  1597.  
  1598.    switch( msg )
  1599.    {
  1600.  
  1601.       case WM_INITDLG :
  1602.  
  1603.          /*
  1604.           * Set the Child Dialog window's System Menu.
  1605.           */
  1606.          SetSystemMenu( hwnd );
  1607.  
  1608.          /*
  1609.           * Get the window handles for the Check Boxes.  The handles
  1610.           * will be used to set the initial values in the Check Boxes
  1611.           * when the dialog is first started.
  1612.           */
  1613.          for( usI=0; usI<INCLUDE_NUMBER_OF_CHECKBOXES; usI++ )
  1614.          {
  1615.             hwndCheckBoxes[ usI ] =
  1616.                WinWindowFromID(
  1617.                   hwnd,
  1618.                   ausCheckBoxIDs[ usI ] );
  1619.          }
  1620.  
  1621.          /*
  1622.           * Set the state of the check boxes.
  1623.           */
  1624.          for( usI=0; usI<INCLUDE_NUMBER_OF_CHECKBOXES; usI++ )
  1625.          {
  1626.              WinSendMsg(
  1627.                hwndCheckBoxes[ usI ],
  1628.                BM_SETCHECK,
  1629.                MPFROM2SHORT( afCheckBoxState[ usI ], 0 ),
  1630.                0L );
  1631.          }  /* End of FOR that sets the Check Boxes. */
  1632.  
  1633.          return( 0 );
  1634.  
  1635.       case WM_CLOSE :
  1636.          /*
  1637.           * The Include dialog is closing.
  1638.           */
  1639.          WinDismissDlg(
  1640.             hwnd,                     /* Dialog box to close.                 */
  1641.             TRUE );                   /* Get rid of the dialog box.           */
  1642.  
  1643.          return( 0 );
  1644.  
  1645.       case WM_HELP :
  1646.          /*
  1647.           * The dialog window has received a request for help from the user,
  1648.           * i.e., the Help pushbutton was pressed.  Send the HM_DISPLAY_HELP
  1649.           * message to the Help Instance with the IPF resource identifier
  1650.           * for the correct HM panel.  This will show the help panel for this
  1651.           * sample program.
  1652.           */
  1653.          WinSendMsg(
  1654.             hwndHelpInstance,
  1655.             HM_DISPLAY_HELP,
  1656.             MPFROMSHORT( 3 ),
  1657.             MPFROMSHORT( HM_RESOURCEID ) );
  1658.          return( 0 );
  1659.  
  1660.       case WM_COMMAND :
  1661.          /*
  1662.           * To get which pushbutton was pressed, the SHORT1FROMMP macro
  1663.           * is used.
  1664.           */
  1665.          switch( SHORT1FROMMP( mp1 ) )
  1666.          {
  1667.             /*
  1668.              * The include pushbutton has been pressed therefore get the
  1669.              * state of the checkboxes so that the Display Messages dialog
  1670.              * can determine if MCI Notification messages are to be displayed.
  1671.              */
  1672.             case ID_INCLUDE_PB :
  1673.                /*
  1674.                 * Query the checkboxes to get their current state...
  1675.                 * - Set the flag that at least one checkbox has been used.
  1676.                 * - Read the state of all of the checkboxes storing the result.
  1677.                 * - If one of the checkboxes has been checked set the flag.
  1678.                 *   This is done so that a message box can be shown indicating
  1679.                 *   that NO checkboxes have been used.
  1680.                 */
  1681.                fOneCheckBoxWasChecked = FALSE;
  1682.  
  1683.                for( usI=0; usI<INCLUDE_NUMBER_OF_CHECKBOXES; usI++ )
  1684.                {
  1685.                   afTempCheckBoxState[ usI ] = (BOOL)
  1686.                      WinSendMsg(
  1687.                         hwndCheckBoxes[ usI ],
  1688.                         BM_QUERYCHECK,
  1689.                         0L,
  1690.                         0L );
  1691.  
  1692.                   if ( afTempCheckBoxState[ usI ] == TRUE )
  1693.                   {
  1694.                      fOneCheckBoxWasChecked = TRUE;
  1695.                   }
  1696.                }  /* End of FOR loop that gets the state of the Check Boxes. */
  1697.  
  1698.                /*
  1699.                 * Set the return code so that the dialog will be dismissed
  1700.                 * if everything is ok.
  1701.                 */
  1702.                usRC = MBID_OK;
  1703.  
  1704.                /*
  1705.                 * See if any of the checkboxes are checked.  If not then tell
  1706.                 * the user that no MCI Notification messages will be seen.
  1707.                 */
  1708.                if ( fOneCheckBoxWasChecked == FALSE )
  1709.                {
  1710.  
  1711.                   usRC =
  1712.                      ShowAMessage(
  1713.                          hwnd,                           /* Owner Window.     */
  1714.                          acStringBuffer[ IDS_NORMAL_ERROR_MESSAGE_BOX_TEXT - 1 ],
  1715.                          IDS_ALL_CHECKBOXES_ARE_FALSE,   /* ID of the message.*/
  1716.                          MB_OKCANCEL  | MB_HELP | MB_MOVEABLE |
  1717.                          MB_APPLMODAL | MB_WARNING );    /* Message box style.*/
  1718.                }
  1719.  
  1720.                /*
  1721.                 * If the user says OK, then go ahead and end the dialog after
  1722.                 * getting the state of the checkboxes from the temp buffer.
  1723.                 * Otherwise do not end the dialog so that the user can change
  1724.                 * the checkboxes.
  1725.                 */
  1726.                if ( usRC == MBID_OK )
  1727.                {
  1728.  
  1729.                   for( usI=0; usI<INCLUDE_NUMBER_OF_CHECKBOXES; usI++ )
  1730.                   {
  1731.                      afCheckBoxState[ usI ] = afTempCheckBoxState[ usI ];
  1732.                   }
  1733.  
  1734.                   WinDismissDlg(
  1735.                      hwnd,                  /* Dialog box to close.           */
  1736.                      TRUE );                /* Get rid of the dialog box.     */
  1737.                }
  1738.  
  1739.                return( 0 );
  1740.  
  1741.             /*
  1742.              * The cancel pushbutton has been pressed the dialog will be
  1743.              * dismissed. (Or the ESC key was pressed)
  1744.              */
  1745.             case DID_CANCEL:
  1746.             case ID_INCLUDE_CANCEL_PB :
  1747.  
  1748.                WinDismissDlg(
  1749.                   hwnd,                     /* Dialog box to close.           */
  1750.                   TRUE );                   /* Get rid of the dialog box.     */
  1751.  
  1752.                return( 0 );
  1753.  
  1754.          }  /* End of Command Switch */
  1755.  
  1756.          return( 0 );
  1757.  
  1758.       default:
  1759.          return( WinDefDlgProc( hwnd, msg, mp1, mp2 ) );
  1760.  
  1761.    }  /* End of Switch */
  1762.  
  1763.    return( (MRESULT) FALSE );
  1764.  
  1765. } /* End of IncludeDialogProc */
  1766.  
  1767.  
  1768. /******************************************************************************
  1769.  * Name        : SendStringToMCD
  1770.  *
  1771.  * Description : This procedure will take the string from the Combo Box,
  1772.  *               check for it's validity and send it to the MCD for processing.
  1773.  *
  1774.  * Concepts    : None.
  1775.  *
  1776.  * MMPM/2 API's: mciSendString
  1777.  *               mciGetErrorString
  1778.  *
  1779.  * Parameters  : hwndComboBox - Handle to the Combo Box.
  1780.  *
  1781.  * Return      : None.
  1782.  *
  1783.  ******************************************************************************/
  1784. VOID SendStringToMCD( HWND hwndComboBox )
  1785. {
  1786.    CHAR   acTempString[ STRING_SIZE ];                  /* Temp string buffer.*/
  1787.    USHORT usResult;
  1788.    ULONG  flStyle;
  1789.    CHAR   acErrorStringBuffer[ MCI_STRING_LENGTH ];     /* Error string buffer*/
  1790.    ULONG  ulSendStringRC    = 0,                        /* Send String API RC.*/
  1791.           lGetErrorStringRC = 0;                        /* Error String API RC*/
  1792.  
  1793.    /*
  1794.     * Get the MCI String Command that is supposed to be in the Entry field
  1795.     * of the combination box.
  1796.     */
  1797.    GetStringFromComboBox(
  1798.       hwndComboBox,
  1799.       &acMCIString[ 0 ] );
  1800.  
  1801.    if ( IsMCIStringValid( &acMCIString[ 0 ] ) == FALSE )
  1802.    {
  1803.       /*
  1804.        * The given MCI String is not valid.  Get out of this routine.
  1805.        */
  1806.       return;
  1807.    }
  1808.  
  1809.    /*
  1810.     * Place the string in the list box portion of the combination box.
  1811.     */
  1812.    WinSendMsg(
  1813.       hwndComboBox,                       /* Handle to the Combination Box.   */
  1814.       LM_INSERTITEM,                      /* Action for the Combo box to do.  */
  1815.       MPFROM2SHORT( LIT_END, 0),          /* MP 1.  Place text at end of list.*/
  1816.       (MPARAM) (PSZ) &acMCIString[ 0 ] ); /* MP 2.  MCI String Command.       */
  1817.  
  1818.    /*
  1819.     * Erase the string that is in the Entry Field of the combination box by
  1820.     * first selecting all of the text in the filed and then clearing it.
  1821.     * Then force the cursor to go back to the entry field to accept the
  1822.     * next string command.
  1823.     */
  1824.    WinSendMsg(
  1825.       hwndComboBox,                       /* Handle to the Combination Box.   */
  1826.       EM_SETSEL,                          /* Action for the Combo box to do.  */
  1827.       MPFROM2SHORT( 0,MCI_STRING_LENGTH ),/* MP 1.  Reserved.                 */
  1828.       (MPARAM) NULL );                    /* MP 2.  Reserved.                 */
  1829.  
  1830.    WinSendMsg(
  1831.       hwndComboBox,                       /* Handle to the Combination Box.   */
  1832.       EM_CLEAR,                           /* Action for the Combo box to do.  */
  1833.       (MPARAM) NULL,                      /* MP 1.  Reserved.                 */
  1834.       (MPARAM) NULL );                    /* MP 2.  Reserved.                 */
  1835.  
  1836.  
  1837.    /*
  1838.     * We have a 'valid' MCI string from the sample programs point of view,
  1839.     * whether it really is valid will be decided by MCD.  Send the MCI String
  1840.     * Command and increment the counter so that we know how many MCI strings
  1841.     * have been sent.
  1842.     *
  1843.     * Set the pointer to an hourglass first, since this might take a couple
  1844.     * of seconds.
  1845.     */
  1846.  
  1847.    WinSetPointer(
  1848.       HWND_DESKTOP,              /* Desktop window handle.                    */
  1849.       WinQuerySysPointer(        /* This API will give the handle of the PTR. */
  1850.          HWND_DESKTOP,           /* Desktop window handle.                    */
  1851.          SPTR_WAIT,              /* The Hourglass icon.                       */
  1852.          FALSE ) );              /* Return the system pointer's handle.       */
  1853.  
  1854.    ulSendStringRC =
  1855.       mciSendString(
  1856.          (PSZ)&acMCIString[ 0 ],          /* The MCI String Command.          */
  1857.          (PSZ)&acMCIReturnString[   0 ],  /* The place to put Return strings. */
  1858.          (USHORT) MCI_RETURN_STRING_LENTGH, /* How large is the Return space. */
  1859.          hwndDisplayDialogBox,            /* Which window receives Notifies.  */
  1860.          usCountOfMCIStringSent );        /* The user parameter.              */
  1861.  
  1862.    WinSetPointer(
  1863.       HWND_DESKTOP,              /* Desktop window handle.                    */
  1864.       WinQuerySysPointer(        /* This API will give the handle of the PTR. */
  1865.          HWND_DESKTOP,           /* Desktop window handle.                    */
  1866.          SPTR_ARROW,             /* The Arrow icon.                           */
  1867.          FALSE ) );              /* Return the system pointer's handle.       */
  1868.  
  1869.    usCountOfMCIStringSent++;
  1870.  
  1871.    /*
  1872.     * Display the return string from mciSendString api.
  1873.     */
  1874.  
  1875.    strcpy (acTempString, acStringBuffer[IDS_RETURN_STRING - 1]);
  1876.    strcat (acTempString, acMCIReturnString);
  1877.    WinSendMsg( hwndDisplayListBox,
  1878.                LM_INSERTITEM,
  1879.                MPFROMSHORT( LIT_END ),
  1880.                MPFROMP( acTempString ));
  1881.  
  1882.    acMCIReturnString[ 0 ] =  (CHAR) NULL;  /* Initialize the return string   */
  1883.  
  1884.    /*
  1885.     * Keep count up to some number which is less than the maximum for the
  1886.     * number of items in a list box.
  1887.     */
  1888.    if ( usCountOfMCIStringSent == (USHORT) 65500 )
  1889.    {
  1890.       usCountOfMCIStringSent = 1;
  1891.    }
  1892.  
  1893.    /*
  1894.     * IF the string return code is not 0 then there was an error.  Indicate
  1895.     * this to the user, find out what the problem was, and show that to the
  1896.     * user.
  1897.     */
  1898.    if ( ulSendStringRC != 0 )
  1899.    {
  1900.  
  1901.       usCountOfMCIStringSent--;
  1902.  
  1903.       lGetErrorStringRC =
  1904.          mciGetErrorString(
  1905.             ulSendStringRC,
  1906.             (PSZ)&acErrorStringBuffer[ 0 ],
  1907.             (USHORT)MCI_ERROR_STRING_LENGTH );
  1908.  
  1909.       /*
  1910.        * Make sure that the retrieving of the error string was successful.
  1911.        */
  1912.       if ( lGetErrorStringRC != MCIERR_SUCCESS )
  1913.       {
  1914.          ShowAMessage(
  1915.             hwndMainDialogBox,                   /* Owner Window.             */
  1916.             acStringBuffer[ IDS_NORMAL_ERROR_MESSAGE_BOX_TEXT - 1 ],
  1917.             IDS_MCI_GETTING_STRING_ERROR_FAILED,  /* ID of the message.       */
  1918.             MB_APPLMODAL | MB_MOVEABLE | MB_HELP |
  1919.                MB_OK | MB_INFORMATION );          /* Message box style.       */
  1920.  
  1921.          return;
  1922.  
  1923.       }  /* End of IF testing for failed Get Error String API. */
  1924.  
  1925.       /*
  1926.        * Before displaying the error, first check to see if we are processing
  1927.        * a batch file. Then, check to see if the string came from the batch
  1928.        * file. If these conditions are true, append the error message which is
  1929.        * returned by the mciGetErrorString with another message to get approval
  1930.        * of the user for further processing of the batch file.
  1931.        */
  1932.       if ( (hFile) && (fStringFromBatchFile) )
  1933.       {
  1934.          strcat(acErrorStringBuffer, acStringBuffer[IDS_CONTINUE_BATCHFILE-1]);
  1935.          flStyle = MB_YESNO;
  1936.       }
  1937.       else
  1938.          flStyle = MB_CANCEL;
  1939.  
  1940.       /*
  1941.        * Show the error string.
  1942.        */
  1943.       usResult =
  1944.         WinMessageBox(
  1945.            HWND_DESKTOP,                /* Parent handle of the message box.  */
  1946.            hwndMainDialogBox,           /* Owner handle of the message box.   */
  1947.            (PSZ) &acErrorStringBuffer,  /* String to show in the message box. */
  1948.            acStringBuffer[ IDS_NORMAL_ERROR_MESSAGE_BOX_TEXT - 1 ],/* Title.  */
  1949.            (USHORT) ID_MESSAGE_BOX,       /* Message Box Id.                    */
  1950.            flStyle | MB_MOVEABLE | MB_APPLMODAL | MB_HELP |
  1951.               MB_INFORMATION );           /* The style of the message box.    */
  1952.  
  1953.       /*
  1954.        * First check to see if the user wants to continue processing the batch
  1955.        * file. Then, check to see the string command included "notify". If
  1956.        * these conditions are true post a message to read the next string
  1957.        * command.
  1958.        * If the "notify" is not included in the string command, we post a
  1959.        * message in the RunTheBatchFile function, This will avoid posting twice.
  1960.        */
  1961.  
  1962.       if ((usResult == MBID_YES) && (fNotify))
  1963.          /*
  1964.           * Continue processing the batch file.
  1965.           */
  1966.          WinPostMsg( hwndMainDialogBox, WM_BATCHFILE, NULL, NULL );
  1967.       else if (usResult == MBID_NO)
  1968.       {
  1969.          hFile = 0;    /* Quit processing the batch file                      */
  1970.          /*
  1971.           * Enable the Batch file push button.
  1972.           */
  1973.          WinEnableWindow(
  1974.             hwndBatchFilePB,        /* Handle of this dialog window.          */
  1975.             TRUE );                 /* ID of the left most PM control.        */
  1976.       }
  1977.    }  /* End of IF testing for failed MCI Send String API. */
  1978.  
  1979.    WinSetFocus( HWND_DESKTOP, hwndComboBox);
  1980.  
  1981. }  /* End of SendStringToMCD */
  1982.  
  1983.  
  1984. /******************************************************************************
  1985.  * Name        : InitializeHelp
  1986.  *
  1987.  * Description : This procedure will set up the initial values in the global
  1988.  *               help structure.  This help structure will then be passed on
  1989.  *               to the Help Manager when the Help Instance is created.  The
  1990.  *               handle to the Help Instance will be kept for later use.
  1991.  *
  1992.  * Concepts    : None.
  1993.  *
  1994.  * MMPM/2 API's: None.
  1995.  *
  1996.  * Parameters  :
  1997.  *
  1998.  * Return      : None.
  1999.  *
  2000.  ******************************************************************************/
  2001. VOID InitializeHelp( VOID )
  2002. {
  2003.  
  2004.    /*
  2005.     * Load the strings for the Help window title and library name.
  2006.     */
  2007.    hmiHelpStructure.pszHelpLibraryName  =
  2008.       acStringBuffer[ IDS_MAIN_HELP_LIBRARY_FILE - 1 ];
  2009.  
  2010.    hmiHelpStructure.pszHelpWindowTitle  =
  2011.       acStringBuffer[ IDS_MAIN_HELP_WINDOW_TITLE - 1 ];
  2012.  
  2013.    /*
  2014.     * Get the size of the initialization structure.
  2015.     */
  2016.    hmiHelpStructure.cb              = sizeof( HELPINIT );
  2017.  
  2018.    hmiHelpStructure.ulReturnCode    = (USHORT) NULL; /* RC from HM initial. */
  2019.    hmiHelpStructure.pszTutorialName = (PSZ) NULL;    /* No tutorial program.*/
  2020.  
  2021.    hmiHelpStructure.phtHelpTable    = (PVOID)(0xffff0000 |
  2022.                                          ID_MCI_STRING_HELPTABLE);
  2023.    /*
  2024.     * The action bar is not used, so set the following to NULL.
  2025.     */
  2026.    hmiHelpStructure.hmodAccelActionBarModule = (HMODULE) NULL;
  2027.    hmiHelpStructure.idAccelTable             = (USHORT) NULL;
  2028.    hmiHelpStructure.idActionBar              = (USHORT) NULL;
  2029.  
  2030.    /*
  2031.     * The Help table is in the executable file.
  2032.     */
  2033.    hmiHelpStructure.hmodHelpTableModule = (HMODULE) NULL;
  2034.  
  2035.    /*
  2036.     * The help panel ID is not displayed.
  2037.     */
  2038.    hmiHelpStructure.fShowPanelId       = (ULONG) NULL;
  2039.  
  2040.    /*
  2041.     * Create the Help Instance for IPF.  Give IPF the Anchor Block
  2042.     * handle and address of the IPF initialization structure, and
  2043.     * check that creation of Help was a success.
  2044.     */
  2045.    hwndHelpInstance =
  2046.        WinCreateHelpInstance(
  2047.           hab,                  /* Anchor Block Handle.                  */
  2048.           &hmiHelpStructure );  /* Help Structure.                       */
  2049.  
  2050.    if ( hwndHelpInstance == (HWND) NULL )
  2051.    {
  2052.       ShowAMessage(
  2053.           hwndMainDialogBox,                            /* Owner Window       */
  2054.           acStringBuffer[ IDS_NORMAL_ERROR_MESSAGE_BOX_TEXT - 1 ],
  2055.           IDS_MAIN_HELP_CREATION_FAILED,                /* ID of the message. */
  2056.           MB_APPLMODAL | MB_MOVEABLE |
  2057.           MB_OK | MB_INFORMATION );                     /* Message box style. */
  2058.    }
  2059.    else
  2060.    {
  2061.       if ( hmiHelpStructure.ulReturnCode )
  2062.       {
  2063.          ShowAMessage(
  2064.              hwndMainDialogBox,                      /* Owner Window          */
  2065.              acStringBuffer[ IDS_NORMAL_ERROR_MESSAGE_BOX_TEXT - 1 ],
  2066.              IDS_MAIN_HELP_CREATION_FAILED,          /* ID of the message.    */
  2067.              MB_APPLMODAL | MB_OK | MB_MOVEABLE |
  2068.              MB_INFORMATION );                       /* Message box style.    */
  2069.  
  2070.       }
  2071.       else   /* help creation worked */
  2072.       {
  2073.          WinAssociateHelpInstance(
  2074.             hwndHelpInstance,       /* The handle of the Help Instance.       */
  2075.             hwndFrame );            /* Associate to this dialog window.       */
  2076.       }
  2077.    }  /* End of IF checking the creation of the Help Instance. */
  2078.  
  2079. }  /* End of InitializeHelp */
  2080.  
  2081.  
  2082. /******************************************************************************
  2083.  * Name        : ShowAMessage
  2084.  *
  2085.  * Description : This function will show text in a message box.  The text
  2086.  *               is pulled from the string table that is originally kept
  2087.  *               in the resource file.  The text is retrieved by the
  2088.  *               message id that is passed into this function.  This id
  2089.  *               is used in the WinLoadString OS/2 API to get the correct
  2090.  *               string from the table.
  2091.  *
  2092.  * Concepts    : None.
  2093.  *
  2094.  * MMPM/2 API's: None.
  2095.  *
  2096.  * Parameters  : hwndOwnerWindow   - Handle to the window which called for
  2097.  *                                   a message box.
  2098.  *               pcMessageTitle    - The tile to be placed in the message
  2099.  *                                   box.
  2100.  *               usMessageId       - The message id that identifies which
  2101.  *                                   string to retrieved from the string
  2102.  *                                   table.
  2103.  *               ulMessageBoxStyle - The style of the message box.  Which
  2104.  *                                   icons, buttons, etc., to show.
  2105.  *
  2106.  * Return      : The result from the message box.
  2107.  *
  2108.  ******************************************************************************/
  2109. USHORT ShowAMessage( HWND   hwndOwnerWindow,
  2110.                      CHAR   *pcMessageTitle,
  2111.                      USHORT usMessageId,
  2112.                      ULONG  ulMessageBoxStyle )
  2113. {
  2114.  
  2115.    CHAR   acStringBuffer[ CCHMAXPATH ];         /* Buffer for RC string.      */
  2116.    USHORT usMessageBoxResult;                   /* Result from Message Box.   */
  2117.  
  2118.    /*
  2119.     * Get the string from the Resource defined string table and show it
  2120.     * in the message box.
  2121.     */
  2122.    WinLoadString(
  2123.       hab,                             /* HAB for this dialog box.            */
  2124.       (HMODULE) NULL,                  /* Get the string from the .exe file.  */
  2125.       usMessageId,                     /* Which string to get.                */
  2126.       (SHORT) CCHMAXPATH,              /* The size of the buffer.             */
  2127.       acStringBuffer );                /* The buffer to place the string.     */
  2128.  
  2129.    usMessageBoxResult =
  2130.       WinMessageBox(
  2131.          HWND_DESKTOP,                 /* Parent handle of the message box.   */
  2132.          hwndOwnerWindow,              /* Owner handle of the message box.    */
  2133.          acStringBuffer,               /* String to show in the message box.  */
  2134.          pcMessageTitle,               /* Title to shown in the message box.  */
  2135.          (USHORT) ID_MESSAGE_BOX,      /* Message Box Id.                     */
  2136.          ulMessageBoxStyle );          /* The style of the message box.       */
  2137.  
  2138.    return( usMessageBoxResult );
  2139.  
  2140. }  /* End of ShowAMessage */
  2141.  
  2142.  
  2143. /******************************************************************************
  2144.  * Name        : IsMCIStringValid
  2145.  *
  2146.  * Description : This function will take a string and decide if it is valid,
  2147.  *               i.e., the string is not empty or full of blanks.
  2148.  *
  2149.  * Concepts    : None.
  2150.  *
  2151.  * MMPM/2 API's: None.
  2152.  *
  2153.  * Parameters  : MCIString - Points to the buffer that will hold
  2154.  *
  2155.  * Return      : TRUE if the string is valid worked otherwise FALSE.
  2156.  *
  2157.  ******************************************************************************/
  2158. BOOL IsMCIStringValid( PSZ pszMCIString )
  2159. {
  2160.    if ( strlen( pszMCIString ) == 0 )
  2161.    {
  2162.       return( FALSE );
  2163.    }
  2164.  
  2165.    return( TRUE );
  2166.  
  2167. }  /* End of IsMCIStringValid */
  2168.  
  2169.  
  2170. /******************************************************************************
  2171.  * Name        : GetStringFromComboBox
  2172.  *
  2173.  * Description : This function will get a string from the String Combo Box's
  2174.  *               Entry Field of the dialog box.
  2175.  *
  2176.  * Concepts    : None.
  2177.  *
  2178.  * MMPM/2 API's: None.
  2179.  *
  2180.  * Parameters  : pszMCIString - Points to the buffer that will hold
  2181.  *                              the Source File Name.
  2182.  *               hwndStringComboBox - Handle to the Combo Box.
  2183.  *
  2184.  * Return      : TRUE if the retrieval worked otherwise FALSE.
  2185.  *
  2186.  ******************************************************************************/
  2187. BOOL GetStringFromComboBox( HWND hwndStringComboBox,
  2188.                             PSZ  pszMCIString )
  2189. {
  2190.    SHORT sTextLength;                      /* Text length of combo box string.*/
  2191.  
  2192.    sTextLength =
  2193.       WinQueryWindowText(
  2194.          hwndStringComboBox,
  2195.          FILE_NAME_SIZE,
  2196.          (PCH) pszMCIString );
  2197.  
  2198.    if ( sTextLength == 0 )
  2199.    {
  2200.       pszMCIString[ 0 ] = (CHAR) NULL;
  2201.  
  2202.       ShowAMessage(
  2203.          hwndMainDialogBox,                    /* Owner Window.               */
  2204.          acStringBuffer[ IDS_NORMAL_ERROR_MESSAGE_BOX_TEXT - 1 ],
  2205.          IDS_MCI_STRING_HAS_NO_SIZE,           /* ID of the message.          */
  2206.          MB_APPLMODAL | MB_MOVEABLE | MB_HELP |
  2207.             MB_CANCEL | MB_INFORMATION );      /* Message box style.          */
  2208.  
  2209.       return( FALSE );
  2210.  
  2211.    }
  2212.  
  2213.    return( TRUE );
  2214.  
  2215. }  /* End of GetStringFromComboBox */
  2216.  
  2217.  
  2218. /******************************************************************************
  2219.  * Name        : SetSystemMenu
  2220.  *
  2221.  * Description : This procedure changes the System Menu of the given dialog
  2222.  *               window so that only the Move and Close options will be
  2223.  *               seen.
  2224.  *
  2225.  * Concepts    : None.
  2226.  *
  2227.  * MMPM/2 API's: None.
  2228.  *
  2229.  * Parameters  : hwndDialogWindow - Handle to the dialog window whose system
  2230.  *                                  menu is to be changed.
  2231.  *
  2232.  * Return      : None.
  2233.  *
  2234.  ******************************************************************************/
  2235. VOID SetSystemMenu( HWND hwndDialogWindow )
  2236. {
  2237.    HWND     hwndSysMenu;                 /* System menu pull-down handle.     */
  2238.  
  2239.    /*
  2240.     * Get the handle of the system menu pull-down.
  2241.     */
  2242.    hwndSysMenu =
  2243.       WinWindowFromID(
  2244.          hwndDialogWindow,
  2245.          (USHORT) FID_SYSMENU );
  2246.  
  2247.    WinSendMsg(
  2248.       hwndSysMenu,
  2249.       MM_DELETEITEM,
  2250.       MPFROM2SHORT( (SHORT) SC_TASKMANAGER, (SHORT) TRUE ),
  2251.       (MPARAM) NULL );
  2252.  
  2253.    WinSendMsg(
  2254.       hwndSysMenu,
  2255.       MM_DELETEITEM,
  2256.       MPFROM2SHORT( SC_RESTORE, TRUE ),
  2257.       (MPARAM) NULL );
  2258.  
  2259.    WinSendMsg(
  2260.       hwndSysMenu,
  2261.       MM_DELETEITEM,
  2262.       MPFROM2SHORT( SC_SIZE, TRUE ),
  2263.       (MPARAM) NULL );
  2264.  
  2265.    WinSendMsg(
  2266.       hwndSysMenu,
  2267.       MM_DELETEITEM,
  2268.       MPFROM2SHORT( SC_MINIMIZE, TRUE ),
  2269.       (MPARAM) NULL );
  2270.  
  2271.    WinSendMsg(
  2272.       hwndSysMenu,
  2273.       MM_DELETEITEM,
  2274.       MPFROM2SHORT( SC_MAXIMIZE, TRUE ),
  2275.       (MPARAM) NULL );
  2276.  
  2277. }  /* End of SetSystemMenu. */
  2278.  
  2279.  
  2280. /******************************************************************************
  2281.  * Name        : SendScrollBarMessage
  2282.  *
  2283.  * Description : This procedure sends scroll bar messages to the vertical
  2284.  *               scroll bar in the subclassed list box in the Display
  2285.  *               Messages dialog box.  This is done so that cursor keys
  2286.  *               for the list box can be trapped to prevent the items
  2287.  *               within the list box from being highlighted, i.e., selected.
  2288.  *
  2289.  * Concepts    : None.
  2290.  *
  2291.  * MMPM/2 API's: None.
  2292.  *
  2293.  * Parameters  : hwndControl       : Handle to the dialog window.
  2294.  *               sScrollBarMessage : Message to send to the scroll bar.
  2295.  *
  2296.  * Return      : None.
  2297.  *
  2298.  ******************************************************************************/
  2299. VOID SendScrollBarMessage(
  2300.          HWND  hwndControl,
  2301.          SHORT sScrollBarMessage )
  2302. {
  2303.    SHORT sCurrentSBPosition;     /* Position of the scroll bar.               */
  2304.    HWND  hwndVerticalSB;         /* Handle to the vertical scroll bar.        */
  2305.  
  2306.  
  2307.    if ( WinQueryFocus( HWND_DESKTOP ) == hwndControl )
  2308.    {
  2309.       /*
  2310.        * Get the handle to the list box's vertical scroll bar so that the
  2311.        * position of the scroll bar can be determined.
  2312.        */
  2313.       hwndVerticalSB =
  2314.          WinWindowFromID(
  2315.             hwndControl,
  2316.             (USHORT) LIST_BOX_VERTICAL_SB_ID );
  2317.  
  2318.       /*
  2319.        * Get the current position of the scroll bar.
  2320.        */
  2321.       sCurrentSBPosition = (SHORT)
  2322.          WinSendMsg(
  2323.             hwndVerticalSB,
  2324.             SBM_QUERYPOS,
  2325.             (MPARAM) 0,
  2326.             (MPARAM) 0 );
  2327.  
  2328.       /*
  2329.        * Send the scroll bar message that was passed into this routine to the
  2330.        * dialog box with the list box.
  2331.        */
  2332.       WinPostMsg(
  2333.          hwndControl,
  2334.          WM_VSCROLL,
  2335.          (MPARAM) (USHORT) LIST_BOX_VERTICAL_SB_ID,
  2336.          (MPARAM) MPFROM2SHORT( sCurrentSBPosition,
  2337.                                 sScrollBarMessage ) );
  2338.    }
  2339.  
  2340. }  /* End of SendScrollBarMessage. */
  2341.  
  2342. /******************************************************************************
  2343.  * Name        : Restore
  2344.  *
  2345.  * Description : This procedure reads the os2.ini file for restored information
  2346.  *               and set the restored position.
  2347.  *
  2348.  * Concepts    : None.
  2349.  *
  2350.  * MMPM/2 API's: None.
  2351.  *
  2352.  * Parameters  : hwnd  - Handle for the main dialog box.
  2353.  *
  2354.  * Return      : None.
  2355.  *
  2356.  ******************************************************************************/
  2357. VOID Restore( HWND hwnd )
  2358. {
  2359.    ULONG    ulSize;                    /* for data size in the ini file       */
  2360.    BOOL     fSuccess = FALSE;          /* for successful reading of ini file */
  2361.  
  2362.    /*
  2363.     * Get the window title string from the Resource string table.
  2364.     */
  2365.    WinLoadString(
  2366.       hab,                             /* HAB for this dialog box.            */
  2367.       (HMODULE) NULL,                  /* Get the string from the .exe file.  */
  2368.       IDS_MAIN_WINDOW_TITLE,           /* Which string to get.                */
  2369.       (SHORT) sizeof( szAppName),      /* The size of the buffer.             */
  2370.       szAppName);                      /* The buffer to place the string.     */
  2371.  
  2372.    /*
  2373.     * Look in the os2.ini file for existing data.
  2374.     *
  2375.     * This call search the os2.ini file for a Key name specified by the
  2376.     * szKeyName parameter under the application heading specified by the
  2377.     * szAppName parameter and returns the size of the data structure written
  2378.     * to the os2.ini.
  2379.     */
  2380.    if ( fSuccess = PrfQueryProfileSize(
  2381.                       HINI_USER,          /* file handle for os2.ini          */
  2382.                       szAppName,          /* Application name to look for     */
  2383.                       szKeyName,          /* Key name to look for             */
  2384.                       &ulSize ))          /* Size of return data structure    */
  2385.    {
  2386.       /*
  2387.        * Check for the size of data structure returned from the ini file is
  2388.        * equal to the actual structure. This check is required to make sure
  2389.        * that the os2.ini file is not corrupted.
  2390.        */
  2391.       if ( fSuccess = (ulSize == sizeof(SWPRESTORE)))
  2392.       {
  2393.          /*
  2394.           *  This call returns data that is written to the os2.ini file.
  2395.           */
  2396.          if (fSuccess = PrfQueryProfileData(
  2397.                            HINI_USER,         /* file handle for os2.ini      */
  2398.                            szAppName,         /* Application name to look for */
  2399.                            szKeyName,         /* Key name to look for         */
  2400.                            (PVOID)&Save,      /* Return actual data           */
  2401.                            (PULONG)&ulSize )) /* Size of return data struc    */
  2402.          {
  2403.  
  2404.             /*
  2405.              *  Initialize the Display message window status flag for
  2406.              *  further use.
  2407.              */
  2408.             fDisplayMsgWindowIsUp =  Save.fDisplayMsgWindowStatus;
  2409.  
  2410.             /*
  2411.              * Set the main to the restored position.
  2412.              */
  2413.             WinSetWindowPos(
  2414.                hwndFrame,                /* Frame window handle               */
  2415.                HWND_TOP,                 /* Place hwnd on top of all siblings */
  2416.                Save.swpMain.x,           /* Window position, x coordinate     */
  2417.                Save.swpMain.y,           /* Window position, y coordinate     */
  2418.                Save.swpMain.cx,          /* Window size                       */
  2419.                Save.swpMain.cy,          /* Window size                       */
  2420.                SWP_ZORDER | SWP_MOVE |   /* Window positioning options        */
  2421.                SWP_SIZE | SWP_SHOW);
  2422.  
  2423.             /*
  2424.              * If Display message window status is true, set the Display
  2425.              * message window to the restored position.
  2426.              */
  2427.             if (fDisplayMsgWindowIsUp)
  2428.             {
  2429.                WinSetWindowPos(
  2430.                   hwndDisplayDialogBox,  /* Display Message window handle     */
  2431.                   HWND_TOP,              /* Place hwnd on top of all siblings */
  2432.                   Save.swpDisplay.x,     /* Window position, x coordinate     */
  2433.                   Save.swpDisplay.y,     /* Window position, y coordinate     */
  2434.                   0L,                    /* Window size                       */
  2435.                   0L,                    /* Window size                       */
  2436.                   SWP_MOVE );            /* Window positioning options        */
  2437.             }
  2438.          }
  2439.       }
  2440.    }
  2441.  
  2442.    /*
  2443.     * If error while reading os2.ini file, display the main window with the
  2444.     * default size.
  2445.     */
  2446.    if (!fSuccess)
  2447.    {
  2448.       WinShowWindow( hwndFrame, TRUE );
  2449.    }
  2450. }
  2451.  
  2452. /******************************************************************************
  2453.  * Name        : SaveMSTInfo
  2454.  *
  2455.  * Description : This procedure saves the resorted information to the ini file
  2456.  *               before destroying the Main and Display messages windows.
  2457.  *
  2458.  * Concepts    : None.
  2459.  *
  2460.  * MMPM/2 API's: None.
  2461.  *
  2462.  * Parameters  : None.
  2463.  *
  2464.  * Return      : None.
  2465.  *
  2466.  ******************************************************************************/
  2467. VOID SaveMSTInfo( VOID )
  2468. {
  2469.  
  2470.    /*
  2471.     * Update the Display Message Window status flag.
  2472.     */
  2473.    Save.fDisplayMsgWindowStatus =  fDisplayMsgWindowIsUp;
  2474.  
  2475.    /*
  2476.     * Before destroying the main window query its size and position.
  2477.     */
  2478.    WinQueryWindowPos( hwndFrame, &Save.swpMain );
  2479.  
  2480.    /*
  2481.     * If Display messages window is up query its size and position also.
  2482.     */
  2483.    if ( fDisplayMsgWindowIsUp )
  2484.       WinQueryWindowPos( hwndDisplayDialogBox, &Save.swpDisplay );
  2485.  
  2486.    /*
  2487.     * Save the current values in the os2.ini file for further use.
  2488.     */
  2489.    PrfWriteProfileData(
  2490.            HINI_USER,                   /* file handle for os2.ini            */
  2491.            szAppName,                   /* Application name to look for       */
  2492.            szKeyName,                   /* Key name to look for               */
  2493.            (PVOID) &Save,               /* Save data                          */
  2494.            sizeof(SWPRESTORE));         /* Size of save data                  */
  2495. }
  2496.  
  2497. /******************************************************************************
  2498.  * Name        : RunTheBatchFile
  2499.  *
  2500.  * Description : This procedure reads the input batch file one line of string
  2501.  *               command at a time and copies the same into the String Combo
  2502.  *               Box's Entry Field of the dialog box.
  2503.  *
  2504.  * Concepts    : None.
  2505.  *
  2506.  * MMPM/2 API's: None.
  2507.  *
  2508.  * Parameters  : hwnd       : Handle to the main dialog window.
  2509.  *
  2510.  * Return      : None.
  2511.  *
  2512.  ******************************************************************************/
  2513. VOID RunTheBatchFile( HWND hwnd )
  2514. {
  2515.    PCHAR   pcResult;
  2516.    PSZ     pszTemp;
  2517.    PSZ     pszMCIString;
  2518.  
  2519.    /*
  2520.     * Initialize the variables to hold the string command
  2521.     */
  2522.    memset( acMCIString, 0, sizeof(acMCIString) );
  2523.  
  2524.    if (hFile != 0)
  2525.    {
  2526.       /*
  2527.        * Read a line of string command from the opened file into acMCIString.
  2528.        */
  2529.       if ((pszMCIString = fgets(acMCIString, MCI_STRING_LENGTH, hFile)) != NULL)
  2530.       {
  2531.          fStringFromBatchFile = TRUE;/* String command came from the batch file */
  2532.          /*
  2533.           * Convert to lower case to look consistent in the combo box.
  2534.           */
  2535.          strlwr( pszMCIString );
  2536.  
  2537.          /*
  2538.           * fgets adding a 0xa character at the end of the string. This is
  2539.           * needed just to get rid of it.
  2540.           */
  2541.          if (pszTemp = strchr(pszMCIString, 0xa))
  2542.             pszTemp[0] = 0;
  2543.  
  2544.          if ( strlen( pszMCIString ) != 0 )
  2545.          {
  2546.             /*
  2547.              * Copy the string command into the combo box.
  2548.              */
  2549.             WinSetDlgItemText( hwnd, ID_STRING_COMBO_BOX, pszMCIString );
  2550.  
  2551.             /*
  2552.              * Check to see "notify" added to the string command.
  2553.              */
  2554.             pcResult = strstr(pszMCIString, "notify");
  2555.  
  2556.             /*
  2557.              * If the string command includes "notify", set fNotify to true and
  2558.              * process the string. We must wait till we get MM_MCINOTIFY message
  2559.              * back to us to set fNotify flag to false and read the next line.
  2560.              */
  2561.             if (pcResult)
  2562.             {
  2563.                fNotify = TRUE;
  2564.                usUserParameter = usCountOfMCIStringSent;
  2565.                SendStringToMCD( hwndComboBox );
  2566.             }
  2567.             /*
  2568.              * Else, process the string and post a message to read the next line.
  2569.              */
  2570.             else
  2571.             {
  2572.                SendStringToMCD( hwndComboBox );
  2573.                WinPostMsg( hwnd, WM_BATCHFILE, NULL, NULL );
  2574.             }
  2575.          }
  2576.          else      /* blank line in the batch file                            */
  2577.             WinPostMsg( hwnd, WM_BATCHFILE, NULL, NULL );
  2578.       }
  2579.       else                                 /* If EOF                          */
  2580.       {
  2581.          hFile = 0;
  2582.          ShowAMessage(
  2583.              hwndMainDialogBox,                          /* Owner Window.     */
  2584.              acStringBuffer[ IDS_MAIN_WINDOW_TITLE - 1 ],
  2585.              IDS_END_OF_BATCH_FILE,                      /* ID of the message.*/
  2586.              MB_CANCEL  | MB_MOVEABLE | MB_APPLMODAL | MB_INFORMATION );
  2587.          /*
  2588.           * Enable the Batch file push button.
  2589.           */
  2590.          WinEnableWindow(
  2591.             hwndBatchFilePB,        /* Handle of this dialog window.          */
  2592.             TRUE );                 /* ID of the left most PM control.        */
  2593.       }
  2594.    }
  2595. }
  2596.  
  2597. /******************************************************************************
  2598.  * Name         :  GetBatchFileAndOpenIt
  2599.  *
  2600.  * Description  :  This procedure will gets an existing batch file and opens it.
  2601.  *
  2602.  * Concepts     :  none
  2603.  *
  2604.  * MMPM/2 API's :  none
  2605.  *
  2606.  * Parameters   :  none
  2607.  *
  2608.  * Return       :  TRUE  -  if the a file open is success.
  2609.  *                 FALSE -  if could not open the file.
  2610.  *
  2611.  ******************************************************************************/
  2612. BOOL GetBatchFileAndOpenIt( VOID )
  2613. {
  2614.    FILEDLG fileDlg;                         /* Structure for open file dialog.*/
  2615.    CHAR    szTitle[FILE_NAME_SIZE];         /* Open file dialog box title.    */
  2616.    USHORT  usResult = 0;                    /* For return code.               */
  2617.    CHAR    szButtonText[STRING_SIZE];       /* For Open dialog button text.   */
  2618.  
  2619.  
  2620.    WinLoadString(
  2621.       hab,                                  /* HAB for this dialog box.       */
  2622.       (HMODULE)0,                           /* Get string from .exe file.     */
  2623.       IDS_OPEN_BATCHFILE_TITLE,             /* Which string to get.           */
  2624.       (SHORT) sizeof(szTitle) ,             /* The size of the buffer.        */
  2625.       szTitle);                             /* Buffer to place string.        */
  2626.  
  2627.    WinLoadString(
  2628.       hab,                                  /* HAB for this dialog box.       */
  2629.       (HMODULE)0,                           /* Get string from .exe file.     */
  2630.       IDS_OPEN_BATCHFILE_BUTTON,            /* Which string to get.           */
  2631.       (SHORT) sizeof(szButtonText),         /* The size of the buffer.        */
  2632.       szButtonText);                        /* Buffer to place string.        */
  2633.  
  2634.    /*
  2635.     * Initialize the structure with zeros.
  2636.     */
  2637.    memset( &fileDlg, 0, sizeof(fileDlg));
  2638.  
  2639.    /*
  2640.     * Initialize the file dialog data structure with the appropriate information.
  2641.     */
  2642.    fileDlg.cbSize = sizeof(FILEDLG);
  2643.    fileDlg.pfnDlgProc = (PFNWP)FileDlgProc;
  2644.    fileDlg.ulUser = (ULONG) hwndMainDialogBox;
  2645.    fileDlg.pszOKButton = (PSZ) szButtonText;
  2646.    fileDlg.pszTitle = szTitle;
  2647.    fileDlg.fl = FDS_HELPBUTTON | FDS_CENTER | FDS_OPEN_DIALOG;
  2648.  
  2649.    /*
  2650.     *Call the standard file dialog to get the file
  2651.     */
  2652.    usResult = WinFileDlg(HWND_DESKTOP, hwndMainDialogBox, &fileDlg);
  2653.  
  2654.    if (usResult != 0)
  2655.    {
  2656.       if (fileDlg.lReturn == DID_OK)
  2657.          OpenBatchFile( fileDlg.szFullFile );
  2658.       else if (fileDlg.lReturn == DID_CANCEL)
  2659.          return( FALSE );
  2660.    }
  2661.    return( TRUE );
  2662. }
  2663.  
  2664. /*************************************************************************
  2665.  * Name         :  OpenFileDlgProc
  2666.  *
  2667.  * Description  :  This function controls the open file dialog box.
  2668.  
  2669.  * Concepts     :  none
  2670.  *
  2671.  * MMPM/2 API's :  none
  2672.  *
  2673.  * Parameters   :  hwnd - Handle for the File dialog box.
  2674.  *                 msg  - Message received by the dialog box.
  2675.  *                 mp1  - Parameter 1 for the just recieved message.
  2676.  *                 mp2  - Parameter 2 for the just recieved message.
  2677.  *
  2678.  * Return       :  result of default processing.
  2679.  *************************************************************************/
  2680. MRESULT EXPENTRY FileDlgProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  2681. {
  2682.  
  2683.    switch( msg )
  2684.    {
  2685.  
  2686.       case WM_HELP :
  2687.          /*
  2688.           * The dialog window has received a request for help from the user,
  2689.           * i.e., the Help pushbutton was pressed.  Send the HM_DISPLAY_HELP
  2690.           * message to the Help Instance with the IPF resource identifier
  2691.           * for the correct HM panel.  This will show the help panel for this
  2692.           * sample program.
  2693.           */
  2694.          WinSendMsg(
  2695.             hwndHelpInstance,
  2696.             HM_DISPLAY_HELP,
  2697.             MPFROMSHORT( 4 ),
  2698.             MPFROMSHORT( HM_RESOURCEID ) );
  2699.          return( 0 );
  2700.  
  2701.       default:
  2702.          return WinDefFileDlgProc(hwnd, msg, mp1, mp2);
  2703.    }
  2704. }
  2705.  
  2706. /*************************************************************************
  2707.  * Name         :  OpenBatchFile
  2708.  *
  2709.  * Description  :  This function opens the batch file for processing.
  2710.  
  2711.  * Concepts     :  none
  2712.  *
  2713.  * MMPM/2 API's :  none
  2714.  *
  2715.  * Parameters   :  szBatchFileName  - Name of the file to open.
  2716.  *
  2717.  * Return       :  TRUE  -  if the a file open is success.
  2718.  *                 FALSE -  if could not open the file.
  2719.  *************************************************************************/
  2720.  
  2721. BOOL OpenBatchFile( CHAR szBatchFileName[] )
  2722. {
  2723.     /*
  2724.      * Open the batch file.
  2725.      */
  2726.     hFile = fopen ( szBatchFileName, "r" );
  2727.     if ( hFile == 0 )
  2728.     {
  2729.        ShowAMessage(
  2730.             hwndMainDialogBox,              /* Owner Window.     */
  2731.             acStringBuffer[ IDS_NORMAL_ERROR_MESSAGE_BOX_TEXT - 1 ],
  2732.             IDS_CANNOT_FIND_BATCH_FILE,     /* ID of the message.*/
  2733.             MB_OK | MB_HELP | MB_MOVEABLE |
  2734.             MB_APPLMODAL | MB_WARNING );    /* Message box style.*/
  2735.        return( FALSE );
  2736.     }
  2737.     return( TRUE );
  2738. }
  2739.