home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dovetail.zip / sdlgproc.cc < prev    next >
C/C++ Source or Header  |  1994-04-06  |  3KB  |  99 lines

  1. //**************************************************************************
  2. #define INCL_WIN
  3. #include <os2.h>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include "dove.h"
  7. #include "process.h"
  8. #include "sbutton.h"
  9. #include "efield.h"
  10. //**************************************************************************
  11.  
  12.  
  13. extern "C"
  14.  {
  15.    // This function must be exported so don't mangle the name
  16.  
  17.    MRESULT EXPENTRY StockDlgProc (HWND, USHORT, MPARAM, MPARAM);
  18.  }
  19. MRESULT EXPENTRY StockDlgProc (HWND    hwnd,
  20.                                    USHORT  msg,
  21.                                    MPARAM  mp1,
  22.                                    MPARAM  mp2)
  23.  
  24.   {// Variable Declarations
  25.     static Sbutton *psUnits = NULL;
  26.     static Efield *peThickness = NULL,
  27.                   *peLength = NULL;
  28.    static char *units[] = {"IN","MM","CM"};
  29.    static float to_mm[] = {25.4,1.,10.};
  30.    static char *fmt[] = {"%.3f","%.2f","%.3f"};
  31.    static float factor, fThick, fLen;
  32.    static int unit;
  33.    char *text;
  34.    char newtext[32];
  35.  
  36.    switch(msg) {
  37.      case WM_INITDLG:
  38.         fThick=fThickness;
  39.         fLen=fLength;
  40.         peLength = NULL;
  41.         factor=to_mm[old_unit];
  42.         psUnits = new Sbutton(hwnd,ID_UNITS);
  43.         psUnits->SetArray(units,3);
  44.         psUnits->SetValue(old_unit);
  45.         peThickness = new Efield(hwnd,ID_THICKNESS);
  46.         sprintf(newtext,fmt[old_unit],fThick/factor);
  47.         peThickness->SetText(newtext);
  48.         peLength = new Efield(hwnd,ID_LENGTH);
  49.         sprintf(newtext,fmt[old_unit],fLen/factor);
  50.         peLength->SetText(newtext);
  51.         unit=old_unit;
  52.         break;
  53.      case WM_COMMAND:
  54.         switch(SHORT1FROMMP(mp1)) {
  55.            case ID_OK:
  56.              text = (char *) *peThickness;
  57.              fThickness = atof(text)*to_mm[unit];
  58.              delete [] text;
  59.              delete peThickness;
  60.              text = (char *) *peLength;
  61.              fLength = atof(text)*to_mm[unit];
  62.              delete [] text;
  63.              delete peLength;
  64.              old_unit=unit;
  65.              delete psUnits;
  66.              WinPostMsg(hMain,UM_RECALC,0,0);
  67.              break;
  68.            case ID_CANCEL:
  69.              delete peThickness;
  70.              delete peLength;
  71.              delete psUnits;
  72.              break;
  73.          }
  74.      case WM_CONTROL:
  75.         switch(SHORT1FROMMP(mp1)) {
  76.            case ID_UNITS:
  77.              if(SHORT2FROMMP(mp1) == SPBN_CHANGE) {
  78.                 unit = (ULONG) *psUnits;
  79.                 if(to_mm[unit] != factor && peLength) { /* alter entry fields */
  80.                    text = (char *) *peThickness;
  81.                    fThick = atof(text)*factor;
  82.                    delete [] text;
  83.                    sprintf(newtext,fmt[unit],fThick/to_mm[unit]);
  84.                    peThickness->SetText(newtext);
  85.                    text = (char *) *peLength;
  86.                    fLen = atof(text)*factor;
  87.                    delete [] text;
  88.                    sprintf(newtext,fmt[unit],fLen/to_mm[unit]);
  89.                    peLength->SetText(newtext);
  90.                    factor=to_mm[unit];
  91.                 }
  92.              }
  93.              break;
  94.          }
  95.          break;
  96.      }
  97.      return WinDefDlgProc(hwnd,msg,mp1,mp2);
  98.  }
  99.