home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / os2tk21j / c / samples / dllapi / dlapi_dg.c__ / dlapi_dg.c
Encoding:
C/C++ Source or Header  |  1993-03-12  |  29.7 KB  |  659 lines

  1. /*static char *SCCSID = "@(#)dlapi_dg.c    6.13 92/03/18";*/
  2. /*==============================================================*\
  3.  *  DLL_DLG.C - window procedures for the dialog boxes as well  *
  4.  *              as utility procedures used by them              *
  5.  *     (C) Copyright IBM Corporation 1992.                      *
  6.  *--------------------------------------------------------------*
  7.  *                                                              *
  8.  *  This module contains the Dialog Procedures for the user     *
  9.  *  defined dialogs as well as any support code they need       *
  10.  *                                                              *
  11.  *--------------------------------------------------------------*
  12.  *                                                              *
  13.  *  This source file contains the following functions:          *
  14.  *                                                              *
  15.  *    GetPatternDlgProc(hwnd, msg, mp1, mp2)                    *
  16.  *    DispFileDlgProc  (hwnd, msg, mp1, mp2)                    *
  17.  *    DisplayFile      (hwnd, rect, pFile)                      *
  18.  *    OpenDlgProc      (hwnd, msg, mp1, mp2)                    *
  19.  *    DisplayDlgProc   (hwnd, msg, mp1, mp2)                    *
  20.  *    MathDlgProc      (hwnd, msg, mp1, mp2)                    *
  21.  *    ResultDlgProc    (hwnd, msg, mp1, mp2)                    *
  22.  *                                                              *
  23. \*==============================================================*/
  24.  
  25. /*--------------------------------------------------------------*\
  26.  *  Include files, macros, defined constants, and externs       *
  27. \*--------------------------------------------------------------*/
  28. #include "dllapi.h"
  29.  
  30. /****************************************************************\
  31.  *  Dialog procedure for the Path/Pattern dialog                *
  32.  *--------------------------------------------------------------*
  33.  *                                                              *
  34.  *  Name:    GetPatternDlgProc(hwnd, msg, mp1, mp2)             *
  35.  *                                                              *
  36.  *  Purpose: Processes all messages sent to the Pattern dialog  *
  37.  *                                                              *
  38.  *  Usage:   Called for each message sent to the dialog box.    *
  39.  *                                                              *
  40.  *  Method:  a switch statement branches to the routines to be  *
  41.  *           performed for each message processed. Any messages *
  42.  *           not specifically processed are passed to the       *
  43.  *           default window procedure WinDefDlgProc()           *
  44.  *                                                              *
  45.  *  Returns: Dependent upon message sent                        *
  46.  *                                                              *
  47. \****************************************************************/
  48. MRESULT EXPENTRY GetPatternDlgProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  49. {
  50.    static POBJSTRUCT pObj=NULL;
  51.    static CHAR   szBuffer[CCHMAXPATH];
  52.    ULONG  ulDriveMap, ulDriveNum=0L, ulDirLen = CCHMAXPATH;
  53.    SHORT  sIndex;
  54.    MRESULT sRC;
  55.  
  56.    switch (msg)
  57.    {
  58.       case WM_INITDLG:
  59.  
  60.           pObj = PVOIDFROMMP(mp2);
  61.           FixSysMenu(hwnd);
  62.                                                   /* Get current drive */
  63.           DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap);
  64.           memset(szBuffer, 0, sizeof(szBuffer));
  65.           szBuffer[0] = (CHAR)(ulDriveNum + '@');
  66.           strcpy(pObj->szCurDriver, szBuffer);
  67.           *(pObj->szCurDriver+1) = ':';
  68.                                  /* Get current dir & attach disk num. */
  69.           DosQueryCurrentDir(0L, pObj->szCurPath, &ulDirLen);
  70.           if(*(pObj->szCurPath+strlen(pObj->szCurPath)-1) != '\\')
  71.              strcat(pObj->szCurPath, "\\");     /* Add '\' at the tail */
  72.  
  73.           memset(szBuffer, 0, sizeof(szBuffer));
  74.           strcpy(szBuffer, pObj->szCurDriver);
  75.           if(*(pObj->szCurPath) != '\\')
  76.                   strcat(szBuffer,"\\");
  77.           strcat(szBuffer, pObj->szCurPath);/*Default path is current diver*/
  78.           WinSendDlgItemMsg(hwnd, IDD_PATH, EM_SETTEXTLIMIT,
  79.                                MPFROM2SHORT(CCHMAXPATH, 0), NULL);
  80.           WinSetDlgItemText(hwnd, IDD_PATH, szBuffer);
  81.  
  82.           if(*(pObj->szCurPattern) == '\000')
  83.              strcpy(pObj->szCurPattern, "*.*");     /* Inition Pattern */
  84.           WinSetDlgItemText(hwnd, IDD_PATTERN, pObj->szCurPattern);
  85.  
  86.           return((MRESULT)FALSE);
  87.                         /* Let the focus go to where the system puts it */
  88.       case WM_COMMAND:
  89.           switch (SHORT1FROMMP(mp1)) {
  90.               case DID_OK:
  91.                                                    /* Get new pattern */
  92.                   memset(szBuffer,0,sizeof(szBuffer));
  93.                   WinQueryDlgItemText(hwnd, IDD_PATTERN, MAX_EDIT_BUFF,
  94.                                         szBuffer);
  95.                   for (sIndex=0; szBuffer[sIndex]!='\000' &&
  96.                          sIndex<MAX_EDIT_BUFF; sIndex++)
  97.                   {
  98.                      if (szBuffer[sIndex]>='a' && szBuffer[sIndex]<='z')
  99.                      {
  100.                         szBuffer[sIndex] = szBuffer[sIndex] - (CHAR)' ';
  101.                      }                                       /* endif */
  102.                   }                                         /* endfor */
  103.                   memset(pObj->szNewPattern,0,sizeof(pObj->szNewPattern));
  104.                   if (*szBuffer == '\000')       /* No input new path */
  105.                      strcpy(pObj->szNewPattern,pObj->szCurPattern);
  106.                   else                          /* Store user pattern */
  107.                      strcpy(pObj->szNewPattern,szBuffer);
  108.  
  109.                                                       /* Get new path */
  110.                   memset(szBuffer,0,sizeof(szBuffer));
  111.                   WinQueryDlgItemText(hwnd, IDD_PATH, CCHMAXPATH,
  112.                                                  szBuffer);
  113.                   for (sIndex=0; szBuffer[sIndex]!='\000' &&
  114.                          sIndex<CCHMAXPATH; sIndex++)
  115.                   {
  116.                      if (szBuffer[sIndex]>='a' && szBuffer[sIndex]<='z')
  117.                      {
  118.                         szBuffer[sIndex] = szBuffer[sIndex] - (CHAR)' ';
  119.                      }                                       /* endif */
  120.                   }                                         /* endfor */
  121.  
  122.                   memset(pObj->szNewDriver,0,sizeof(pObj->szNewDriver));
  123.                   memset(pObj->szNewPath,0,sizeof(pObj->szNewPath));
  124.  
  125.                   if(*(szBuffer+strlen(szBuffer)-1) != '\\')
  126.                      strcat(szBuffer, "\\");   /* Add '\' at the tail */
  127.                   if (*szBuffer == '\000')       /* No input new path */
  128.                   {
  129.                      strcpy(pObj->szNewDriver,pObj->szCurDriver);
  130.                      strcpy(pObj->szNewPath,pObj->szCurPath);
  131.                   }
  132.                   else if(*(szBuffer+1) == ':') /* they specified a drive */
  133.                   {
  134.                      *(pObj->szNewDriver) = *szBuffer;/*Store disk number */
  135.                      *((pObj->szNewDriver)+1) = *(szBuffer+1);
  136.                      if(*(szBuffer+2) != '\\')             /* If Path= c: */
  137.                      {
  138.                         *(pObj->szNewPath) = '\\';         /* Set path= \ */
  139.                      }
  140.                                                         /*Store user path*/
  141.                      strcat(pObj->szNewPath,(szBuffer+2));
  142.                   }
  143.                   else
  144.                   {
  145.                      strcpy(pObj->szNewDriver,pObj->szCurDriver);
  146.                      strcpy(pObj->szNewPath,szBuffer);   /* Store user path */
  147.                   }
  148.                   WinDismissDlg(hwnd, TRUE);
  149.                   return((MRESULT)TRUE);
  150.  
  151.               case DID_CANCEL:
  152.                   WinDismissDlg(hwnd, FALSE);
  153.                   return((MRESULT)TRUE);
  154.           }
  155.           break;
  156.  
  157.       case WM_CLOSE:
  158.           WinDismissDlg(hwnd, FALSE);
  159.           return((MRESULT)TRUE);
  160.  
  161.       default:
  162.           sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  163.           return sRC;
  164.    }
  165.    return((MRESULT)TRUE);
  166. }
  167.  
  168. /****************************************************************\
  169.  *  Dialog procedure for the Display file dialog                *
  170.  *--------------------------------------------------------------*
  171.  *                                                              *
  172.  *  Name:    DispFileDlgProc(hwnd, msg, mp1, mp2)               *
  173.  *                                                              *
  174.  *  Purpose: Processes all messages sent to the display dialog  *
  175.  *                                                              *
  176.  *  Usage:   Called for each message sent to the dialog box.    *
  177.  *                                                              *
  178.  *  Method:  a switch statement branches to the routines to be  *
  179.  *           performed for each message processed. Any messages *
  180.  *           not specifically processed are passed to the       *
  181.  *           default window procedure WinDefDlgProc()           *
  182.  *                                                              *
  183.  *  Returns: Dependent upon message sent                        *
  184.  *                                                              *
  185. \****************************************************************/
  186. MRESULT EXPENTRY DispFileDlgProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  187. {
  188.    SHORT            Ret=-1;
  189.    PVOID            pvAddress=0;
  190.    PFILELIST        pTail=NULL, pNext=NULL;    /* The last file of list */
  191.    MRESULT sRC;
  192.  
  193.    switch (msg)
  194.    {
  195.       case WM_INITDLG:
  196.           FixSysMenu(hwnd);
  197.           pBackup=NULL;
  198.                                   /* Default click the buttom of backup */
  199.           WinSendDlgItemMsg(hwnd, IDD_ACCESSBACKUP,
  200.                               BM_CLICK, (MPARAM)0L, (MPARAM)0L);
  201.           return((MRESULT)FALSE);
  202.                         /* Let the focus go to where the system puts it */
  203.       case WM_COMMAND:
  204.           switch (SHORT1FROMMP(mp1)) {
  205.              case DID_OK:
  206.                  pNext = pFindFile;
  207.                  DosSetMem(pNext, sizeof(PFILELIST),
  208.                            PAG_READ|PAG_WRITE|PAG_EXECUTE);
  209.                  while (pNext != NULL)
  210.                  {
  211.                     if(!DosAllocMem(&pvAddress,sizeof(PFILELIST),fALLOC))
  212.                     {        /* Store file list to backup structure */
  213.                        if (pBackup == NULL)
  214.                        {                       /* Back up 1'st file */
  215.                           pBackup = (PFILELIST)pvAddress;
  216.                           strcpy(pBackup->szFileName,pNext->szFileName);
  217.                           pBackup->pNextFile = NULL;
  218.                           pTail = pBackup;
  219.                        }
  220.                        else
  221.                        {
  222.                           pTail->pNextFile = (PFILELIST)pvAddress;
  223.                           pTail = pTail->pNextFile;
  224.                           strcpy(pTail->szFileName, pNext->szFileName);
  225.                           pTail->pNextFile = NULL;
  226.                        }
  227.                        pNext = pNext->pNextFile;
  228.                     }
  229.                  }                                    /* while loop */
  230.                  pNext = pFindFile; /* Protect the memory of file list */
  231.                  if(pNext != NULL)
  232.                  {
  233.                     DosSetMem(pNext,sizeof(PFILELIST),
  234.                                       PAG_GUARD|PAG_READ|PAG_WRITE);
  235.                  }
  236.                  Ret = (SHORT)WinSendDlgItemMsg(hwnd, (ULONG)IDD_ACCESSBACKUP,
  237.                             BM_QUERYCHECKINDEX, (MPARAM)0L, (MPARAM)0L);
  238.                  if(Ret == 0)
  239.                  {
  240.                     pFlList = pBackup;
  241.                  }
  242.                  else
  243.                  {
  244.                     pFlList = pFindFile;
  245.                  }
  246.                  WinDismissDlg(hwnd, TRUE);
  247.                  return((MRESULT)TRUE);
  248.  
  249.              case DID_CANCEL:
  250.                  WinDismissDlg(hwnd, FALSE);
  251.                  return((MRESULT)TRUE);
  252.           }
  253.           break;
  254.  
  255.       case WM_CLOSE:
  256.           WinDismissDlg(hwnd, FALSE);
  257.           return((MRESULT)TRUE);
  258.  
  259.       default:
  260.           sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  261.           return sRC;
  262.    }
  263.    return((MRESULT)TRUE);
  264. }
  265.  
  266. /****************************************************************\
  267.  *                                                              *
  268.  *  Name:    DisplayFile(hwnd, rect, pFile)                     *
  269.  *                                                              *
  270.  *  Purpose: This routine searches and display files which are  *
  271.  *           matching the pattern.                              *
  272.  *                                                              *
  273.  *  Usage:   After files searching, this module will create a   *
  274.  *           child window to display the matched files.         *
  275.  *                                                              *
  276.  *  Returns: VOID                                               *
  277.  *                                                              *
  278. \****************************************************************/
  279. VOID DisplayFile (HWND hwnd, RECTL rect, PPFILELIST pFile)
  280. {
  281.    CHAR         szBuf[CCHMAXPATH];
  282.    APIRET       sCount=0;
  283.    PFILELIST    pTail=NULL;                         /* The last file of list */
  284.  
  285.    if(hwndChild)
  286.      WinDestroyWindow(hwndChild);
  287.    hwndChild = WinCreateWindow (hwnd,
  288.                                 WC_LISTBOX,
  289.                                 "File List...",
  290.                                 WS_VISIBLE | FCF_MINMAX,
  291.                                 rect.xLeft,
  292.                                 rect.yBottom,
  293.                                 rect.xRight-rect.xLeft,
  294.                                 rect.yTop-rect.yBottom-5,
  295.                                 hwnd,
  296.                                 HWND_TOP,
  297.                                 ID_CHILDWIN,
  298.                                 NULL,
  299.                                 (PVOID)NULL);
  300.    pTail = *pFile;
  301.    if(*pFile != NULL)
  302.    {
  303.       strcpy(szBuf, "The found file list ....");
  304.       WinSendDlgItemMsg(hwnd, ID_CHILDWIN, LM_INSERTITEM,
  305.                         MPFROM2SHORT(LIT_END, 0),
  306.                         MPFROMP(szBuf));
  307.    }
  308.    while (pTail != NULL)
  309.    {
  310.       strcpy(szBuf, pTail->szFileName);
  311.       WinSendDlgItemMsg(hwnd, ID_CHILDWIN, LM_INSERTITEM,
  312.                         MPFROM2SHORT(LIT_END, 0),
  313.                         MPFROMP(pTail->szFileName));
  314.       sCount++;
  315.       pTail = pTail->pNextFile;
  316.    }                                                        /* endwhile */
  317.    memset(szBuf, 0, sizeof(szBuf));
  318.    sprintf(szBuf, "There are %d files found.", sCount);
  319.    WinSendDlgItemMsg(hwnd, ID_CHILDWIN, LM_INSERTITEM,
  320.                      MPFROM2SHORT(LIT_END, 0),
  321.                      MPFROMP(szBuf));
  322.    while(*pFile != NULL)                 /* Free the File list structure */
  323.    {
  324.       pTail = *pFile;
  325.       *pFile = (*pFile)->pNextFile;
  326.       DosFreeMem(pTail);
  327.    }
  328.    return;
  329. }
  330.  
  331. /****************************************************************\
  332.  *  Dialog procedure for the Open file dialog                   *
  333.  *--------------------------------------------------------------*
  334.  *                                                              *
  335.  *  Name:    OpenDlgProc(hwnd, msg, mp1, mp2)                   *
  336.  *                                                              *
  337.  *  Purpose: Processes all messages sent to the Open file dialog*
  338.  *                                                              *
  339.  *  Usage:   Called for each message sent to the dialog box.    *
  340.  *                                                              *
  341.  *  Method:  a switch statement branches to the routines to be  *
  342.  *           performed for each message processed. Any messages *
  343.  *           not specifically processed are passed to the       *
  344.  *           default window procedure WinDefDlgProc()           *
  345.  *                                                              *
  346.  *  Returns: Dependent upon message sent                        *
  347.  *                                                              *
  348. \****************************************************************/
  349. MRESULT EXPENTRY OpenDlgProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  350. {
  351.     static PFILEINFO pFile;
  352.     static CHAR   szBuffer[CCHMAXPATH];
  353.     ULONG  ulDriveMap, ulDriveNum=0L, ulDirLen = CCHMAXPATH;
  354.     SHORT  sIndex=0;
  355.     MRESULT sRC;
  356.  
  357.     switch (msg)
  358.     {
  359.         case WM_INITDLG:
  360.  
  361.             pFile = PVOIDFROMMP(mp2);
  362.             FixSysMenu(hwnd);
  363.             memset(pFile, 0, sizeof(pFile));
  364.                                                     /* Get current drive */
  365.             DosQueryCurrentDisk(&ulDriveNum, &ulDriveMap);
  366.             *(pFile->szFileName) = (CHAR)(ulDriveNum + '@');
  367.             *(pFile->szFileName+1) = ':';
  368.                                    /* Get current dir & attach disk num. */
  369.             memset(szBuffer, 0, sizeof(szBuffer));
  370.             DosQueryCurrentDir(0L, szBuffer, &ulDirLen);
  371.  
  372.             if(*(szBuffer+strlen(szBuffer)-1) != '\\')
  373.                strcat(szBuffer, "\\");            /* Add '\' at the tail */
  374.             if(*(szBuffer) != '\\')       /* Add '\' at begining of path */
  375.                strcat(pFile->szFileName,"\\");
  376.  
  377.             strcat(pFile->szFileName,szBuffer);  /* Display current path */
  378.             WinSendDlgItemMsg(hwnd, IDD_PATH, EM_SETTEXTLIMIT,
  379.                                MPFROM2SHORT(CCHMAXPATH, 0), NULL);
  380.             WinSetDlgItemText(hwnd, IDD_PATH, pFile->szFileName );
  381.  
  382.             return((MRESULT)FALSE);
  383.                          /* Let the focus go to where the system puts it */
  384.         case WM_COMMAND:
  385.             switch (SHORT1FROMMP(mp1)) {
  386.                case DID_OK:
  387.                   memset(szBuffer,0,sizeof(szBuffer));
  388.                   WinQueryDlgItemText(hwnd, IDD_PATH, CCHMAXPATH,
  389.                                         szBuffer);
  390.                   memset(pFile->szFileName,0,sizeof(pFile->szFileName));
  391.                   for (sIndex=0; szBuffer[sIndex]!='\000' &&
  392.                         sIndex<CCHMAXPATH; sIndex++)
  393.                   {
  394.                      if (szBuffer[sIndex]>='a' && szBuffer[sIndex]<='z')
  395.                      {
  396.                         szBuffer[sIndex] = szBuffer[sIndex] - (CHAR)' ';
  397.                      }                /* Changed lowercase to uppercase */
  398.                   }
  399.                   strcpy(pFile->szFileName, szBuffer);
  400.                   WinDismissDlg(hwnd, TRUE);
  401.                   break;
  402.  
  403.                case DID_CANCEL:
  404.                   WinDismissDlg(hwnd, FALSE);
  405.                   break;
  406.                }
  407.             break;
  408.  
  409.         case WM_CLOSE:
  410.             WinDismissDlg(hwnd, FALSE);
  411.             return((MRESULT)TRUE);
  412.  
  413.         default:
  414.             sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  415.             return sRC;
  416.     }
  417.     return (MRESULT)RETURN_SUCCESS;
  418. }
  419.  
  420. /****************************************************************\
  421.  *  Dialog procedure for the Display text dialog                *
  422.  *--------------------------------------------------------------*
  423.  *                                                              *
  424.  *  Name:    DisplayDlgProc(hwnd, msg, mp1, mp2)                *
  425.  *                                                              *
  426.  *  Purpose: Processes all messages sent to the Display text    *
  427.  *           dialog window.                                     *
  428.  *                                                              *
  429.  *  Usage:   Called for each message sent to the dialog box.    *
  430.  *                                                              *
  431.  *  Method:  a switch statement branches to the routines to be  *
  432.  *           performed for each message processed. Any messages *
  433.  *           not specifically processed are passed to the       *
  434.  *           default window procedure WinDefDlgProc()           *
  435.  *                                                              *
  436.  *  Returns: Dependent upon message sent                        *
  437.  *                                                              *
  438. \****************************************************************/
  439. MRESULT EXPENTRY DisplayDlgProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  440. {
  441.    CHAR    szBuf[CCHMAXPATH];
  442.    static PFILEINFO pFile;
  443.    MRESULT sRC;
  444.  
  445.    switch (msg)
  446.    {
  447.       case WM_INITDLG:
  448.  
  449.           pFile = PVOIDFROMMP(mp2);
  450.           FixSysMenu(hwnd);
  451.           strcpy(szBuf,"File: ");          /* Display file path & name */
  452.           strcat(szBuf,pFile->szFileName);
  453.           WinSendDlgItemMsg(hwnd, IDD_PATH, EM_SETTEXTLIMIT,
  454.                                MPFROM2SHORT(CCHMAXPATH, 0), NULL);
  455.           WinSetDlgItemText(hwnd, IDD_PATH, szBuf);
  456.                                                /* Display file content */
  457.           WinSendDlgItemMsg(hwnd, IDD_TEXT, EM_SETTEXTLIMIT,
  458.                                MPFROM2SHORT(BUFF_SIZE, 0), NULL);
  459.           WinSetDlgItemText(hwnd, IDD_TEXT, pFile->szBuffer);
  460.  
  461.           return((MRESULT)FALSE);
  462.                        /* Let the focus go to where the system puts it */
  463.       case WM_COMMAND:
  464.           switch (SHORT1FROMMP(mp1)) {
  465.               case DID_OK:
  466.                  WinDismissDlg(hwnd, TRUE);
  467.                  break;
  468.               }
  469.           break;
  470.  
  471.       default:
  472.           sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  473.           return sRC;
  474.    }
  475.    return (MRESULT)RETURN_SUCCESS;
  476. }
  477.  
  478. /****************************************************************\
  479.  *  Dialog procedure for the Calculator Entry dialog            *
  480.  *--------------------------------------------------------------*
  481.  *                                                              *
  482.  *  Name:    MathDlgProc(hwnd, msg, mp1, mp2)                   *
  483.  *                                                              *
  484.  *  Purpose: Processes all messages sent to the Calculator input*
  485.  *           dialog window.                                     *
  486.  *                                                              *
  487.  *  Usage:   Called for each message sent to the dialog box.    *
  488.  *                                                              *
  489.  *  Method:  a switch statement branches to the routines to be  *
  490.  *           performed for each message processed. Any messages *
  491.  *           not specifically processed are passed to the       *
  492.  *           default window procedure WinDefDlgProc()           *
  493.  *                                                              *
  494.  *  Returns: Dependent upon message sent                        *
  495.  *                                                              *
  496. \****************************************************************/
  497. MRESULT EXPENTRY MathDlgProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  498. {
  499.    static PMATHELEMENT pMath;
  500.    static CHAR szBuffer[OP_SIZE];
  501.    SHORT  sIndex;
  502.    MRESULT sRC;
  503.  
  504.    switch (msg)
  505.    {
  506.        case WM_INITDLG:
  507.            pMath = PVOIDFROMMP(mp2);
  508.            FixSysMenu(hwnd);
  509.            pMath->fOperand1 = 0;
  510.            pMath->fOperand2 = 0;
  511.            *pMath->pszOperation = '\000';
  512.            memset(pMath->szResult, 0, sizeof(pMath->szResult) );
  513.            WinSendDlgItemMsg(hwnd, IDD_OPERAND1, EM_SETTEXTLIMIT,
  514.                                MPFROM2SHORT(OP_SIZE, 0), NULL);
  515.            WinSendDlgItemMsg(hwnd, IDD_OPERAND2, EM_SETTEXTLIMIT,
  516.                                MPFROM2SHORT(OP_SIZE, 0), NULL);
  517.            WinSendDlgItemMsg(hwnd, IDD_OPERATION, EM_SETTEXTLIMIT,
  518.                                MPFROM2SHORT(1L, 0), NULL);
  519.            return((MRESULT)FALSE);
  520.                          /* Let the focus go to where the system puts it */
  521.        case WM_COMMAND:
  522.            switch (SHORT1FROMMP(mp1))
  523.            {
  524.               case DID_OK:
  525.                  memset(szBuffer,0,sizeof(szBuffer));
  526.                  WinQueryDlgItemText(hwnd, IDD_OPERAND1, OP_SIZE+1,
  527.                                         szBuffer);
  528.                  for (sIndex=0; sIndex<OP_SIZE && szBuffer[sIndex]!='\000';
  529.                             sIndex++)
  530.                  {
  531.                     if( (szBuffer[sIndex]<'0' || szBuffer[sIndex]>'9')
  532.                         && (szBuffer[sIndex] != '.') )
  533.                     {
  534.                        MessageBox(hwnd, IDMSG_ERROROPERAND, "Error !",
  535.                                 MB_OK | MB_ERROR | MB_MOVEABLE, TRUE);
  536.                        return((MRESULT)FALSE);          /* Illegal input */
  537.                     }
  538.                  }                                             /* endfor */
  539.                  pMath->fOperand1 = atol(szBuffer);
  540.  
  541.                  memset(szBuffer,0,sizeof(szBuffer));
  542.                  WinQueryDlgItemText(hwnd, IDD_OPERAND2, OP_SIZE+1,
  543.                                         szBuffer);
  544.                  for (sIndex=0; sIndex<OP_SIZE && szBuffer[sIndex]!='\000';
  545.                              sIndex++)
  546.                  {
  547.                     if( (szBuffer[sIndex]<'0' || szBuffer[sIndex]>'9')
  548.                         && (szBuffer[sIndex] != '.') )
  549.                     {
  550.                        MessageBox(hwnd, IDMSG_ERROROPERAND, "Error !",
  551.                                 MB_OK | MB_ERROR | MB_MOVEABLE, TRUE);
  552.  
  553.                        *pMath->pszOperation = '\000';
  554.                        return((MRESULT)FALSE);          /* Illegal input */
  555.                     }
  556.                  }                                             /* endfor */
  557.                  pMath->fOperand2 = atol(szBuffer);
  558.  
  559.                  memset(szBuffer,0,sizeof(szBuffer));
  560.                  WinQueryDlgItemText(hwnd, IDD_OPERATION, OP_SIZE,
  561.                                         pMath->pszOperation);
  562.                  if(*pMath->pszOperation!='+' && *pMath->pszOperation!='-' &&
  563.                     *pMath->pszOperation!='*' && *pMath->pszOperation!='/')
  564.                  {
  565.                      MessageBox(hwnd, IDMSG_ERROROPERAND, "Error !",
  566.                                 MB_OK | MB_ERROR | MB_MOVEABLE, TRUE);
  567.  
  568.                      *pMath->pszOperation = '\000';
  569.                      return((MRESULT)FALSE);            /* Illegal input */
  570.                  }
  571.                  memset(pMath->szResult, 0, sizeof(pMath->szResult) );
  572.                  WinDismissDlg(hwnd, TRUE);
  573.                  break;
  574.  
  575.               case DID_CANCEL:
  576.                  WinDismissDlg(hwnd, FALSE);
  577.                  break;
  578.            }
  579.            break;
  580.  
  581.        case WM_CLOSE:
  582.            WinDismissDlg(hwnd, FALSE);
  583.            return((MRESULT)TRUE);
  584.  
  585.        default:
  586.            sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  587.            return sRC;
  588.    }
  589.    return (MRESULT)RETURN_SUCCESS;
  590. }
  591.  
  592. /****************************************************************\
  593.  *                                                              *
  594.  *  Name:    ResultDlgProc(hwnd, msg, mp1, mp2)                 *
  595.  *                                                              *
  596.  *  Purpose: Processes all messages sent to the result display  *
  597.  *           dialog window.                                     *
  598.  *                                                              *
  599.  *  Usage:   Called for each message sent to the dialog box.    *
  600.  *                                                              *
  601.  *  Method:  a switch statement branches to the routines to be  *
  602.  *           performed for each message processed. Any messages *
  603.  *           not specifically processed are passed to the       *
  604.  *           default window procedure WinDefDlgProc()           *
  605.  *                                                              *
  606.  *  Returns: Dependent upon message sent                        *
  607.  *                                                              *
  608. \****************************************************************/
  609. MRESULT EXPENTRY ResultDlgProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  610. {
  611.    static  PMATHELEMENT pResult;
  612.    CHAR    szBuf[BUFF_SIZE];
  613.    CHAR    szTemp[BUFF_SIZE];
  614.    SHORT   i;
  615.    MRESULT sRC;
  616.  
  617.    switch (msg)
  618.    {
  619.        case WM_INITDLG:
  620.  
  621.            pResult = PVOIDFROMMP(mp2);
  622.            FixSysMenu(hwnd);
  623.            memset(szBuf, 0, sizeof(szBuf));
  624.            sprintf(szBuf,"%ld", pResult->fOperand1); /* szBuf= 'OP1'     */
  625.            memset(szTemp, 0, sizeof(szTemp));
  626.            sprintf(szTemp,"%ld", pResult->fOperand2);
  627.            strcat(szBuf," ");                    /* szBuf= 'OP1 '        */
  628.            strcat(szBuf,pResult->pszOperation);  /* szBuf= 'OP1 +'       */
  629.            strcat(szBuf," ");                    /* szBuf= 'OP1 + '      */
  630.            strcat(szBuf, szTemp);                /* szBuf= 'OP1 + OP2'   */
  631.            strcat(szBuf, " ");                   /* szBuf= 'OP1 + OP2 '  */
  632.            strcat(szBuf, "=");                   /* szBuf= 'OP1 + OP2 =' */
  633.                                                  /* Display the formula  */
  634.            WinSetDlgItemText(hwnd, IDD_TEXT, szBuf);
  635.            for (i=BUFF_SIZE-1; i && pResult->szResult[i]!='.'; i--)
  636.            {
  637.               if (pResult->szResult[i] == '0')
  638.                  pResult->szResult[i] = '\000';  /* Erase tail's zero    */
  639.            }                                     /* Display the result   */
  640.            WinSetDlgItemText(hwnd, IDD_VALUE, pResult->szResult);
  641.  
  642.            return((MRESULT)FALSE);
  643.                          /* Let the focus go to where the system puts it */
  644.        case WM_COMMAND:
  645.            switch (SHORT1FROMMP(mp1))
  646.            {
  647.               case DID_OK:
  648.                  WinDismissDlg(hwnd, TRUE);
  649.                  break;
  650.            }
  651.            break;
  652.  
  653.        default:
  654.            sRC = WinDefDlgProc(hwnd, msg, mp1, mp2);
  655.            return sRC;
  656.    }
  657.    return (MRESULT)RETURN_SUCCESS;
  658. }
  659.