home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 8 Other / 08-Other.zip / TEST.ZIP / TEST.SQC
Text File  |  1993-01-04  |  36KB  |  913 lines

  1. #define INCL_WIN
  2. #define INCL_GPI
  3. #define INCL_DOSPROCESS
  4.  
  5. #include <os2.h>                        /* PM header file               */
  6. #include <stdio.h>
  7. #include <sqlenv.h>
  8. #include <sqlca.h>
  9. #include <string.h>
  10. #include <math.h>
  11. #include <stdlib.h>
  12. #include "edihelp.h"                      /* Resource symbolic identifiers*/
  13. #define SLEEPTIME 1
  14.  
  15. #define STRINGLENGTH 100                /* Length of string             */
  16. #define APPLWINWIDTH 400                /* Application Window'w width   */
  17. #define APPLWINHEIGTH 200               /* Application Window's heigth  */
  18. #define ANIMATE WM_USER
  19.  
  20. /*********************/
  21. /* Global Variables. */
  22. /*********************/
  23. ULONG ulFrameFlags=FCF_TASKLIST | FCF_SIZEBORDER |
  24.   FCF_TITLEBAR | FCF_MINMAX |
  25.   FCF_SYSMENU | FCF_MENU | FCF_ICON | FCF_ACCELTABLE;
  26. PSZ szWinClass[] = "EDI Window Class";
  27. QMSG qmsg;                            /* Message from message queue   */
  28. HPS  hps, hpsMemory;
  29. HAB  hab;                               /* PM anchor block handle       */
  30. HDC hdc, hdcMemory;
  31. HWND hwndClient = NULLHANDLE;           /* Client area window handle    */
  32. HWND hwndFrame = NULLHANDLE;            /* Frame window handle          */
  33. HWND hwndFetch = NULLHANDLE;            /* SQL Fetch window handle      */
  34. BITMAPINFOHEADER bmpSrc;
  35. HBITMAP hbmSrc;
  36. CHAR szHello[STRINGLENGTH];             /* String parameters, set in    */
  37. CHAR sz2[STRINGLENGTH];                 /* and used in the processing   */
  38. CHAR sz3[STRINGLENGTH];                 /* of WM_COMMAND, in window     */
  39. CHAR szString[STRINGLENGTH];            /* procedure.                   */
  40. PSZ  pszErrMsg;
  41. BOOL bFirstTime = TRUE;
  42. SHORT sxPels, syPels;
  43. LONG alBmpFormats[2];
  44. LONG lPointSize;
  45. LONG lcxPelsPerInch, lcyPelsPerInch;
  46. LONG lcxPelsPerMeter, lcyPelsPerMeter;
  47. CHAR sDrvPath[80];
  48. INT rc;
  49. CHAR szRecord[ 74];
  50.  
  51. EXEC SQL BEGIN DECLARE SECTION;
  52.   char szSegId[ 4];
  53.   char szSegNm[ 71];
  54. EXEC SQL END DECLARE SECTION;
  55.  
  56.  
  57. /***********************/
  58. /* Function prototypes */
  59. /***********************/
  60. MRESULT EXPENTRY EdiHelpMakeProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  61. MRESULT EXPENTRY DrivePathProc(HWND hwnd, ULONG msg,
  62.    MPARAM mp1, MPARAM mp2);
  63. MRESULT EXPENTRY SegFetchProc(HWND hwnd, ULONG msg,
  64.    MPARAM mp1, MPARAM mp2);
  65. BOOL FAR FindFont( HPS hps, LONG *lLcid, CHAR *szFontName);
  66. LONG FAR GetSetID( HPS hps);
  67. BOOL FAR SetPtSize( HPS hps, LONG lLcid, LONG lPointSize,
  68.    FIXED *width, FIXED *height);
  69. void FAR SetWidthsTable( HPS hps, LONG *alWidths,
  70.    LONG *alWidthTable, CHAR *szStr, LONG *lTotal);
  71. SHORT FAR Random_Range( SHORT lower_lim, SHORT upper_lim,
  72.    SHORT lower_exc, SHORT upper_exc);
  73.  
  74. /******************************************/
  75. /* Required IPF Structures For Help Text. */
  76. /******************************************/
  77. HELPINIT hmiHelpData;
  78. HWND hwndHelpInstance;
  79.  
  80. EXEC SQL INCLUDE SQLCA;
  81.  
  82. main(int argc, char *argv[], char *envp[])
  83. {
  84.   HDC hdcTemp;
  85.   HPS hpsTemp;
  86.   HMQ  hmq;                             /* Message queue handle         */
  87.   if ((hab = WinInitialize(0)) == 0L) /* Initialize PM     */
  88.      AbortHello( hwndFrame, hwndClient); /* Terminate the application    */
  89.  
  90.   if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L)/* Create a msg queue */
  91.      AbortHello( hwndFrame, hwndClient); /* Terminate the application    */
  92.  
  93.   /*********************************/
  94.   /* IPF Initialization Structure. */
  95.   /*********************************/
  96.   hmiHelpData.cb = sizeof( HELPINIT);
  97.   hmiHelpData.ulReturnCode = 0;
  98.   hmiHelpData.pszTutorialName = NULL;
  99.   hmiHelpData.phtHelpTable = ( PVOID)( 0xffff0000 | MAIN_HELPTABLE);
  100.   hmiHelpData.hmodAccelActionBarModule = 0;
  101.   hmiHelpData.idAccelTable = 0;
  102.   hmiHelpData.idActionBar = 0;
  103.   hmiHelpData.pszHelpWindowTitle = ( PSZ)"EDI 3020 Standards Help";
  104.   hmiHelpData.hmodHelpTableModule = 0;
  105.   hmiHelpData.fShowPanelId = 0;
  106.   hmiHelpData.pszHelpLibraryName = ( PSZ)"EDIHELP.HLP";
  107.  
  108.   /***************************/
  109.   /* Create instance of IPF. */
  110.   /***************************/
  111. /*
  112.   hwndHelpInstance = WinCreateHelpInstance( hab, &hmiHelpData);
  113.   if( !hwndHelpInstance)
  114.     WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
  115.       (PSZ)"Help Not Available", (PSZ)"Help Creation Error",
  116.       1, MB_OK | MB_APPLMODAL | MB_MOVEABLE);
  117.   else {
  118.     if( hmiHelpData.ulReturnCode){
  119.       WinMessageBox( HWND_DESKTOP, HWND_DESKTOP,
  120.         (PSZ)"Help Terminated Due to Error",
  121.         (PSZ)"Help Creation Error",
  122.         1, MB_OK | MB_APPLMODAL | MB_MOVEABLE);
  123.       WinDestroyHelpInstance( hwndHelpInstance);
  124.       }
  125.     }
  126. */
  127.   if (!(rc = WinRegisterClass(          /* Register window class        */
  128.      hab,                               /* Anchor block handle          */
  129.      (PSZ)szWinClass,                   /* Window class name            */
  130.      (PFNWP)EdiHelpMakeProc,               /* Address of window procedure  */
  131.      CS_SIZEREDRAW,                     /* Class style                  */
  132.      0                                  /* No extra window words        */
  133.      )))
  134.      AbortHello(hwndFrame, hwndClient); /* Terminate the application    */
  135.  
  136.   if ((hwndFrame = WinCreateStdWindow(
  137.                HWND_DESKTOP,            /* Desktop window is parent     */
  138.                WS_VISIBLE,              /* STD. window styles           */
  139.                &ulFrameFlags,           /* Frame control flag           */
  140.                (PSZ)szWinClass,         /* Client window class name     */
  141.                "EDI Make Help Utility", /* Window text                  */ 
  142.                0,                       /* No special class style       */
  143.                (HMODULE)0L,             /* Resource is in .EXE file     */
  144.                ID_WINDOW,               /* Frame window identifier      */
  145.                &hwndClient              /* Client window handle         */
  146.                )) == 0L)
  147.      AbortHello(hwndFrame, hwndClient); /* Terminate the application    */
  148.  
  149.   WinOpenWindowDC( hwndFrame);
  150.  
  151.   /***************************************************/
  152.   /* Resolve the number of pels per inch in both the */
  153.   /* horizontal and vertical directions.             */
  154.   /***************************************************/
  155.   hpsTemp = WinGetPS( HWND_DESKTOP);
  156.   hdcTemp = GpiQueryDevice( hpsTemp);
  157.   if(( hdcTemp != 0L) && ( hdcTemp != HDC_ERROR)){
  158.     DevQueryCaps( hdcTemp, CAPS_VERTICAL_RESOLUTION, 1L,
  159.       &lcyPelsPerMeter);
  160.     DevQueryCaps( hdcTemp, CAPS_HORIZONTAL_RESOLUTION, 1L,
  161.       &lcxPelsPerMeter);
  162.     lcxPelsPerInch = ( lcxPelsPerMeter * 254) / 10000;
  163.     lcyPelsPerInch = ( lcyPelsPerMeter * 254) / 10000;
  164.     }
  165.  
  166.   /****************************************************/
  167.   /* Set window position to be one half inch to right */
  168.   /* and one half inch up.  Make the window size      */
  169.   /* 7 inches by 6 inches.  Set input focus.          */
  170.   /****************************************************/
  171.   if( !WinSetWindowPos( hwndFrame, 0L, (SHORT)lcxPelsPerInch / 2,
  172.       (SHORT)lcyPelsPerInch / 2, (SHORT)lcxPelsPerInch * 7,
  173.       (SHORT)lcyPelsPerInch * 6, SWP_SIZE | SWP_MOVE))
  174.     AbortHello( hwndFrame, hwndClient); /* Terminate the application    */
  175.   WinReleasePS( hpsTemp);
  176.   WinSetFocus(HWND_DESKTOP, hwndFrame);
  177.  
  178.   /******************************/
  179.   /* Associate instance of IPF. */
  180.   /******************************/
  181.   if( hwndHelpInstance)
  182.     WinAssociateHelpInstance( hwndHelpInstance, hwndFrame);
  183.  
  184.   /**********************************************************************/
  185.   /* Get and dispatch messages from the application message queue       */
  186.   /* until WinGetMsg returns FALSE, indicating a WM_QUIT message.       */
  187.   /**********************************************************************/
  188.   while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) ){
  189.     DosEnterCritSec();
  190.     WinDispatchMsg( hab, &qmsg );
  191.     DosExitCritSec(); }
  192.  
  193.   if( hwndHelpInstance) WinDestroyHelpInstance( hwndHelpInstance);
  194.   WinDestroyWindow( hwndFrame);          /* Tidy up...                   */
  195.   WinDestroyMsgQueue( hmq);              /* Tidy up...                   */
  196.   WinTerminate( hab);                    /* Terminate the application    */
  197. } /* End of main */
  198.  
  199. /**************************************************************************
  200.  *  Name       : EdiHelpMakeProc
  201.  *************************************************************************/
  202. MRESULT EXPENTRY EdiHelpMakeProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  203. {
  204.   CHAR szStr1[]="EDI Help Utility";
  205.   CHAR szStr2[]="All standards, cross-platform";
  206.   CHAR szStr3[]="clear-text searchable EDI Help";
  207.   CHAR szStr4[]="(Putting the EDI user in touch)";
  208.   LONG lReturn;
  209.   POINTL aptl[ 4];
  210.   SIZEF sizefxCharBox;
  211.   FIXED width, height;
  212.   CHAR szFontName[]="Courier";
  213.   CHAR szFontName1[]="Times New Roman";
  214.   BOOL fRet = FALSE;
  215.   BITMAPINFOHEADER2 bmp;
  216.   LONG lTotal, lLcid;
  217.   HPS hpsd;
  218.   float fPitch;
  219.   POINTL ptl, shear;
  220.   LONG alWidths[80];
  221.   LONG alWidthTable[256];
  222.   SIZEL sizl;
  223.   SHORT x, y, i;
  224.   LONG pattern[]={
  225.       PATSYM_DEFAULT, PATSYM_DENSE1, PATSYM_DENSE2,
  226.       PATSYM_DENSE3, PATSYM_DENSE4, PATSYM_DENSE5,
  227.       PATSYM_DENSE6, PATSYM_DENSE7, PATSYM_DENSE8,
  228.       PATSYM_NOSHADE};
  229.   ULONG flStyle = FCF_SHELLPOSITION;
  230.  
  231.   switch( msg)
  232.   {
  233.     case WM_CREATE:
  234.       hdc = WinOpenWindowDC( hwnd);  /* Create window device context. */
  235.       sizl.cx = 0;              /* Create Micro-PS.  Keep as global. */
  236.       sizl.cy = 0;
  237.       hps = GpiCreatePS( hab, hdc, &sizl, PU_PELS | GPIT_MICRO |
  238.         GPIA_ASSOC | GPIF_DEFAULT);
  239.  
  240.       lReturn = WinLoadString( hab, (HMODULE)0L, IDS_HELLO, STRINGLENGTH, szHello );
  241.       lReturn = WinLoadString( hab, (HMODULE)0L, IDS_3,     STRINGLENGTH, sz3     );
  242.       strcpy( szString, szHello );      /* Copy text Hello into szString*/
  243.  
  244.       /********************************************************/
  245.       /* Create memory device context for our screen bit-map. */
  246.       /********************************************************/
  247.       hdcMemory = DevOpenDC( hab, OD_MEMORY, (PSZ)"*", 0L, 0L, 0L);
  248.       sizl.cx = 0;   /* Create presentation space for screen bit-map. */
  249.       sizl.cy = 0;
  250.       hpsMemory = GpiCreatePS( hab, hdcMemory, &sizl,
  251.         PU_PELS | GPIF_DEFAULT | GPIT_MICRO | GPIA_ASSOC);
  252.  
  253.       /*************************************************/
  254.       /* Get the screen dimension in pels and save it. */
  255.       /*************************************************/
  256.       sxPels = WinQuerySysValue( HWND_DESKTOP, SV_CXSCREEN);
  257.       syPels = WinQuerySysValue( HWND_DESKTOP, SV_CYSCREEN);
  258.  
  259.       /*******************************************/
  260.       /* Set up bit-map header for correct size. */
  261.       /*******************************************/
  262.       GpiQueryDeviceBitmapFormats( hpsMemory, 2L, alBmpFormats);
  263.       memset( &bmp, 0, sizeof( bmp));
  264.       bmp.cbFix = sizeof bmp;
  265.       bmp.cx = sxPels;
  266.       bmp.cPlanes = (USHORT)alBmpFormats[0];
  267.       bmp.cBitCount = (USHORT)alBmpFormats[1];
  268.       bmp.cy = syPels;
  269.       hbmSrc = GpiCreateBitmap( hpsMemory, &bmp, 0L, NULL, NULL);
  270.       GpiSetBitmap( hpsMemory, hbmSrc);
  271.       aptl[0].x = 0; aptl[0].y = 0;
  272.       aptl[1].x = bmp.cx; aptl[1].y = bmp.cy;
  273.       aptl[2].x = 0; aptl[2].y = 0;
  274.  
  275.       /************************************************/
  276.       /* Copy the desktop image to our memory device. */
  277.       /************************************************/
  278.       hpsd = WinGetScreenPS( HWND_DESKTOP);
  279.       GpiBitBlt( hpsMemory, hpsd, 3L, aptl, ROP_SRCCOPY, BBO_AND);
  280.  
  281.       /*********************/
  282.       /* Release resource. */
  283.       /*********************/
  284.       WinReleasePS( hpsd);
  285.       return( MRESULT)FALSE;
  286.  
  287.     case WM_COMMAND:
  288.       /*
  289.        * When the user chooses option 1, 2, or 3 from the Options pull-
  290.        * down, the text string is set to 1, 2, or 3, and
  291.        * WinInvalidateRegion sends a WM_PAINT message.
  292.        * When Exit is chosen, the application posts itself a WM_CLOSE
  293.        * message.
  294.        */
  295.       {
  296.       USHORT command;                   /* WM_COMMAND command value     */
  297.       command = SHORT1FROMMP(mp1);      /* Extract the command value    */
  298.       switch (command)
  299.       {
  300.         case ID_PATH:
  301.           rc = WinDlgBox( HWND_DESKTOP, hwnd, DrivePathProc, 0, ID_PATH, &sDrvPath);
  302.           WinInvalidateRegion( hwnd, 0L, FALSE );
  303.           return(( MRESULT) TRUE);
  304.        case ID_DBFETCH:
  305.           if (!(rc = WinRegisterClass(          /* Register window class        */
  306.              hab,                               /* Anchor block handle          */
  307.              (PSZ)szWinClass,                   /* Window class name            */
  308.              (PFNWP)SegFetchProc,               /* Address of window procedure */
  309.              CS_SIZEREDRAW,                     /* Class style                  */
  310.              0                                  /* No extra window words        */
  311.              )))
  312.             AbortHello( hwndFrame, hwndClient); /* Terminate the application    */
  313.  
  314.           hwndFrame = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE, &flStyle,
  315.                         (PSZ)szWinClass, "", 0L, (HMODULE)0, ID_FETCHWINDOW,
  316.                         &hwndFetch);
  317.           WinSetFocus( HWND_DESKTOP, hwndFetch);
  318.           EXEC SQL WHENEVER SQLERROR GO TO ext;
  319.           EXEC SQL WHENEVER NOT FOUND GO TO cls;
  320.           EXEC SQL DECLARE c1 CURSOR FOR
  321.             SELECT SegId, SegNm FROM Standrds.X31SegHdx;
  322.           EXEC SQL OPEN c1;
  323.           do
  324.           {
  325.             EXEC SQL FETCH c1 INTO :szSegId, :szSegNm;
  326.             strcpy( szRecord, szSegId);
  327.             strcat( szRecord, szSegNm);
  328.             printf( "%s\n", szRecord);
  329.           } while ( 1);
  330.          cls:
  331.           EXEC SQL CLOSE c1;
  332.          ext:
  333.           if( SQLCODE != 0)
  334.             printf( "Error: SQLCODE = %d.\n", SQLCODE);
  335.           EXEC SQL WHENEVER SQLERROR CONTINUE;
  336.           printf( "\nFinished Test Select.");
  337.           sqlestpd( &sqlca);
  338.           if( SQLCODE != 0)
  339.             printf( "\nStop DB Error: SQLCODE = %d", SQLCODE);
  340.           WinInvalidateRegion( hwnd, 0L, FALSE );
  341.           break;
  342.         case ID_OPTION3:
  343.           strcpy( szString, sz3 );
  344.           WinInvalidateRegion( hwnd, 0L, FALSE );
  345.           break;
  346.         case ID_EXITPROG:
  347.           WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
  348.           break;
  349.         default:
  350.           return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  351.       }
  352.  
  353.       break;
  354.       }
  355.     case WM_ERASEBACKGROUND:
  356.       /*
  357.        * Return TRUE to request PM to paint the window background
  358.        * in SYSCLR_WINDOW.
  359.        */
  360.       return (MRESULT)( TRUE );
  361.     case WM_PAINT:
  362.       /*
  363.        * Window contents are drawn here in WM_PAINT processing.
  364.        */
  365.       if ( bFirstTime) {
  366.         bFirstTime = FALSE;
  367.         WinSendMsg( hwnd, ANIMATE, NULL, NULL);
  368.        } else {
  369.         HPS    hps;                       /* Presentation Space handle    */
  370.         RECTL  rc;                        /* Rectangle coordinates        */
  371.         POINTL pt;                        /* String screen coordinates    */
  372.                                             /* Create a presentation space  */
  373.         hps = WinBeginPaint( hwnd, 0L, &rc);
  374.         WinDrawText( hps, (LONG) strlen( szString), szString, &rc, 0L, 0L,
  375.           DT_CENTER | DT_VCENTER | DT_TEXTATTRS | DT_ERASERECT);
  376.         WinEndPaint( hps ); }                     /* Drawing is complete   */
  377.         return (MRESULT)TRUE;
  378.       
  379.    case ANIMATE:
  380.       /*****************************************************/
  381.       /* Reset presentation spaces, then get it again and  */
  382.       /* animate with shearing.                            */
  383.       /*****************************************************/
  384.       WinSetPointer( HWND_DESKTOP,
  385.         WinQuerySysPointer( HWND_DESKTOP, SPTR_WAIT, FALSE));
  386.       GpiResetPS( hps, GRES_ALL);
  387.       GpiResetPS( hpsMemory, GRES_ALL);
  388.  
  389.       /*********************************/
  390.       /* Clear out presentation page.  */
  391.       /*********************************/
  392.       aptl[0].x = 0;                    /* Target lower-left */
  393.       aptl[0].y = 0;
  394.       aptl[1].x = sxPels;               /* Target upper-right */
  395.       aptl[1].y = syPels;
  396.       GpiBitBlt( hps, hps, 2L, aptl, ROP_ZERO, BBO_AND);
  397.       GpiBitBlt(hpsMemory, hpsMemory, 2L, aptl, ROP_ZERO, BBO_AND);
  398.  
  399.       /*****************************************************/
  400.       /* Look for font by name else find any outline font. */
  401.       /*****************************************************/
  402.       if( !FindFont( hpsMemory, &lLcid, szFontName1))
  403.         FindFont( hpsMemory, &lLcid, NULL);
  404.       lPointSize = 30;  /* Set font to 30 points. */
  405.       fRet = SetPtSize( hpsMemory, lLcid, lPointSize, &width, &height);
  406.       if( fRet){
  407.         sizefxCharBox.cy = height;
  408.         sizefxCharBox.cx = width;
  409.         }
  410.       fRet = GpiSetCharBox( hpsMemory, &sizefxCharBox);
  411.  
  412.       /******************************************************/
  413.       /* Set color and shear for memory presentation space. */
  414.       /* Then put all text in this presentation page.       */
  415.       /******************************************************/
  416.       GpiSetColor( hpsMemory, CLR_CYAN);
  417.       shear.x = 10; shear.y = 25;
  418.       GpiSetCharShear( hpsMemory, &shear);
  419.       SetWidthsTable( hpsMemory, alWidths,
  420.         alWidthTable, szStr1, &lTotal);
  421.       ptl.x = (( 7 * lcxPelsPerInch) - lTotal)/2; /* Center text 4 */
  422.       ptl.y = lcyPelsPerInch * 4;         /* inches from bottom */
  423.       GpiMove( hpsMemory, &ptl);
  424.       GpiCharStringPos( hpsMemory, NULL, CHS_VECTOR,
  425.         (LONG)strlen( szStr1), (PSZ)szStr1, alWidths);
  426.  
  427.       /***************************************************/
  428.       /* Change point size of font and get rid of shear. */
  429.       /***************************************************/
  430.       lPointSize = 18;
  431.       fRet = SetPtSize( hpsMemory, lLcid, lPointSize, &width, &height);
  432.       if( fRet){
  433.         sizefxCharBox.cy = height;
  434.         sizefxCharBox.cx = width;
  435.         }
  436.       fRet = GpiSetCharBox( hpsMemory, &sizefxCharBox);
  437.       shear.x = 0; shear.y = 1;
  438.       GpiSetCharShear( hpsMemory, &shear);
  439.  
  440.       /************************************************************/
  441.       /* Center next 2 lines of text in memory presentation page. */
  442.       /************************************************************/
  443.       SetWidthsTable( hpsMemory, alWidths,
  444.         alWidthTable, szStr2, &lTotal);
  445.       ptl.x = (( 7 * lcxPelsPerInch) - lTotal)/2;  /* Center text */
  446.       ptl.y = lcyPelsPerInch * 3;      /* 3 inches from bottom */
  447.       GpiMove( hpsMemory, &ptl);
  448.       GpiCharStringPos( hpsMemory, NULL, CHS_VECTOR,
  449.         (LONG)strlen( szStr2), (PSZ)szStr2, alWidths);
  450.       SetWidthsTable( hpsMemory, alWidths,
  451.         alWidthTable, szStr3, &lTotal);
  452.       ptl.x = ((7 * lcxPelsPerInch) - lTotal)/2;  /* Center text */
  453.       ptl.y = lcyPelsPerInch * 2.5;  /* 2.5 inches from bottom */
  454.       GpiMove( hpsMemory, &ptl);
  455.       GpiCharStringPos( hpsMemory, NULL, CHS_VECTOR,
  456.         (LONG)strlen( szStr3), (PSZ)szStr3, alWidths);
  457.  
  458.       /*********************************************/
  459.       /* Change color and center last              */
  460.       /* line of text in memory presentation page. */
  461.       /*********************************************/
  462.       GpiSetColor( hpsMemory, CLR_YELLOW);
  463.       SetWidthsTable( hpsMemory, alWidths,
  464.         alWidthTable, szStr4, &lTotal);
  465.       ptl.x = ((7 * lcxPelsPerInch) - lTotal)/2;  /* Center text */
  466.       ptl.y = lcyPelsPerInch * 1.75;      /* 1 inches from bottom */
  467.       GpiMove( hpsMemory, &ptl);
  468.       GpiCharStringPos( hpsMemory, NULL, CHS_VECTOR,
  469.         (LONG)strlen( szStr4), (PSZ)szStr4, alWidths);
  470.  
  471.       /******************************************/
  472.       /* Fade in top 3 text lines with Bit Blt. */
  473.       /******************************************/
  474.       aptl[0].x = 0; aptl[0].y = lcyPelsPerInch * 2;
  475.       aptl[1].x = lcxPelsPerInch * 7; aptl[1].y = lcyPelsPerInch * 5;
  476.       aptl[2].x = 0; aptl[2].y = lcyPelsPerInch * 2;
  477.       for( x = 1; x < 10; x++){
  478.         GpiSetPattern( hps, pattern[x]);
  479.         GpiBitBlt( hps, hpsMemory, 3L, aptl, ROP_MERGECOPY, BBO_AND);
  480.         DosSleep( SLEEPTIME);
  481.         }
  482.       DosSleep( 2500);  /* Wait 2.5 seconds. */
  483.  
  484.       /****************************************/
  485.       /* Fade in last text line with Bit Blt. */
  486.       /****************************************/
  487.       aptl[0].x = 0; aptl[0].y = lcyPelsPerInch * .5;
  488.       aptl[1].x = lcxPelsPerInch * 7; aptl[1].y = lcyPelsPerInch * 2;
  489.       aptl[2].x = 0; aptl[2].y = lcyPelsPerInch * .5;
  490.       for( x = 1; x < 10; x++){
  491.         GpiSetPattern( hps, pattern[x]);
  492.         GpiBitBlt( hps, hpsMemory, 3L, aptl, ROP_MERGECOPY, BBO_AND);
  493.         DosSleep( SLEEPTIME);
  494.         }
  495.       DosSleep( 3000);    /* Wait 3 seconds */
  496.  
  497.       /***********************************************/
  498.       /* Fade out all text from screen with Bit Blt. */
  499.       /***********************************************/
  500.       aptl[0].x = 0; aptl[0].y = lcyPelsPerInch * .5;
  501.       aptl[1].x = lcxPelsPerInch * 7; aptl[1].y = lcyPelsPerInch * 5;
  502.       aptl[2].x = 0; aptl[2].y = lcyPelsPerInch * .5;
  503.       for( x = 9; x > 1; x--){
  504.         GpiSetPattern( hps, pattern[x]);
  505.         GpiBitBlt( hps, hpsMemory, 3L, aptl, ROP_MERGECOPY, BBO_AND);
  506.         DosSleep( SLEEPTIME);
  507.         }
  508.       /***********************************/
  509.       /* Get master bit-map from memory. */
  510.       /***********************************/
  511.       GpiResetPS( hpsMemory, GRES_ALL);
  512.       GpiQueryBitmapParameters( hbmSrc, &bmpSrc);
  513.       GpiSetBitmap( hpsMemory, hbmSrc);
  514.  
  515.       /***************************************/
  516.       /* Clear out screen presentation page. */
  517.       /***************************************/
  518.       aptl[0].x = 0; aptl[0].y = 0;
  519.       aptl[1].x = sxPels; aptl[1].y = syPels;
  520.       GpiBitBlt( hps, hps, 2L, aptl, ROP_ZERO, BBO_AND);
  521.       DosSleep( 500);  /* Wait .5 seconds. */
  522.  
  523.       /************************************************/
  524.       /* Randomly blt in tenth inch squares of master */
  525.       /* bit-map.  Do 8000 squares then stop.         */
  526.       /************************************************/
  527.       for( i = 0; i < 8000; i++){
  528.         aptl[0].x = Random_Range( 0,
  529.           ( 7 * lcxPelsPerInch) - ( lcxPelsPerInch / 10), 0, 0);
  530.         aptl[0].y = Random_Range( 0,
  531.           ( 6 * lcyPelsPerInch) - ( lcyPelsPerInch / 10), 0, 0);
  532.         aptl[1].x = aptl[0].x + ( lcxPelsPerInch / 7);
  533.         aptl[1].y = aptl[0].y + ( lcyPelsPerInch / 7);
  534.         aptl[2].x = aptl[0].x; aptl[2].y = aptl[0].y;
  535.         GpiBitBlt( hps, hpsMemory, 3L, aptl, ROP_SRCCOPY, BBO_AND);
  536.         }
  537.       WinInvalidateRect( hwnd, NULL, FALSE);  /* Cause full paint. */
  538.       WinSetPointer( HWND_DESKTOP,
  539.         WinQuerySysPointer( HWND_DESKTOP, SPTR_APPICON, FALSE));
  540.       return (MRESULT)TRUE;
  541.  
  542.    case WM_CLOSE:
  543.       /*
  544.        * This is the place to put your termination routines
  545.        */
  546.       WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );/* Cause termination*/
  547.       break;
  548.     default:
  549.       /*
  550.        * Everything else comes here.  This call MUST exist
  551.        * in your window procedure.
  552.        */
  553.  
  554.       return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  555.   }
  556.   return (MRESULT)FALSE;
  557. } /* End of EdiHelpMakeProc */
  558.  
  559. /**************************************************************************
  560.  *  Name       : AbortHello
  561.  *************************************************************************/
  562. VOID AbortHello(HWND hwndFrame, HWND hwndClient)
  563. {
  564.    PERRINFO  pErrInfoBlk;
  565.    PSZ       pszOffSet;
  566.    void      stdprint(void);
  567.  
  568.    DosBeep(100,10);
  569.    if ((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
  570.    {
  571.       pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
  572.       pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
  573.       if((INT)hwndFrame && (INT)hwndClient)
  574.          WinMessageBox(HWND_DESKTOP,         /* Parent window is desk top */
  575.                        hwndFrame,            /* Owner window is our frame */
  576.                        (PSZ)pszErrMsg,       /* PMWIN Error message       */
  577.                        "Error Msg",          /* Title bar message         */
  578.                        MSGBOXID,             /* Message identifier        */
  579.                        MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL ); /* Flags */
  580.       WinFreeErrorInfo(pErrInfoBlk);
  581.    }
  582.    WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
  583. } /* End of AbortHello */
  584.  
  585. /*************************************/
  586. /*  Random number in range function. */
  587. /*************************************/
  588. SHORT FAR Random_Range( SHORT lower_lim, SHORT upper_lim,
  589.   SHORT lower_exc, SHORT upper_exc)
  590.   {
  591.   int i;
  592. getrand:
  593.    i = ((((double)rand()) / 32767) * ( upper_lim - lower_lim)) + lower_lim;
  594.    if( i >= lower_exc && i <= upper_exc)
  595.       goto getrand;
  596.    return( i);
  597.   }
  598.  
  599. /******************************/
  600. /* Get a set ID for our font. */
  601. /******************************/
  602. LONG FAR GetSetID( HPS hps)
  603.   {
  604.   #define MAXSETID 254L
  605.   INT i;
  606.   LONG lLcid = GPI_ERROR;
  607.   LONG lCount;
  608.   BOOL fRet = FALSE;
  609.   PLONG alLcids = NULL;
  610.   PLONG alTypes;
  611.   PSTR8 aNames;
  612.  
  613.   /************************************************/
  614.   /* See if any local set IDs have been used yet. */
  615.   /************************************************/
  616.   lCount = GpiQueryNumberSetIds( hps);
  617.   if(lCount == 0)
  618.     return( 1L);
  619.  
  620.   /***********************************/
  621.   /* Find first unused local set ID. */
  622.   /***********************************/
  623.   if( lCount != GPI_ALTERROR){
  624.     alLcids = malloc((SHORT)( 16 * lCount));
  625.     alTypes = (PLONG)( alLcids + lCount);
  626.     aNames = (PSTR8)( alTypes + lCount);
  627.     if( alLcids != NULL)
  628.       fRet = GpiQuerySetIds( hps, lCount, alTypes, aNames, alLcids);
  629.     if( fRet){
  630.       for( lLcid = 1; lLcid < (MAXSETID + 1); lLcid++){
  631.         for( i = 0; (i < (INT)lCount) && ( alLcids[i] != lLcid); i++);
  632.         if( i == (INT)lCount) break;
  633.         }
  634.       if( lLcid == MAXSETID + 1) lLcid = GPI_ERROR;
  635.       }
  636.     free( alLcids);
  637.     }
  638.   return( lLcid);
  639.   }
  640.  
  641. /************************************/
  642. /* Set point size for outline font. */
  643. /************************************/
  644. BOOL FAR SetPtSize( HPS hps, LONG lLcid, LONG lPointSize,
  645.   FIXED *width, FIXED *height)
  646.   {
  647.   #define POINTSPERINCH 72L
  648.   HDC hdc;
  649.   BOOL fRet = FALSE;
  650.   LONG lYDevResFont;
  651.   POINTL aptlPoints[2];
  652.   LONG lYSizeInPels;
  653.   LONG lYSizeInWC;
  654.  
  655.   /*******************************************/
  656.   /* Query current font vertical resolution. */
  657.   /*******************************************/
  658.   hdc = GpiQueryDevice( hps);
  659.   DevQueryCaps( hdc, CAPS_VERTICAL_FONT_RES, 1L, &lYDevResFont);
  660.  
  661.   /**********************************************************/
  662.   /* Calculate point size and convert to world coordinates. */
  663.   /**********************************************************/
  664.   lYSizeInPels = (( lYDevResFont * lPointSize)/POINTSPERINCH);
  665.   aptlPoints[0].x = 0L; aptlPoints[0].y = 0L;
  666.   aptlPoints[1].x = 0L; aptlPoints[1].y = lYSizeInPels;
  667.   GpiConvert( hps, CVTC_DEVICE, CVTC_WORLD, 2L, aptlPoints) ;
  668.   lYSizeInWC = aptlPoints[1].y-aptlPoints[0].y;
  669.  
  670.   /********************************************************/
  671.   /* Set the font for the presentation space and make the */
  672.   /* width and height value type fixed.                   */
  673.   /********************************************************/
  674.   fRet = GpiSetCharSet( hps, lLcid);
  675.   *width = lYSizeInWC * 0x10000;
  676.   *height = lYSizeInWC * 0x10000;
  677.   return( fRet);
  678.   }
  679.  
  680.  
  681. /************************************************/
  682. /* Set width table and calculate string length. */
  683. /************************************************/
  684. void FAR SetWidthsTable(HPS hps, LONG *alWidths,
  685.    LONG *alWidthTable, CHAR *szStr, LONG *lTotal)
  686.   {
  687.   FONTMETRICS fm;
  688.   PKERNINGPAIRS akpairs = NULL;
  689.   LONG i, j;
  690.  
  691.   /*******************************************/
  692.   /* Get width table for all 256 codepoints. */
  693.   /*******************************************/
  694.   GpiQueryWidthTable( hps, 0L, 256L, alWidthTable);
  695.  
  696.   /**************************************************/
  697.   /* Check for kerning font and get pair if needed. */
  698.   /**************************************************/
  699.   GpiQueryFontMetrics( hps, (LONG)sizeof( FONTMETRICS), &fm);
  700.   if( fm.sKerningPairs){
  701.     akpairs = malloc( fm.sKerningPairs * sizeof( KERNINGPAIRS));
  702.     GpiQueryKerningPairs( hps, fm.sKerningPairs, akpairs);
  703.     }
  704.  
  705.   /***********************************************************/
  706.   /* Set widths for each character in string before kerning. */
  707.   /***********************************************************/
  708.   for( i=0; i < (LONG)strlen( szStr); i++)
  709.     alWidths[i] = alWidthTable[ szStr[i]];
  710.  
  711.   /*************************************************/
  712.   /* Modify widths array with kerning adjustments. */
  713.   /*************************************************/
  714.   if( fm.sKerningPairs){
  715.     for( i=0; i < (LONG)strlen( szStr); i++){
  716.       for( j = 0; j < fm.sKerningPairs; j++){
  717.         if( szStr[i] == (UCHAR)akpairs[j].sFirstChar &&
  718.           szStr[i+1] == (UCHAR)akpairs[j].sSecondChar){
  719.           alWidths[i] += akpairs[j].lKerningAmount;
  720.           break;
  721.           }
  722.         }
  723.       }
  724.     }
  725.   if( fm.sKerningPairs) free( akpairs);  /* Free kerning values. */
  726.   /*********************************/
  727.   /* Calculate total string width. */
  728.   /*********************************/
  729.   *lTotal = 0;
  730.   for( i=0; i < (LONG)strlen( szStr); i++)
  731.   *lTotal = *lTotal + alWidths[i];
  732.   return;
  733.   }
  734.  
  735. /******************************/
  736. /* Find outline font by name. */
  737. /******************************/
  738. BOOL FAR FindFont( HPS hps, LONG *lLcid, CHAR *szFontName)
  739.   {
  740.   PFONTMETRICS afmMetrics = NULL;
  741.   LONG lNumFonts, lReqFonts, i, lRemFonts = GPI_ALTERROR;
  742.   BOOL fRet = FALSE;
  743.   HDC hdc = 0L;
  744.   USHORT usCodepage = GPI_ERROR;
  745.   FATTRS fatAttrs;
  746.  
  747.   /*********************************************************/
  748.   /* Query number of public fonts known by PM and allocate */
  749.   /* memory in which to read their metrics information.    */
  750.   /*********************************************************/
  751.   lReqFonts = 0;
  752.   if( szFontName != NULL)
  753.     lNumFonts = GpiQueryFonts( hps, QF_PUBLIC, (PSZ)szFontName, &lReqFonts,
  754.       0L, NULL);
  755.   else lNumFonts = GpiQueryFonts( hps, QF_PUBLIC, NULL, &lReqFonts,
  756.     0L, NULL);
  757.  
  758.   /*********************************************/
  759.   /* Get memory for font metrics if any exist. */
  760.   /*********************************************/
  761.   if(( lNumFonts != GPI_ALTERROR) && ( lNumFonts != 0L))
  762.     afmMetrics = malloc((SHORT)( lNumFonts * sizeof( FONTMETRICS)));
  763.  
  764.   /**************************************/
  765.   /* Query font information into array. */
  766.   /**************************************/
  767.   if( afmMetrics != NULL)
  768.     if( szFontName != NULL)
  769.       lRemFonts = GpiQueryFonts( hps, QF_PUBLIC, (PSZ)szFontName,
  770.         &lNumFonts, (LONG)sizeof( FONTMETRICS), afmMetrics);
  771.     else
  772.       lRemFonts = GpiQueryFonts( hps, QF_PUBLIC, NULL, &lNumFonts,
  773.         (LONG)sizeof( FONTMETRICS), afmMetrics);
  774.  
  775.   /******************************************/
  776.   /* Search for outline font and create it. */
  777.   /******************************************/
  778.   if( lRemFonts != GPI_ALTERROR){
  779.     for( i=0; i < (INT)lNumFonts; i++){
  780.       if( afmMetrics[i].fsDefn & FM_DEFN_OUTLINE){
  781.         *lLcid = GetSetID( hps);  /* Get a set ID for the font. */
  782.  
  783.         /**********************************/
  784.         /* Set the attribute of the font. */
  785.         /**********************************/
  786.         if( *lLcid != GPI_ERROR) usCodepage = GpiQueryCp( hps);
  787.         fatAttrs.usRecordLength = sizeof( FATTRS);
  788.         fatAttrs.fsSelection = 0;
  789.         fatAttrs.lMatch = 0L;
  790.         strcpy( fatAttrs.szFacename, afmMetrics[i].szFacename);
  791.         fatAttrs.idRegistry = afmMetrics[i].idRegistry;
  792.         fatAttrs.usCodePage = usCodepage;
  793.         fatAttrs.lMaxBaselineExt = 0L;
  794.         fatAttrs.lAveCharWidth = 0L;
  795.         fatAttrs.fsType = 0;
  796.         fatAttrs.fsFontUse = ( FATTR_FONTUSE_OUTLINE |
  797.           FATTR_FONTUSE_TRANSFORMABLE);
  798.  
  799.         /************************/
  800.         /* Create logical font. */
  801.         /************************/
  802.         if( usCodepage != GPI_ERROR){
  803.           fRet = GpiCreateLogFont( hps, NULL,
  804.           *lLcid, &fatAttrs) != GPI_ERROR;
  805.           }
  806.         break ;
  807.         }
  808.       }
  809.     }
  810.     if( afmMetrics != NULL) free( afmMetrics); /* Free memory from array. */
  811.   return( fRet);
  812.   }
  813.  
  814. /************************************/
  815. /* Drive and Path dialog procedure. */
  816. /************************************/
  817. MRESULT EXPENTRY DrivePathProc(HWND hwnd, ULONG msg,
  818.    MPARAM mp1, MPARAM mp2)
  819.   {
  820.   CHAR sDrvPathTemp[80];
  821.   switch( msg) {
  822.  
  823.     /**********************/
  824.     /* Initialize dialog. */
  825.     /**********************/
  826.     case WM_INITDLG:
  827. /*      sDrvPathTemp = PVOIDFROMMP( mp2);*/
  828. /*      pfwnField1 = WinSubclassWindow(
  829.         WinWindowFromID( hwnd, IDD_GRIDEDIT), NumberSubProc1);
  830.       pfwnField2=WinSubclassWindow(
  831.         WinWindowFromID(hwnd, IDD_TIMEEDIT), NumberSubProc2);
  832.       sprintf(szTemp, "%d\0", pnew->sCapTime);
  833.       WinSetDlgItemText(hwnd, IDD_TIMEEDIT, (PSZ)szTemp);
  834.       sprintf(szTemp, "%d\0", pnew->sGrid);
  835.       WinSetDlgItemText(hwnd, IDD_GRIDEDIT, (PSZ)szTemp);
  836.       WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, IDD_GRIDEDIT));
  837. */
  838.       return(( MRESULT) TRUE);
  839.  
  840.     /**************************/
  841.     /* Process notifications. */
  842.     /**************************/
  843.     case WM_COMMAND:
  844.       switch (COMMANDMSG(&msg)->cmd){
  845.  
  846.         /**************************/
  847.         /* Process OK pushbutton. */
  848.         /**************************/
  849. /*
  850.         case DID_OK:
  851.           WinQueryDlgItemText(hwnd, IDD_TIMEEDIT, 5, (PSZ)szTemp);
  852.           sTemp=atoi(szTemp);
  853.           if((sTemp<1) || (sTemp>60)){
  854.             WinMessageBox(HWND_DESKTOP, hwnd,
  855.             (PSZ)"Time value needs to be between 1 and 60.",
  856.             (PSZ)"New Puzzle", 0,
  857.             MB_MOVEABLE | MB_OK | MB_ICONEXCLAMATION);
  858.             return(MRESULT)TRUE;
  859.             }
  860.           pnew->sCapTime=sTemp;
  861.           WinQueryDlgItemText(hwnd, IDD_GRIDEDIT, 5, (PSZ)szTemp);
  862.           sTemp=atoi(szTemp);
  863.           if((sTemp<4) || (sTemp>25)){
  864.             WinMessageBox(HWND_DESKTOP, hwnd,
  865.             (PSZ)"Grid value needs to be between 4 and 25.",
  866.             (PSZ)"New Puzzle", 0,
  867.             MB_MOVEABLE | MB_OK | MB_ICONEXCLAMATION);
  868.             return(MRESULT)TRUE;
  869.             }
  870.           pnew->sGrid=sTemp;
  871.           WinSubclassWindow(
  872.             WinWindowFromID(hwnd, IDD_GRIDEDIT), pfwnField1);
  873.           WinSubclassWindow(
  874.             WinWindowFromID(hwnd, IDD_TIMEEDIT), pfwnField2);
  875.           WinDismissDlg(hwnd, TRUE);
  876.           return(MRESULT)TRUE;
  877. */
  878.         /******************************/
  879.         /* Process Cancel pushbutton. */
  880.         /******************************/
  881. /*
  882.         case DID_CANCEL:
  883.           WinSubclassWindow(
  884.             WinWindowFromID(hwnd, IDD_GRIDEDIT), pfwnField1);
  885.           WinSubclassWindow(
  886.             WinWindowFromID(hwnd, IDD_TIMEEDIT), pfwnField2);
  887.           WinDismissDlg(hwnd, FALSE);
  888.           return(MRESULT)TRUE;
  889. */
  890.         }
  891.       break;
  892.     }
  893.   return WinDefDlgProc( hwnd, msg, mp1, mp2);
  894.   }
  895.  
  896.  
  897. /************************************/
  898. /* fetch segment from DBM procedure. */
  899. /************************************/
  900. MRESULT EXPENTRY SegFetchProc(HWND hwnd, ULONG msg,
  901.    MPARAM mp1, MPARAM mp2)
  902.   {
  903.     switch( msg){
  904.       case WM_CREATE:
  905.         return((MRESULT) FALSE);
  906.       case WM_CLOSE:
  907.       default:
  908.         return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  909.     }
  910.   }
  911. /*********************** End of the EdiHelp.c *******************************/
  912.  
  913.