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

  1. /**************************************************************************
  2.  *  File name  :  MMBrowse.c
  3.  *
  4.  *  Description:  This application serves as a template than can be use to demonstrate the
  5.  *                    use of the MultiMedia I/O subsytem (MMIO).
  6.  *
  7.  *                This source file contains the following functions:
  8.  *
  9.  *                GetBitMap(HWND, PSZ)
  10.  *                GetFOURCCDialogProc ( HWND, ULONG, MPARAM, MPARAM )
  11.  *                FixSysMenu(HWND);
  12.  *                AboutDlgProc(HWND, ULONG, MPARAM, MPARAM);
  13.  *                QueryAllDialogProc ( HWND, USHORT, MPARAM, MPARAM );
  14.  *                RemovePermDialogProc ( HWND, USHORT, MPARAM, MPARAM );
  15.  *                DisplayImageFile ( HWND, PSZ );
  16.  *                DisplayMessageBox ( HWND, USHORT, USHORT, USHORT );
  17.  *                OpenFileDialog ( HWND, PSZ, PSZ, PSZ, PSZ );
  18.  *                FourccToString( FOURCC, PSZ );
  19.  *                MakeItBusy ( BOOL );
  20.  *                Main ( int argc, char *argv[], char *envp[] );
  21.  *                DrawBitMap ( HWND );
  22.  *                CenterDialog ( HWND );
  23.  *                FixSysMenu (HWND);
  24.  *                InstallTempIOProc ( HWND );
  25.  *                LoadBitmap (HAB, HDC, HPS *, PSZ );
  26.  *                InitializeHelp ( HWND);
  27.  *                MyWindowProc(hwnd, msg, mp1, mp2)
  28.  *                MessageBox(hwnd idMsg, fsStyle, fBeep)
  29.  *                MainCommand(mp1, mp2)
  30.  *
  31.  *  Concepts   :  MMIO IOProcs
  32.  *
  33.  *  API's      :   mmioClose
  34.  *                 mmioWrite
  35.  *                 mmioRead
  36.  *                 mmioGetHeader
  37.  *                 mmioSetHeader
  38.  *                 mmioQueryHeaderLength
  39.  *                 mmioSendMessage
  40.  *                 mmioOpen
  41.  *                 mmioGetFormats
  42.  *                 mmioQueryFormatCount
  43.  *                 mmioInstallIOProc
  44.  *                 mmioStringToFOURCC
  45.  *                 mmioIdentifyFile
  46.  *                 mmioIniFileHandler
  47.  *                 mmioFOURCC
  48.  *
  49.  *    Files    :  MMBrowse.c  MMBrowse.h  MMBrowse.rc MMbrowse.ipf
  50.  *
  51.  *  Copyright (C) 1991 IBM Corporation
  52.  *
  53.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  54.  *      sample code created by IBM Corporation. This sample code is not
  55.  *      part of any standard or IBM product and is provided to you solely
  56.  *      for  the purpose of assisting you in the development of your
  57.  *      applications.  The code is provided "AS IS", without
  58.  *      warranty of any kind.  IBM shall not be liable for any damages
  59.  *      arising out of your use of the sample code, even if they have been
  60.  *      advised of the possibility of such damages.                                                    *
  61.  *************************************************************************/
  62. #define INCL_DOSERRORS
  63. #define INCL_DOSMODULEMGR
  64. #define INCL_DOSPROCESS
  65. #define INCL_DOSSEMAPHORES
  66. #define INCL_DOSMEMMGR
  67. #define INCL_GPI
  68. #define INCL_GPICONTROL
  69. #define INCL_GPILCIDS
  70. #define INCL_GPIMETAFILES
  71. #define INCL_GPIPRIMITIVES
  72. #define INCL_GPIREGIONS
  73. #define INCL_PM
  74. #define INCL_WIN
  75. #define INCL_WINDIALOGS
  76. #define INCL_WINERRORS
  77. #define INCL_WINFRAMEMGR
  78. #define INCL_WINHELP
  79. #define INCL_WINMENUS
  80. #define INCL_WINMESSAGEMGR
  81. #define INCL_WINMLE
  82. #define INCL_WINPOINTERS
  83. #define INCL_WINSTDDLGS
  84. #define INCL_WINSTDFILE
  85. #define INCL_WINSTDSLIDER
  86. #define INCL_WINSWITCHLIST
  87. #define INCL_WINSYS
  88. #define INCL_WINTIMER
  89. #define INCL_WINWINDOWMGR
  90.  
  91. #include <os2.h>
  92. #include <stdio.h>
  93. #include <string.h>
  94. #include <malloc.h>
  95. #include "mmbrowse.h"
  96. #include "mmioos2.h"
  97.  
  98. VOID main ( int argc, char *argv[], char *envp[] )
  99. {
  100.     HMQ   hmq;                             /* Message queue handle         */
  101.     HWND  hwndClient;                      /* Client area window handle    */
  102.     HWND  hwndFrame;                       /* Frame window handle          */
  103.     QMSG  qmsg;                            /* Message from message queue   */
  104.     ULONG flCreate;                        /* Window creation control flags*/
  105.     BOOL  bReturnCode;
  106.     SWCNTRL swcntrl;                       /* struct with Task Mgr info */
  107.  
  108.  
  109.     hab = WinInitialize( 0 );          /* Initialize PM                */
  110.  
  111.     hmq = WinCreateMsgQueue( hab, 0 );    /* Create a message queue       */
  112.  
  113.     bReturnCode = WinRegisterClass( hab,
  114.                                     "MMBrowser",
  115.                                     (PFNWP) MyWindowProc,
  116.                                     CS_SIZEREDRAW,
  117.                                     0 );
  118.  
  119.     flCreate = FCF_STANDARD & ~FCF_SHELLPOSITION;
  120.  
  121.     hwndFrame = WinCreateStdWindow ( HWND_DESKTOP,
  122.                                      0L,
  123.                                      &flCreate,
  124.                                      "MMBrowser",
  125.                                      "",
  126.                                      0L,
  127.                                      0,
  128.                                      ID_WINDOW,
  129.                                      &hwndClient );
  130.  
  131.     bReturnCode = WinSetWindowPos( hwndFrame,
  132.                                    HWND_TOP,
  133.                                    100, 100, 400, 280,
  134.                                    SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW );
  135.  
  136.  
  137.     memset(&swcntrl, 0, sizeof(SWCNTRL));                  /* init structure */
  138.  
  139.     swcntrl.hwnd = hwndFrame;
  140.     strcpy(swcntrl.szSwtitle, "MMBrowser" );
  141.  
  142.     WinAddSwitchEntry((PSWCNTRL)&swcntrl);            /* add app to Task Mgr */
  143.  
  144.     InitializeHelp (hwndFrame );
  145.  
  146.     /*
  147.      *  Now, dispatch all messages...
  148.      */
  149.  
  150.     while( WinGetMsg( hab, &qmsg, 0, 0, 0 ) )
  151.     {
  152.          WinDispatchMsg( hab, &qmsg );
  153.     }
  154.  
  155.     WinDestroyHelpInstance(hwndHelpInstance);
  156.     WinDestroyWindow( hwndFrame );
  157.     WinDestroyMsgQueue( hmq );
  158.     WinTerminate( hab );
  159.  
  160. }
  161.  
  162. VOID MakeItBusy ( BOOL BusyStatus )
  163. {
  164.     if( BusyStatus == TRUE )
  165.     {
  166.          WinSetPointer ( HWND_DESKTOP,
  167.                          WinQuerySysPointer ( HWND_DESKTOP,
  168.                                               SPTR_WAIT,
  169.                                               FALSE));
  170.     }
  171.     else
  172.     {
  173.          WinSetPointer ( HWND_DESKTOP,
  174.                          WinQuerySysPointer ( HWND_DESKTOP,
  175.                                               SPTR_ARROW,
  176.                                               FALSE));
  177.     }
  178. }
  179.  
  180. MRESULT EXPENTRY MyWindowProc ( HWND hwnd,
  181.                                 USHORT msg,
  182.                                 MPARAM mp1,
  183.                                 MPARAM mp2 )
  184. {
  185.     USHORT command;
  186.     BOOL   bReturnCode;
  187.     ULONG  ReturnCode;
  188.     PMMINIFILEINFO  pmmIniFileInfo;
  189.     FOURCC IOProcFourCC;
  190.     FOURCC IOProcFourSource;
  191.     FOURCC IOProcFourTarget;
  192.     ULONG  ulIndex = 0;
  193.     CHAR   szTempBuffer1[STRING_LENGTH];
  194.     CHAR   szTempBuffer2[STRING_LENGTH];
  195.     FOURCC fccIOProc;
  196.     FOURCC fccSourceIOProc;
  197.     MMFORMATINFO mmFormatInfoSource;
  198.     MMFORMATINFO mmFormatInfoTarget;
  199. switch( msg )
  200.     {
  201.  
  202.          case WM_CREATE:
  203.  
  204.               /*
  205.                * Get the open dialog title from resource file.
  206.                */
  207.  
  208.               WinLoadString( hab,
  209.                              0,
  210.                              IDS_OPEN_DIALOG_TITLE,
  211.                              STRING_LENGTH,
  212.                              szOpenDialogTitle ) ;
  213.  
  214.               /*
  215.                * Get the open dialog file extension from resource file.
  216.                */
  217.  
  218.               WinLoadString( hab,
  219.                              0,
  220.                              IDS_OPEN_DIALOG_FILE_EXT,
  221.                              STRING_LENGTH,
  222.                              szOpenDialogFileExt );
  223.  
  224.               /*
  225.                * Get the open ok button from resource file.
  226.                */
  227.  
  228.               WinLoadString( hab,
  229.                              0,
  230.                              IDS_OPEN_OK_BUTTON,
  231.                              STRING_LENGTH,
  232.                              szOpenOKButton );
  233.  
  234.                              /*
  235.                * Get the install ok button from resource file.
  236.                */
  237.  
  238.               WinLoadString( hab,
  239.                              0,
  240.                              IDS_INSTALL_OK_BUTTON,
  241.                              STRING_LENGTH,
  242.                              szInstallOKButton );
  243.  
  244.               /*
  245.                * Get the install dialog box title from resource file.
  246.                */
  247.  
  248.               WinLoadString( hab,
  249.                              0,
  250.                              IDS_INSTALL_TITLE,
  251.                              STRING_LENGTH,
  252.                              szInstallTitle );
  253.  
  254.               /*
  255.                * Get the install dialog box file extension from resource file.
  256.                */
  257.  
  258.               WinLoadString( hab,
  259.                              0,
  260.                              IDS_INSTALL_FILE_EXT,
  261.                              STRING_LENGTH,
  262.                              szInstallFileExt );
  263.  
  264.               /*
  265.                * Copy the IO Proc standard name from resource file.
  266.                */
  267.  
  268.               WinLoadString( hab,
  269.                              0,
  270.                              IDS_IOPROC_NAME,
  271.                              STRING_LENGTH,
  272.                              szIOProcName );
  273.  
  274.          break;  // end of WM_CREATE
  275.  
  276.  
  277.          case WM_HELP :
  278.               WinSendMsg ( hwndHelpInstance,
  279.                            HM_DISPLAY_HELP,
  280.                            MPFROMLONG ( 1 ),
  281.                            MPFROMSHORT ( HM_RESOURCEID ) );
  282.  
  283.               return( 0 );
  284.          break;
  285.  
  286.          case WM_ERASEBACKGROUND:
  287.               return ( MRFROMLONG ( TRUE ) );
  288.          break;
  289.  
  290.          case WM_COMMAND:
  291.               command = SHORT1FROMMP(mp1);      /* Extract the command value    */
  292.               switch (command)
  293.               {
  294.  
  295.                    /*
  296.                     * Open a file (read and view)
  297.                     */
  298.  
  299.                    case ID_FILE_OPEN:
  300.  
  301.                         /*
  302.                          * Get filename from user to open
  303.                          */
  304.                         pszFileName = malloc ( MAX_FILENAME_SIZE );
  305.  
  306.                         if( pszFileName == NULL )
  307.                         {
  308.                              break;
  309.  
  310.                         }
  311.  
  312.                         if( OpenFileDialog ( hwnd,   // handle of owner window
  313.                                              szOpenDialogTitle,        // title of open dialog box
  314.                                              "*.*",                    // file extension
  315.                                              szOpenOKButton,
  316.                                              pszFileName ) == FALSE )  // return filename here.
  317.                         {
  318.                              free ( pszFileName );
  319.                              break;
  320.                              // error.
  321.                         }
  322.  
  323.                         if( !GetBitMap ( hwnd, pszFileName ) )
  324.                         {
  325.                              free ( pszFileName );
  326.                              break;
  327.                              // error.
  328.                         }
  329.  
  330.  
  331.                         strcpy ( szSource, pszFileName );
  332.                         free ( pszFileName );
  333.  
  334.  
  335.                         WinInvalidateRegion( hwnd, 0, FALSE );
  336.                    break;
  337.                    case ID_FILE_SAVEAS:
  338.                         if( mmioIdentifyFile( szSource,
  339.                             0L,
  340.                             &mmFormatInfoSource,
  341.                             &IOProcFourSource,
  342.                             0L,
  343.                             0L))
  344.                         {
  345.                         WinMessageBox( HWND_DESKTOP,
  346.                         HWND_DESKTOP,
  347.                         "Please Open an Image File",
  348.                         "Save as .....",
  349.                         (HMODULE) NULL,
  350.                         (ULONG) MB_OK | MB_MOVEABLE |
  351.                          MB_ERROR );
  352.                          break;
  353.                         }
  354.                         fccSourceIOProc = mmFormatInfoSource.fccIOProc;
  355.                         SaveFile( hwnd, szSource, fccSourceIOProc);
  356.                         WinInvalidateRegion( hwnd, 0, FALSE );
  357.                         break;
  358.  
  359.                    case ID_CONFIG_INST_TEMP:
  360.                         pszFileName = malloc ( MAX_FILENAME_SIZE );
  361.  
  362.                         if( pszFileName == NULL )
  363.                         {
  364.                        /*
  365.                         * could not allocate enough memory for the filename.
  366.                         */
  367.  
  368.                         WinMessageBox( HWND_DESKTOP,
  369.                                         hwnd,
  370.                                         "Could not allocate enough memory for filename string. Please contact author.",
  371.                                         "Install Temporary IO Procedure",
  372.                                         (HMODULE) NULL,
  373.                                         (ULONG) MB_OK | MB_MOVEABLE |
  374.                                         MB_ERROR );
  375.                         break;
  376.                         }
  377.  
  378.                         /*
  379.                          *  Get the DLL filename
  380.                          */
  381.  
  382.                         if( OpenFileDialog ( hwnd,        // handle of owner window
  383.                         "Install Temporary IO Procedure", // title of open dialog box
  384.                         "*.DLL",                          // file extension
  385.                         szInstallOKButton,
  386.                         pszFileName ) == FALSE )  // return filename here.
  387.                         {
  388.                           WinInvalidateRegion( hwnd, 0, FALSE );
  389.                           break;
  390.                         }
  391.  
  392.                         bReturnCode = InstallTempIOProc ( hwnd );
  393.                         if (Cancel == TRUE)
  394.                         {
  395.                         Cancel = FALSE;
  396.                         WinInvalidateRegion ( hwnd, 0, FALSE );
  397.                         break;
  398.                         } /* endif */
  399.  
  400.                         /*
  401.                          * error messages already output before here
  402.                          */
  403.  
  404.                         if (!bReturnCode)
  405.                         {
  406.                         /*
  407.                          * Temp IO Proc installed !
  408.                          */
  409.                          WinMessageBox( HWND_DESKTOP,
  410.                                         hwnd,
  411.                                         "Temporary IO Procedure installed successfully.",
  412.                                         "Installed Temporary IO Procedure",
  413.                                         (HMODULE) NULL,
  414.                                         (ULONG) MB_OK | MB_MOVEABLE |
  415.                                         MB_INFORMATION );
  416.                           }
  417.                         WinInvalidateRegion ( hwnd, 0, FALSE );
  418.                         break;
  419.  
  420.  
  421.                    /*
  422.                     * Install an IO Proc into MMEMMIO.INI file.
  423.                     */
  424.  
  425.                    case ID_CONFIG_INST_PERM:
  426.  
  427.                         pszFileName = malloc ( MAX_FILENAME_SIZE );
  428.  
  429.                         if( pszFileName == NULL )
  430.                         {
  431.                              break;
  432.                         }
  433.  
  434.                         if( OpenFileDialog ( hwnd,                  // handle of owner window
  435.                                              szInstallTitle,        // title of open dialog box
  436.                                              "*.DLL",               // file extension
  437.                                              szInstallOKButton,
  438.                                              pszFileName ) == FALSE )  // return filename here.
  439.                         {
  440.                              WinInvalidateRegion( hwnd, 0, FALSE );
  441.                              break;
  442.                         }
  443.  
  444.                         pmmIniFileInfo = malloc ( sizeof( MMINIFILEINFO ) );
  445.  
  446.                         if( pmmIniFileInfo == NULL )
  447.                         {
  448.                              // error. can't allocate memory.
  449.                              break;
  450.                         }
  451.  
  452.  
  453.                         /*
  454.                          * Get a FOURCC.
  455.                          */
  456.  
  457.                         bReturnCode = WinDlgBox ( HWND_DESKTOP,
  458.                                                  (HWND) hwnd,
  459.                                                  (PFNWP) GetFOURCCDialogProc,
  460.                                                  (HMODULE) NULL,
  461.                                                  GET_FOURCC,   // dialog template identity
  462.                                                 (PVOID) NULL);
  463.                         if (bReturnCode == FALSE)
  464.                         break;
  465.  
  466.                         IOProcFourCC = mmioStringToFOURCC ( szFOURCC, MMIO_TOUPPER ) ;
  467.  
  468.                         /*
  469.                          * Place the Four-character-code into the
  470.                          * IniFileInfo struct.
  471.                          */
  472.  
  473.                         pmmIniFileInfo->fccIOProc = IOProcFourCC;
  474.  
  475.                         /*
  476.                          * Place the DLL name string into the IniFileInfo
  477.                          * struct.
  478.                          */
  479.  
  480.                         strcpy ( pmmIniFileInfo->szDLLName, pszFileName );
  481.  
  482.                         /*
  483.                          * Place the Procedure name string into the IniFileInfo
  484.                          * struct.
  485.                          */
  486.  
  487.                         strcpy ( pmmIniFileInfo->szProcName, szIOProcName );
  488.  
  489.                         /*
  490.                          *  Call mmioIniFileHandler to install our IO Proc.
  491.                          */
  492.  
  493.                         ReturnCode = mmioIniFileHandler ( pmmIniFileInfo,
  494.                                                          MMIO_FINDPROC);
  495.  
  496.  
  497.                         if( ReturnCode == MMIO_SUCCESS )
  498.                         {
  499.  
  500.  
  501.                              WinMessageBox( HWND_DESKTOP,
  502.                                             hwnd,
  503.                                             "Already Installed",
  504.                                             szInstallTitle,
  505.                                             (HMODULE) NULL,
  506.                                             MB_OK | MB_MOVEABLE |
  507.                                             MB_ERROR );
  508.                              break;
  509.  
  510.                         }
  511.                         ReturnCode = mmioIniFileHandler ( pmmIniFileInfo,
  512.                                                           MMIO_INSTALLPROC );
  513.                         if( ReturnCode == MMIO_SUCCESS )
  514.                         {
  515.  
  516.                         DisplayMessageBox ( hwnd,
  517.  
  518.                                             IDS_INSTALL_TITLE,
  519.                                             IDS_INSTALL_EXIT,
  520.                                             MB_OK | MB_MOVEABLE |
  521.                                             MB_INFORMATION );
  522.  
  523.                         DisplayMessageBox ( hwnd,
  524.                                             IDS_INSTALL_TITLE,
  525.                                             IDS_INSTALL_NOTE,
  526.                                             MB_OK | MB_MOVEABLE |
  527.                                             MB_INFORMATION );
  528.  
  529.                         break;
  530.                         }
  531.  
  532.                            WinMessageBox( HWND_DESKTOP,
  533.                                           hwnd,
  534.                                          "Installation Failed",
  535.                                           szInstallTitle,
  536.                                           (HMODULE) NULL,
  537.                                           MB_OK | MB_MOVEABLE |
  538.                                           MB_ERROR );
  539.                              break;
  540.                    /*
  541.                     * Remove an IO Proc from INI file.
  542.                     */
  543.  
  544.                    case ID_CONFIG_REM_PERM:
  545.  
  546.                         ReturnCode = WinDlgBox ( HWND_DESKTOP,
  547.                                                  (HWND) hwnd,
  548.                                                  (PFNWP) RemovePermDialogProc,
  549.                                                  (HMODULE) NULL,
  550.                                                  REMOVE_PERM_LIST_BOX,
  551.                                                  (PVOID) NULL);
  552.  
  553.                         WinInvalidateRegion( hwnd, 0, FALSE );
  554.                    break;
  555.  
  556.                    case ID_CONFIG_QUERY_ALL:
  557.  
  558.                         ReturnCode = WinDlgBox ( HWND_DESKTOP,
  559.                                                  (HWND) hwnd,
  560.                                                  (PFNWP) QueryAllDialogProc,
  561.                                                  (HMODULE) NULL,
  562.                                                  QUERY_ALL_LIST_BOX,
  563.                                                  (PVOID) NULL);
  564.  
  565.                         WinInvalidateRegion( hwnd, 0, FALSE );
  566.                    break;
  567.  
  568.  
  569.                    case IDM_HELPUSINGHELP:
  570.                         if ( WinSendMsg ( hwndHelpInstance,
  571.                                           HM_DISPLAY_HELP,
  572.                                           MPVOID,
  573.                                           MPVOID ) )
  574.                         {
  575.                              WinMessageBox( HWND_DESKTOP,
  576.                                             hwnd,
  577.                                             "Cannot display Help For Help.",
  578.                                             "Help For Help",
  579.                                             (HMODULE) NULL,
  580.                                             MB_OK | MB_ERROR );
  581.                         }
  582.                         WinInvalidateRegion( hwnd, 0, FALSE );
  583.                    break;
  584.  
  585.                    case IDM_HELPGENERAL:
  586.                         if ( WinSendMsg ( hwndHelpInstance,
  587.                                           HM_DISPLAY_HELP,
  588.                                           MPFROM2SHORT(PANEL_HELPGENERAL,NULL), MPFROMSHORT(HM_RESOURCEID)))
  589.                         {
  590.                         WinInvalidateRegion( hwnd, 0, FALSE );
  591.                         break;
  592.                         }
  593.                         break;
  594.                    case IDM_HELPINDEX:
  595.                         if (WinSendMsg ( hwndHelpInstance,
  596.                                          HM_HELP_INDEX,
  597.                                          MPVOID,
  598.                                          MPVOID))
  599.                         {
  600.                                 WinMessageBox( HWND_DESKTOP,
  601.                                                hwnd,
  602.                                                "Cannot display Help Index.",
  603.                                                "Help Index",
  604.                                                (HMODULE) NULL,
  605.                                                MB_OK | MB_ERROR );
  606.                        }
  607.                        WinInvalidateRegion( hwnd, 0, FALSE );
  608.                        break;
  609.  
  610.                    case IDM_HELPPRODUCTINFO:
  611.  
  612.                         WinDlgBox(HWND_DESKTOP,
  613.                                   hwnd,
  614.                                   (PFNWP)AboutDlgProc,
  615.                                   0,
  616.                                   IDD_PRODUCTINFO,
  617.                                   (PVOID)NULL);
  618.  
  619.                         WinInvalidateRegion( hwnd, 0, FALSE );
  620.                    break;
  621.  
  622.                    /*
  623.                     * Exit from program.
  624.                     */
  625.  
  626.                    case ID_EXITPROG:
  627.                         WinPostMsg( hwnd, WM_CLOSE, 0L, 0L );
  628.                    break;
  629.  
  630.                    default:
  631.                         return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  632.               }
  633.  
  634.          break; // end of WM_COMMAND
  635.  
  636.  
  637.          case WM_PAINT:
  638.  
  639.               if (!WinIsWindowVisible(hwnd))
  640.               {
  641.                    return((MRESULT)NULL);
  642.               }
  643.  
  644.               /*
  645.                * Check our Presentation Space. If a bitmap exists,
  646.                * then display it. Otherwise, do our normal stuff.
  647.                */
  648.  
  649.               if (hpsMemory)
  650.               {
  651.                    MakeItBusy ( TRUE );
  652.                    DrawBitMap(hwnd);
  653.                    MakeItBusy ( FALSE );
  654.               }
  655.  
  656.               WinDefWindowProc ( hwnd, msg, mp1, mp2 );
  657.  
  658.          break;
  659.          return((MRESULT)TRUE);
  660.  
  661.          case WM_CLOSE:
  662.               WinPostMsg( hwnd, WM_QUIT, 0L, 0L );  /* Cause termination */
  663.          break;
  664.  
  665.          /*
  666.           *  Everything else comes here.
  667.           */
  668.  
  669.          default:
  670.               return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  671.     }
  672.  
  673.     return FALSE;
  674. }
  675.  
  676. /**********************************************************************/
  677. /*                                                                    */
  678. /*  Name:   OpenFileDialog                                            */
  679. /*                                                                    */
  680. /*  Purpose: open the standard file open dialog as file extention     */
  681. /*           and return the filename                                  */
  682. /*                                                                    */
  683. /*  Usage:   called when the user needs to supply a name for          */
  684. /*           the file to be opened                                    */
  685. /*                                                                    */
  686. /*  Method:  calls the standard file open dialog to get the           */
  687. /*           file name.                                               */
  688. /*                                                                    */
  689. /*  Parameters: HWD hwnd         Handle of the owner window.          */
  690. /*              PSZ szTitle      Title of open dialog.                */
  691. /*              PSZ pszFileExt   File extention. (for example : *.txt)*/
  692. /*              PSZ pszFullPath  PSZ for returning the file name.     */
  693. /*                                                                    */
  694. /*  Returns: TRUE if successful in getting a file name, FALSE         */
  695. /*              if not in pushing CANCEL                              */
  696. /*           PSZ pszFullPath pointer to filename (full path)          */
  697. /*                                                                    */
  698. /**********************************************************************/
  699.  
  700. BOOL OpenFileDialog(HWND hwndOwner,
  701.                     PSZ szTitle,
  702.                     PSZ szFileExt,
  703.                     PSZ szButton,
  704.                     PSZ szFullPath )
  705. {
  706.     FILEDLG fdg;
  707.  
  708.     memset(&fdg, 0, sizeof(FILEDLG));
  709.     fdg.cbSize = sizeof(FILEDLG);          /* Size of FILEDLG.                */
  710.  
  711.     fdg.pszTitle = szTitle;                /* String to display in title bar. */
  712.  
  713.     fdg.pszOKButton = szButton ;
  714.  
  715.     fdg.ulUser = 0L;                       /* User defined field.             */
  716.     fdg.fl = FDS_CENTER |
  717.              FDS_OPEN_DIALOG;
  718.  
  719.     fdg.pfnDlgProc = NULL;
  720.     fdg.lReturn = 0L;                      /* Result code from dialog dismissal. */
  721.     fdg.lSRC = 0L;                         /* System return code.          */
  722.     fdg.hMod = 0;                          /* Custom file dialog template. */
  723.     fdg.usDlgId = 0;                       /* Custom file dialog ID.       */
  724.     fdg.x = 100;                           /* X coordinate of the dialog.  */
  725.     fdg.y = 100;                           /* Y coordinate of the dialog.  */
  726.  
  727.     /* set selected fully qualified path */
  728.     strcpy( fdg.szFullFile, szFileExt);
  729.  
  730.  
  731.     /* get the file */
  732.  
  733.     if ( !WinFileDlg ( HWND_DESKTOP,
  734.                        hwndOwner,
  735.                        (PFILEDLG)&fdg ) )
  736.        return FALSE;
  737.  
  738.  
  739.     /* copy file name into file name buffer */
  740.  
  741.     strcpy ( szFullPath, fdg.szFullFile );
  742.     if (fdg.lReturn == DID_CANCEL)
  743.     return FALSE;
  744.     else
  745.     return(TRUE);
  746.  
  747.  
  748. }
  749.  
  750. /*************************************************************************
  751.  * Name        :  DisplayMessageBox
  752.  *
  753.  * Description :  This procedure will display messages for the application
  754.  *                based upon string IDs passed in.  The actual text will be
  755.  *                loaded from the string table in the resource.
  756.  *
  757.  * Parameters  :  usTitleID   - ID of the title string
  758.  *                usMessageID - ID of the message string
  759.  *                usStyle     - Style of the message box (WinMessageBox)
  760.  *
  761.  * Return      :  none.
  762.  *
  763.  *************************************************************************/
  764.  
  765. VOID DisplayMessageBox ( HWND   hwnd,
  766.                          USHORT usTitleID,
  767.                          USHORT usMessageID,
  768.                          USHORT usStyle)
  769. {
  770.    CHAR     achTitle[STRING_LENGTH];
  771.    CHAR     achMessage[STRING_LENGTH];
  772.    USHORT   usResult;
  773.  
  774.    /*
  775.     * Get the string from the Resource defined string table and show it
  776.     * in the message box.
  777.     */
  778.  
  779.    WinLoadString(
  780.       hab,                          /* HAB for this dialog box.            */
  781.       (HMODULE) NULL,               /* Get the string from the .exe file.  */
  782.       usTitleID,                    /* Which string to get.                */
  783.       (SHORT) sizeof( achTitle),    /* The size of the buffer.             */
  784.       achTitle );                   /* The buffer to place the string.     */
  785.  
  786.    WinLoadString(
  787.       hab,                          /* HAB for this dialog box.            */
  788.       (HMODULE) NULL,               /* Get the string from the .exe file.  */
  789.       usMessageID,                  /* Which string to get.                */
  790.       (SHORT) sizeof( achMessage),  /* The size of the buffer.             */
  791.       achMessage );                 /* The buffer to place the string.     */
  792.  
  793.    usResult =
  794.       WinMessageBox(
  795.          HWND_DESKTOP,              /* Parent handle of the message box.   */
  796.          hwnd,                      /* Owner handle of the message box.    */
  797.          achMessage,                /* String to show in the message box.  */
  798.          achTitle,                  /* Title to shown in the message box.  */
  799.          (HMODULE) NULL,            /* Message Box Id.  Not Needed.        */
  800.          (ULONG) usStyle );         /* The style of the message box.       */
  801.  
  802. }  /* End of DisplayMessageBox */
  803.  
  804.  
  805. /*
  806.  * Get FOURCC Dialog Box Procedure
  807.  */
  808.  
  809. MRESULT EXPENTRY GetFOURCCDialogProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 )
  810. {
  811.    HWND  hwndEntryField;         /* Window handle for entry field */
  812.  
  813.     switch ( msg )
  814.     {
  815.          case WM_INITDLG:
  816.  
  817.               /* Set the maximum number of characters in the
  818.                * entry field to 4.
  819.                */
  820.               hwndEntryField = WinWindowFromID ( hwndDlg, GET_FOURCC_TEXT );
  821.               WinSendMsg ( hwndEntryField, EM_SETTEXTLIMIT,
  822.                          (MPARAM) 4, (MPARAM) NULL );
  823.               break;
  824.  
  825.  
  826.          case WM_COMMAND:                    /* Posted by pushbutton or key  */
  827.  
  828.               /*
  829.                * PM sends a WM_COMMAND message when the user presses either
  830.                * the Enter or Escape pushbuttons.
  831.                */
  832.               switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
  833.               {
  834.  
  835.                    case GET_FOURCC_OK_BUTTON:
  836.  
  837.                         WinQueryWindowText( WinWindowFromID( hwndDlg,
  838.                                                              GET_FOURCC_TEXT ),
  839.                                             STRING_LENGTH,
  840.                                             szFOURCC );
  841.  
  842.                         WinPostMsg( hwndDlg, WM_CLOSE, 0L, 0L );
  843.                    break;
  844.  
  845.                    case GET_FOURCC_CANCEL_BUTTON:
  846.                    WinDismissDlg(hwndDlg, FALSE);
  847.                    Cancel = TRUE;
  848.                    return (MRESULT) FALSE;
  849.                    break;
  850.  
  851.                    case GET_FOURCC_HELP_BUTTON:
  852.                         WinSendMsg ( hwndHelpInstance,
  853.                                      HM_DISPLAY_HELP,
  854.                                      MPFROM2SHORT(HELP_GET_FOURCC,NULL),
  855.                                      MPFROMSHORT(HM_RESOURCEID ));
  856.                    return (MRESULT) FALSE;
  857.                    break;
  858.  
  859.                    case ID_EXITPROG:
  860.                         WinPostMsg( hwndDlg, WM_CLOSE, 0L, 0L );
  861.                    break;
  862.               }
  863.  
  864.          case WM_CLOSE:
  865.  
  866.               /*
  867.                * Come here to close the dialog box..
  868.                */
  869.  
  870.               WinDismissDlg( hwndDlg, TRUE );  /* Removes the dialog box    */
  871.               WinPostMsg( hwndDlg, WM_QUIT, 0L, 0L );  /* Cause termination */
  872.               return (MRESULT) FALSE;
  873.          break;
  874.  
  875.          default:
  876.  
  877.               /*
  878.                * Any event messages that the dialog procedure has not processed
  879.                * come here and are processed by WinDefDlgProc.
  880.                */
  881.  
  882.               return WinDefDlgProc( hwndDlg, msg, mp1, mp2 );
  883.     }
  884.     return (MRESULT) FALSE;
  885. }
  886.  
  887. VOID FourccToString( FOURCC fcc, PSZ pszString )
  888. {
  889.     pszString[0] = (BYTE) fcc;
  890.     pszString[1] = (BYTE) (fcc >> 8);
  891.     pszString[2] = (BYTE) (fcc >> 16);
  892.     pszString[3] = (BYTE) (fcc >> 24);
  893.     pszString[4] = 0;
  894. }
  895.  
  896. /*
  897.  * Remove permanently installed IO Procs Dialog Box procedure.
  898.  */
  899.  
  900. MRESULT EXPENTRY RemovePermDialogProc( HWND   hwnd,
  901.                                        USHORT msg,
  902.                                        MPARAM mp1,
  903.                                        MPARAM mp2 )
  904. {
  905.     ULONG         ulReturnCode;
  906.     CHAR          szBuffer[ sizeof( FOURCC ) + MAX_FILENAME_SIZE + 4 ];
  907.     MMINIFILEINFO mmIniFileInfo;
  908.     PCHAR         pszFourCC;
  909.     SHORT         sItemIndex;
  910.     CHAR          szParsedFourCC [ sizeof( FOURCC) + 1 ] ;
  911.     CHAR          szMessage[ MAX_FILENAME_SIZE + MAX_FILENAME_SIZE ];
  912.     BOOL          bTest;
  913.     switch( msg )
  914.  
  915.     {
  916.  
  917.          case WM_INITDLG :
  918.  
  919.               memset ( &mmIniFileInfo,
  920.                        '\0',
  921.                        sizeof ( MMINIFILEINFO ) );
  922.  
  923.               pszFourCC = malloc ( 4 );
  924.  
  925.               strcpy ( mmIniFileInfo.szProcName, szIOProcName );
  926.  
  927.               ulReturnCode = mmioIniFileHandler ( &mmIniFileInfo,
  928.                                                   MMIO_FINDPROC   |
  929.                                                   MMIO_MATCHFIRST |
  930.                                                   MMIO_MATCHPROCEDURENAME );
  931.  
  932.               if( ulReturnCode == MMIOERR_MATCH_NOT_FOUND )
  933.                    break;
  934.  
  935.               if( ulReturnCode != MMIO_SUCCESS )
  936.                    break;
  937.  
  938.               /*
  939.                *  We need to fill the listbox with the installed I/O procs.
  940.                *  To do this, use mmioIniFileHandler with Query Next flag.
  941.                */
  942.               while( TRUE )   // forever loop - well, until we break
  943.               {
  944.                         szBuffer[0] = '\0';
  945.                         FourccToString ( mmIniFileInfo.fccIOProc,
  946.                                     pszFourCC );
  947.  
  948.                    sprintf ( szBuffer,
  949.                              "%s - %s",
  950.                              pszFourCC,
  951.                              mmIniFileInfo.szDLLName );
  952.  
  953.                    /*
  954.                     * Add this entry to the end of the list box.
  955.                     */
  956.  
  957.                    WinSendMsg( WinWindowFromID( hwnd,
  958.                                REMOVE_PERM_LIST_BOX_ENTRIES),
  959.                                LM_INSERTITEM,
  960.                                (MPARAM) LIT_END,
  961.                                szBuffer);
  962.                        bTest = 1;
  963.                        while(bTest == 1)
  964.                           {
  965.                          ulReturnCode = mmioIniFileHandler ( &mmIniFileInfo,
  966.                                                             MMIO_FINDPROC |
  967.                                                             MMIO_MATCHNEXT ) ;
  968.  
  969.                         if (( ulReturnCode == MMIOERR_MATCH_NOT_FOUND ) ||
  970.                         ( ulReturnCode != MMIO_SUCCESS ))
  971.                         return FALSE;
  972.  
  973.  
  974.                         bTest =strcmp(mmIniFileInfo.szProcName, "IOProc_Entry");
  975.                         if(bTest == 0)
  976.                             bTest = 0;
  977.                         else
  978.                             bTest = 1;
  979.                           }
  980.                 }
  981.               return( (MRESULT) 0);
  982.          break;
  983.  
  984.          case WM_CLOSE :
  985.  
  986.               WinDismissDlg( hwnd, TRUE );  /* Removes the dialog box    */
  987.               WinPostMsg( hwnd, WM_QUIT, 0L, 0L );  /* Cause termination */
  988.               return (MRESULT) FALSE;
  989.  
  990.          break;
  991.  
  992.          case WM_HELP :
  993.               WinSendMsg ( hwndHelpInstance,
  994.                            HM_DISPLAY_HELP,
  995.                            MPFROMLONG ( 1 ),
  996.                            MPFROMSHORT ( HM_RESOURCEID ) );
  997.  
  998.               return( 0 );
  999.          break;
  1000.  
  1001.          case WM_COMMAND :
  1002.  
  1003.               /*
  1004.                * To get which pushbutton was pressed the SHORT1FROMMP macro
  1005.                * is used.
  1006.                */
  1007.  
  1008.               switch (SHORT1FROMMP(mp1))
  1009.               {
  1010.  
  1011.                    case REMOVE_PERM_LIST_BOX_OK:
  1012.  
  1013.                         /*
  1014.                          * Remove highlighted IO procs
  1015.                          */
  1016.  
  1017.                         sItemIndex = (SHORT)WinSendMsg ( WinWindowFromID( hwnd,
  1018.                                                   REMOVE_PERM_LIST_BOX_ENTRIES),
  1019.                                                   LM_QUERYSELECTION,
  1020.                                                   MPFROMLONG ( LIT_FIRST ),
  1021.                                                   (MPARAM) NULL );
  1022.  
  1023.                         while( sItemIndex != LIT_NONE)   // change to LIT_NONE
  1024.                         {
  1025.  
  1026.                              WinSendMsg ( WinWindowFromID( hwnd,
  1027.                                           REMOVE_PERM_LIST_BOX_ENTRIES),
  1028.                                           LM_QUERYITEMTEXT,
  1029.                                           MPFROM2SHORT ( sItemIndex,
  1030.                                                          sizeof( szBuffer )),
  1031.                                           szBuffer );
  1032.                              /*
  1033.                               * Take buffer and parse for FOURCC and DLL name.
  1034.                               */
  1035.  
  1036.                              memset ( &mmIniFileInfo,
  1037.                                       '\0',
  1038.                                       sizeof ( MMINIFILEINFO ) );
  1039.  
  1040.                              szParsedFourCC[ 0 ] = '\0';
  1041.  
  1042.                              strncat ( szParsedFourCC, &szBuffer[0], 4 );
  1043.  
  1044.                              mmIniFileInfo.fccIOProc = mmioStringToFOURCC ( szParsedFourCC ,
  1045.                                                                             0 );
  1046.  
  1047.                              strcpy ( mmIniFileInfo.szDLLName, &szBuffer[7] );
  1048.  
  1049.                              strcpy ( mmIniFileInfo.szProcName, szIOProcName );
  1050.  
  1051.                              ulReturnCode = mmioIniFileHandler ( &mmIniFileInfo,
  1052.                                                                  MMIO_MATCHDLL |
  1053.                                                                  MMIO_MATCHFOURCC |
  1054.                                                                  MMIO_REMOVEPROC);
  1055.                              if( ulReturnCode == MMIO_SUCCESS )
  1056.                              {
  1057.                                   sprintf ( szMessage,
  1058.                                             "%s %s (FOURCC value: %s)",
  1059.                                             "Successfully removed. Please Reboot to have removal take permanent effect.",
  1060.                                             mmIniFileInfo.szDLLName,
  1061.                                             szParsedFourCC );
  1062.                                   WinMessageBox( HWND_DESKTOP,
  1063.                                                  hwnd,
  1064.                                                  szMessage,
  1065.                                                  "Remove Permanent IO Proc",
  1066.                                                  (HMODULE) NULL,
  1067.                                                  (ULONG) MB_OK | MB_MOVEABLE |
  1068.                                                          MB_INFORMATION );
  1069.                              }
  1070.                              else
  1071.                              {
  1072.                                   sprintf ( szMessage ,
  1073.                                             "%s %s %s %ul."
  1074.                                             "Could not remove",
  1075.                                             szMessage,
  1076.                                             "Return code from mmioIniFileHandler:",
  1077.                                             ulReturnCode );
  1078.  
  1079.                                   WinMessageBox( HWND_DESKTOP,
  1080.                                                  hwnd,
  1081.                                                  szMessage,
  1082.                                                  "Remove Permanent IO Proc",
  1083.                                                  (HMODULE) NULL,
  1084.                                                  (ULONG) MB_OK | MB_MOVEABLE |
  1085.                                                          MB_ERROR );
  1086.                              }
  1087.  
  1088.                              /*
  1089.                               * Get next selected item in the list box.
  1090.                               */
  1091.  
  1092.                              sItemIndex = (SHORT) WinSendMsg ( WinWindowFromID( hwnd, REMOVE_PERM_LIST_BOX_ENTRIES),
  1093.                                                        LM_QUERYSELECTION,
  1094.                                                        MPFROMLONG (sItemIndex),
  1095.                                                        (MPARAM) NULL );
  1096.                         }
  1097.  
  1098.                         WinSendMsg ( hwnd, WM_CLOSE, (MPARAM) NULL, (MPARAM) NULL);
  1099.                         return( (MRESULT) FALSE);
  1100.  
  1101.                    break;
  1102.  
  1103.                    case REMOVE_PERM_LIST_BOX_CANCEL:   /* user selected "Cancel"  */
  1104.                         WinSendMsg( hwnd, WM_CLOSE, (MPARAM) NULL, (MPARAM) NULL);
  1105.                    break;
  1106.  
  1107.                    case REMOVE_PERM_LIST_BOX_HELP:
  1108.  
  1109.                         WinSendMsg ( hwndHelpInstance,
  1110.                                      HM_DISPLAY_HELP,
  1111.                                      MPFROM2SHORT(ID_HELP_REMOVE_PERM_LIST_BOX, NULL),
  1112.                                      MPFROMSHORT(HM_RESOURCEID ));
  1113.                    break;
  1114.  
  1115.                    default:
  1116.                    break;
  1117.  
  1118.                }  /* End of Command Switch */
  1119.                return( (MRESULT) 0);
  1120.          break;
  1121.  
  1122.          default:
  1123.                return( WinDefDlgProc( hwnd, msg, mp1, mp2));
  1124.          break;
  1125.  
  1126.     }  /* End of msg Switch */
  1127.  
  1128.     return( (MRESULT) FALSE);
  1129.  
  1130. }
  1131.  
  1132. HBITMAP LoadBitmap ( HAB hab,
  1133.                      HDC hdc,
  1134.                      HPS *hps,
  1135.                      PSZ pszFileName )
  1136. {
  1137.     HBITMAP       hbm;
  1138.     MMIOINFO      mmioinfo;
  1139.     MMFORMATINFO  mmFormatInfo;
  1140.     HMMIO         hmmio;
  1141.     ULONG         ulImageHeaderLength;
  1142.     MMIMAGEHEADER mmImgHdr;
  1143.     ULONG         ulBytesRead;
  1144.     ULONG         dwNumRowBytes;
  1145.     PBYTE         pRowBuffer;
  1146.     ULONG         dwRowCount;
  1147.     SIZEL         ImageSize;
  1148.     ULONG         dwHeight, dwWidth;
  1149.     SHORT          wBitCount;
  1150.     FOURCC        fccStorageSystem;
  1151.     ULONG         dwPadBytes;
  1152.     ULONG         dwRowBits;
  1153.     ULONG         ulReturnCode;
  1154.     ULONG         dwReturnCode;
  1155.     HBITMAP       hbReturnCode;
  1156.     LONG          lReturnCode;
  1157.     FOURCC        fccIOProc;
  1158.  
  1159.  
  1160.     ulReturnCode = mmioIdentifyFile ( pszFileName,
  1161.                                       0L,
  1162.                                       &mmFormatInfo,
  1163.                                       &fccStorageSystem,
  1164.                                       0L,
  1165.                                       0L);
  1166.  
  1167.     /*
  1168.      *  If this file was NOT identified, then this function won't
  1169.      *  work, so return an error by indicating an empty bitmap.
  1170.      */
  1171.  
  1172.     if ( ulReturnCode == MMIO_ERROR )
  1173.     {
  1174.          return (0L);
  1175.     }
  1176.  
  1177.     /*
  1178.      *  If mmioIdentifyFile did not find a custom-written IO proc which
  1179.      *  can understand the image file, then it will return the DOS IO Proc
  1180.      *  info because the image file IS a DOS file.
  1181.      */
  1182.  
  1183.     if( mmFormatInfo.fccIOProc == FOURCC_DOS )
  1184.     {
  1185.  
  1186.          WinMessageBox( HWND_DESKTOP,
  1187.                         HWND_DESKTOP,
  1188.                         "Image file could not be interpreted by any permanently or temporarily installed IO procedures.",
  1189.                         "Open Image File",
  1190.                         (HMODULE) NULL,
  1191.                         (ULONG) MB_OK | MB_MOVEABLE |
  1192.                                 MB_ERROR );
  1193.          return ( 0L );
  1194.     }
  1195.  
  1196.     /*
  1197.      *  Ensure this is an IMAGE IOproc, and that it can read
  1198.      *  translated data
  1199.      */
  1200.  
  1201.     if ( (mmFormatInfo.ulMediaType != MMIO_MEDIATYPE_IMAGE) ||
  1202.          ((mmFormatInfo.ulFlags & MMIO_CANREADTRANSLATED) == 0) )
  1203.     {
  1204.  
  1205.          WinMessageBox( HWND_DESKTOP,
  1206.                         HWND_DESKTOP,
  1207.                         "No IMAGE IO Procedures exist which can translate the data in the image file specified.",
  1208.                         "Open Image File",
  1209.                         (HMODULE) NULL,
  1210.                         (ULONG) MB_OK | MB_MOVEABLE |
  1211.                                 MB_ERROR );
  1212.          return (0L);
  1213.     }
  1214.     else
  1215.     {
  1216.          fccIOProc = mmFormatInfo.fccIOProc;
  1217.     }
  1218.  
  1219.     /* Clear out and initialize mminfo structure */
  1220.  
  1221.     memset ( &mmioinfo,
  1222.              0L,
  1223.              sizeof ( MMIOINFO ) );
  1224.  
  1225.     mmioinfo.fccIOProc = fccIOProc;
  1226.     mmioinfo.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
  1227.  
  1228.     hmmio = mmioOpen ( (PSZ) pszFileName,
  1229.                        &mmioinfo,
  1230.                        MMIO_READ | MMIO_DENYWRITE | MMIO_NOIDENTIFY );
  1231.  
  1232.     if ( ! hmmio )
  1233.     {
  1234.          // If file could not be opened, return with error
  1235.  
  1236.          return (0L);
  1237.     }
  1238.  
  1239.     dwReturnCode = mmioQueryHeaderLength ( hmmio,
  1240.                                          (PLONG)&ulImageHeaderLength,
  1241.                                            0L,
  1242.                                            0L);
  1243.  
  1244.     if ( ulImageHeaderLength != sizeof ( MMIMAGEHEADER ) )
  1245.     {
  1246.          /* We have a problem.....possibly incompatible versions */
  1247.  
  1248.          ulReturnCode = mmioClose (hmmio, 0L);
  1249.  
  1250.          return (0L);
  1251.     }
  1252.  
  1253.     ulReturnCode = mmioGetHeader ( hmmio,
  1254.                                    &mmImgHdr,
  1255.                                    (LONG) sizeof ( MMIMAGEHEADER ),
  1256.                                    (PLONG)&ulBytesRead,
  1257.                                    0L,
  1258.                                    0L);
  1259.  
  1260.     if ( ulReturnCode != MMIO_SUCCESS )
  1261.     {
  1262.          /* Header unavailable */
  1263.  
  1264.          ulReturnCode = mmioClose (hmmio, 0L);
  1265.  
  1266.          return (0L);
  1267.     }
  1268.  
  1269.     /*
  1270.      *  Determine the number of bytes required, per row.
  1271.      *      PLANES MUST ALWAYS BE = 1
  1272.      */
  1273.  
  1274.     dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
  1275.     dwWidth = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
  1276.     wBitCount = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
  1277.     dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
  1278.     dwNumRowBytes = dwRowBits >> 3;
  1279.  
  1280.     /*
  1281.      *  Account for odd bits used in 1bpp or 4bpp images that are
  1282.      *  NOT on byte boundaries.
  1283.      */
  1284.  
  1285.     if ( dwRowBits % 8 )
  1286.     {
  1287.          dwNumRowBytes++;
  1288.     }
  1289.  
  1290.     /*
  1291.      *  Ensure the row length in bytes accounts for byte padding.
  1292.      *  All bitmap data rows must are aligned on LONG/4-BYTE boundaries.
  1293.      *  The data FROM an IOProc should always appear in this form.
  1294.      */
  1295.  
  1296.     dwPadBytes = ( dwNumRowBytes % 4 );
  1297.  
  1298.     if ( dwPadBytes )
  1299.     {
  1300.          dwNumRowBytes += 4 - dwPadBytes;
  1301.     }
  1302.  
  1303.     /* Allocate space for ONE row of pels */
  1304.  
  1305.     if ( DosAllocMem( (PPVOID)&pRowBuffer,
  1306.                       (ULONG)dwNumRowBytes,
  1307.                       fALLOC))
  1308.     {
  1309.          ulReturnCode = mmioClose (hmmio, 0L);
  1310.  
  1311.          return(0L);
  1312.     }
  1313.  
  1314.     // ***************************************************
  1315.     // Create a memory presentation space that includes
  1316.     // the memory device context obtained above.
  1317.     // ***************************************************
  1318.  
  1319.     ImageSize.cx = dwWidth;
  1320.     ImageSize.cy = dwHeight;
  1321.  
  1322.     *hps = GpiCreatePS ( hab,
  1323.                          hdc,
  1324.                          &ImageSize,
  1325.                          PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC );
  1326.  
  1327.     if ( !*hps )
  1328.     {
  1329.          mmioClose (hmmio, 0L);
  1330.          return(0L);
  1331.     }
  1332.  
  1333.     // ***************************************************
  1334.     // Create an uninitialized bitmap.  This is where we
  1335.     // will put all of the bits once we read them in.
  1336.     // ***************************************************
  1337.  
  1338.     hbm = GpiCreateBitmap ( *hps,
  1339.                             &mmImgHdr.mmXDIBHeader.BMPInfoHeader2,
  1340.                             0L,
  1341.                             NULL,
  1342.                             NULL);
  1343.  
  1344.     if ( !hbm )
  1345.     {
  1346.          ulReturnCode = mmioClose (hmmio, 0L);
  1347.  
  1348.          return(0L);
  1349.     }
  1350.  
  1351.     // ***************************************************
  1352.     // Select the bitmap into the memory device context.
  1353.     // ***************************************************
  1354.  
  1355.     hbReturnCode = GpiSetBitmap ( *hps,
  1356.                                   hbm );
  1357.  
  1358.     //***************************************************************
  1359.     //  LOAD THE BITMAP DATA FROM THE FILE
  1360.     //      One line at a time, starting from the BOTTOM
  1361.     //*************************************************************** */
  1362.  
  1363.     for ( dwRowCount = 0; dwRowCount < dwHeight; dwRowCount++ )
  1364.     {
  1365.          ulBytesRead = (ULONG) mmioRead ( hmmio,
  1366.                                           pRowBuffer,
  1367.                                           dwNumRowBytes );
  1368.  
  1369.          if ( !ulBytesRead )
  1370.          {
  1371.               break;
  1372.          }
  1373.  
  1374.          /*
  1375.           *  Allow context switching while previewing.. Couldn't get
  1376.           *  it to work. Perhaps will get to it when time is available...
  1377.           */
  1378.  
  1379.          lReturnCode = GpiSetBitmapBits ( *hps,
  1380.                                           (LONG) dwRowCount,
  1381.                                           (LONG) 1,
  1382.                                           (PBYTE) pRowBuffer,
  1383.                                           (PBITMAPINFO2) &mmImgHdr.mmXDIBHeader.BMPInfoHeader2);
  1384.  
  1385.     }
  1386.  
  1387.     ulReturnCode = mmioClose (hmmio, 0L);
  1388.  
  1389.     DosFreeMem(pRowBuffer);
  1390.  
  1391.     return(hbm);
  1392. }
  1393.  
  1394.  
  1395. /*
  1396.  *  GetBitMap
  1397.  *
  1398.  *  Get a bitmap for the specified file
  1399.  */
  1400.  
  1401. HBITMAP GetBitMap ( HWND hwnd,
  1402.                     PSZ  pszFileName)
  1403. {
  1404.     HBITMAP hBmp;
  1405.     BOOL    bReturnCode;
  1406.  
  1407.     /*
  1408.      *  Load Bitmap, which will then be drawn during WM_PAINT processing
  1409.      *
  1410.      *  First, we need a memory device context. We'll keep this around
  1411.      *  to reuse for subsequent preview operations
  1412.      */
  1413.  
  1414.     if ( !hdcMemory )
  1415.     {
  1416.          hdcMemory = DevOpenDC ( WinQueryAnchorBlock(hwnd),
  1417.                                  OD_MEMORY,
  1418.                                  "*",
  1419.                                  0L,
  1420.                                  NULL,
  1421.                                  0);
  1422.     }
  1423.  
  1424.     /*
  1425.      *  Discard previous memory presentation space if present
  1426.      */
  1427.  
  1428.     if ( hpsMemory )
  1429.     {
  1430.          hBmp = GpiSetBitmap ( hpsMemory,
  1431.                                0);
  1432.  
  1433.          bReturnCode = GpiDestroyPS ( hpsMemory );
  1434.  
  1435.          hpsMemory = 0;
  1436.     }
  1437.  
  1438.     /*
  1439.      * Delete previously loaded bitmap if present
  1440.      */
  1441.  
  1442.     if ( hBmp && hBmp != HBM_ERROR )
  1443.     {
  1444.          bReturnCode = GpiDeleteBitmap ( hBmp );
  1445.     }
  1446.  
  1447.     MakeItBusy ( TRUE );
  1448.  
  1449.     hBmp = LoadBitmap ( WinQueryAnchorBlock(hwnd),
  1450.                         hdcMemory,
  1451.                         &hpsMemory,
  1452.                         pszFileName );
  1453.  
  1454.     MakeItBusy ( FALSE );
  1455.  
  1456.     if (!hBmp)
  1457.     {
  1458.     // Error loading bitmap
  1459.     return hBmp;
  1460.     }
  1461.  
  1462.     /*
  1463.      *  Be sure that the image gets repainted
  1464.      */
  1465.  
  1466.     bReturnCode = WinInvalidateRect(hwnd, NULL, FALSE);
  1467.  
  1468.     return hBmp;
  1469. }
  1470.  
  1471. /*
  1472.  *  DrawBitMap
  1473.  *
  1474.  *  Draw the previously loaded bitmap in the rectangle occupied by the
  1475.  *  frame ID_WINDOW.
  1476.  */
  1477.  
  1478. VOID DrawBitMap ( HWND hwnd )
  1479. {
  1480.     SWP    swp;
  1481.     POINTL aptl[4];
  1482.     HPS    hps;
  1483.     SIZEL  ImageSize;
  1484.     BOOL   bReturnCode;
  1485.     ULONG  ulReturnCode;
  1486.     LONG   lReturnCode;
  1487.  
  1488.  
  1489.     /*
  1490.      *  Validate memory presentation space before attempting to draw bitmap
  1491.      */
  1492.  
  1493.     ulReturnCode = GpiQueryPS ( hpsMemory, &ImageSize) ;
  1494.  
  1495.     if ( ! ulReturnCode )
  1496.     {
  1497.          return;
  1498.     }
  1499.  
  1500.     hps = WinBeginPaint ( hwnd,
  1501.                           0,
  1502.                           NULL);
  1503.  
  1504.     /*
  1505.      *  Get position of image frame
  1506.      */
  1507.  
  1508.     bReturnCode = WinQueryWindowPos ( hwnd, &swp);
  1509.  
  1510.     aptl[0].x = 0;              // target lower left
  1511.     aptl[0].y = 0;
  1512.  
  1513.     aptl[1].x = swp.cx;         // target upper right
  1514.     aptl[1].y = swp.cy;
  1515.  
  1516.     aptl[2].x = 0;              // source lower left
  1517.     aptl[2].y = 0;
  1518.  
  1519.     aptl[3].x = ImageSize.cx;   // source upper right
  1520.     aptl[3].y = ImageSize.cy;
  1521.  
  1522.     /*
  1523.      *  Call GpiBitBlt and supply 4 aptl structures.  This tells
  1524.      *  it to stretch or compress the bitmap depending on what is
  1525.      *  in the aptl structures.  See above lines for their current
  1526.      *  settings.
  1527.      */
  1528.  
  1529.     bReturnCode = GpiSetColor (hps, GpiQueryColor (hpsMemory));
  1530.  
  1531.     bReturnCode = GpiSetBackColor (hps, GpiQueryBackColor (hpsMemory));
  1532.  
  1533.     lReturnCode = GpiBitBlt (hps, hpsMemory, 4L, aptl, ROP_SRCCOPY, BBO_OR);
  1534.  
  1535.     bReturnCode = WinEndPaint (hps);
  1536. }
  1537.  
  1538. /*
  1539.  * Install a temporary IO Proc (into memory).
  1540.  *
  1541.  * Returns:
  1542.  *
  1543.  *    TRUE  - Error encountered.
  1544.  *    FALSE - Temporary IO Proc installed successfully.
  1545.  */
  1546.  
  1547. BOOL InstallTempIOProc ( HWND hwnd )
  1548. {
  1549.     ULONG     ulReturnCode;
  1550.     PMMIOPROC ioReturnCode;
  1551.     HMODULE   hDLLModule;
  1552.     CHAR      Failure[ CCHMAXPATH ];
  1553.     PMMIOPROC pIOProc;
  1554.     FOURCC    fccIOProc;
  1555.  
  1556.  
  1557.     ulReturnCode = DosLoadModule ( Failure,           // Obj name if failure
  1558.                                    CCHMAXPATH,        // Obj name size
  1559.                                    pszFileName,
  1560.                                    &(hDLLModule));     // Handle to the module.
  1561.  
  1562.     if ( ulReturnCode != NO_ERROR )
  1563.     {
  1564.          /*
  1565.           * Could not load the DLL into memory.
  1566.           */
  1567.  
  1568.          WinMessageBox( HWND_DESKTOP,
  1569.                         hwnd,
  1570.                         "Could not load the IO Procedure into memory. Please contact author.",
  1571.                         "Install Temporary IO Procedure",
  1572.                         (HMODULE) NULL,
  1573.                         (ULONG) MB_OK | MB_MOVEABLE |
  1574.                                 MB_ERROR );
  1575.          return ( TRUE );
  1576.     }
  1577.  
  1578.     /*
  1579.      * Get the address of the IO Proc using DosQueryProcAddr.
  1580.      */
  1581.  
  1582.     ulReturnCode = DosQueryProcAddr ( hDLLModule,           // handle to MIDI module
  1583.                                       0,                 // get entry point
  1584.                                       "IOProc_Entry",       // ASCII procedure name
  1585.                                       (PFN *) &pIOProc );   // addr of IO Proc.
  1586.  
  1587.     if ( ulReturnCode != NO_ERROR )
  1588.     {
  1589.          /*
  1590.           * Could not obtain procedure address
  1591.           */
  1592.  
  1593.          WinMessageBox( HWND_DESKTOP,
  1594.                         hwnd,
  1595.                         "Could not obtain IO Procedure address. Please contact author.",
  1596.                         "Install Temporary IO Procedure",
  1597.                         (HMODULE) NULL,
  1598.                         (ULONG) MB_OK | MB_MOVEABLE |
  1599.                                 MB_ERROR );
  1600.          return ( TRUE );
  1601.     }
  1602.  
  1603.     /*
  1604.      *  Ask user for the FOURCC of this temporary IO Procedure to install.
  1605.      */
  1606.  
  1607.     ulReturnCode = WinDlgBox ( HWND_DESKTOP,
  1608.                                (HWND) hwnd,
  1609.                                (PFNWP) GetFOURCCDialogProc,
  1610.                                (HMODULE) NULL,
  1611.                                GET_FOURCC,   // dialog template identity
  1612.                                (PVOID) NULL);
  1613.  
  1614.     if (Cancel == TRUE)
  1615.     {
  1616.            WinMessageBox( HWND_DESKTOP,
  1617.                           hwnd,
  1618.                          "Installation of Temporary IO Procedure failed.",
  1619.                          "Installed Temporary IO Procedure",
  1620.                           (HMODULE) NULL,
  1621.                           (ULONG) MB_OK | MB_MOVEABLE |
  1622.                           MB_ERROR );
  1623.         return (TRUE);
  1624.     } /* endif */
  1625.     fccIOProc = mmioStringToFOURCC ( szFOURCC, 0 ) ;
  1626.  
  1627.     ioReturnCode = mmioInstallIOProc ( fccIOProc,          // 4 char code
  1628.                                        pIOProc,            // addr of IOProc
  1629.                                        MMIO_INSTALLPROC ); // install it
  1630.  
  1631.     if ( ioReturnCode == NULL )
  1632.     {
  1633.          /*
  1634.           * Could not install IO procedure using mmioInstallIOProc.
  1635.           */
  1636.  
  1637.          WinMessageBox( HWND_DESKTOP,
  1638.                         hwnd,
  1639.                         "MMIO failed to install IO Procedure. Please contact author.",
  1640.                         "Install Temporary IO Procedure",
  1641.                         (HMODULE) NULL,
  1642.                         (ULONG) MB_OK | MB_MOVEABLE | MB_ERROR );
  1643.          return ( TRUE );
  1644.     }
  1645.  
  1646.     /*
  1647.      *  If we got all the way here, then we successfully installed the
  1648.      *  temporary IO procedure.
  1649.      */
  1650.  
  1651.     return ( FALSE );
  1652.  
  1653. }
  1654.  
  1655. MRESULT EXPENTRY QueryAllDialogProc( HWND   hwnd,
  1656.                                      USHORT msg,
  1657.                                      MPARAM mp1,
  1658.                                      MPARAM mp2 )
  1659. {
  1660.     CHAR          szBuffer[ sizeof( FOURCC ) + MAX_FILENAME_SIZE + 4 ];
  1661.     LONG          lNumIOProcs;
  1662.     MMFORMATINFO  mmFormatInfo;
  1663.     PMMFORMATINFO pmmFormatInfoArray;
  1664.     PSZ           pszFourccString;
  1665.     ULONG         ulReturnCode;
  1666.     LONG          lFormatsRead;
  1667.     LONG          index;
  1668.     LONG          lBytesRead;
  1669.  
  1670.     switch( msg )
  1671.     {
  1672.  
  1673.          case WM_INITDLG :
  1674.  
  1675.               /*
  1676.                * Call mmioQueryFormatCount, which will return the number
  1677.                * of formats which are supported.
  1678.                */
  1679.  
  1680.               memset( &mmFormatInfo,
  1681.                       '\0',
  1682.                       sizeof(MMFORMATINFO) );
  1683.  
  1684.               mmFormatInfo.ulMediaType |= MMIO_MEDIATYPE_IMAGE;
  1685.  
  1686.               ulReturnCode = mmioQueryFormatCount ( &mmFormatInfo,
  1687.                                                     &lNumIOProcs,
  1688.                                                     0,
  1689.                                                     0 );
  1690.  
  1691.               if( ulReturnCode != MMIO_SUCCESS )
  1692.               {
  1693.                    /*
  1694.                     * Error - mmioQueryFormatCount failed.
  1695.                     */
  1696.  
  1697.                    break;
  1698.               }
  1699.  
  1700.               /*
  1701.                * Allocate enough memory for n number of FormatInfo blocks
  1702.                */
  1703.  
  1704.               pmmFormatInfoArray = malloc (lNumIOProcs * sizeof( MMFORMATINFO ) );
  1705.  
  1706.               if( pmmFormatInfoArray == NULL )
  1707.               {
  1708.                    /*
  1709.                     * Could not allocate enough memory for mmFormatInfo array.
  1710.                     */
  1711.  
  1712.                    break;
  1713.               }
  1714.  
  1715.               /*
  1716.                * call mmioGetFormats to get info on the formats supported.
  1717.                */
  1718.  
  1719.               ulReturnCode = mmioGetFormats( &mmFormatInfo,
  1720.                                              lNumIOProcs,
  1721.                                              pmmFormatInfoArray,
  1722.                                              &lFormatsRead,
  1723.                                              0,
  1724.                                              0 );
  1725.  
  1726.               if( ulReturnCode != MMIO_SUCCESS )
  1727.               {
  1728.                    /*
  1729.                     *  mmioGetFormats failed.
  1730.                     */
  1731.  
  1732.                    break;
  1733.               }
  1734.  
  1735.               if( lFormatsRead != lNumIOProcs )
  1736.               {
  1737.                    /*
  1738.                     * Error in MMIO - number of formats read in by
  1739.                     * mmioGetFormats is not equal to number of formats
  1740.                     * found by mmioQueryFormatCount.
  1741.                     */
  1742.  
  1743.                    break;
  1744.               }
  1745.  
  1746.               pszFourccString = malloc ( 4 );
  1747.  
  1748.               /*
  1749.                * Fill listbox entries with correct info.
  1750.                */
  1751.  
  1752.               for ( index = 0; index <lNumIOProcs; index++ )
  1753.               {
  1754.  
  1755.                    mmioGetFormatName(pmmFormatInfoArray, szBuffer, &lBytesRead, 0L, 0L);
  1756.                    FourccToString ( pmmFormatInfoArray->fccIOProc,
  1757.                                    pszFourccString );
  1758.  
  1759.                    /* Insert NULL string terminator */
  1760.  
  1761.                    *( szBuffer + lBytesRead ) = (CHAR)NULL;
  1762.  
  1763.                    WinSendMsg( WinWindowFromID( hwnd,
  1764.                                QUERY_ALL_LIST_BOX_ENTRIES),
  1765.                                LM_INSERTITEM,
  1766.                                (MPARAM) LIT_END,
  1767.                                szBuffer);  // buffer to insert into entry
  1768.  
  1769.                    /*
  1770.                     *  advance to next entry in mmFormatInfo array
  1771.                     */
  1772.  
  1773.                    pmmFormatInfoArray++;
  1774.               }
  1775.               return( (MRESULT) 0);
  1776.          break;
  1777.  
  1778.          case WM_CLOSE :
  1779.  
  1780.               WinDismissDlg( hwnd, TRUE );  /* Removes the dialog box    */
  1781.               WinPostMsg( hwnd, WM_QUIT, 0L, 0L );  /* Cause termination */
  1782.               return (MRESULT) FALSE;
  1783.          break;
  1784.  
  1785.          case WM_HELP :
  1786.               WinSendMsg ( hwndHelpInstance,
  1787.                            HM_DISPLAY_HELP,
  1788.                            MPFROMLONG ( 1 ),
  1789.                            MPFROMSHORT ( HM_RESOURCEID ) );
  1790.  
  1791.               return( 0 );
  1792.          break;
  1793.          case WM_COMMAND :
  1794.               /*
  1795.                * To get which pushbutton was pressed the SHORT1FROMMP macro
  1796.                * is used.
  1797.                */
  1798.               switch (SHORT1FROMMP(mp1))
  1799.               {
  1800.  
  1801.                    case QUERY_ALL_LIST_BOX_OK:
  1802.                         WinSendMsg ( hwnd, WM_CLOSE, (MPARAM) NULL, (MPARAM) NULL);
  1803.                         return( (MRESULT) FALSE);
  1804.                    break;
  1805.  
  1806.                    case QUERY_ALL_LIST_BOX_CANCEL:   /* user selected "Cancel"  */
  1807.                         WinSendMsg( hwnd, WM_CLOSE, (MPARAM) NULL, (MPARAM) NULL);
  1808.                    break;
  1809.  
  1810.                    case QUERY_ALL_LIST_BOX_HELP:
  1811.                         WinSendMsg (hwndHelpInstance,
  1812.                                     HM_HELP_INDEX,
  1813.                                     MPVOID,
  1814.                                     MPVOID);
  1815.                   break;
  1816.  
  1817.                    default:
  1818.                    break;
  1819.  
  1820.                }  /* End of Command Switch */
  1821.                return( (MRESULT) 0);
  1822.          break;
  1823.  
  1824.          default:
  1825.                return( WinDefDlgProc( hwnd, msg, mp1, mp2));
  1826.          break;
  1827.  
  1828.     }  /* End of msg Switch */
  1829.  
  1830.     return( (MRESULT) FALSE);
  1831.  
  1832. }
  1833.  
  1834. /*************************************************************************
  1835.  * Name        : InitializeHelp
  1836.  *
  1837.  * Description : This procedure will set up the initial values in the
  1838.  *               global help structure.  This help structure will then
  1839.  *               be passed on to the Help Manager when the Help Instance
  1840.  *               is created.  The handle to the Help Instance will be
  1841.  *               kept for later use.
  1842.  *
  1843.  * Concepts    : None.
  1844.  *
  1845.  * MME API's   : None.
  1846.  *
  1847.  * Parameters  : None.
  1848.  *
  1849.  * Return      : TRUE - error encountered
  1850.  *               FALSE - no errors encountered - help instance created!
  1851.  *
  1852.  *************************************************************************/
  1853.  
  1854.  
  1855. VOID InitializeHelp( HWND hwndFrame)
  1856. {
  1857.  
  1858.     HELPINIT hini;
  1859.     fHelpEnabled = FALSE;
  1860.     /* if we return because of an error, Help will be disabled */
  1861.  
  1862.     /* initialize help init structure */
  1863.  
  1864.     hini.cb = sizeof(HELPINIT);
  1865.     hini.ulReturnCode = 0;
  1866.     hini.pszTutorialName = (PSZ)NULL;   /* if tutorial added, add name here */
  1867.     hini.phtHelpTable = (PHELPTABLE)MAKELONG(MMBROWSER_HELP_TABLE, 0xFFFF);
  1868.     hini.hmodHelpTableModule = 0L;
  1869.     hini.hmodAccelActionBarModule = 0L;
  1870.     hini.idAccelTable = 0L;
  1871.     hini.idActionBar = 0L;
  1872.     hini.pszHelpWindowTitle = "MMBrowser Help";
  1873.     hini.fShowPanelId = CMIC_HIDE_PANEL_ID;
  1874.     hini.pszHelpLibraryName = "MMBROWSE.HLP";
  1875.  
  1876.     /* creating help instance */
  1877.  
  1878.     hwndHelpInstance = WinCreateHelpInstance(hab, &hini);
  1879.  
  1880.     if(!hwndHelpInstance || hini.ulReturnCode)
  1881.     {
  1882.         return;
  1883.     }
  1884.  
  1885.     /* associate help instance with main frame */
  1886.  
  1887.     if(!WinAssociateHelpInstance(hwndHelpInstance, hwndFrame))
  1888.     {
  1889.         return;
  1890.  
  1891.     }
  1892.  
  1893.     fHelpEnabled = TRUE;
  1894.     }
  1895.  
  1896. /****************************************************************
  1897.  *  Dialog procedure for the About dialog box
  1898.  *--------------------------------------------------------------
  1899.  *
  1900.  *  Name:    AboutDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  1901.  *
  1902.  *  Purpose: Handles all the messages associated with the About Box
  1903.  *
  1904.  *  Usage:   Called for each message sent to the About Box dialog box.
  1905.  *
  1906.  *  Method:  The about box only has a button control so this routine
  1907.  *           only processes WM_COMMAND messages. Any WM_COMMAND
  1908.  *           posted must have come from the Ok button so we dismiss
  1909.  *           the dialog upon receiving it.
  1910.  *
  1911.  *  Returns: Dependent upon message sent
  1912.  *
  1913.  ****************************************************************/
  1914. MRESULT EXPENTRY AboutDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
  1915. {
  1916.    MRESULT sRC;
  1917.  
  1918.    switch(msg)
  1919.    {
  1920.       case WM_INITDLG:
  1921. //         FixSysMenu(hwnd);
  1922.          return (MRESULT)0L;
  1923.  
  1924.       case WM_COMMAND:
  1925.          WinDismissDlg(hwnd, TRUE);
  1926.          return (MRESULT)0L;
  1927.  
  1928.       default:
  1929.          sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  1930.          return sRC;
  1931.    }
  1932.    return (MRESULT)0L;
  1933. }
  1934.  
  1935. /****************************************************************
  1936.  *  FixSysMenu procedure
  1937.  *--------------------------------------------------------------
  1938.  *
  1939.  *  Name:    FixSysMenu(HWND hwndDlg)
  1940.  *
  1941.  *  Purpose: This routine removes the Restore, Size, Minimize, and
  1942.  *           Maximize options from the system menu of a dialog.
  1943.  *
  1944.  *  Usage
  1945.  *
  1946.  *  Method:  Called during the WM_INITDLG of a dialog procedure.
  1947.  *
  1948.  *  Returns: VOID
  1949.  *
  1950.  ****************************************************************/
  1951. VOID FixSysMenu(HWND hwndDlg)
  1952. {
  1953.    HWND hwndMenu;                      /* Handle to system menu */
  1954.  
  1955.    hwndMenu = WinWindowFromID(hwndDlg, FID_SYSMENU);
  1956.  
  1957.    WinSendMsg(hwndMenu,  /* Delete Restore from the system menu */
  1958.               MM_DELETEITEM,
  1959.               MPFROM2SHORT(SC_RESTORE, TRUE),
  1960.               MPFROMP(NULL));
  1961.  
  1962.    WinSendMsg(hwndMenu,     /* Delete Size from the system menu */
  1963.               MM_DELETEITEM,
  1964.               MPFROM2SHORT(SC_SIZE, TRUE),
  1965.               MPFROMP(NULL));
  1966.  
  1967.    WinSendMsg(hwndMenu, /* Delete Minimize from the system menu */
  1968.               MM_DELETEITEM,
  1969.               MPFROM2SHORT(SC_MINIMIZE, TRUE),
  1970.               MPFROMP(NULL));
  1971.  
  1972.    WinSendMsg(hwndMenu, /* Delete Maximize from the system menu */
  1973.               MM_DELETEITEM,
  1974.               MPFROM2SHORT(SC_MAXIMIZE, TRUE),
  1975.               MPFROMP(NULL));
  1976.    return;
  1977.  
  1978. }
  1979.  
  1980. //*******************************************************************
  1981. // Function : DoConvert
  1982. //
  1983. //
  1984. // Description :
  1985. //    This function provides a simple method of converting an
  1986. //    image from one format to another, so long as both are
  1987. //    supported by OS/2 MME MMIO IOProcs.  It uses MMIO
  1988. //    functions to transparently open, read and write file headers,
  1989. //    read and write image data, and close the files.
  1990. //
  1991. //    This function will also signal the progress of the conversion
  1992. //    so that this progress can illustrated to a user.
  1993. //
  1994. // Parameters (all input, unchanged by function):
  1995. //      Source file name
  1996. //      Source file IOProc handler
  1997. //      Target file name
  1998. //      Target file IOProc handler
  1999. //
  2000. // Return Code:
  2001. //      0 if successful, or
  2002. //        ERR_CANCELLED
  2003. //        ERR_SOURCEOPEN
  2004. //        ERR_TARGETOPEN
  2005. //        ERR_SOURCEHEADER
  2006. //        ERR_TARGETHEADER
  2007. //        ERR_SOURCEWRITE
  2008. //        ERR_TARGETWRITE
  2009. //        ERR_SOURCECLOSE
  2010. //        ERR_TARGETCLOSE
  2011. //        ERR_MEMORY
  2012. //
  2013. //********************************************************************
  2014. BOOL DoConvert(
  2015.    PSZ    pszSource,          // Source file name
  2016.    FOURCC fccSourceIOProc,
  2017.    PSZ    pszTarget,
  2018.    FOURCC fccTargetIOProc)    //
  2019.    {
  2020.    MMIOINFO      mmioinfoSource;
  2021.    MMIOINFO      mmioinfoTarget;
  2022.    HMMIO         hmmioSource;
  2023.    HMMIO         hmmioTarget;
  2024.    ULONG         ulImageHeaderLength;
  2025.    MMIMAGEHEADER mmImgHdr;
  2026.    ULONG         ulBytesRead;
  2027.    ULONG         dwNumRowBytes;
  2028.    PBYTE         pRowBuffer;
  2029.    ULONG         dwRowCount;
  2030.    ULONG         dwWidth;
  2031.    ULONG         dwHeight;
  2032.    ULONG         dwPadBytes;
  2033.    ULONG         dwRowBits;
  2034.    LONG          rc;
  2035.    LONG          rcSrcQueryCount = 0;
  2036.    LONG          rcTrgQueryCount = 0;
  2037.    LONG          rcTrgSetImage   = 0;
  2038.    ULONG         iIndex, iCount, iCount2;
  2039.  
  2040.  
  2041.  
  2042.    /*******************************/
  2043.    /* Set up/open the SOURCE file */
  2044.    /*******************************/
  2045.    memset (&mmioinfoSource, 0L, sizeof (MMIOINFO));
  2046.    mmioinfoSource.fccIOProc = fccSourceIOProc;
  2047.    mmioinfoSource.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
  2048.    memset (&mmioinfoTarget, 0L, sizeof (MMIOINFO));
  2049.    mmioinfoTarget.fccIOProc = fccTargetIOProc;
  2050.    mmioinfoTarget.ulTranslate = MMIO_TRANSLATEHEADER | MMIO_TRANSLATEDATA;
  2051.  
  2052.    hmmioSource = mmioOpen ((PSZ)pszSource, &mmioinfoSource,
  2053.                           MMIO_READ | MMIO_DENYWRITE
  2054.                         | MMIO_NOIDENTIFY);
  2055.  
  2056.    if (!hmmioSource)
  2057.       return (ERR_SOURCEOPEN);
  2058.  
  2059.    /*******************************/
  2060.    /* Set up/open the TARGET file */
  2061.    /*******************************/
  2062.  
  2063.  
  2064.    hmmioTarget = mmioOpen ((PSZ)pszTarget,
  2065.                            &mmioinfoTarget,
  2066.                            MMIO_CREATE | MMIO_WRITE |
  2067.                            MMIO_DENYWRITE | MMIO_NOIDENTIFY);
  2068.  
  2069.    if (!hmmioTarget)
  2070.       {
  2071.       mmioClose (hmmioSource, 0L);
  2072.       return (ERR_TARGETOPEN);
  2073.       }
  2074.  
  2075.    // find out if source has multiple image support
  2076.    rcSrcQueryCount = mmioSendMessage(hmmioSource, MMIOM_QUERYIMAGECOUNT, (LONG)&iCount, (LONG)0);
  2077.    if (rcSrcQueryCount) iCount = 1;
  2078.  
  2079.    // find out if the target has multiple image support
  2080.    rcTrgQueryCount = mmioSendMessage(hmmioTarget, MMIOM_QUERYIMAGECOUNT, (LONG)&iCount2, (LONG)0);
  2081.  
  2082.    for (iIndex=0; iIndex<iCount; iIndex++) { /* loop through known images */
  2083.  
  2084.       if (!rcSrcQueryCount && !rcTrgQueryCount) {  /* if Both support images */
  2085.  
  2086.          /* Determine if the target can write arrays, and if not */
  2087.          /* then write the the default image from the source     */
  2088.  
  2089.          if (rcTrgSetImage && iIndex > 0) break;  /* Target Can't Write array */
  2090.  
  2091.          /* Now, determine if the target can write arrays */
  2092.          rcTrgSetImage = mmioSendMessage (hmmioTarget, MMIOM_SETIMAGE, (LONG)iIndex, (LONG)0);
  2093.  
  2094.          if (!rcTrgSetImage) mmioSendMessage (hmmioSource, MMIOM_SETIMAGE, (LONG)iIndex, (LONG)0);
  2095.  
  2096.       } else if (!rcSrcQueryCount) {      /* Source does but target doesn't */
  2097.          /* Use the default image from source to copy to target */
  2098.          /* so do set the index of the first, let it default    */
  2099.          /* get the base photo cd image (2 of 5)                */
  2100.          if (iIndex > 0) break;
  2101.       } else if (!rcTrgQueryCount) {      /* Target does but source doesn't */
  2102.          /* Use the only image to do a default write to target */
  2103.       } else {
  2104.          /* neither do: just write one image from here to there */
  2105.       }
  2106.  
  2107.       /****************************/
  2108.       /* Obtain the SOURCE HEADER */
  2109.       /****************************/
  2110.       mmioQueryHeaderLength (hmmioSource, (PLONG)&ulImageHeaderLength, 0L, 0L);
  2111.       if (ulImageHeaderLength != sizeof (MMIMAGEHEADER))
  2112.          /* We have a problem.....possibly incompatible versions */
  2113.          {
  2114.          mmioClose (hmmioSource, 0L);
  2115.          mmioClose (hmmioTarget, 0L);
  2116.          return (ERR_SOURCEHEADER);
  2117.          }
  2118.  
  2119.       rc = (LONG)mmioGetHeader (hmmioSource, &mmImgHdr,
  2120.                      (LONG)sizeof (MMIMAGEHEADER), (PLONG)&ulBytesRead,
  2121.                      0L, 0L);
  2122.  
  2123.       if (rc != MMIO_SUCCESS)
  2124.          /* Header unavailable */
  2125.          {
  2126.          mmioClose (hmmioSource, 0L);
  2127.          mmioClose (hmmioTarget, 0L);
  2128.          return (ERR_SOURCEHEADER);
  2129.          }
  2130.  
  2131.  
  2132.       /*************************/
  2133.       /* Set the TARGET HEADER */
  2134.       /*************************/
  2135.       mmioQueryHeaderLength (hmmioTarget, (PLONG)&ulImageHeaderLength, 0L, 0L);
  2136.       if (ulImageHeaderLength != sizeof (MMIMAGEHEADER))
  2137.          {
  2138.          /* We have a problem.....possibly incompatible versions */
  2139.          mmioClose (hmmioSource, 0L);
  2140.          mmioClose (hmmioTarget, 0L);
  2141.          return (ERR_TARGETHEADER);
  2142.          }
  2143.  
  2144.       /* Use the SAME data as came from the SOURCE FILE.  It must be
  2145.          compatible with the OS/2 bitmaps, etc.   */
  2146.       rc = (LONG)mmioSetHeader (hmmioTarget, &mmImgHdr,
  2147.                      (LONG)sizeof (MMIMAGEHEADER), (PLONG)&ulBytesRead,
  2148.                      0L, 0L);
  2149.  
  2150.       if (rc != MMIO_SUCCESS)
  2151.          /* Header unavailable */
  2152.          {
  2153.          mmioClose (hmmioSource, 0L);
  2154.          mmioClose (hmmioTarget, 0L);
  2155.          return (ERR_TARGETHEADER);
  2156.          }
  2157.  
  2158.  
  2159.       /* Determine the number of bytes required, per row */
  2160.       /*      PLANES MUST ALWAYS BE = 1 */
  2161.       dwHeight = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cy;
  2162.       dwWidth  = mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cx;
  2163.       dwRowBits = dwWidth * mmImgHdr.mmXDIBHeader.BMPInfoHeader2.cBitCount;
  2164.       dwNumRowBytes = dwRowBits >> 3;
  2165.  
  2166.       /* Account for odd bits used in 1bpp or 4bpp images that are NOT on byte boundaries. */
  2167.       if (dwRowBits % 8)
  2168.          dwNumRowBytes++;
  2169.  
  2170.       /* Ensure the row length in bytes accounts for byte padding.  All bitmap data rows
  2171.          must are aligned on LONG/4-BYTE boundaries.   The data FROM an IOProc
  2172.          should always appear in this form. */
  2173.       dwPadBytes = (dwNumRowBytes % 4);
  2174.       if (dwPadBytes)
  2175.          dwNumRowBytes += 4 - dwPadBytes;
  2176.  
  2177.       /* Allocate space for one row */
  2178.       if (DosAllocMem((PVOID)&pRowBuffer, (ULONG)dwNumRowBytes, fALLOC))
  2179.          {
  2180.          mmioClose (hmmioSource, 0L);
  2181.          mmioClose (hmmioTarget, 0L);
  2182.          return(ERR_MEMORY);
  2183.          }
  2184.  
  2185.       for (dwRowCount = 0;
  2186.            dwRowCount < dwHeight;
  2187.            dwRowCount++)
  2188.          {
  2189.          ulBytesRead = (ULONG)mmioRead (hmmioSource, pRowBuffer, dwNumRowBytes);
  2190.  
  2191.          if (ulBytesRead)
  2192.             mmioWrite (hmmioTarget, pRowBuffer, (ULONG)ulBytesRead);
  2193.          else
  2194.             break;
  2195.  
  2196.                                  }
  2197.    }
  2198.  
  2199.    mmioClose (hmmioSource, 0L);
  2200.    mmioClose (hmmioTarget, 0L);
  2201.  
  2202.    DosFreeMem(pRowBuffer);
  2203.  
  2204.  
  2205.    return(0);
  2206.    }
  2207.    VOID SaveFile (HWND hwndClient, PSZ pszSource, FOURCC fccSourceIOProc )
  2208.    {
  2209.    FILEDLG fdg;
  2210.    HWND hwndDlg;
  2211.    INT    Result;
  2212.    PSZ    Result1;
  2213.    CHAR Test[STRING_LENGTH];
  2214.    CHAR VID[]=".VID";
  2215.    CHAR DIB[]=".DIB";
  2216.    CHAR PCX[]=".PCX";
  2217.    CHAR TGA[]=".TGA";
  2218.    CHAR TIF[]=".TIF";
  2219.    CHAR RDI[]=".RDI";
  2220.    CHAR BMP[]=".BMP";
  2221.    FOURCC fccTargetIOProc;
  2222.  
  2223.    memset(&fdg, 0, sizeof(FILEDLG));
  2224.    fdg.cbSize = sizeof(FILEDLG);
  2225.    fdg.fl = FDS_SAVEAS_DIALOG | FDS_CENTER;
  2226.    fdg.pszTitle = "The Save File Dialog";
  2227.    strcpy(fdg.szFullFile, "*.bmp");
  2228.    hwndDlg= WinFileDlg(HWND_DESKTOP, hwndClient, (PFILEDLG) &fdg);
  2229.    if (hwndDlg && (fdg.lReturn == DID_OK))
  2230.    {
  2231.                          Result1 = strchr(fdg.szFullFile,'.');
  2232.                          if(Result1 == NULL)
  2233.                             Result1 = "BMP";
  2234.  
  2235.                          strcpy(Test,Result1);
  2236.  
  2237.                          strupr(Test);
  2238.                               if(strcmp(Test, VID) == 0 && mmioFOURCC('M','M','O','T') > 0)
  2239.                               fccTargetIOProc = mmioFOURCC('M','M','O','T');
  2240.                          else if(strcmp(Test, RDI) == 0 && mmioFOURCC('R','D','I','B') > 0)
  2241.                               fccTargetIOProc = mmioFOURCC('R','D','I','B');
  2242.                          else if(strcmp(Test, PCX) == 0 && mmioFOURCC('P','C','X','C') > 0)
  2243.                               fccTargetIOProc = mmioFOURCC('P','C','X','C');
  2244.                          else if(strcmp(Test, BMP) == 0 && mmioFOURCC('O','S','2','0') > 0)
  2245.                               fccTargetIOProc = mmioFOURCC('O','S','2','0');
  2246.                          else if(strcmp(Test, DIB) == 0 && mmioFOURCC('W','1','3','0') > 0)
  2247.                               fccTargetIOProc = mmioFOURCC('W','1','3','0');
  2248.                          else if(strcmp(Test, TGA) == 0 && mmioFOURCC('T','G','A','U') > 0)
  2249.                               fccTargetIOProc = mmioFOURCC('T','G','A','U');
  2250.                          else if(strcmp(Test, TIF) == 0 && mmioFOURCC('T','I','F','U') > 0)
  2251.                               fccTargetIOProc = mmioFOURCC('T','I','F','U');
  2252.                          else
  2253.                          {
  2254.                          WinMessageBox( HWND_DESKTOP,
  2255.                          HWND_DESKTOP,
  2256.                          "Will Save As a OS2.BMP",
  2257.                          "Save As....",
  2258.                          (HMODULE) NULL,
  2259.                          (ULONG) MB_OK | MB_MOVEABLE );
  2260.                           fccTargetIOProc = mmioFOURCC('O','S','2','0');
  2261.                           }
  2262.                           MakeItBusy(TRUE);
  2263.                           DoConvert(pszSource, fccSourceIOProc, fdg.szFullFile, fccTargetIOProc);
  2264.                           MakeItBusy(FALSE);
  2265.    }
  2266. }
  2267.