home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 November / Dppcpro1198.iso / Nov / Intelcad / Extras / mfcapp / MfcAppDlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-19  |  25.0 KB  |  718 lines

  1. // MfcAppDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <afxcview.h>
  6. #include "mfcapp.h"
  7. #include "varlist.h"
  8. #include "MfcAppDlg.h"
  9. #include "sds.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. #define ARRAYELEMENTS(array) (sizeof(array)/sizeof((array)[0]))
  18.  
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CMfcAppDlg dialog
  21.  
  22. CMfcAppDlg::CMfcAppDlg(CWnd* pParent /*=NULL*/)
  23.     : CDialog(CMfcAppDlg::IDD, pParent)
  24. {
  25.     //{{AFX_DATA_INIT(CMfcAppDlg)
  26.         // NOTE: the ClassWizard will add member initialization here
  27.     //}}AFX_DATA_INIT
  28. }
  29.  
  30. void CMfcAppDlg::DoDataExchange(CDataExchange* pDX)
  31. {
  32.     CDialog::DoDataExchange(pDX);
  33.     //{{AFX_DATA_MAP(CMfcAppDlg)
  34.         // NOTE: the ClassWizard will add DDX and DDV calls here
  35.     //}}AFX_DATA_MAP
  36. }
  37.  
  38.  
  39. BEGIN_MESSAGE_MAP(CMfcAppDlg, CDialog)
  40.     //{{AFX_MSG_MAP(CMfcAppDlg)
  41.     ON_NOTIFY(NM_CLICK, IDC_VAR_LIST, OnDblclkVarList)
  42.     ON_NOTIFY(NM_DBLCLK, IDC_VAR_LIST, OnDblclkVarList)
  43.     //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CMfcAppDlg message handlers
  48.  
  49. BOOL CMfcAppDlg::OnInitDialog() 
  50. {
  51.     CDialog::OnInitDialog();
  52.  
  53.     LV_COLUMN lvcol;
  54.     char sBuffer[50];
  55.  
  56.     // First set up the headers in the list conrol.
  57.     CListCtrl* pVarList = (CListCtrl*)GetDlgItem(IDC_VAR_LIST);
  58.        
  59.     // Column 1.
  60.     lvcol.mask = LVCF_TEXT | LVCF_WIDTH;
  61.     lvcol.iSubItem = 0;
  62.     lvcol.cx = 100;
  63.     strcpy(sBuffer, "SysVar");
  64.     lvcol.pszText = sBuffer;
  65.     lvcol.cchTextMax = strlen(sBuffer);
  66.     pVarList->InsertColumn(0, &lvcol);
  67.  
  68.     // Column 2.
  69.     lvcol.cx = 245;
  70.     strcpy(sBuffer, "Value");
  71.     lvcol.cchTextMax = strlen(sBuffer);
  72.     pVarList->InsertColumn(1, &lvcol);
  73.  
  74.     // Now populate the list.
  75.     AddItems();
  76.     
  77.     return TRUE;  // return TRUE unless you set the focus to a control
  78.                   // EXCEPTION: OCX Property Pages should return FALSE
  79. }
  80.  
  81. void CMfcAppDlg::OnDblclkVarList(NMHDR* pNMHDR, LRESULT* pResult) 
  82. {
  83.     char sXBuf[10], sYBuf[10], sZBuf[10], text[100], tmp[255];
  84.     int index, resVal;
  85.     sds_resbuf result;
  86.     
  87.     BOOL readOnly = FALSE;
  88.     is2DPoint = FALSE;
  89.     CListCtrl* pVarList = (CListCtrl*)GetDlgItem(IDC_VAR_LIST);
  90.  
  91.     // Look for the selected item. We'll go backwards just for sport.
  92.     for(index = (pVarList->GetItemCount()-1); index!=-1; --index) {                 
  93.        if (pVarList->GetItemState(index,LVIS_SELECTED)) {        
  94.             pVarList->GetItemText(index, 0, text, 100);
  95.             break;
  96.        }
  97.     }
  98.     
  99.     // Now re-check the string in the array for a leading underscore.
  100.     // If one exists, this is a read only variable. In such a case, 
  101.     // we will simply put up a message box with the current value and
  102.     // an OK button.
  103.     readOnly = varlist[index][0] == '_' ? TRUE : FALSE;
  104.  
  105.     // Now get the current value of the variable selected.
  106.     sds_getvar(text, &result);
  107.  
  108.     switch (result.restype) {
  109.     case RTSTR:              // This is a string variable. 
  110.         {        
  111.             // If this variable is read only, put up a message box with
  112.             // the current value.
  113.             if (readOnly) {
  114.                 char msg[255];
  115.                 if (!strlen(result.resval.rstring))
  116.                     sprintf(msg, "%s not currently set.", text);
  117.                 else
  118.                     sprintf(msg, "%s currently %s.", text, result.resval.rstring);
  119.                 MessageBox( msg, "Read Only variable:",  MB_OK);
  120.                 return;
  121.             }
  122.  
  123.             CStrDlg inPutDlg(this);
  124.             // Since MFC supplies us with Dialog Data Exchange and Validation,
  125.             // All we need to do is set the edit boxes variable to the current
  126.             // value of the variable, and it will appear in the dialog as the 
  127.             // default when the dialog is displayed. Magic.
  128.             inPutDlg.m_NewVal = result.resval.rstring;
  129.  
  130.             // Now show the dialog.
  131.             int retVal = inPutDlg.DoModal();
  132.             if (retVal == IDOK) {  // OK was pressed.
  133.                 // Make sure we have enough string space to copy what the user 
  134.                 // has entered into the edit field.
  135.                 result.resval.rstring = (char*)malloc(strlen(LPCSTR(inPutDlg.m_NewVal)) + 1);
  136.                 // Pressing OK with Dialog Data Exchange updates the variable for us.
  137.                 strcpy(result.resval.rstring , inPutDlg.m_NewVal);
  138.                 // Now actually set the variable to what the user has requested.
  139.                 // Icad will let us know if it was a bogus value.
  140.                 resVal = sds_setvar(text, &result);
  141.  
  142.                 // If the value was ok, the update the List control.
  143.                 if (resVal == RTNORM) {
  144.                     LV_ITEM lvitem;
  145.                     lvitem.iItem = index;
  146.                     lvitem.pszText = result.resval.rstring ;
  147.                     lvitem.mask = LVIF_TEXT;
  148.                     lvitem. stateMask = 0;
  149.                     lvitem.iSubItem = 1;
  150.                     lvitem.iImage = 0;
  151.                     lvitem.lParam = NULL;
  152.                     lvitem.iIndent = 0;
  153.                     pVarList->SetItem(&lvitem);
  154.                 } else { 
  155.                     // sds_setvar() has returned RTERROR for some reason.
  156.                     // So let the user know.
  157.                     sprintf(tmp, "Unable to set %s to %s!", text, result.resval.rstring);
  158.                     AfxMessageBox(tmp, MB_OK, 0);
  159.                 }
  160.                 // Remove string space allocated above.
  161.                 free(result.resval.rstring);
  162.             }
  163.         }        
  164.         break;
  165.  
  166.     case RTREAL:
  167.         {
  168.             // If this variable is read only, put up a message box with
  169.             // the current value.
  170.             if (readOnly) {
  171.                 char msg[255];
  172.                 sprintf(msg, "%s currently %f.", text, result.resval.rreal);
  173.                 MessageBox(msg, "Read Only variable:",  MB_OK);
  174.                 return;
  175.             }
  176.  
  177.             CRealDlg inPutDlg(this);
  178.             char tmpBuffer[50];
  179.             inPutDlg.m_RealVal = result.resval.rreal;
  180.             // Since MFC supplies us with Dialog Data Exchange and Validation,
  181.             // All we need to do is set the edit boxes variable to the current
  182.             // value of the variable, and it will appear in the dialog as the 
  183.             // default when the dialog is displayed. Magic.
  184.  
  185.             // Now show the dialog.
  186.             int retVal = inPutDlg.DoModal();
  187.  
  188.             if (retVal == IDOK) {  // OK was pressed.
  189.                 // Pressing OK with Dialog Data Exchange updates the variable for us.
  190.                 result.resval.rreal = inPutDlg.m_RealVal;
  191.                 // Now actually set the variable to what the user has requested.
  192.                 // Icad will let us know if it was a bogus value.
  193.                 resVal = sds_setvar(text, &result);
  194.  
  195.                 // If the value was ok, the update the List control.
  196.                 if (resVal == RTNORM) {
  197.                     LV_ITEM lvitem;
  198.                     lvitem.iItem = index;
  199.                     FloatToString(result.resval.rreal, tmpBuffer, 6);
  200.                     lvitem.pszText = tmpBuffer;
  201.                     lvitem.mask = LVIF_TEXT;
  202.                     lvitem. stateMask = 0;
  203.                     lvitem.iSubItem = 1;
  204.                     lvitem.iImage = 0;
  205.                     lvitem.lParam = NULL;
  206.                     lvitem.iIndent = 0;
  207.                     pVarList->SetItem(&lvitem);
  208.                 } else {   
  209.                     // sds_setvar() has returned RTERROR for some reason.
  210.                     // So let the user know.
  211.                     sprintf(tmp, "Unable to set %s to %f!", text, result.resval.rstring);
  212.                     MessageBox(tmp, MB_OK, 0);
  213.                 }
  214.             }
  215.         }
  216.         break;
  217.     case RTSHORT: 
  218.         {
  219.             // If this variable is read only, put up a message box with
  220.             // the current value.
  221.             if (readOnly) {
  222.                 char msg[255];
  223.                 sprintf(msg, "%s currently %d.", text, result.resval.rint);
  224.                 MessageBox(msg, "Read Only variable:",  MB_OK);
  225.                 return;
  226.             }
  227.  
  228.             CShortDlg inPutDlg(this);
  229.             char tmpBuffer[50];
  230.             // Since MFC supplies us with Dialog Data Exchange and Validation,
  231.             // All we need to do is set the edit boxes variable to the current
  232.             // value of the variable, and it will appear in the dialog as the 
  233.             // default when the dialog is displayed. Magic.
  234.             inPutDlg.m_IntVal = result.resval.rint;
  235.  
  236.             // Now show the dialog.
  237.             int retVal = inPutDlg.DoModal();
  238.             if (retVal == IDOK) {  // OK was pressed.
  239.                 // Pressing OK with Dialog Data Exchange updates the variable for us.
  240.                 result.resval.rint = inPutDlg.m_IntVal;
  241.                 // Now actually set the variable to what the user has requested.
  242.                 // Icad will let us know if it was a bogus value.
  243.                 resVal = sds_setvar(text, &result);
  244.  
  245.                 // If the value was ok, the update the List control.
  246.                 if (resVal == RTNORM) {
  247.                     LV_ITEM lvitem;
  248.                     lvitem.iItem = index;
  249.                     itoa(result.resval.rint, tmpBuffer, 10);
  250.                     lvitem.pszText = tmpBuffer;
  251.                     lvitem.mask = LVIF_TEXT;
  252.                     lvitem. stateMask = 0;
  253.                     lvitem.iSubItem = 1;
  254.                     lvitem.iImage = 0;
  255.                     lvitem.lParam = NULL;
  256.                     lvitem.iIndent = 0;
  257.                     pVarList->SetItem(&lvitem);
  258.                 } else { 
  259.                     // sds_setvar() has returned RTERROR for some reason.
  260.                     // So let the user know.                    
  261.                     sprintf(tmp, "Unable to set %s to %d!", text, result.resval.rint);
  262.                     MessageBox(tmp, MB_OK, 0);
  263.                 }
  264.             }
  265.         }
  266.         break;
  267.  
  268.     case RTPOINT:
  269.         {
  270.             is2DPoint = TRUE;
  271.             // If this variable is read only, put up a message box with
  272.             // the current value.
  273.             if (readOnly) {
  274.                 char msg[255];
  275.                 sprintf(msg, "%s currently ", text);
  276.                 // Floats need to be converted to strings.
  277.                 FloatToString(result.resval.rpoint[0], sXBuf, 6);
  278.                 // Build up the string we are about to put in the 
  279.                 // message box.
  280.                 strcat(msg, " (");
  281.                 strcat(msg, sXBuf);
  282.                 // Floats need to be converted to strings.
  283.                 FloatToString(result.resval.rpoint[1], sYBuf, 6);
  284.                 strcat(msg, " ");strcat(msg, sYBuf);strcat(msg, ")");
  285.  
  286.                 MessageBox(msg, "Read Only variable:",  MB_OK);
  287.                 return;
  288.             }
  289.  
  290.             CPointDlg inPutDlg(this);
  291.             char tmpBuffer[50];
  292.             // Since MFC supplies us with Dialog Data Exchange and Validation,
  293.             // All we need to do is set the edit boxes variable to the current
  294.             // value of the variable, and it will appear in the dialog as the 
  295.             // default when the dialog is displayed. Magic.
  296.             inPutDlg.m_Point_X = result.resval.rpoint[0];
  297.             inPutDlg.m_Point_Y = result.resval.rpoint[1];
  298.  
  299.             // Now show the dialog.
  300.             int retVal = inPutDlg.DoModal();
  301.             if (retVal == IDOK) {  // OK was pressed.
  302.                 // Pressing OK with Dialog Data Exchange updates the variable for us.
  303.                 result.resval.rpoint[0] = inPutDlg.m_Point_X;
  304.                 result.resval.rpoint[1] = inPutDlg.m_Point_Y;
  305.                 // Now actually set the variable to what the user has requested.
  306.                 // Icad will let us know if it was a bogus value.
  307.                 resVal = sds_setvar(text, &result);
  308.  
  309.                 // If the value was ok, the update the List control.
  310.                 if (resVal == RTNORM) {
  311.                     LV_ITEM lvitem;
  312.                     lvitem.iItem = index;
  313.                     // Floats need to be converted to strings.
  314.                     FloatToString(result.resval.rpoint[0], sXBuf, 6);
  315.                     // Build up the string we are about to put in the 
  316.                     // message box.
  317.                     strcpy(tmpBuffer, "(");
  318.                     strcat(tmpBuffer, sXBuf);
  319.  
  320.                     FloatToString(result.resval.rpoint[1], sYBuf, 6);
  321.                     strcat(tmpBuffer, " ");strcat(tmpBuffer, sYBuf);strcat(tmpBuffer, ")");
  322.  
  323.                     lvitem.pszText = tmpBuffer;
  324.                     lvitem.mask = LVIF_TEXT;
  325.                     lvitem. stateMask = 0;
  326.                     lvitem.iSubItem = 1;
  327.                     lvitem.iImage = 0;
  328.                     lvitem.lParam = NULL;
  329.                     lvitem.iIndent = 0;
  330.                     pVarList->SetItem(&lvitem);
  331.                 } else { 
  332.                     // sds_setvar() has returned RTERROR for some reason.
  333.                     // So let the user know.
  334.                     
  335.                     // Floats need to be converted to strings.
  336.                     FloatToString(result.resval.rpoint[0], sXBuf, 6);
  337.                     // Build up the string we are about to put in the 
  338.                     // message box.
  339.                     strcpy(tmpBuffer, "(");
  340.                     strcat(tmpBuffer, sXBuf);
  341.  
  342.                     FloatToString(result.resval.rpoint[1], sYBuf, 6);
  343.                     strcat(tmpBuffer, " ");strcat(tmpBuffer, sYBuf);strcat(tmpBuffer, ")");
  344.                     sprintf(tmp, "Unable to set %s to %s!", text, tmpBuffer);
  345.                     MessageBox(tmp, MB_OK, 0);
  346.                 }
  347.             }
  348.         }
  349.         break;
  350.     case RT3DPOINT:
  351.         {
  352.             // If this variable is read only, put up a message box with
  353.             // the current value.
  354.             if (readOnly) {
  355.                 char msg[255];
  356.                 sprintf(msg, "%s currently ", text);
  357.                 // Floats need to be converted to strings.
  358.                 FloatToString(result.resval.rpoint[0], sXBuf, 6);
  359.                 // Build up the string we are about to put in the 
  360.                 // message box.
  361.                 strcat(msg, " (");
  362.                 strcat(msg, sXBuf);
  363.  
  364.                 FloatToString(result.resval.rpoint[1], sYBuf, 6);
  365.                 strcat(msg, " ");strcat(msg, sYBuf);
  366.  
  367.                 FloatToString(result.resval.rpoint[2], sZBuf, 6);
  368.                 strcat(msg, " ");strcat(msg, sZBuf);strcat(msg, ")");
  369.  
  370.                 MessageBox(msg, "Read Only variable:",  MB_OK);
  371.                 return;
  372.             }
  373.  
  374.             CPointDlg inPutDlg(this);
  375.             char tmpBuffer[50];
  376.  
  377.             // Since MFC supplies us with Dialog Data Exchange and Validation,
  378.             // All we need to do is set the edit boxes variable to the current
  379.             // value of the variable, and it will appear in the dialog as the 
  380.             // default when the dialog is displayed. Magic.
  381.             inPutDlg.m_Point_X = result.resval.rpoint[0];
  382.             inPutDlg.m_Point_Y = result.resval.rpoint[1];
  383.             inPutDlg.m_Point_Z = result.resval.rpoint[2];
  384.  
  385.             // Now show the dialog.
  386.             int retVal = inPutDlg.DoModal();
  387.             if (retVal == IDOK) {  // OK was pressed.
  388.                 // Pressing OK with Dialog Data Exchange updates the variable for us.
  389.                 result.resval.rpoint[0] = inPutDlg.m_Point_X;
  390.                 result.resval.rpoint[1] = inPutDlg.m_Point_Y;
  391.                 result.resval.rpoint[2] = inPutDlg.m_Point_Z;
  392.                 // Now actually set the variable to what the user has requested.
  393.                 // Icad will let us know if it was a bogus value.
  394.                 resVal = sds_setvar(text, &result);
  395.  
  396.                 // If the value was ok, the update the List control.
  397.                 if (resVal == RTNORM) {
  398.                     LV_ITEM lvitem;
  399.                     lvitem.iItem = index;
  400.                     // Floats need to be converted to strings.
  401.                     FloatToString(result.resval.rpoint[0], sXBuf, 6);
  402.                     // Build up the string we are about to put in the 
  403.                     // message box.
  404.                     strcpy(tmpBuffer, "(");
  405.                     strcat(tmpBuffer, sXBuf);
  406.  
  407.                     FloatToString(result.resval.rpoint[1], sYBuf, 6);
  408.                     strcat(tmpBuffer, " ");strcat(tmpBuffer, sYBuf);
  409.  
  410.                     FloatToString(result.resval.rpoint[1], sZBuf, 6);
  411.                     strcat(tmpBuffer, " ");strcat(tmpBuffer, sZBuf);strcat(tmpBuffer, ")");
  412.  
  413.                     lvitem.pszText = tmpBuffer;
  414.                     lvitem.mask = LVIF_TEXT;
  415.                     lvitem. stateMask = 0;
  416.                     lvitem.iSubItem = 1;
  417.                     lvitem.iImage = 0;
  418.                     lvitem.lParam = NULL;
  419.                     lvitem.iIndent = 0;
  420.                     pVarList->SetItem(&lvitem);
  421.                 } else { 
  422.                     // sds_setvar() has returned RTERROR for some reason.
  423.                     // So let the user know.
  424.                     
  425.                     // Floats need to be converted to strings.
  426.                     FloatToString(result.resval.rpoint[0], sXBuf, 6);
  427.                     // Build up the string we are about to put in the 
  428.                     // message box.
  429.                     strcpy(tmpBuffer, "(");
  430.                     strcat(tmpBuffer, sXBuf);
  431.  
  432.                     FloatToString(result.resval.rpoint[1], sYBuf, 6);
  433.                     strcat(tmpBuffer, " ");strcat(tmpBuffer, sYBuf);
  434.  
  435.                     FloatToString(result.resval.rpoint[1], sZBuf, 6);
  436.                     strcat(tmpBuffer, " ");strcat(tmpBuffer, sZBuf);strcat(tmpBuffer, ")");
  437.  
  438.                     sprintf(tmp, "Unable to set %s to %s!", text, tmpBuffer);
  439.                     MessageBox(tmp, MB_OK, 0);
  440.                 }
  441.             }
  442.         }
  443.         break;
  444.     default:
  445.         break;
  446.     }
  447.  
  448.     *pResult = 0;
  449. }
  450.  
  451. void CMfcAppDlg::AddItems()
  452. {
  453.     LV_ITEM lvitem;
  454.     char sBuffer[100];
  455.     char sXBuf[15], sYBuf[15], sZBuf[15];
  456.     sds_resbuf result;
  457.     BOOL readOnly = FALSE;
  458.  
  459.     CListCtrl* pVarList = (CListCtrl*)GetDlgItem(IDC_VAR_LIST);
  460.  
  461.     for (int i = 0; i < ARRAYELEMENTS(varlist); i++) {
  462.  
  463.         strcpy(sBuffer, varlist[i]);
  464.  
  465.         lvitem.iItem = i;
  466.         lvitem.pszText = NULL;
  467.         lvitem.mask = LVIF_TEXT;
  468.         lvitem.stateMask = 0;
  469.         lvitem.iSubItem = 0;
  470.         lvitem.iImage = 0;
  471.         lvitem.lParam = NULL;
  472.         lvitem.iIndent = 0;
  473.  
  474.         if (sBuffer[0] == '_') {
  475.             readOnly = TRUE;
  476.             sds_getvar(sBuffer+1, &result);
  477.             lvitem.pszText = sBuffer + 1;
  478.             lvitem.cchTextMax = strlen(sBuffer + 1);
  479.  
  480.             pVarList->InsertItem(&lvitem);
  481.         } else {
  482.             sds_getvar(sBuffer, &result);
  483.             lvitem.pszText = sBuffer;
  484.             lvitem.cchTextMax = strlen(sBuffer);
  485.  
  486.             pVarList->InsertItem(&lvitem);
  487.         }
  488.  
  489.         lvitem.iSubItem = 1;
  490.  
  491.         switch (result.restype) {
  492.         case RTSTR:
  493.             if (strlen(result.resval.rstring) > 0) {
  494.                 lvitem.pszText = result.resval.rstring;
  495.             } else {
  496.                 lvitem.pszText = "\"\"";
  497.             }
  498.             break;
  499.         case RTREAL:
  500.             FloatToString(result.resval.rreal, sBuffer, 6);
  501.             lvitem.pszText = sBuffer;
  502.             break;
  503.         case RTSHORT:
  504.             itoa(result.resval.rint, sBuffer, 10);
  505.             lvitem.pszText = sBuffer;
  506.             break;
  507.         case RTPOINT:
  508.             FloatToString(result.resval.rpoint[0], sXBuf, 6);
  509.             strcpy(sBuffer, "(");
  510.             strcat(sBuffer, sXBuf);
  511.  
  512.             FloatToString(result.resval.rpoint[1], sYBuf, 6);
  513.             strcat(sBuffer, " ");strcat(sBuffer, sYBuf);strcat(sBuffer, ")");
  514.  
  515.             lvitem.pszText = sBuffer;
  516.             break;
  517.         case RT3DPOINT:
  518.             FloatToString(result.resval.rpoint[0], sXBuf, 6);
  519.             strcpy(sBuffer, "(");
  520.             strcat(sBuffer, sXBuf);
  521.  
  522.             FloatToString(result.resval.rpoint[1], sYBuf, 6);
  523.             strcat(sBuffer, " ");strcat(sBuffer, sYBuf);
  524.  
  525.             FloatToString(result.resval.rpoint[2], sZBuf, 6);
  526.             strcat(sBuffer, " ");strcat(sBuffer, sZBuf);strcat(sBuffer, ")");
  527.  
  528.             lvitem.pszText = sBuffer;
  529.             break;
  530.         default:
  531.             itoa(i, sBuffer, 10);
  532.             strcat(sBuffer, " --**");
  533.             lvitem.pszText = sBuffer;
  534.             break;
  535.         }
  536.  
  537.         char readOnlyBuf[255];
  538.         if (readOnly == TRUE) {
  539.             readOnly = FALSE;
  540.             sprintf(readOnlyBuf, "%s %s", lvitem.pszText, " (Read Only)");
  541.             lvitem.pszText = readOnlyBuf;
  542.         }
  543.  
  544.         lvitem.cchTextMax = strlen(lvitem.pszText);
  545.         pVarList->SetItem(&lvitem);
  546.     }
  547. }
  548.  
  549. void CMfcAppDlg::FloatToString(double value, char *psBuffer, short prec)
  550. {
  551.     int dec, sign;
  552.     short place = 0;
  553.     char *psTemp = _fcvt(value, prec, &dec, &sign);
  554.     
  555.     if (dec >= 20) {
  556.         _gcvt( value, 6, psBuffer );
  557.         return;
  558.     }
  559.     memset(psBuffer, '\0', prec + 4);
  560.  
  561.     if (sign) {
  562.         strcpy(psBuffer, "-");
  563.         place++;
  564.     }
  565.     dec = (dec > 4) ? 4 : (dec < -4) ? -4 : dec;
  566.     if (dec <= 0) {
  567.         if (prec) {
  568.             strcat(psBuffer, "0.");
  569.             place += 2;
  570.         } else {
  571.             strcat(psBuffer, "0");
  572.             place++;
  573.         }
  574.         memset(psBuffer + place, '0', abs(dec));
  575.         strcat(psBuffer, psTemp);
  576.     } else {
  577.         strncat(psBuffer, psTemp, dec);
  578.         if (prec)
  579.             strcat(psBuffer, ".");
  580.         strcat(psBuffer, psTemp + dec);
  581.     }
  582. }
  583.  
  584. /////////////////////////////////////////////////////////////////////////////
  585. // CStrDlg dialog
  586.  
  587. CStrDlg::CStrDlg(CWnd* pParent /*=NULL*/)
  588.     : CDialog(CStrDlg::IDD, pParent)
  589. {
  590.     //{{AFX_DATA_INIT(CStrDlg)
  591.     m_NewVal = _T("");
  592.     //}}AFX_DATA_INIT
  593. }
  594.  
  595.  
  596. void CStrDlg::DoDataExchange(CDataExchange* pDX)
  597. {
  598.     CDialog::DoDataExchange(pDX);
  599.     //{{AFX_DATA_MAP(CStrDlg)
  600.     DDX_Text(pDX, IDC_STRING_VALUE_EDITBOX, m_NewVal);
  601.     //}}AFX_DATA_MAP
  602. }
  603.  
  604.  
  605. BEGIN_MESSAGE_MAP(CStrDlg, CDialog)
  606.     //{{AFX_MSG_MAP(CStrDlg)
  607.     //}}AFX_MSG_MAP
  608. END_MESSAGE_MAP()
  609.  
  610. /////////////////////////////////////////////////////////////////////////////
  611. // CStrDlg message handlers
  612.  
  613. /////////////////////////////////////////////////////////////////////////////
  614. // CRealDlg dialog
  615.  
  616. CRealDlg::CRealDlg(CWnd* pParent /*=NULL*/)
  617.     : CDialog(CRealDlg::IDD, pParent)
  618. {
  619.     //{{AFX_DATA_INIT(CRealDlg)
  620.     m_RealVal = 0.0;
  621.     //}}AFX_DATA_INIT
  622. }
  623.  
  624.  
  625. void CRealDlg::DoDataExchange(CDataExchange* pDX)
  626. {
  627.     CDialog::DoDataExchange(pDX);
  628.     //{{AFX_DATA_MAP(CRealDlg)
  629.     DDX_Text(pDX, IDC_REAL_VALUE_EDITBOX, m_RealVal);
  630.     //}}AFX_DATA_MAP
  631. }
  632.  
  633.  
  634. BEGIN_MESSAGE_MAP(CRealDlg, CDialog)
  635.     //{{AFX_MSG_MAP(CRealDlg)
  636.         // NOTE: the ClassWizard will add message map macros here
  637.     //}}AFX_MSG_MAP
  638. END_MESSAGE_MAP()
  639.  
  640. /////////////////////////////////////////////////////////////////////////////
  641. // CRealDlg message handlers
  642. /////////////////////////////////////////////////////////////////////////////
  643. // CShortDlg dialog
  644.  
  645. CShortDlg::CShortDlg(CWnd* pParent /*=NULL*/)
  646.     : CDialog(CShortDlg::IDD, pParent)
  647. {
  648.     //{{AFX_DATA_INIT(CShortDlg)
  649.     m_IntVal = 0;
  650.     //}}AFX_DATA_INIT
  651. }
  652.  
  653.  
  654. void CShortDlg::DoDataExchange(CDataExchange* pDX)
  655. {
  656.     CDialog::DoDataExchange(pDX);
  657.     //{{AFX_DATA_MAP(CShortDlg)
  658.     DDX_Text(pDX, IDC_SHORT_VALUE_EDITBOX, m_IntVal);
  659.     //}}AFX_DATA_MAP
  660. }
  661.  
  662.  
  663. BEGIN_MESSAGE_MAP(CShortDlg, CDialog)
  664.     //{{AFX_MSG_MAP(CShortDlg)
  665.         // NOTE: the ClassWizard will add message map macros here
  666.     //}}AFX_MSG_MAP
  667. END_MESSAGE_MAP()
  668.  
  669. /////////////////////////////////////////////////////////////////////////////
  670. // CShortDlg message handlers
  671. /////////////////////////////////////////////////////////////////////////////
  672. // CPointDlg dialog
  673.  
  674. CPointDlg::CPointDlg(CWnd* pParent /*=NULL*/)
  675.     : CDialog(CPointDlg::IDD, pParent)
  676. {
  677.     //{{AFX_DATA_INIT(CPointDlg)
  678.     m_Point_X = 0.0;
  679.     m_Point_Y = 0.0;
  680.     m_Point_Z = 0.0;
  681.     //}}AFX_DATA_INIT
  682. }
  683.  
  684.  
  685. void CPointDlg::DoDataExchange(CDataExchange* pDX)
  686. {
  687.     CDialog::DoDataExchange(pDX);
  688.     //{{AFX_DATA_MAP(CPointDlg)
  689.     DDX_Text(pDX, IDC_POINT_X_EDIT, m_Point_X);
  690.     DDX_Text(pDX, IDC_POINT_Y_EDIT, m_Point_Y);
  691.     DDX_Text(pDX, IDC_POINT_Z_EDIT, m_Point_Z);
  692.     //}}AFX_DATA_MAP
  693. }
  694.  
  695.  
  696. BEGIN_MESSAGE_MAP(CPointDlg, CDialog)
  697.     //{{AFX_MSG_MAP(CPointDlg)
  698.     //}}AFX_MSG_MAP
  699. END_MESSAGE_MAP()
  700.  
  701. /////////////////////////////////////////////////////////////////////////////
  702. // CPointDlg message handlers
  703.  
  704. BOOL CPointDlg::OnInitDialog() 
  705. {
  706.     CDialog::OnInitDialog();
  707.  
  708.     // For 2D points, hide the Z input edit box and static text.
  709.     if(((CMfcAppDlg*)GetParent())->is2DPoint) {
  710.         GetDlgItem(IDC_POINT_Z_EDIT)->ShowWindow(SW_HIDE);
  711.         GetDlgItem(IDC_POINT_Z)->ShowWindow(SW_HIDE);
  712.     }
  713.     return TRUE;  // return TRUE unless you set the focus to a control
  714.                   // EXCEPTION: OCX Property Pages should return FALSE
  715. }
  716.  
  717.  
  718.