home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / CMD / SVGAINST / SVGA.C < prev    next >
C/C++ Source or Header  |  1995-04-14  |  89KB  |  2,617 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  4. /*                                                                           */
  5. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  6. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  7. /*    drivers. You may use this code in accordance with the IBM License      */
  8. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  9. /*    Copyright statement may not be removed.                                */
  10. /*                                                                           */
  11. /*****************************************************************************/
  12. /*SCCSID = %%s %%s %%s */
  13.  
  14. /****************************************************************************/
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*                                                                          */
  18. /****************************************************************************/
  19.  
  20. /*********************************************************************/
  21. /*                                                                   */
  22. /*  SOURCE FILE NAME: svga.c                                         */
  23. /*                                                                   */
  24. /*  DESCRIPTIVE NAME: Main source file for S3 SVGA action routine DLL*/
  25. /*                                                                   */
  26. /*  FUNCTION: This contains the entry points for SVGA.DLL            */
  27. /*                                                                   */
  28. /*********************************************************************/
  29. #define  INCL_DOS
  30. #define  INCL_DOSERRORS
  31. #define  INCL_DOSPROCESS
  32. #define  INCL_DOSRESOURCES
  33. #define  INCL_WIN
  34. #define  INCL_GPIDISPPRF
  35.  
  36. #include <math.h>
  37. #include <stdio.h>
  38. #include <string.h>
  39. #include <memory.h>
  40. #include <malloc.h>
  41. #include <stdlib.h>
  42. #include <stddef.h>
  43. #include <ctype.h>
  44. #include <time.h>
  45. #include <process.h>
  46. #include "dispmain.h"
  47. #include "dispact.h"
  48. #include "svga.h"
  49.  
  50. /********************************************
  51.  *private function declarations for this module
  52.  *********************************************/
  53. VOID    APIENTRY svga_ParseAdapter(PDSPINSTL_CHAIN pInstalChain,
  54.                                    PADAPTERENTRY pAdpentry);
  55. VOID    APIENTRY svga_ParseMonitor(PDSPINSTL_CHAIN pInstalChain,
  56.                                    PVIDEOENTRY pVidentry);
  57. ULONG   APIENTRY svga_WriteResolution(PSZ pszConfig,PVIDEOENTRY pVidentry);
  58. ULONG   APIENTRY svga_WriteNewResolution(PVIDEOENTRY pVidEntry);
  59. ULONG   APIENTRY svga_GetCurrentResolution(VOID);
  60. INT     APIENTRY svga_WriteResolIni(PINIPARMS);
  61. INT     APIENTRY svga_WriteInterlIni(PINIPARMS);
  62. INT     APIENTRY svga_WriteRefrIni(PINIPARMS);
  63. ULONG   APIENTRY svga_UpWriteIni(PSZ pszApplication,PSZ pszKey,PSZ pszString);
  64. MRESULT EXPENTRY WaitSvgaDlgProc(HWND hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2);
  65. //@TM  feature
  66. MRESULT EXPENTRY SelectSvgaUtilDlgProc(HWND hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2);
  67. MRESULT EXPENTRY SvgaUtilDlgProc(HWND hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2);
  68. APIRET  CreateSvgaTmpBat(CHAR *achBuffer );
  69. VOID    InitHelp( HWND *phwndHelpInstance );
  70. //@TM
  71. BOOL    OpenResolutionsFile(PRESOLUTIONS pResolutions,PULONG pulCount);
  72. APIRET  GetResolutionsData(PRESOLUTIONS pResolutions,
  73.                            PRESOLUTIONS pResolutionsToDisplay,
  74.                            HWND hwnd,
  75.                            PDSPINSTL_CHAIN  pInstalChain,
  76.                            BOOL fUseDefault,
  77.                            PULONG pulCount,
  78.                            PFN pfnGetNext,
  79.                            BOOL *fShowResolutionsToUser);
  80. BOOL   ReadResolutionsFile(PRESOLUTIONS pResolutions,HFILE hf,PULONG pulCount);
  81. VOID   RunSvga(PVOID);
  82. PSZ    strip_white(PSZ pszString);
  83. BOOL   ValidateResolutions(PRESOLUTIONS pResolutions,
  84.                            PRESOLUTIONS pResolutionsToDisplay,
  85.                            PDSPINSTL_CHAIN   pDspInstlHeadChain,
  86.                            BOOL fUseDefault,
  87.                            PULONG pulCount,
  88.                            ULONG ulCount,
  89.                            PFN pfnGetNext);
  90. BOOL   CompareResolutions(PSZ pszResolution,PRESOLUTIONS pSupportedResolutions,
  91.                             ULONG ulCount);
  92. APIRET APIENTRY GetDllHandle( PHMODULE phmodResource);
  93. VOID   APIENTRY WaitThread(PVOID);
  94. VOID   StringToResolution(PSZ pszString,PRESOLUTIONDATA pResolutionData);
  95. VOID   APIENTRY BuildSvgaNodes(PDSPINSTL_CHAIN pDspinstlChain,
  96.                                PRESOLUTIONS pSelectedResolutions,
  97.                                ULONG ulCount,
  98.                                LONG lDesignatedResolution);
  99. PSZ             GetSelectedResolution(PRESOLUTIONS pResolution,ULONG ulCount);
  100. PDSPINSTL_CHAIN GetLastElement(PDSPINSTL_CHAIN pDspInstlChain);
  101. USHORT APIENTRY16 Dos16GetPrty(USHORT usScope,PUSHORT pusPriority,USHORT pid);
  102. VOID   SvgaReportError(ULONG rc,PSZ pszMsg,HWND hwndOwner);
  103. VOID   svgaLog(PSZ pszMsg);
  104. USHORT SvgaMessageBox(ULONG rc,PSZ pszMsg,HWND hwndOwner);
  105. PSZ    GetDesignatedResolution(PDSPINSTL_CHAIN pChain,ULONG ulCount,
  106.                                LONG lDesignatedResolution);
  107.  
  108.                                                    /* Amol; D58319;12/09/92*/
  109. BOOL   CheckSVGAMem (PRESOLUTIONS, ULONG);
  110. BOOL   IsResolutionOver1Mg(PSZ pszResolution,PRESOLUTIONDATA  pResolution);
  111.  
  112. /*****************************************
  113.  *private data declarations
  114.  *****************************************/
  115. PSZ  pszConfig        = "MONITOR.CFG";       //name of  monitor file to pass
  116. PSZ  pszAdapter       = "ADAPTER.CFG";       //name of  adapter file to pass
  117. PSZ  pszDefMonKey;                           //default  monitor key
  118. PSZ  pszSelMonKey;                           //selected monitor key
  119. PSZ  pszDefAdpKey;
  120. PSZ  pszSelAdpKey;
  121. PSZ  pszResolutionString = NULL;
  122. RESOLUTIONS   ResolutionsArray[MAX_RESOLUTIONS];
  123. RESOLUTIONS   ResolutionsToDisplay[MAX_RESOLUTIONS];
  124. HMODULE hmodResource;
  125. BOOL    f1024K;                        /* Amol; Defect #58319; 12/09/92    */
  126. //@TMCHAR *szErrorMsg []=
  127. //@TM{
  128. //@TM   "A error has occurred reading the svgadata.pmi file",
  129. //@TM   "Unable to determine hardware configuration",
  130. //@TM   "Unable to resolve module handle",
  131. //@TM   "The current hardware configuration does not support the high resolution mode. \
  132. //@TM If you continue, your video support might be unusable.  Do you want to continue ?"
  133. //@TM};
  134.  
  135. CHAR   szResolution[SIZ_PARMS];
  136. CHAR   szInterLace [SIZ_PARMS];
  137. CHAR   szRefresh   [SIZ_PARMS];
  138. CHAR   szString1   [SIZ_PARMS];
  139. CHAR   szString2   [SIZ_PARMS];
  140. CHAR   szString3   [SIZ_PARMS];
  141.  
  142.  
  143. INIPARMS  IniParms [] =
  144. {
  145.      MONITOR_RES,      szResolution,szString1,svga_WriteResolIni,
  146.      MONITOR_VREFRESH, szRefresh   ,szString2,NULL,
  147.      MONITOR_INTERLACE,szInterLace ,szString3,NULL,
  148. };
  149. PFN  pfnLogFunction = NULL;
  150. TID  tidThread;
  151.  
  152. /****************************************************************\
  153.  *
  154.  *--------------------------------------------------------------
  155.  *
  156.  *  Name:Default_Primary
  157.  *
  158.  *  Purpose:This action routine handles svga specific routines that
  159.  *          need to be called from the display install utility for the
  160.  *          default primary selection.This routine does the following:
  161.  *        a)Gets a pointer to the head of the selected display install
  162.  *                 chain
  163.  *        b)Does the setup for the GetResolutionsData routine and calls it
  164.  *        c)If no error occurred call to have the resolutions displayed to
  165.  *          the user.
  166.  *        d)Call to have the linked list built,based upon the resoluition
  167.  *          the user has selected.
  168.  *
  169.  *
  170.  *  Returns:
  171.  *         Non-Zero -  Error occurred,User Aborted.
  172.  *          0        - Successful Operation,Continue
  173. \****************************************************************/
  174. LONG EXPENTRY Default_Primary(HWND hwnd,PDSPINSTL_GLOBAL_DATA pInstalData)
  175. {
  176.  
  177.     PRESOLUTIONS  pResolutions;
  178.     ULONG ulSelections = 0;
  179.     LONG lRetValue;
  180.     PDSPINSTL_CHAIN pHeadofChain;
  181.     BOOL fShowResolutionsToUser  = TRUE;
  182.     LONG lGetDesignated = -1;
  183.  
  184.     pfnLogFunction = pInstalData->pfnLogFunction;
  185.  
  186.     /*
  187.      * If resolution string passed in make it global
  188.      */
  189.  
  190.     if( pInstalData->pszResolutionString )
  191.     {
  192.        pszResolutionString = malloc(
  193.                                 strlen( pInstalData->pszResolutionString)
  194.                                   + 1);
  195.        strcpy( pszResolutionString, pInstalData->pszResolutionString );
  196.     }
  197.  
  198.     /*
  199.      *start at the head
  200.      *of the chain
  201.      */
  202.     if((*pInstalData->pfnNextElementRoutine)(&pHeadofChain,
  203.                                              CHAIN_HEAD,
  204.                                              NULL) )
  205.     {
  206.           return(CANCEL_OPERATION);
  207.     }
  208.  
  209.    /*
  210.     *set up to get the supported resolutions
  211.     */
  212.     memset(ResolutionsArray,0,sizeof(RESOLUTIONS) * MAX_RESOLUTIONS);
  213.     memset(ResolutionsToDisplay,0,sizeof(RESOLUTIONS) * MAX_RESOLUTIONS);
  214.     /*
  215.      *get the resolutions data,setting the default flag
  216.      *to true.
  217.      */
  218.     if((lRetValue = GetResolutionsData(ResolutionsArray,
  219.                                        ResolutionsToDisplay,
  220.                                        hwnd,pHeadofChain,
  221.                                        TRUE,
  222.                                        &ulSelections,
  223.                                        pInstalData->pfnNextElementRoutine,
  224.                                        &fShowResolutionsToUser) ))
  225.     {
  226.          if (lRetValue != CONTINUE_WITH_ERR)
  227.              return(lRetValue);
  228.     }
  229.  
  230.     if(fShowResolutionsToUser)
  231.     {
  232.          /*
  233.           *display the list of resolutions
  234.           */
  235.          if( lRetValue =  (*pInstalData->pfnSpecifyResolution)(hwnd,&ResolutionsToDisplay,
  236.                                                     ulSelections,
  237.                                                     FALSE) )
  238.          {
  239.                /*
  240.                 *user aborted
  241.                 */
  242.                return(lRetValue);
  243.          }
  244.     }
  245.     else
  246.     {
  247.           /*
  248.            *this should only be happening on speedway
  249.            *make sure the first one in our list is selected
  250.            */
  251.            lGetDesignated = 0;
  252.     }
  253.  
  254.  
  255.     /*
  256.      *build the key for the
  257.      *first node and set the next node to be the
  258.      *node that was selected
  259.      */
  260. //    BuildSvgaNodes(pHeadofChain,
  261. //                         ResolutionsToDisplay,
  262. //                         ulSelections,
  263. //                         lGetDesignated);
  264. //
  265.     return(lRetValue);
  266. }
  267.  
  268. /****************************************************************\
  269.  *
  270.  *--------------------------------------------------------------
  271.  *
  272.  *  Name:Default_Secondary
  273.  *
  274.  *  Purpose:This action routine handles the calling of the specify
  275.  *          adapter and specify monitor routines. The key that is
  276.  *          returned in the adapter structre is saved off so as to
  277.  *          used later while querying the .DSP files.
  278.  *
  279.  *
  280.  *
  281.  *  Usage:
  282.  *
  283.  *  Returns:
  284.  *          Non-Zero -  Error occurred,User Aborted.
  285.  *          0        - Successful Operation,Continue
  286. \****************************************************************/
  287. LONG EXPENTRY Default_Secondary(HWND hwnd,PDSPINSTL_GLOBAL_DATA pInstalData)
  288. {
  289.     ADAPTERENTRY adpentry;
  290.     VIDEOENTRY videntry;
  291.     LONG rc;
  292.     PDSPINSTL_CHAIN pDspChain;
  293.  
  294.  
  295.  
  296.     pfnLogFunction = pInstalData->pfnLogFunction;
  297.     /*
  298.      *start at the head
  299.      *of the chain
  300.      */
  301.     pDspChain = pInstalData->pHeadDspInstl_Chain;
  302.  
  303.     if((rc = (*pInstalData->pfnSpecifyVideoMonitor)(hwnd,pszConfig, &videntry)))
  304.     {
  305.         /*
  306.          *user aborted
  307.          */
  308.         return(CANCEL_OPERATION);
  309.     }
  310.     return(rc);
  311. }
  312. /****************************************************************\
  313.  *
  314.  *--------------------------------------------------------------
  315.  *
  316.  *  Name:Selected_Primary
  317.  
  318.  *  Purpose:This action routine handles svga specific routines that
  319.  *          need to be called from the display install utility for the
  320.  *          selected primary selection.This routine does the following:
  321.  *        a)Gets a pointer to the head of the selected display install
  322.  *                 chain
  323.  *        b)Does the setup for the GetResolutionsData routine and calls it
  324.  *        c)If no error occurred call to have the resolutions displayed to
  325.  *          the user.
  326.  *        d)Call to have the linked list built,based upon the resolution
  327.  *          the user has selected.
  328.  *        Note - Kenner
  329.  *        Changed the  usedefaultflag so that it is always true.
  330.  *        this will insure that only resolutions the hardware can support
  331.  *        are displayed to the customer.
  332.  *
  333.  *  Returns:
  334.  *          Non-Zero -  Error occurred,User Aborted.
  335.  *          0        - Successful Operation,Continue
  336. \****************************************************************/
  337. LONG EXPENTRY Selected_Primary(HWND hwnd,PDSPINSTL_GLOBAL_DATA pInstalData)
  338. {
  339.  
  340.     PRESOLUTIONS  pResolutions;
  341.     ULONG ulSelections = 0;
  342.     LONG lRetValue;
  343.     PDSPINSTL_CHAIN pHeadofChain;
  344.     BOOL fShowResolutionsToUser  = TRUE;
  345.     LONG lGetDesignated = -1;
  346.  
  347.  
  348.     pfnLogFunction = pInstalData->pfnLogFunction;
  349.  
  350.     /*
  351.      * If resolution string passed in make it global
  352.      */
  353.  
  354.     if( pInstalData->pszResolutionString )
  355.     {
  356.        pszResolutionString = malloc(
  357.                                 strlen( pInstalData->pszResolutionString)
  358.                                   + 1);
  359.        strcpy( pszResolutionString, pInstalData->pszResolutionString );
  360.     }
  361.  
  362.  
  363.     /*
  364.      *start at the head
  365.      *of the chain
  366.      */
  367.     if( (*pInstalData->pfnNextElementRoutine)(&pHeadofChain,
  368.                                               CHAIN_HEAD,
  369.                                               NULL) )
  370.     {
  371.           return(CANCEL_OPERATION);
  372.     }
  373.  
  374.    /*
  375.     *read in the resolutions file
  376.     */
  377.     memset(ResolutionsArray,0,sizeof(RESOLUTIONS) * MAX_RESOLUTIONS);
  378.     memset(ResolutionsToDisplay,0,sizeof(RESOLUTIONS) * MAX_RESOLUTIONS);
  379.     if((lRetValue = GetResolutionsData(ResolutionsArray,
  380.                                        ResolutionsToDisplay,
  381.                                        hwnd,pHeadofChain,
  382.                                        TRUE,
  383.                                        &ulSelections,
  384.                                        pInstalData->pfnNextElementRoutine,
  385.                                        &fShowResolutionsToUser) ))
  386.     {
  387.          if (lRetValue != CONTINUE_WITH_ERR)
  388.              return(lRetValue);
  389.     }
  390.     if(fShowResolutionsToUser)
  391.     {
  392.           if( lRetValue =  (*pInstalData->pfnSpecifyResolution)(hwnd,&ResolutionsToDisplay,
  393.                                                ulSelections,
  394.                                                FALSE) )
  395.           {
  396.                 return(lRetValue);
  397.  
  398.           }
  399.      }
  400.      else
  401.      {
  402.            /*
  403.             *this should only be happening on speedway
  404.             *make sure the first one in our list is selected
  405.             */
  406.             lGetDesignated = 0;
  407.      }
  408.  
  409.  
  410.  
  411.     /*
  412.      *build the key for the
  413.      *first node and set the next node to be the
  414.      *node that was selected
  415.      */
  416. //    BuildSvgaNodes(pHeadofChain,
  417. //                         ResolutionsToDisplay,
  418. //                         ulSelections,
  419. //                         lGetDesignated);
  420.     return(lRetValue);
  421. }
  422. /****************************************************************\
  423.  *
  424.  *--------------------------------------------------------------
  425.  *
  426.  *  Name:BuildSvgaNodes
  427.  *
  428.  *  Purpose:This routine will build the configuration node and the
  429.  *          associated key to look for in the dsp files.The next node
  430.  *          in the link will be set to the one that matches what the
  431.  *          user selected. The next link will be set to the first
  432.  *          node that does not have a resoulution associated with
  433.  *          it.
  434.  *          Updated 8-18-92 -Kenner
  435.  *          Check the first node that does not have a resolution
  436.  *          to see if HI-RESOLUTION was selected,if so reset the
  437.  *          key to pick up the hires fonts.
  438.  *
  439.  *         Head      ->      pszKey  = "C600x400x256"
  440.  *         NextNode  ->      pszKey  = "600x400x256"
  441.  *         NextNode  ->      pszKey  = "FONT_HI" || "FONT_LO"
  442.  *  Returns:
  443.  *        VOID
  444. \****************************************************************/
  445. VOID APIENTRY BuildSvgaNodes(PDSPINSTL_CHAIN pDspinstlChain,
  446.                               PRESOLUTIONS pSelectedResolutions,
  447.                               ULONG ulCount,
  448.                               LONG lGetDesignated)
  449. {
  450.      PSZ pszSelectedResolution;
  451.      PDSPINSTL_CHAIN pTempChain,pLastResolution;
  452.  
  453.      /*
  454.       *get the selected resolutions
  455.       */
  456.      if(lGetDesignated == -1)
  457.      {
  458.           pszSelectedResolution = GetSelectedResolution(pSelectedResolutions,ulCount);
  459.      }
  460.      else
  461.      {
  462.           /*
  463.            *get the reslution
  464.            *designated
  465.            */
  466.           pszSelectedResolution = GetDesignatedResolution(pDspinstlChain,ulCount,
  467.                                                           lGetDesignated);
  468.      }
  469.  
  470.      /*
  471.       *get the first node after the head of the
  472.       *list that does not have a associated resolution
  473.       */
  474.      pLastResolution = GetLastElement(pDspinstlChain);
  475.  
  476.      /*
  477.       *build the key for the head
  478.       *of our chain
  479.       */
  480.      pDspinstlChain->pszKey = malloc(MAX_SIZ_KEY);
  481.      *(pDspinstlChain->pszKey) = 'C';
  482.  
  483.      for(pTempChain = pDspinstlChain;pTempChain;
  484.                              pTempChain = pTempChain->pNextDspInstl)
  485.      {
  486.           /*
  487.            *find the right one in the node that matches what we have
  488.            *selected
  489.            */
  490.            if(pTempChain->pszResolution)
  491.            {
  492.                /*
  493.                 *found it
  494.                 */
  495.                if(!strcmp(pTempChain->pszResolution,
  496.                     pszSelectedResolution) )
  497.                {
  498.                   pDspinstlChain->pNextDspInstl =
  499.                     pTempChain;
  500.                   /*
  501.                    *we used to incorrectly use the resolution
  502.                    *as the key,should be using the key from
  503.                    *the dsc file to match the key
  504.                    *for the dsp file
  505.                    */
  506.  
  507.  
  508.                   strcat(pDspinstlChain->pszKey,pTempChain->pszKey);
  509.                   /*
  510.                    *set the next node to
  511.                    *start with the next node in the list
  512.                    *that does not have a resolution
  513.                    */
  514.                   pTempChain->pNextDspInstl = pLastResolution;
  515.                   /*
  516.                    *we should now be looking at the first diskette
  517.                    *that does not have a resolution,this should now
  518.                    *be the fonts diskette
  519.                    *check to see if the resoulution that was selected was
  520.                    *HI-RES if so reset the key to pick-up the hires font
  521.                    *dsp file
  522.                    */
  523. //                if(!strcmp(pszSelectedResolution,_1024_768_256 ) ||
  524. //                       !strcmp(pszSelectedResolution,_1024_768_16 ) )
  525. //                {
  526. //                      pLastResolution->pszKey = malloc(MAX_SIZ_KEY);
  527. //                      strcpy(pLastResolution->pszKey,FONT_HI);
  528. //                }
  529.  
  530.                   break;
  531.                }
  532.           }
  533.      }
  534.      return;
  535. }
  536. /****************************************************************\
  537.  *
  538.  *--------------------------------------------------------------
  539.  *
  540.  *  Name:GetLastElement()
  541.  *
  542.  *  Purpose:Returns the a pointer to the last node in the list
  543.  *          that contains a valid resolution.
  544.  *
  545.  *  Returns:
  546.  *          pDspTemp - will point to either the first node that does
  547.  *                     not have a resolution or the last node in
  548.  *                     the linked list whichever occurs first
  549. \****************************************************************/
  550. PDSPINSTL_CHAIN GetLastElement(PDSPINSTL_CHAIN pDspInstlChain)
  551. {
  552.      PDSPINSTL_CHAIN pDspTemp;
  553.  
  554.      /*
  555.       *the assumption for svga is that the first node is
  556.       *always null
  557.       */
  558.      for(pDspTemp = pDspInstlChain->pNextDspInstl;pDspTemp->pszResolution;)
  559.      {
  560.           if(!pDspTemp->pNextDspInstl)
  561.           {
  562.                pDspTemp = NULL;
  563.                break;
  564.           }
  565.           pDspTemp = pDspTemp->pNextDspInstl;
  566.      }
  567.      return(pDspTemp);
  568. }
  569. /****************************************************************\
  570.  *
  571.  *--------------------------------------------------------------
  572.  *
  573.  *  Name:GetSelectedResolution
  574.  *
  575.  *  Purpose: This routine will loop through the  list of pSelectedResolutions
  576.  *           for up to ulCount number of elements looking for the ulSelected
  577.  *           flag to be set to TRUE. A pointer to the first ulSelected
  578.  *           element will be returned or NULL if no selection was made.
  579.  *  Returns:
  580.  *          pszResolutions  = a pointer to the selected resolutions string
  581.  *                            or NULL if none was selected.
  582. \****************************************************************/
  583. PSZ GetSelectedResolution(PRESOLUTIONS pSelectedResolutions,ULONG ulCount)
  584. {
  585.      ULONG ulCounter;
  586.      PRESOLUTIONS pTemp;
  587.      PSZ pszResolutions = NULL;
  588.  
  589.  
  590.      for(ulCounter =0,pTemp = pSelectedResolutions; ulCounter < ulCount;
  591.                               pTemp++,ulCounter++)
  592.      {
  593.  
  594.           if(pTemp->ulSelected)
  595.           {
  596.                pszResolutions= pTemp->achResolutionString;
  597.                break;
  598.           }
  599.      }
  600.      return(pszResolutions);
  601. }
  602. /****************************************************************\
  603.  *
  604.  *--------------------------------------------------------------
  605.  *
  606.  *  Name:Selected_Secondary
  607.  *
  608.  *  Purpose:This action routine handles the calling of the specify
  609.  *          adapter and specify monitor routines. The key that is
  610.  *          returned in the adapter structre is saved off so as to
  611.  *          used later while querying the .DSP files.
  612.  *
  613.  *
  614.  *
  615.  *  Usage:This routine should be called when the user has selected
  616.  *        to install a secondary monitor/adapter.
  617.  *
  618.  *  Returns:
  619.  *          Non-Zero -  Erorr occurred,User Aborted.
  620.  *          0        - Successful Operation,Continue
  621. \****************************************************************/
  622. LONG EXPENTRY Selected_Secondary(HWND hwnd,PDSPINSTL_GLOBAL_DATA pInstalData)
  623. {
  624.     ADAPTERENTRY adpentry;
  625.     VIDEOENTRY videntry;
  626.     LONG rc;
  627.     PDSPINSTL_CHAIN pDspChain;
  628.  
  629.  
  630.     pfnLogFunction = pInstalData->pfnLogFunction;
  631.     /*
  632.      *start at the head
  633.      *of the chain
  634.      */
  635.     pDspChain = pInstalData->pHeadDspInstl_Chain;
  636.  
  637.     if(!(rc = (*pInstalData->pfnSpecifyDisplayAdapter)(hwnd,pszAdapter, &adpentry) ) )
  638.     {
  639.         /*
  640.          *parse out the adapter info
  641.          *and save the key
  642.          */
  643.         svga_ParseAdapter(pDspChain,&adpentry);
  644.         if((rc = (*pInstalData->pfnSpecifyVideoMonitor)(hwnd,pszConfig, &videntry)))
  645.         {
  646.               SvgaReportError(rc,NULL,hwnd);
  647.  
  648.         }
  649.  
  650.     }
  651.     return(rc);
  652. }
  653. /****************************************************************\
  654.  *
  655.  *--------------------------------------------------------------
  656.  *
  657.  *  Name:svga_ParseAdapter
  658.  *
  659.  *  Purpose:This routine will move over to the last argument in
  660.  *          the achParms buffer and save it off the the key that
  661.  *          is passed,pszKey is assumed to contain a buffer big
  662.  *          enough to hold the key
  663.  *  Returns:
  664.  *          VOID
  665. \****************************************************************/
  666. VOID  APIENTRY svga_ParseAdapter(PDSPINSTL_CHAIN pInstalChain,
  667.                                  PADAPTERENTRY pAdpentry)
  668. {
  669.  
  670.      SHORT sCount;
  671.      PSZ   pszEnd;
  672.      PDSPINSTL_CHAIN  pTempChain;
  673.  
  674.      /*
  675.       *move over to the key for the adapter
  676.       *and save it off
  677.       */
  678.      pszEnd = pAdpentry->achParms;
  679.      for(sCount= (pAdpentry->cParms -1);sCount;sCount--)
  680.      {
  681.           pszEnd = (pszEnd + strlen(pszEnd) +1);
  682.      }
  683.      /*
  684.       *start at the head of the
  685.       *chain and give every node
  686.       *a copy of the key that was selected
  687.       */
  688.      for(pTempChain = pInstalChain;pTempChain; )
  689.      {
  690.           strcpy(pTempChain->pszKey,pszEnd);
  691.           pTempChain = pTempChain->pNextDspInstl;
  692.      }
  693. }
  694. /****************************************************************\
  695.  *
  696.  *--------------------------------------------------------------
  697.  *
  698.  *  Name:svga_WriteNewResolution
  699.  *
  700.  *  Purpose:To parse the resolution strings and make the
  701.  *          updates to the ini file.
  702.  *  Returns:
  703.  *          Non Zero - Error occurred
  704.  *          0        - No error
  705. \****************************************************************/
  706. ULONG APIENTRY svga_WriteNewResolution(PVIDEOENTRY pVidEntry)
  707. {
  708.     ULONG  cbCount;
  709.     PSZ    pszDelimiter;
  710.     PSZ    pszApplicationName;
  711.     CHAR   szMonitorRes[SIZ_TOWRITE];
  712.     CHAR   szMonitorInt[SIZ_TOWRITE];
  713.     CHAR   szMonitorRef[SIZ_TOWRITE];
  714.     CHAR   szStringToWrite[C_MAX_VID_PARMS];
  715.     SHORT  sArgs;
  716.     ULONG  ulReturn = 0;
  717.     PINIPARMS pIniParms;
  718.  
  719.     do
  720.     {
  721.  
  722.            for(cbCount = 0;cbCount <pVidEntry->cVideoParms;cbCount++)
  723.            {
  724.                memset(szResolution,0,sizeof(szResolution) );
  725.                memset(szInterLace,0,sizeof(szInterLace) );
  726.                memset(szStringToWrite,0,C_MAX_VID_PARMS);
  727.  
  728.  
  729.                /*
  730.                 *parse the three substrings out
  731.                 */
  732.                 pIniParms= IniParms;
  733.                 for(pszDelimiter = pVidEntry->avidparm[cbCount].achParms,sArgs = 0;
  734.                                                        sArgs <pVidEntry->avidparm[cbCount].cParms;
  735.                                                        sArgs++,
  736.                                                        pIniParms++)
  737.                 {
  738.                     strcpy(pIniParms->pszParms,pszDelimiter);
  739.                     pszDelimiter = (pszDelimiter + (strlen(pszDelimiter) + 1) );
  740.                 }
  741.  
  742.  
  743.                 /*
  744.                  *write each one out to the ini file
  745.                  */
  746.                 pIniParms= IniParms;
  747.                 for(sArgs = 0;sArgs <pVidEntry->cVideoParms;
  748.                                                        sArgs++,
  749.                                                        pIniParms++)
  750.                 {
  751.  
  752.                      if( pIniParms->pfnWriteParmToIni(IniParms) )
  753.                      {
  754.                          /*
  755.                           *generate error
  756.                           */
  757.                           break;
  758.                      }
  759.                 }
  760.            }
  761.      }ONCE;
  762.  
  763.      return(ulReturn);
  764. }
  765. /****************************************************************\
  766.  *
  767.  *--------------------------------------------------------------
  768.  *
  769.  *  Name:svga_UpWriteIni
  770.  *
  771.  *  Purpose:Update the ini file.
  772.  *
  773.  *
  774.  *
  775.  *  Usage: Used to update the user ini,expects formed keys,and strings.
  776.  *
  777.  *
  778.  *  Returns:
  779.  *          0 - if successful execution completed
  780.  *          1 - if error
  781. \****************************************************************/
  782. ULONG APIENTRY svga_UpWriteIni(PSZ pszApplication,PSZ pszKey,PSZ pszString)
  783. {
  784.  
  785.     HINI   UserIni  =  HINI_USERPROFILE;
  786.     ULONG  ulReturn = 0;
  787.  
  788.     if(!PrfWriteProfileString(UserIni,
  789.                               pszApplication,
  790.                               pszKey,
  791.                               pszString) )
  792.      {
  793.          ulReturn = WRITE_INI_ERROR;
  794.      }
  795.      return(ulReturn);
  796. }
  797. /****************************************************************\
  798.  *
  799.  *--------------------------------------------------------------
  800.  *
  801.  *  Name:svga_WriteResolIni()
  802.  *
  803.  *  Purpose:Set up to right the resolution to the ini file
  804.  *          based on the arguments contained in the pIniParms
  805.  *          structure.
  806.  *
  807.  *  Returns:
  808.  *          0 - if successful execution completed
  809.  *          1 - if error
  810. \****************************************************************/
  811. INT   APIENTRY svga_WriteResolIni(PINIPARMS pIniParms)
  812. {
  813.      APIRET ulRet;
  814.  
  815.      /*
  816.       *write out the string to the ini
  817.       */
  818.      ulRet = svga_UpWriteIni(MONITOR_RES,
  819.                                  pIniParms->pszParms,
  820.                                  pIniParms[INDEX_VREFRESH].pszParms);
  821.  
  822.      return(!ulRet);
  823.  
  824. }
  825. /****************************************************************\
  826.  *
  827.  *--------------------------------------------------------------
  828.  *
  829.  *  Name:WaitThread
  830.  *
  831.  *  Purpose:This thread will sleep for SLEEP_TIME milliseconds,
  832.  *          query the process id of that was passed to in the
  833.  *          pWaitData structure.Once the process id we are interested
  834.  *          in,is no longer a valid process,this thread will post
  835.  *          the AM_QUIT message back to the owner of hwnd.
  836.  *          The session id that was passed to the thread in the
  837.  *          pWaitData structure will also be terminated.
  838.  *  Returns:
  839.  *          VOID
  840. \****************************************************************/
  841. VOID APIENTRY WaitThread(PVOID pvMessageData)
  842. {
  843.     PSVGAWAITDATA pWaitData;
  844.     RESULTCODES  Results;
  845.     ULONG ulProcessId;
  846.     USHORT usPriority,rc;
  847.     HWND hwndMain;
  848.  
  849.     pWaitData = (PSVGAWAITDATA)pvMessageData;
  850.  
  851. //    DosSetPriority( 2, 1, -20, 0);
  852.     do
  853.     {
  854.           /*
  855.            *
  856.            */
  857.            DosSleep(SLEEP_TIME);
  858.            if(rc = Dos16GetPrty(PRTYS_PROCESS,
  859.                              &usPriority,
  860.                              (USHORT)pWaitData->ulProcessid) )
  861.            {
  862.                if(rc == ERROR_INVALID_PROCID)
  863.                {
  864.                     break;
  865.                }
  866.  
  867.            }
  868.  
  869.      }FOREVER;
  870.  
  871.      /*
  872.       *send message back to the main loop
  873.       *that we are done
  874.       */
  875.      if(pWaitData->hwnd)
  876.      {
  877. //          DosEnterCritSec();
  878.           WinPostMsg(pWaitData->hwnd, AM_QUIT,(MPARAM)FALSE, 0);
  879.      }
  880.  
  881.  
  882.      /*
  883.       *kill off the session that svga.exe
  884.       *was started in
  885.       */
  886.       DosStopSession(0,pWaitData->ulSession);
  887.       DosExit(EXIT_THREAD,0);
  888. }
  889.  
  890. /****************************************************************\
  891.  *
  892.  *--------------------------------------------------------------
  893.  *
  894.  *  Name:WaitSvgaDlgProc()
  895.  *
  896.  *  Purpose:This routine throws up the Hardware determination in
  897.  *          progress dialog box,and waits for the AM_QUIT message
  898.  *          to be sent back to it. No buttons are enable on the
  899.  *          dialog box,so no other messages,except the default are
  900.  *          expected.
  901.  *  Returns:
  902.  *          TRUE is always returned.
  903. \****************************************************************/
  904. MRESULT EXPENTRY WaitSvgaDlgProc(HWND hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2)
  905. {
  906.  
  907.     HWND     hwndListBox;
  908.     ULONG    iItem,ulCount;
  909.     static    SVGAWAITDATA WaitData;
  910.  
  911.  
  912.     switch (msg)
  913.     {
  914.         case WM_INITDLG:
  915.             hwndListBox = WinWindowFromID(hwnd, IDL_GENERAL);
  916.             CenterDialog(hwnd);
  917.  
  918.             /*
  919.              * Create a seperate thread to run svga.exe
  920.              */
  921.  
  922.             WaitData.hwnd = hwnd;
  923.  
  924.             if(DosCreateThread(&tidThread,
  925.                                (PFNTHREAD)RunSvga,
  926.                                (ULONG)&WaitData,
  927.                                FALSE,
  928.                                STACK_SIZE_THRD) )
  929.             {
  930.                 WinPostMsg(hwnd, AM_QUIT,(MPARAM)TRUE, 0);
  931.             }
  932.  
  933.  
  934. //91642             if( RunSvga(hwnd) )
  935. //91642             {
  936. //91642                 WinPostMsg(hwnd, AM_QUIT,(MPARAM)TRUE, 0);
  937. //91642             }
  938.             break;
  939.         case WM_CLOSE:
  940.             break;
  941.         /*
  942.          *our thread should send us this message
  943.          *when the svga process dies
  944.          */
  945.         case AM_QUIT:
  946. //91642             DosKillThread(tidThread);
  947.              WinDismissDlg(hwnd,SHORT1FROMMP(mp1));
  948.              break;
  949.  
  950.         default:
  951.             return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  952.             break;
  953.     }
  954.     return 0L;
  955. }
  956.  
  957. /****************************************************************\
  958.  *
  959.  *-----------------------------------------------------------------------
  960.  *
  961.  *  Name:SelectSvgaUtilDlgProc()
  962.  *
  963.  *  Purpose:This routine is the main dialog procedure for selecting an SVGA
  964.  *          monitor configuration utility.
  965.  *
  966.  *  Called by: GetResolutionsData()
  967.  *
  968.  *  Calls to:  InitHelp()
  969.  *             CreateSvgaTmpBat()
  970.  *             SvgaUtilDlgProc()
  971.  *             SvgaReportError()
  972.  *
  973.  *  Returns:
  974.  *          (MPARAM)TRUE is returned on an error condition or WM_CANCEL
  975. \************************************************************************/
  976.  
  977. MRESULT EXPENTRY SelectSvgaUtilDlgProc(HWND hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2)
  978. {
  979.     BOOL   fError;
  980.     APIRET apiRet;
  981.  
  982.     switch(msg)
  983.     {
  984.         case WM_INITDLG:
  985.              /*
  986.                initialize Help Manager
  987.              */
  988.              InitHelp(&hwndHelpInstance);
  989.              if (hwndHelpInstance)
  990.                 WinAssociateHelpInstance(hwndHelpInstance, hwnd);
  991.  
  992.              CenterDialog(hwnd);
  993.              break;
  994.  
  995.         case WM_COMMAND:
  996.              switch (SHORT1FROMMP(mp1))
  997.              {
  998.  
  999.                  case DID_OK:
  1000.  
  1001.                     apiRet = DID_OK;
  1002.  
  1003.                     /*
  1004.                      * Use Default Settings
  1005.                      */
  1006.  
  1007.                     if (SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwnd, IDB_DEFAULTSETTINGS),
  1008.                                                 BM_QUERYCHECK, 0L, 0L)))
  1009.                     {
  1010.                          if (CreateSvgaTmpBat( NULL ))
  1011.                          {
  1012.                              SvgaReportError(MSG_UNABLE_TO_DETERMINE_HARD,
  1013.                                              NULL,
  1014.                                              hwnd);
  1015.  
  1016.                              apiRet = DID_ERROR;
  1017.                          }
  1018.  
  1019.                     }
  1020.                     else if (SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwnd, IDB_SVGAUTIL),
  1021.                                                 BM_QUERYCHECK, 0L, 0L)))
  1022.                     {
  1023.  
  1024.                          apiRet = WinDlgBox((HWND)HWND_DESKTOP,
  1025.                                             HWND_DESKTOP,
  1026.                                             (PFNWP)SvgaUtilDlgProc,
  1027.                                             hmodResource,
  1028.                                             DLG_SVGAUTIL,
  1029.                                             NULL);
  1030.                     }
  1031.  
  1032.                     if (apiRet == DID_OK)
  1033.                         WinPostMsg(hwnd, AM_QUIT,0,0);
  1034.                     else if (apiRet == DID_ERROR)
  1035.                         WinPostMsg(hwnd, AM_QUIT,(MPARAM)TRUE, 0);
  1036.                  break;
  1037.  
  1038.                  case DID_CANCEL:
  1039.                      WinPostMsg(hwnd, AM_QUIT,(MPARAM)TRUE, 0);
  1040.                      break;
  1041.  
  1042.              }
  1043.              break;
  1044.  
  1045.         case AM_QUIT:
  1046.              WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
  1047.              break;
  1048.  
  1049.         default:
  1050.             return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1051.                break;
  1052.  
  1053.     }
  1054.     return 0L;
  1055. }
  1056.  
  1057. /****************************************************************\
  1058.  *
  1059.  *-----------------------------------------------------------------------
  1060.  *
  1061.  *  Name:SvgaUtilDlgProc()
  1062.  *
  1063.  *  Purpose:This routine prompt the user for the SVGA display adapter
  1064.  *          utility file location and then creates the batch file
  1065.  *          used by RunSvga().
  1066.  *
  1067.  *  Called by: GetResolutionsData()
  1068.  *
  1069.  *  Calls to:  InitHelp()
  1070.  *             CreateSvgaTmpBat()
  1071.  *             SvgaReportError()
  1072.  *
  1073.  *  Returns:
  1074.  *          DID_OK, DID_CANCEL, DID_ERROR
  1075. \************************************************************************/
  1076.  
  1077. MRESULT EXPENTRY SvgaUtilDlgProc(HWND hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2)
  1078. {
  1079.  
  1080.    FILEDLG  pfdFileDlg;
  1081.    static CHAR szTitle[CCHMAXPATH];
  1082.    PSZ pszFullFile = "*.*";
  1083.    HWND hwndWinFileDlg;
  1084.    PSVGAUTILDATA pUtilData;
  1085.    static       CHAR  pszSourceDir[] = "A:\\";
  1086.    PSZ          pszName;
  1087.    APIRET       apiRet;
  1088.    ULONG        ulBufLen;
  1089.    USHORT       i;
  1090.    FILESTATUS  FileBuf;
  1091.    BOOL        fError;
  1092.    CHAR        szBuffer[CCHMAXPATH];
  1093.  
  1094.  
  1095.     switch(msg)
  1096.     {
  1097.          case WM_INITDLG:
  1098.  
  1099.              if (hwndHelpInstance)
  1100.                 WinAssociateHelpInstance(hwndHelpInstance, hwnd);
  1101.  
  1102.             /*
  1103.              * malloc util data structure
  1104.              */
  1105.              pUtilData = malloc( sizeof( SVGAUTILDATA ) );
  1106.              pUtilData->pszBuffer = malloc( CCHMAXPATH );
  1107.              pUtilData->pszMsg = malloc( CCHMAXPATH );
  1108.              pUtilData->pszTitle = malloc( CCHMAXPATH );
  1109.              pUtilData->fParms = FALSE;
  1110.  
  1111.              pUtilData->hab = WinInitialize(0);
  1112.  
  1113.              /*
  1114.               * Load resource strings from dll
  1115.               */
  1116.              WinLoadString(pUtilData->hab, hmodResource, MSG_FILE_NOT_EXIST, CCHMAXPATH,
  1117.                   pUtilData->pszMsg);
  1118.              WinLoadString(pUtilData->hab, hmodResource, MSG_SVGAUTIL_NOT_FOUND, CCHMAXPATH,
  1119.                   pUtilData->pszTitle);
  1120.              WinLoadString(pUtilData->hab, hmodResource, MSG_FILEDLG_TITLE, CCHMAXPATH,
  1121.                   szTitle);
  1122.  
  1123.              WinSetWindowULong(hwnd, QWL_USER, (ULONG)pUtilData);
  1124.  
  1125.              CenterDialog(hwnd);
  1126.              WinPostMsg(hwnd,WM_INIT,0,0);
  1127.              break;
  1128.  
  1129.  
  1130.  
  1131.          case WM_INIT:
  1132.              WinSendDlgItemMsg(hwnd,      /* set text limit of entry field */
  1133.                       IDE_SOURCEDIR,
  1134.                       EM_SETTEXTLIMIT,
  1135.                       MPFROMSHORT(CCHMAXPATH -10),
  1136.                       (MPARAM)0L);
  1137.  
  1138.              WinSetDlgItemText(hwnd,   /* set source directory a:\ */
  1139.                      IDE_SOURCEDIR,
  1140.                      pszSourceDir);
  1141.  
  1142.  
  1143.              WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, IDE_SOURCEDIR));
  1144.  
  1145.              break;
  1146.  
  1147.          case AM_QUIT:
  1148.  
  1149.              pUtilData = (PSVGAUTILDATA)WinQueryWindowULong(hwnd, QWL_USER);
  1150.  
  1151.              free( pUtilData->pszBuffer );
  1152.              free( pUtilData->pszMsg );
  1153.              free( pUtilData->pszTitle );
  1154.              free( pUtilData );
  1155.              WinTerminate(pUtilData->hab);
  1156.              WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
  1157.              break;
  1158.  
  1159.          case WM_COMMAND:
  1160.  
  1161.              switch (SHORT1FROMMP(mp1))
  1162.              {
  1163.  
  1164.                  case DID_OK:
  1165.  
  1166.                      fError = FALSE;
  1167.                      fSvgaUtilPresent = FALSE;
  1168.  
  1169.                      pUtilData = (PSVGAUTILDATA)WinQueryWindowULong(hwnd, QWL_USER);
  1170.  
  1171.                      WinQueryDlgItemText( hwnd,
  1172.                                            IDE_SOURCEDIR,
  1173.                                            CCHMAXPATH - 10,
  1174.                                            pUtilData->pszBuffer );
  1175.                      /*
  1176.                       * If user selects okay without entering
  1177.                       * a utility program
  1178.                       */
  1179.  
  1180.                      if(!strcmp( pUtilData->pszBuffer, pszSourceDir) ||
  1181.                          strlen(pUtilData->pszBuffer) <= 3)
  1182.                      {
  1183.                             WinPostMsg(hwnd,WM_INIT,0,0);
  1184.                             break;
  1185.                      }
  1186.                      else
  1187.                      {
  1188.                           /*
  1189.                             parse buffer to first space character and
  1190.                             only copy name,  not parameters
  1191.                            */
  1192.  
  1193.                           pUtilData->fParms = FALSE;
  1194.                           ulBufLen = strlen( pUtilData->pszBuffer );
  1195.                           for( i=0; i<ulBufLen; i++ ) {
  1196.                              if( *((CHAR *)pUtilData->pszBuffer + i) == ' ')
  1197.                              {
  1198.                                  pszName =malloc( i );
  1199.                                  memcpy( pszName, pUtilData->pszBuffer, i );
  1200.                                  *(pszName + i) = '\0';
  1201.                                  pUtilData->fParms = TRUE;
  1202.                                  break;
  1203.                              }
  1204.                           }
  1205.  
  1206.                           if(!pUtilData->fParms)
  1207.                           {
  1208.                              pszName = strdup( pUtilData->pszBuffer );
  1209.                           }
  1210.  
  1211.                           /*
  1212.                            *make sure the program can be found
  1213.                            */
  1214.  
  1215.                            DosError( HARDERROR_DISABLE );
  1216.  
  1217.                            apiRet = DosQueryPathInfo( pszName,
  1218.                                                FIL_STANDARD,
  1219.                                                &FileBuf,
  1220.                                                sizeof( FileBuf ) );
  1221.  
  1222.                            DosError( HARDERROR_ENABLE );
  1223.  
  1224.                            if(apiRet) {
  1225.                               sprintf( szBuffer, pUtilData->pszMsg, pszName );
  1226.                               WinMessageBox( HWND_DESKTOP,
  1227.                                              hwnd,
  1228.                                              szBuffer,
  1229.                                              pUtilData->pszTitle,
  1230.                                              HELP_DLG_SELECTSVGAUTIL,
  1231.                                              MB_OK | MB_HELP | MB_INFORMATION | MB_MOVEABLE);
  1232.  
  1233.                              free( pszName );
  1234.                              WinPostMsg(hwnd,WM_INIT,0,0);
  1235.                              break;
  1236.                           }
  1237.  
  1238.                           fSvgaUtilPresent = TRUE;
  1239.  
  1240.                           if( CreateSvgaTmpBat( pUtilData->pszBuffer ) )
  1241.                           {
  1242.                               SvgaReportError(MSG_UNABLE_TO_DETERMINE_HARD,
  1243.                                               NULL,
  1244.                                               hwnd);
  1245.  
  1246.                                 fError = TRUE;
  1247.                           }
  1248.  
  1249.  
  1250.                           free( pszName );
  1251.                      }
  1252.  
  1253.                      (fError ? WinPostMsg(hwnd, AM_QUIT,(MPARAM)DID_ERROR, 0) :
  1254.                               WinPostMsg(hwnd, AM_QUIT,(MPARAM)DID_OK,0));
  1255.                      break;
  1256.  
  1257.                  case DID_LOCATE:
  1258.  
  1259.                            memset( &pfdFileDlg,0,sizeof(FILEDLG));
  1260.                            pfdFileDlg.cbSize = sizeof(FILEDLG);
  1261.                            pfdFileDlg.fl = FDS_HELPBUTTON | FDS_CENTER | FDS_OPEN_DIALOG;
  1262.                            pfdFileDlg.pszTitle = szTitle;
  1263.  
  1264.                            pUtilData = (PSVGAUTILDATA)WinQueryWindowULong(hwnd,
  1265.                                                                  QWL_USER);
  1266.                            WinQueryDlgItemText( hwnd,
  1267.                                                 IDE_SOURCEDIR,
  1268.                                                 CCHMAXPATH - 10,
  1269.                                                 pUtilData->pszBuffer );
  1270.  
  1271.                            pfdFileDlg.pszIDrive = "A:";
  1272.                            if(strcmp( pUtilData->pszBuffer, pszSourceDir ))
  1273.                            {
  1274.                               ulBufLen = strlen( pUtilData->pszBuffer );
  1275.                               for(i=0;i<ulBufLen;i++)
  1276.                               {
  1277.                                  if(*pUtilData->pszBuffer != ' ')
  1278.                                  {
  1279.                                     *pfdFileDlg.pszIDrive =
  1280.                                          *pUtilData->pszBuffer;
  1281.                                     break;
  1282.                                  }
  1283.                                  pUtilData->pszBuffer++;
  1284.                               }
  1285.                            }
  1286.  
  1287.                            strcpy( pfdFileDlg.szFullFile, pszFullFile );
  1288.  
  1289.                            hwndWinFileDlg = WinFileDlg( HWND_DESKTOP, hwnd, &pfdFileDlg );
  1290.  
  1291.                            if( hwndWinFileDlg && (pfdFileDlg.lReturn == DID_OK ) )
  1292.                            {
  1293.                                WinSetDlgItemText( hwnd, IDE_SOURCEDIR, pfdFileDlg.szFullFile );
  1294.                            }
  1295.                            break;
  1296.  
  1297.                  case DID_CANCEL:
  1298.                      WinPostMsg(hwnd, AM_QUIT,(MPARAM)DID_CANCEL, 0);
  1299.                      break;
  1300.  
  1301.  
  1302.                  default:
  1303.                      WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
  1304.                      break;
  1305.  
  1306.              }
  1307.              break;
  1308.  
  1309.          default:
  1310.              return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1311.              break;
  1312.  
  1313.     }
  1314.  
  1315.     return 0L;
  1316.  
  1317. }
  1318.  
  1319. /****************************************************************\
  1320.  *
  1321.  *--------------------------------------------------------------
  1322.  *
  1323.  *  Name:GetResolutionsData()
  1324.  *
  1325.  *  Purpose:This routine should be used to determine which resolutions
  1326.  *          to display to the user. If the default flag is set,the
  1327.  *          svgadata.pmi file will be read,and the intersection of the
  1328.  *          dsc file and svgadata file will be displayed. Otherwise all
  1329.  *          of the resolutions the dsc file supports will be displayed.
  1330.  *
  1331.  *          pResolutions           - pointer to where to read in the
  1332.  *                                   resolutions from the svgadata.pmi
  1333.  *                                   file.
  1334.  *
  1335.  *          pResolutionsToDisplay  - pointer to the array of structures
  1336.  *                                   where to store the list of suppoted
  1337.  *                                   resolutions to display to the user.
  1338.  *
  1339.  *          hwnd                   - parent window handle
  1340.  *
  1341.  *          pInstalData            - pointer to the head of the list that
  1342.  *                                   contains the list of resolutions from
  1343.  *                                   the dsc file.
  1344.  *          fUseDefault            - flag to indicate whether to use
  1345.  *                                   only the intersection of the dsc
  1346.  *                                   resolutions and the svgadata.pmi
  1347.  *                                   resolutons.
  1348.  *          pulCount               - pointer to the number of supported
  1349.  *                                   resolutions to display
  1350.  *
  1351.  *  Returns:
  1352.  *          apiRet - re-map all error codes to CANCEL_OPERATION
  1353.  *                   ,forces the calling program to return to the main
  1354.  *                   panel
  1355.  *          0      - NO error
  1356. \****************************************************************/
  1357. APIRET  GetResolutionsData(PRESOLUTIONS pResolutions,
  1358.                            PRESOLUTIONS pResolutionsToDisplay,
  1359.                            HWND hwnd,
  1360.                            PDSPINSTL_CHAIN  pInstalChain,
  1361.                            BOOL fUseDefault,
  1362.                            PULONG pulCount,
  1363.                            PFN pfnGetNext,
  1364.                            BOOL *pulShowSelectionsToUser)
  1365. {
  1366.     APIRET apiRet = 0;
  1367.     HWND hwndMain;
  1368.     ULONG ulCount,ulSize;
  1369.     PVOID pVoid;
  1370.     static bOnce = TRUE;
  1371.     RESOLUTIONDATA  resData;
  1372.     SCREENRESOLUTION screenRes;
  1373.     HINI   UserIni  =  HINI_USERPROFILE;
  1374.  
  1375.  
  1376.     do
  1377.     {
  1378.  
  1379.          /*
  1380.           *make sure we run svga.exe at least once,or if the
  1381.           *svgadata.pmi file does not exist
  1382.           */
  1383.          if(OpenResolutionsFile(pResolutions,&ulCount) || bOnce)
  1384.          {
  1385.               /*
  1386.                *get handle to our dll's resources
  1387.                */
  1388.               if(apiRet = GetDllHandle(&hmodResource) )
  1389.               {
  1390.                    SvgaReportError(MSG_GET_DLL_HANDLE,NULL,hwnd);
  1391.                    break;
  1392.               }
  1393.  
  1394.  
  1395.               /*
  1396.                * If a resolution string was passed in then run
  1397.                * unattended.
  1398.                */
  1399.               if( pszResolutionString )
  1400.               {
  1401.                     if (CreateSvgaTmpBat( NULL ))
  1402.                     {
  1403.                         SvgaReportError(MSG_UNABLE_TO_DETERMINE_HARD,
  1404.                                         NULL,
  1405.                                         hwnd);
  1406.  
  1407.                         apiRet = DID_ERROR;
  1408.                     }
  1409.  
  1410.                    apiRet = WinDlgBox((HWND)HWND_DESKTOP,
  1411.                                        HWND_DESKTOP,
  1412.                                        (PFNWP)WaitSvgaDlgProc,
  1413.                                        hmodResource,
  1414.                                        DLG_RUNSVGA,
  1415.                                        NULL);
  1416.  
  1417.               }
  1418.               else
  1419.               {
  1420.                   /*
  1421.                    * Prompt for svga utility, create svgatmp.bat
  1422.                    * If function fails don't run svgatmp.bat
  1423.                    */
  1424.  
  1425.                    if(!(apiRet = WinDlgBox((HWND)HWND_DESKTOP,
  1426.                                  HWND_DESKTOP,
  1427.                                 (PFNWP)SelectSvgaUtilDlgProc,
  1428.                                  hmodResource,
  1429.                                  DLG_SELECTSVGAUTIL,
  1430.                                  NULL)))
  1431.                    {
  1432.                        /*
  1433.                         *throw up a message box
  1434.                         *to indicate wait a moment
  1435.                         *while we run the svgatmp.bat
  1436.                         */
  1437.                        apiRet = WinDlgBox((HWND)HWND_DESKTOP,
  1438.                                            HWND_DESKTOP,
  1439.                                            (PFNWP)WaitSvgaDlgProc,
  1440.                                            hmodResource,
  1441.                                            DLG_RUNSVGA,
  1442.                                            NULL);
  1443.  
  1444.                        if( apiRet )
  1445.                        {
  1446.  
  1447.                           SvgaReportError(MSG_UNABLE_TO_DETERMINE_HARD,
  1448.                                   NULL,
  1449.                                   hwnd);
  1450.  
  1451.                        }
  1452.  
  1453.                    }
  1454.               }
  1455.          }
  1456.          /*
  1457.           *if we got no error while trying to run svga
  1458.           */
  1459.          if(!apiRet)
  1460.          {
  1461.              bOnce = FALSE;
  1462.              /*
  1463.               *we should have a valid file
  1464.               *by now
  1465.               */
  1466.              if(apiRet = OpenResolutionsFile(pResolutions,&ulCount) )
  1467.              {
  1468.                   /*
  1469.                    *report error if we still don't have something
  1470.                    *we can read
  1471.                    */
  1472.                    SvgaReportError(MSG_BAD_RESOLUTIONS_FILE,NULL,hwnd);
  1473.                    break;
  1474.              }
  1475.  
  1476.          }
  1477.          *pulShowSelectionsToUser = FALSE;
  1478.  
  1479.      }ONCE;
  1480.  
  1481.      /*
  1482.       * See if a resolution was passed to the action routine DLL.
  1483.       * If so, see if is supported in the .PMI.  and then write
  1484.       * the resolution to the .ini file.
  1485.       */
  1486.  
  1487.      if(!apiRet && pszResolutionString )
  1488.      {
  1489.         f1024K = CheckSVGAMem( pResolutions, ulCount );
  1490.  
  1491.         if(CompareResolutions( pszResolutionString,
  1492.                            pResolutions, ulCount ) == TRUE)
  1493.         {
  1494.  
  1495.            StringToResolution( pszResolutionString, &resData );
  1496.  
  1497.            screenRes.height = resData.Vert;
  1498.            screenRes.width  = resData.Horiz;
  1499.            screenRes.colors = resData.Colors;
  1500.            screenRes.planes = 1;
  1501.            screenRes.floptions = DSP_RESOLUTION_OBTAINABLE;
  1502.  
  1503.            if(!PrfWriteProfileData(UserIni,
  1504.                                   "PM_DISPLAYDRIVERS",
  1505.                                   "DEFAULTSYSTEMRESOLUTION",
  1506.                                    &screenRes,
  1507.                                    sizeof( SCREENRESOLUTION )))
  1508.  
  1509.            {
  1510.                 apiRet = WRITE_INI_ERROR;
  1511.            }
  1512.  
  1513.         }
  1514.  
  1515.      }
  1516.      if(apiRet)
  1517.      {
  1518.           if (apiRet != CONTINUE_WITH_ERR)
  1519.               apiRet = CANCEL_OPERATION;
  1520.      }
  1521.  
  1522.      return(apiRet);
  1523. }
  1524. /****************************************************************\
  1525.  *
  1526.  *--------------------------------------------------------------
  1527.  *
  1528.  *  Name:OpenResolutionsFile()
  1529.  *
  1530.  *  Purpose: This routine will open the svgadata.pmi file and if
  1531.  *           successful will call readresolutions file.
  1532.  *
  1533.  *  pResolutions  - pointer to a array of resolutions structures that
  1534.  *                  is expected to be large enough to hold all of the
  1535.  *                  supported resoulutions.
  1536.  *  pulCount     -  the count of supported resolutions will be stored
  1537.  *                  here.
  1538.  *  Returns:
  1539.  *          FALSE   - No Error occurred.
  1540.  *          TRUE    - Error occurred.
  1541. \****************************************************************/
  1542. BOOL OpenResolutionsFile(PRESOLUTIONS pResolutions,PULONG pulCount)
  1543. {
  1544.  
  1545.     BOOL fError =FALSE;
  1546.     HFILE    hf;
  1547.     ULONG    ulAction,rc;
  1548.     PSZ    pszResolutionsFile = RESOLUTIONS_FILE;
  1549.     ULONG  ulBootDrive;
  1550.  
  1551.     /*
  1552.      *set the boot drive
  1553.      */
  1554.     DosQuerySysInfo(QSV_BOOT_DRIVE,
  1555.                     QSV_BOOT_DRIVE,
  1556.                     &ulBootDrive,
  1557.                     sizeof(ulBootDrive));
  1558.     *pszResolutionsFile = (CHAR)(ulBootDrive + 'A' - 1);
  1559.     if(!(rc = DosOpen(pszResolutionsFile,
  1560.                        &hf,
  1561.                        &ulAction,
  1562.                        0,
  1563.                        FILE_ARCHIVED | FILE_READONLY | FILE_SYSTEM
  1564.                                      | FILE_HIDDEN,
  1565.                        FILE_OPEN,
  1566.                        OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
  1567.                        NULL)))
  1568.     {
  1569.           if(ReadResolutionsFile(pResolutions,hf,pulCount) )
  1570.           {
  1571.                fError = TRUE;
  1572.           }
  1573.           DosClose(hf);
  1574.     }
  1575.     else
  1576.     {
  1577.           fError =TRUE;
  1578.     }
  1579.  
  1580.     return(fError);
  1581. }
  1582.  
  1583. /****************************************************************\
  1584.  *
  1585.  *--------------------------------------------------------------
  1586.  *
  1587.  *  Name:ReadResolutionsFile()
  1588.  *
  1589.  *  Purpose: This routine will read the  parameter file, and parse
  1590.  *           the graphics information and save the supported resolutions
  1591.  *           mode into the pResolutions structure that was passed.
  1592.  *           It is assumed the pResolutions structure is large enough to
  1593.  *           hold all of the supported resolutions.
  1594.  *
  1595.  *           pResolutions          - pointer to the list of structures
  1596.  *                                   where the resolutions will be stored.
  1597.  *           hfile                 - handle to the file that should have
  1598.  *                                   already been opened.
  1599.  *           pulCount              - where the number of supported resolutions
  1600.  *                                   that was placed in pResolutions will be
  1601.  *                                   stored.
  1602.  *  Returns:
  1603.  *          FALSE   - No error occurred.
  1604.  *          TRUE    - error occurred.
  1605. \****************************************************************/
  1606. BOOL ReadResolutionsFile(PRESOLUTIONS pResolutions,HFILE hf,PULONG pulCount)
  1607. {
  1608.      BOOL fError = TRUE;
  1609.      PVOID pvBuffer = NULL;
  1610.      FILESTATUS fstsFile;
  1611.      ULONG ulBytesRead,ulIndex;
  1612.      PSZ pszNextResolution,pszNextMode;
  1613.  
  1614.  
  1615.      do
  1616.      {
  1617.           *pulCount = 0;
  1618.           DosQueryFileInfo(hf,
  1619.                        FIL_STANDARD,
  1620.                        &fstsFile,
  1621.                        sizeof(FILESTATUS));                  /* get size of file */
  1622.  
  1623.           if(fstsFile.cbFile < (ULONG)-1)                 /* file size < 64K ? */
  1624.           {
  1625.                pvBuffer = malloc(fstsFile.cbFile + 1);
  1626.                if( pvBuffer )
  1627.                {
  1628.                    DosRead(hf,pvBuffer,fstsFile.cbFile,&ulBytesRead);
  1629.                    pszNextResolution = pvBuffer;
  1630.                    while(pszNextResolution)
  1631.                    {
  1632.                         /*
  1633.                          *get to the next graphics mode string
  1634.                          */
  1635.                         if(pszNextMode = strstr(pszNextResolution,GRAPHICS_MODE))
  1636.                         {
  1637.                              pszNextResolution = (strchr(pszNextMode,':') + 1);
  1638.                              pszNextResolution = strip_white(pszNextResolution);
  1639.                              ulIndex           = strcspn(pszNextResolution,".");
  1640.                              strncpy(pResolutions->achResolutionString,
  1641.                                        pszNextResolution,ulIndex);
  1642.                              pResolutions++;
  1643.                              (*pulCount)++;
  1644.                         }
  1645.                         else
  1646.                         {
  1647.                              pszNextResolution = NULL;
  1648.                         }
  1649.                    }
  1650.  
  1651.                    fError = FALSE;
  1652.  
  1653.                }
  1654.  
  1655.           }
  1656.           fError = FALSE;
  1657.  
  1658.      }ONCE;
  1659.  
  1660.      if(pvBuffer)
  1661.      {
  1662.           free(pvBuffer);
  1663.      }
  1664.      return(fError);
  1665. }
  1666.  
  1667. /*************************************************************
  1668.  *
  1669.  *
  1670.  *    Name: CreateSvgaTmpBat()
  1671.  *
  1672.  *    Purpose:   This function will make sure svga.exe exist, if
  1673.  *               so, it will create the svgatmp.bat file used by
  1674.  *               RunSvga()
  1675.  *
  1676.  *    Returns:  apiRet.
  1677.  *
  1678.  **************************************************************/
  1679. APIRET CreateSvgaTmpBat( CHAR *pszBuffer )
  1680.  {
  1681.       APIRET apiRet = 0;
  1682.       HFILE hFile;
  1683.       ULONG ulAction, ulTemp, ulBootDrive;
  1684.       PSZ   pszSvgaTmpBatFile = SVGATMP_BAT;
  1685.       CHAR  szSvgaFullProg[CCHMAXPATH];
  1686.       PSZ   pszArg1 = " ON";
  1687.       PSZ   pszArg2 = " INIT";
  1688.  
  1689.  
  1690.       memset( szSvgaFullProg,0, sizeof( szSvgaFullProg ) );
  1691.       /*
  1692.        ** get full program path for svga.exe
  1693.        */
  1694.       if(!(apiRet = DosSearchPath(SEARCH_ENVIRONMENT,
  1695.                         "PATH",
  1696.                          SVGA_PROGRAM,
  1697.                          szSvgaFullProg,
  1698.                          CCHMAXPATH)) )
  1699.       {
  1700.           /* get boot drive  */
  1701.           DosQuerySysInfo(QSV_BOOT_DRIVE,
  1702.                           QSV_BOOT_DRIVE,
  1703.                             &ulBootDrive,
  1704.                            sizeof(ulBootDrive));
  1705.  
  1706.           *pszSvgaTmpBatFile = (CHAR)(ulBootDrive + 'A' - 1);
  1707.  
  1708.           if(!(apiRet = DosOpen(pszSvgaTmpBatFile,
  1709.                      &hFile,
  1710.                      &ulAction,
  1711.                      0,
  1712.                      FILE_NORMAL,
  1713.                      FILE_TRUNCATE | FILE_CREATE,
  1714.                      OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE,
  1715.                      NULL)))
  1716.           {
  1717.               strcat( szSvgaFullProg, pszArg1 );
  1718.  
  1719.               if( fSvgaUtilPresent ){
  1720.                    strcat( pszBuffer, "\r\n" );
  1721.                    DosWrite(hFile, pszBuffer, strlen(pszBuffer),
  1722.                         &ulTemp);
  1723.                    DosWrite(hFile, szSvgaFullProg, strlen(szSvgaFullProg),
  1724.                         &ulTemp);
  1725.               }
  1726.               else{
  1727.                    strcat( szSvgaFullProg, pszArg2 );
  1728.                    DosWrite(hFile, szSvgaFullProg, strlen(szSvgaFullProg),
  1729.                         &ulTemp);
  1730.               }
  1731.  
  1732.               DosClose(hFile);
  1733.           }
  1734.  
  1735.       }
  1736.  
  1737.       return( apiRet );
  1738.  
  1739. }
  1740.  
  1741. /****************************************************************\
  1742.  *
  1743.  *--------------------------------------------------------------
  1744.  *
  1745.  *  Name:RunSvga
  1746.  *
  1747.  *  Purpose:This routine will run the dos batch file svgatmp.bat.
  1748.  *          If user has a Svga Utility, svga.exe will be passed
  1749.  *          the argument "ON", else svga.exe will be passed the
  1750.  *          arguement "ON DEFAULT". If the svga.exe is successfully
  1751.  *          started up in another session then, a separate thread will
  1752.  *          be started up,which will monitor the  process id that is
  1753.  *          passed to it.
  1754.  *
  1755.  *  Returns:
  1756.  *          Non - zero  - The system error number that occurred.
  1757.  *          0 - No Error occurred
  1758. \****************************************************************/
  1759. VOID RunSvga(PVOID pvMessageData)
  1760. {
  1761.     APIRET    apiRet = 0;
  1762.     ULONG     rc,ulSession,ulProcessId, ulBootDrive;
  1763.     CHAR      szArgs[CCHMAXPATH];
  1764.     CHAR      szFullProg[CCHMAXPATH];
  1765.     PSZ       pszSvgaTmpBatFile = SVGATMP_BAT;
  1766.     PSZ       pszCommandCom = "C:\\OS2\\MDOS\\COMMAND.COM";
  1767.     static PSZ  pszConfigSys = szConfigSys;
  1768.     static PSZ  pszAutoExecName = szAutoExecName;
  1769.     static PSZ  pszConfigDsp = szConfigDsp;
  1770.     static PSZ  pszAutoExecDsp = szAutoExecDsp;
  1771.     STARTDATA StartData;
  1772.     FILESTATUS fsts;
  1773.     static   PSVGAWAITDATA pWaitData;
  1774.     HQUEUE         hqueue;
  1775.     REQUESTDATA    requestData;
  1776.     ULONG          ulData;
  1777.     PSESSIONRESULT psesres;
  1778.     BYTE           bElemPrty;
  1779.     CHAR           szError[CCHMAXPATH];
  1780.  
  1781.     pWaitData = (PSVGAWAITDATA)pvMessageData;
  1782.  
  1783.     memset(szArgs,0,sizeof(szArgs) );
  1784.     memset(szFullProg,0,sizeof(szFullProg) );
  1785.     memset(&StartData,0,sizeof(StartData) );
  1786.  
  1787.     /*
  1788.      *make sure the program can be found, first search the
  1789.      *os2\mdos directory, if not found,  search the path.
  1790.      */
  1791.  
  1792.     DosQuerySysInfo(QSV_BOOT_DRIVE,
  1793.                     QSV_BOOT_DRIVE,
  1794.                     &ulBootDrive,
  1795.                     sizeof(ulBootDrive));
  1796.  
  1797.     *pszCommandCom = (CHAR)(ulBootDrive + 'A' - 1);
  1798.  
  1799.     if( apiRet = DosQueryPathInfo( pszCommandCom,
  1800.                                    1,
  1801.                                    &fsts, sizeof(fsts)))
  1802.     {
  1803.           apiRet = DosSearchPath(SEARCH_ENVIRONMENT,
  1804.                                 "PATH",
  1805.                                  COMMAND_COM,
  1806.                                  szFullProg,
  1807.                                  CCHMAXPATH);
  1808.     }
  1809.     else
  1810.       strcpy( szFullProg, pszCommandCom );
  1811.  
  1812.  
  1813.     if(!apiRet)
  1814.     {
  1815.  
  1816.          *pszSvgaTmpBatFile = (CHAR)(ulBootDrive + 'A' - 1);
  1817.  
  1818.          if( fSvgaUtilPresent ) {
  1819.  
  1820.              /* Before executing command.com, if svga utility present then
  1821.                   copy save config.sys and autoexec.bat to *.dsp )  */
  1822.  
  1823.              *pszConfigSys      = (CHAR)(ulBootDrive + 'A' - 1);
  1824.              *pszAutoExecName   = (CHAR)(ulBootDrive + 'A' - 1);
  1825.              *pszAutoExecDsp    = (CHAR)(ulBootDrive + 'A' - 1);
  1826.              *pszConfigDsp      = (CHAR)(ulBootDrive + 'A' - 1);
  1827.  
  1828.              DosCopy( pszConfigSys, pszConfigDsp, DCPY_EXISTING );
  1829.              DosCopy( pszAutoExecName, pszAutoExecDsp, DCPY_EXISTING );
  1830.  
  1831.          }
  1832.          strcpy( szArgs, "/C ");
  1833.          strcat( szArgs, pszSvgaTmpBatFile );
  1834.  
  1835.          StartData.Length = sizeof(StartData);
  1836.          StartData.Related   = SSF_RELATED_CHILD;
  1837.          StartData.FgBg      = SSF_FGBG_FORE;
  1838.          StartData.TraceOpt  = SSF_TRACEOPT_NONE;
  1839.          StartData.PgmTitle  = COMMAND_COM;
  1840.          StartData.PgmName   = szFullProg;
  1841.          StartData.PgmInputs = szArgs;
  1842.          StartData.TermQ     = "\\queues\\svgainst.que";
  1843.          StartData.Environment = NULL;
  1844.          StartData.InheritOpt = 0;
  1845.          StartData.SessionType = SSF_TYPE_VDM;
  1846.          StartData.PgmHandle  =  0;
  1847.  
  1848.          if(!(apiRet = DosCreateQueue(&hqueue,
  1849.                                      QUE_FIFO,
  1850.                                      "\\queues\\svgainst.que")))
  1851.          {
  1852.              apiRet  = DosStartSession(&StartData,
  1853.                                (PULONG)&pWaitData->ulSession,
  1854.                                (PPID)&pWaitData->ulProcessid);
  1855.  
  1856.              if( apiRet == 0 || apiRet == ERROR_SMG_START_IN_BACKGROUND)
  1857.              {
  1858.                 /* initialize data */
  1859.                 apiRet = 0;
  1860.                 requestData.ulData = -1;
  1861.                 requestData.pid    = pWaitData->ulSession;
  1862.  
  1863.                 while(!DosReadQueue( hqueue,
  1864.                                       &requestData,
  1865.                                       &ulData,
  1866.                                       (PPVOID)&psesres,
  1867.                                       0,
  1868.                                       DCWW_WAIT,
  1869.                                       &bElemPrty,
  1870.                                       NULL) &&
  1871.                                       requestData.ulData);
  1872.  
  1873.                 if(psesres->usResultCode)
  1874.                 {
  1875.                    apiRet = psesres->usResultCode;
  1876.                    sprintf(szError, "SVGA.EXE error:rc=%ld", apiRet);
  1877.                    svgaLog(szError);
  1878.  
  1879.                 }
  1880.  
  1881.              }
  1882.              else
  1883.              {
  1884.                 sprintf(szError, "DosStartSession error:rc=%ld",apiRet);
  1885.                 svgaLog(szError);
  1886.              }
  1887.  
  1888.              DosCloseQueue(hqueue);
  1889.          }
  1890.  
  1891.     }
  1892.     if( fSvgaUtilPresent )
  1893.     {
  1894.          DosCopy( pszConfigDsp, pszConfigSys, DCPY_EXISTING );
  1895.          DosCopy( pszAutoExecDsp, pszAutoExecName, DCPY_EXISTING);
  1896.          DosDelete( pszAutoExecDsp );
  1897.          DosDelete( pszConfigDsp );
  1898.     }
  1899.  
  1900.     (apiRet ? WinPostMsg(pWaitData->hwnd, AM_QUIT,(MPARAM)TRUE, 0)
  1901.         :     WinPostMsg(pWaitData->hwnd, AM_QUIT,(MPARAM)FALSE, 0));
  1902.  
  1903.     DosExit(EXIT_THREAD,0);
  1904.  
  1905.  
  1906. }
  1907.  
  1908. /****************************************************************\
  1909.  *
  1910.  *--------------------------------------------------------------
  1911.  *
  1912.  *  Name:strip_white
  1913.  *
  1914.  *  Purpose:strip leading blank character from a string.
  1915.  *
  1916.  *  Returns:
  1917.  *        Pointer to the first non-blank character in the string
  1918.  *        that is passed.
  1919. \****************************************************************/
  1920. PSZ strip_white(PSZ pszString)
  1921. {
  1922.      while(*pszString == ' ')
  1923.      {
  1924.           pszString++;
  1925.      }
  1926.      return(pszString);
  1927. }
  1928. /****************************************************************\
  1929.  *
  1930.  *--------------------------------------------------------------
  1931.  *
  1932.  *  Name:ValidateResolutions
  1933.  *
  1934.  *  Purpose:If we are not using the default supported resolutions
  1935.  *          or if we are using only the supported resolutions and
  1936.  *          they are correctly validated,the resolutions that are
  1937.  *          contained in the pDspChain will be saved in the
  1938.  *          pResolutionToDisplay Stucture. It is expected that the
  1939.  *          pResolutions stucture is large enough to hold all of the
  1940.  *          supported resolutions.
  1941.  *
  1942.  *
  1943.  *          pResolutions          - pointer to the list of supported resolutions
  1944.  *          pResolutionsToDisplay - pointer to the resolutions data structure
  1945.  *                                  where the resolutions from the dsc file
  1946.  *                                  are saved to.
  1947.  *          pInstalData           - pointer to the linked list of resolutions
  1948.  *                                  that was passed to us by the
  1949.  *                                  display install utility.
  1950.  *          fUseDefault           - flag to indicate whether to use the only
  1951.  *                                  default resolutions or not.
  1952.  *          pulCount              - The number of resolutions that were
  1953.  *                                  stored in the pResolutionsToDisplay
  1954.  *                                  structure.
  1955.  *          ulCount               - The number of supported resolutios
  1956.  *                                  in the pResolutions structure.
  1957.  *  Returns:
  1958.  *          FALSE  - Currently always returns FALSE.
  1959.  *          TRUE   - if error
  1960. \****************************************************************/
  1961. BOOL ValidateResolutions(PRESOLUTIONS     pResolutions,
  1962.                          PRESOLUTIONS     pResolutionsToDisplay,
  1963.                          PDSPINSTL_CHAIN  pInstalData,
  1964.                          BOOL fUseDefault,
  1965.                          PULONG pulCount,
  1966.                          ULONG ulCount,
  1967.                          PFN pfnGetNext)
  1968.  
  1969. {
  1970.  
  1971.      PDSPINSTL_CHAIN pDspChain;
  1972.  
  1973. /* Amol; Defect #58319; 12/09/92 */
  1974.      f1024K                         /* Check if SVGA card has more than    */
  1975.      = CheckSVGAMem                 /* 512K memory                         */
  1976.          (pResolutions, ulCount);
  1977.  
  1978.      *pulCount = 0;
  1979.      for(pDspChain = pInstalData;pDspChain;
  1980.                               pDspChain = pDspChain->pNextDspInstl)
  1981.      {
  1982.           /*
  1983.            *if we've got a resolution
  1984.            */
  1985.           if(pDspChain->pszResolution)
  1986.           {
  1987.                /*
  1988.                 *if we are not using the default include
  1989.                 *it  ||
  1990.                 *if we are using the default compare it
  1991.                 *against the resolutions the adapter card
  1992.                 *supports for this machine
  1993.                 */
  1994.                if(!fUseDefault  || CompareResolutions(pDspChain->pszResolution,
  1995.                                                   pResolutions,ulCount) )
  1996.                {
  1997.                     /*
  1998.                      *save off the resolutions that are supported
  1999.                      */
  2000.                      strcpy(pResolutionsToDisplay->achResolutionString,
  2001.                               pDspChain->pszResolution);
  2002.                      (*pulCount)++;
  2003.                      pResolutionsToDisplay++;
  2004.                }
  2005.           }
  2006.      }
  2007.      return(FALSE);
  2008. }
  2009.  
  2010. /****************************************************************\
  2011.  *
  2012.  *--------------------------------------------------------------
  2013.  *
  2014.  *  Name:CompareResolutions
  2015.  *
  2016.  *  Purpose:To determine if the string pszResolution is contained in
  2017.  *          the list of supported resolutions (pSupportedResolutions).
  2018.  *          This routine will parse through ulResolutionCount number of
  2019.  *          items in the pSupportedResolutions strucuture that is passed.
  2020.  *  Returns:
  2021.  *          TRUE  -   Supported Resolution
  2022.  *          FALSE -   Not supported Resolution
  2023. \****************************************************************/
  2024. BOOL CompareResolutions(PSZ pszResolution,PRESOLUTIONS pSupportedResolutions,
  2025.                            ULONG ulResolutionCount)
  2026. {
  2027.     BOOL fSupported = FALSE;
  2028.     PRESOLUTIONS pTemp;
  2029.     ULONG ulCounter = 0;
  2030.     RESOLUTIONDATA  DscResolution,SupportedResolution;
  2031.  
  2032.  
  2033.     memset(&DscResolution,0,sizeof(RESOLUTIONDATA) );
  2034.     StringToResolution(pszResolution,&DscResolution);
  2035.     for(pTemp = pSupportedResolutions;ulCounter < ulResolutionCount;
  2036.                                    ulCounter++,
  2037.                                    pTemp++)
  2038.     {
  2039.                /*
  2040.                 *convert each one to resolution format
  2041.                 */
  2042.                memset(&SupportedResolution,0,sizeof(SupportedResolution) );
  2043.                StringToResolution(pTemp->achResolutionString,&SupportedResolution);
  2044.  
  2045.                /*
  2046.                 *does  the string match any of
  2047.                 *our  resoutions
  2048.                 */
  2049.  
  2050. /* Amol; Defect #58319; 12/09/1992  */
  2051.                /*
  2052.                 *if the video board has less than one meg of vram
  2053.                 *then filter out any drivers that need one meg
  2054.                 */
  2055.  
  2056.                if (!f1024K &&
  2057.                    IsResolutionOver1Mg (pszResolution, &DscResolution))
  2058.  
  2059.                   break;
  2060.  
  2061.               if(DscResolution.Horiz == SupportedResolution.Horiz)
  2062.               {
  2063.                     if(DscResolution.Vert == SupportedResolution.Vert)
  2064.                     {
  2065.                          if(DscResolution.Colors == SupportedResolution.Colors)
  2066.                          {
  2067.                               fSupported = TRUE;
  2068.                               break;
  2069.                          }
  2070.                     }
  2071.                }
  2072.     }
  2073.     return(fSupported);
  2074. }
  2075. /****************************************************************\
  2076.  *
  2077.  *--------------------------------------------------------------
  2078.  *
  2079.  *  Name:StringToResolution
  2080.  *
  2081.  *  Purpose: Convert a resolution in string format to
  2082.  *           it's corresponding parts and put them into
  2083.  *           the resolution data structure.
  2084.  *  Returns:
  2085.  *
  2086.  *          VOID - there is no error return.
  2087. \****************************************************************/
  2088. VOID StringToResolution(PSZ pszString,PRESOLUTIONDATA pResolutionData)
  2089. {
  2090.      PSZ pszTokens = "0123456789",pszNextToken;
  2091.      SHORT sPass;
  2092.  
  2093.  
  2094.      for(sPass = 0,pszNextToken = pszString; sPass < RESOLUTION_NUM; sPass++)
  2095.      {
  2096.           pszNextToken = strpbrk(pszNextToken,pszTokens);
  2097.           if(pszNextToken)
  2098.           {
  2099.                switch(sPass)
  2100.                {
  2101.                case 0:
  2102.                     pResolutionData->Horiz  = atoi(pszNextToken);
  2103.                     break;
  2104.                case 1:
  2105.                     pResolutionData->Vert = atoi(pszNextToken);
  2106.                     break;
  2107.                case 2:
  2108.                     pResolutionData->Colors = atoi(pszNextToken);
  2109.                     break;
  2110.                }
  2111.                pszNextToken = (pszNextToken + strspn(pszNextToken,pszTokens) );
  2112.           }
  2113.      }
  2114.      return;
  2115. }
  2116. //////////////////////////////////////////////////////////////////
  2117. //
  2118. //  Name: SvgaReportError
  2119. //
  2120. //  Purpose: Display error message.
  2121. //
  2122. //  Usage: Called when a fatal error occurrs while installing a
  2123. //         device driver.
  2124. //
  2125. //  Method: - Display message box with error message.
  2126. //          - Log error to logfile.
  2127. //
  2128. //  Returns:
  2129. //
  2130. //////////////////////////////////////////////////////////////////
  2131.  
  2132. VOID SvgaReportError(ULONG rc,PSZ pszMsg,HWND hwndOwner)
  2133. {
  2134. //@TM    PSZ  pszErrorTitle = "Svga Installation Error";
  2135.     HAB  hab;
  2136.     CHAR szMsg[CCHMAXPATH];
  2137.     CHAR szErrorTitle[CCHMAXPATH];
  2138.     PSZ  pszEnvironment = NULL;
  2139.  
  2140.  
  2141.     WinAlarm(HWND_DESKTOP, WA_ERROR);
  2142.     hab = WinInitialize(0);
  2143.  
  2144. //@TM    if (!pszMsg)
  2145. //@TM    {
  2146. //@TM        pszMsg = szErrorMsg[rc];
  2147. //@TM    }
  2148.  
  2149.     WinLoadString(hab, hmodResource, rc, CCHMAXPATH,
  2150.            szMsg);
  2151.  
  2152.  
  2153.     WinLoadString(hab, hmodResource, MSG_SVGA_ERROR_TITLE, CCHMAXPATH,
  2154.            szErrorTitle);
  2155.  
  2156.     WinMessageBox(HWND_DESKTOP,
  2157.                   hwndOwner,
  2158.                   szMsg,
  2159.                   szErrorTitle,
  2160.                   MBX_INSTERROR,
  2161.                   MB_OK | MB_ERROR | MB_MOVEABLE | MB_SYSTEMMODAL);
  2162.  
  2163.  
  2164.     /*
  2165.      *log the error
  2166.      */
  2167.      svgaLog(szMsg);
  2168.  
  2169.      WinTerminate( hab );
  2170.  
  2171. } /* SvgaReportError() */
  2172.  
  2173. //////////////////////////////////////////////////////////////////
  2174. //
  2175. //  Name: CenterDialog
  2176. //
  2177. //  Purpose: Center a dialog box on the main window.
  2178. //
  2179. //  Usage: Called during the WM_INITDLG of all dialog window
  2180. //         procedures.
  2181. //
  2182. //  Method:
  2183. //
  2184. //  Returns:
  2185. //        VOID
  2186. //////////////////////////////////////////////////////////////////
  2187. VOID CenterDialog(HWND hwnd)
  2188. {
  2189.   SWP    swpDlgPos;                      /* structure for position of dialog */
  2190.   SWP    swpFramePos;                     /* structure for position of frame */
  2191.   POINTL ptlDesktop;                          /* height and width of desktop */
  2192.  
  2193.   /* get gesktop size */
  2194.   ptlDesktop.x = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  2195.   ptlDesktop.y = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  2196.  
  2197.   /* get dialog position */
  2198.   WinQueryWindowPos(hwnd, &swpDlgPos);
  2199.  
  2200.   if (WinIsWindowVisible(hwnd) &&      /* center everything but logo and */
  2201.       (hwnd != hwnd))                  /* and main frame on hwndMain     */
  2202.   {
  2203.     /* get frame position */
  2204.     WinQueryWindowPos(hwnd, &swpFramePos);
  2205.  
  2206.     /* center the dialog vertically on frame */
  2207.     swpDlgPos.y = (SHORT)((swpFramePos.cy / 2) - (swpDlgPos.cy / 2) + swpFramePos.y);
  2208.  
  2209.     /* center the dialog horizontally on frame */
  2210.     swpDlgPos.x = (SHORT)((swpFramePos.cx /2) - (swpDlgPos.cx /2) + swpFramePos.x);
  2211.   }
  2212.   else
  2213.   {
  2214.     /* center the dialog vertically on the desktop */
  2215.     swpDlgPos.y = (SHORT)((ptlDesktop.y / 2) - (LONG)(swpDlgPos.cy / 2));
  2216.  
  2217.     /* center the dialog horizontally on the desktop */
  2218.     swpDlgPos.x = (SHORT)((ptlDesktop.x /2) - (LONG)(swpDlgPos.cx /2));
  2219.   }
  2220.  
  2221.   /* be sure the dialog didn't go off the left edge of the screen */
  2222.   if (swpDlgPos.x < 0)
  2223.     swpDlgPos.x = 0;
  2224.  
  2225.   /* be sure the dialog didn't go off the bottom edge of the screen */
  2226.   if (swpDlgPos.y < 0)
  2227.     swpDlgPos.y = 0;
  2228.  
  2229.   /* be sure the dialog didn't go off the right edge of the screen */
  2230.   if (((LONG)swpDlgPos.x + (LONG)swpDlgPos.cx) > ptlDesktop.x)
  2231.     swpDlgPos.x = (SHORT)(ptlDesktop.x - (LONG)swpDlgPos.cx);
  2232.  
  2233.   /* be sure the dialog didn't go off the top edge of the screen */
  2234.   if (((LONG)swpDlgPos.y + (LONG)swpDlgPos.cy) > ptlDesktop.y)
  2235.     swpDlgPos.y = (SHORT)(ptlDesktop.y - (LONG)swpDlgPos.cy);
  2236.  
  2237.   /* reposition the dialog and make it visible. */
  2238.   WinSetWindowPos(hwnd,
  2239.                   HWND_TOP,
  2240.                   swpDlgPos.x,
  2241.                   swpDlgPos.y,
  2242.                   0, 0,
  2243.                   SWP_ACTIVATE | SWP_MOVE | SWP_ZORDER | SWP_SHOW);
  2244.  
  2245. } /* CenterDialog() */
  2246.  
  2247. /****************************************************************\
  2248.  *
  2249.  *--------------------------------------------------------------
  2250.  *
  2251.  *  Name:GetDllHandle
  2252.  *
  2253.  *  Purpose: Get a module resource handle to the svga.dll.
  2254.  *
  2255.  *
  2256.  *
  2257.  *  Usage:Pass a  pointer to a  resource handle to the routine. If
  2258.  *        error,the system error number is returned,else 0 is
  2259.  *        returned.
  2260.  *  Returns:
  2261.  *          apiRet - System Error number
  2262.  *          0 - if no error
  2263. \****************************************************************/
  2264. APIRET APIENTRY GetDllHandle( PHMODULE phmodResource)
  2265. {
  2266.      APIRET apiRet;
  2267.      CHAR szFailName[CCHMAXPATH];
  2268.      PSZ  pszModuleName = S3_MODULE;
  2269.      PSZ  pszModuleTemp = S3_MODULE;
  2270.      ULONG  ulDrive;
  2271.      CHAR szPath[CCHMAXPATH];
  2272.      PSZ  pchCur,pszTemp;
  2273.      ULONG ulSize;
  2274.  
  2275.      DosError(HARDERROR_DISABLE);
  2276.  
  2277.  
  2278.      memset(szFailName,0,sizeof(szFailName) );
  2279.      /*
  2280.       *try to load in from the dpath
  2281.       */
  2282.      if( pszTemp = strchr(pszModuleTemp,'.') )
  2283.      {
  2284.           *pszTemp = 0;
  2285.      }
  2286.      if(apiRet  = DosLoadModule(szFailName, 0,pszModuleTemp, phmodResource) )
  2287.      {
  2288.           /*
  2289.            *if not go out to the drives
  2290.            */
  2291.           for(ulDrive= 1; ulDrive <= MAXDRIVES;ulDrive++ )
  2292.           {
  2293.                /*
  2294.                 *build the paths for each drive,
  2295.                 *where oh,where might you be tonight
  2296.                 */
  2297.                memset(szPath,0,sizeof(szPath) );
  2298.                ulSize = sizeof(szPath) - 3;
  2299.                DosQueryCurrentDir(ulDrive,&szPath[3],&ulSize);
  2300.  
  2301.                szPath[0] = 'A' + ulDrive - 1;
  2302.                szPath[1] = ':';
  2303.                szPath[2] = '\\';
  2304.                if( (szPath[strlen(szPath)-1]) != '\\')
  2305.                {
  2306.                     strcat(szPath,"\\");
  2307.                }
  2308.                strcat(szPath,pszModuleName);
  2309.                /*
  2310.                 *try to load off this drive
  2311.                 */
  2312.                apiRet  = DosLoadModule(szFailName, sizeof(szFailName),
  2313.                                        szPath, phmodResource);
  2314.  
  2315.                if(!apiRet)
  2316.                {
  2317.                    /*
  2318.                     *we loaded,time to boogey out
  2319.                     */
  2320.                    break;
  2321.                }
  2322.           }
  2323.      }
  2324.      DosError(HARDERROR_ENABLE);
  2325.  
  2326.      return(apiRet);
  2327. }
  2328. /****************************************************************\
  2329.  *
  2330.  *--------------------------------------------------------------
  2331.  *
  2332.  *  Name: svgaLog
  2333.  *
  2334.  *  Purpose:   Generic logging routine for svga installation
  2335.  *             error. Note: this should be changed so that the
  2336.  *             display install utility can pass through a funciton
  2337.  *             pointer to it's own logging function.NOTE>>>>>>
  2338.  *
  2339.  *
  2340.  *
  2341.  *  Usage:
  2342.  *
  2343.  *  Method:
  2344.  *          -
  2345.  *
  2346.  *          -
  2347.  *          -
  2348.  *
  2349.  *          -
  2350.  *          -
  2351.  *
  2352.  *  Returns:
  2353.  *
  2354.  *          VOID
  2355. \****************************************************************/
  2356. VOID svgaLog(PSZ pszMsg)
  2357. {
  2358.      CHAR szDateTime [SIZ_DATE_TIME];
  2359.      CHAR *pszNull;
  2360.  
  2361.  
  2362.      memset(szDateTime,' ',sizeof(szDateTime) );
  2363.      _strdate(szDateTime);
  2364.      /*
  2365.       *get rid of the null and keep the date,time
  2366.       *on the same line in the log file
  2367.       */
  2368.      if( (pszNull = strchr(szDateTime,'\0') ) )
  2369.      {
  2370.           *pszNull = ' ';
  2371.      }
  2372.      _strtime( &szDateTime[SIZ_DATE_TIME /2]);
  2373.  
  2374.      if(pfnLogFunction)
  2375.      {
  2376.           (*pfnLogFunction)(szDateTime);
  2377.           (*pfnLogFunction)(pszMsg);
  2378.      }
  2379. }
  2380.  
  2381. //////////////////////////////////////////////////////////////////
  2382. //
  2383. //  Name: SvgaReportError
  2384. //
  2385. //  Purpose: Display error message.
  2386. //
  2387. //  Usage: Called when a fatal error occurrs while installing a
  2388. //         device driver.
  2389. //
  2390. //  Method: - Display message box with error message.
  2391. //          - Log error to logfile.
  2392. //
  2393. //  Returns:
  2394. //
  2395. //////////////////////////////////////////////////////////////////
  2396. USHORT SvgaMessageBox(ULONG rc,PSZ pszMsg,HWND hwndOwner)
  2397. {
  2398. //@TM    PSZ  pszErrorTitle = "Svga Installation Message";
  2399.     HAB  hab;
  2400.     USHORT usRc;
  2401.     CHAR szMsg[CCHMAXPATH];
  2402.     CHAR szErrorTitle[CCHMAXPATH];
  2403.  
  2404.  
  2405.     WinAlarm(HWND_DESKTOP, WA_ERROR);
  2406.     hab = WinInitialize(0);
  2407.  
  2408. //@TM    if (!pszMsg)
  2409. //@TM    {
  2410. //@TM        pszMsg = szErrorMsg[rc];
  2411. //@TM    }
  2412.  
  2413.     WinLoadString(hab, hmodResource, MSG_SVGA_INSTALL, CCHMAXPATH,
  2414.            szErrorTitle);
  2415.     WinLoadString(hab, hmodResource, rc, CCHMAXPATH,
  2416.            szMsg);
  2417.  
  2418.     usRc = WinMessageBox(HWND_DESKTOP,
  2419.                   hwndOwner,
  2420.                   szMsg,
  2421.                   szErrorTitle,
  2422.                   MBX_INSTERROR,
  2423.                   MB_YESNO | MB_ERROR | MB_MOVEABLE |
  2424.                   MB_DEFBUTTON2 | MB_SYSTEMMODAL );
  2425.  
  2426.      WinTerminate( hab );
  2427.      return(usRc);
  2428. }
  2429.  
  2430. /****************************************************************\
  2431.  *
  2432.  *--------------------------------------------------------------
  2433.  *
  2434.  *  Name:GetSelectedResolution
  2435.  *
  2436.  *  Purpose: This routine will loop through the  list of pSelectedResolutions
  2437.  *           for up to ulCount number of elements looking for the ulSelected
  2438.  *           flag to be set to TRUE. A pointer to the first ulSelected
  2439.  *           element will be returned or NULL if no selection was made.
  2440.  *  Returns:
  2441.  *          pszResolutions  = a pointer to the selected resolutions string
  2442.  *                            or NULL if none was selected.
  2443. \****************************************************************/
  2444. PSZ GetDesignatedResolution(PDSPINSTL_CHAIN pChain,
  2445.                             ULONG ulCount,
  2446.                             LONG lOffSetToGet)
  2447. {
  2448.  
  2449.      ULONG ulCounter;
  2450.      PSZ pszResolutions = NULL;
  2451.      PDSPINSTL_CHAIN  pTemp;
  2452.  
  2453.  
  2454.      for(ulCounter =0,pTemp = pChain; pTemp;
  2455.                               pTemp = pTemp->pNextDspInstl,ulCounter++)
  2456.      {
  2457.  
  2458.           if(pTemp->pszResolution)
  2459.           {
  2460.                pszResolutions= pTemp->pszResolution;
  2461.                break;
  2462.           }
  2463.      }
  2464.      return(pszResolutions);
  2465. }
  2466.  
  2467. /***************************************************************************/
  2468.  
  2469.  
  2470.                                                 /* Amol; D58319; 12/09/92  */
  2471. BOOL CheckSVGAMem (PRESOLUTIONS pResolutions, ULONG ulResolutionCount)
  2472. /*-------------------------------------------------------------------------*\
  2473.  *
  2474.  * This is a routine to check if 1024x768 resolution has been specified for
  2475.  * this SVGA card. If it has been, then the routine returns TRUE else returns
  2476.  * FALSE. If the 1024x768 resolution is indeed supported, then it means that
  2477.  * the card has at least 1 MB memory on it.
  2478.  *
  2479. \*-------------------------------------------------------------------------*/
  2480. {
  2481.    ULONG          ulCounter   =  0;
  2482.    RESOLUTIONDATA resData;
  2483.  
  2484.    for (; ulCounter < ulResolutionCount; ulCounter++)
  2485.    {
  2486.       StringToResolution               /* Convert string to resolution     */
  2487.          ((pResolutions + ulCounter)->achResolutionString, &resData);
  2488.  
  2489.       if ((resData.Horiz >= 1024)   && /* Does this support 1024x768x256 ? */
  2490.           (resData.Vert  >= 768)    &&
  2491.           (resData.Colors >= 256))
  2492.                                        /* Yes, it does support the above ! */
  2493.          return TRUE;                  /* Done - return TRUE status        */
  2494.    }
  2495.  
  2496.    return FALSE;                       /* Done - return FALSE status       */
  2497.  
  2498. } /* CheckSVGAMem */
  2499.  
  2500. /***************************************************************************/
  2501.  
  2502.  
  2503.                                                 /* Amol; D58319; 12/11/92  */
  2504. BOOL IsResolutionOver1Mg (PSZ pszResolution,PRESOLUTIONDATA  pResolutions)
  2505. /*-------------------------------------------------------------------------*\
  2506.  *
  2507.  * This is a routine to check if pszResolution specifies a driver requiring
  2508.  * 1 MB or more.
  2509.  *
  2510.  * The routine returns TRUE if the driver requires 1 MB or more else returns
  2511.  * FALSE.
  2512.  *
  2513. \*-------------------------------------------------------------------------*/
  2514. {
  2515.    PSZ  pszResCopy = strdup (pszResolution);
  2516.  
  2517.    strupr (pszResCopy);
  2518.  
  2519.    if ((pResolutions->Horiz  >= 1024)  && /* Check for 1024x768x256 mode   */
  2520.        (pResolutions->Vert   >=  768)  &&
  2521.        (pResolutions->Colors >=  256))
  2522.                                        /* This means more than 1 MB VRAM   */
  2523.       return TRUE;                     /* Done - return TRUE status        */
  2524.  
  2525.    if (strstr (pszResCopy, "1.0")   && /* Check if 1.0 MB was specified    */
  2526.        (strstr (pszResCopy, "MG")   ||
  2527.         strstr (pszResCopy, "MB")))
  2528.                                        /* 1.0 MB was NOT specified         */
  2529.       return TRUE;                     /* Done - return TRUE status        */
  2530.  
  2531.    return FALSE;                       /* Done - return FALSE status       */
  2532.  
  2533. }  /* IsResolutionOver1Mg */
  2534.  
  2535.  
  2536. //////////////////////////////////////////////////////////////////
  2537. //
  2538. //  Name: InitHelp
  2539. //
  2540. //  Purpose: Initializes the IPF help facility.
  2541. //
  2542. //  Usage: Called once during initialization of the program.
  2543. //
  2544. //  Method: Initializes the HELPINIT structure and creates the
  2545. //          help instance.
  2546. //
  2547. //  Returns:
  2548. //
  2549. //////////////////////////////////////////////////////////////////
  2550.  
  2551. VOID InitHelp(HWND *phwndHelpInstance)
  2552. {
  2553.   HELPINIT hmInitStruct;
  2554.   CHAR     szMsg[CCHMAXPATH];
  2555.   CHAR     szErrorTitle[CCHMAXPATH];
  2556.   CHAR     szMainTitle[CCHMAXPATH];
  2557.   PSZ      pszHelpFile = "C:\\OS2\\HELP\\DSPINSTL.HLP";
  2558.   static   HAB      hab;
  2559.   ULONG    ulBootDrive;
  2560.  
  2561.  
  2562. #ifndef RESPONSE_FILE
  2563.  
  2564.  
  2565.   hab = WinInitialize( 0 );
  2566.   WinLoadString(hab, hmodResource, MSG_MAINHELPTITLE, CCHMAXPATH,
  2567.          szMainTitle);
  2568.  
  2569.   DosQuerySysInfo(QSV_BOOT_DRIVE,
  2570.                   QSV_BOOT_DRIVE,
  2571.                   &ulBootDrive,
  2572.                   sizeof(ulBootDrive));
  2573.  
  2574.   *pszHelpFile = (CHAR)(ulBootDrive + 'A' - 1);
  2575.  
  2576.   /* inititalize help init structure */
  2577.   hmInitStruct.cb = sizeof(HELPINIT);
  2578.   hmInitStruct.ulReturnCode = 0;
  2579.   hmInitStruct.pszTutorialName = (PSZ)NULL;
  2580.   hmInitStruct.phtHelpTable = (PHELPTABLE)(0xffff0000 | MAIN_HELP_TABLE);
  2581.   hmInitStruct.hmodHelpTableModule = 0;
  2582.   hmInitStruct.hmodAccelActionBarModule = 0;
  2583.   hmInitStruct.idAccelTable = 0;
  2584.   hmInitStruct.idActionBar = 0;
  2585.   hmInitStruct.pszHelpWindowTitle = szMainTitle;
  2586.   hmInitStruct.fShowPanelId = (ULONG)CMIC_HIDE_PANEL_ID;
  2587.   hmInitStruct.pszHelpLibraryName = pszHelpFile;
  2588.  
  2589.   /* creating help instance */
  2590.   *phwndHelpInstance = WinCreateHelpInstance(hab, &hmInitStruct);
  2591.  
  2592.   if (!*phwndHelpInstance || hmInitStruct.ulReturnCode)
  2593.   {
  2594.         WinLoadString(hab, hmodResource, MSG_APPTITLE, CCHMAXPATH,
  2595.                szErrorTitle);
  2596.  
  2597.         WinLoadString(hab, hmodResource, MSG_HELPNOTAVAIL, CCHMAXPATH,
  2598.                szMsg);
  2599.  
  2600.         WinMessageBox(HWND_DESKTOP,
  2601.                       HWND_DESKTOP,
  2602.                       szMsg,
  2603.                       szErrorTitle,
  2604.                       0,
  2605.                       MB_OK | MB_INFORMATION | MB_MOVEABLE);
  2606.  
  2607.         if (*phwndHelpInstance)
  2608.         {
  2609.             WinDestroyHelpInstance(hwndHelpInstance);
  2610.         }
  2611.    }
  2612. #endif
  2613. } /* InitHelp() */
  2614.  
  2615. /**************************************************************************/
  2616.  
  2617.