home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / wordpad / ddxm.cpp < prev    next >
C/C++ Source or Header  |  1998-03-26  |  2KB  |  73 lines

  1. // ddxm.cpp : implementation file
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "ddxm.h"
  15. #include "wordpad.h"
  16. #include "resource.h"
  17.  
  18. // this routine prints a floatingpoint number with 2 digits after the decimal
  19. void PASCAL DDX_Twips(CDataExchange* pDX, int nIDC, int& value)
  20. {
  21.     HWND hWndCtrl = pDX->PrepareEditCtrl(nIDC);
  22.     TCHAR szT[64];
  23.  
  24.     if (pDX->m_bSaveAndValidate)
  25.     {
  26.         ::GetWindowText(hWndCtrl, szT, sizeof(szT));
  27.         if (szT[0] != NULL) // not empty
  28.         {
  29.             if (!theApp.ParseMeasurement(szT, value))
  30.             {
  31.                 AfxMessageBox(IDS_INVALID_MEASUREMENT,MB_OK|MB_ICONINFORMATION);
  32.                 pDX->Fail();            // throws exception
  33.             }
  34.             theApp.PrintTwips(szT, value, 2);
  35.             theApp.ParseMeasurement(szT, value);
  36.         }
  37.         else // empty
  38.             value = INT_MAX;
  39.     }
  40.     else
  41.     {
  42.         // convert from twips to default units
  43.         if (value != INT_MAX)
  44.         {
  45.             theApp.PrintTwips(szT, value, 2);
  46.             SetWindowText(hWndCtrl, szT);
  47.         }
  48.     }
  49. }
  50.  
  51. void PASCAL DDV_MinMaxTwips(CDataExchange* pDX, int value, int minVal, int maxVal)
  52. {
  53.     ASSERT(minVal <= maxVal);
  54.     if (value < minVal || value > maxVal)
  55.     {
  56.         // "The measurement must be between %1 and %2."
  57.         if (!pDX->m_bSaveAndValidate)
  58.         {
  59.             TRACE0("Warning: initial dialog data is out of range.\n");
  60.             return;     // don't stop now
  61.         }
  62.         TCHAR szMin[32];
  63.         TCHAR szMax[32];
  64.         theApp.PrintTwips(szMin, minVal, 2);
  65.         theApp.PrintTwips(szMax, maxVal, 2);
  66.         CString prompt;
  67.         AfxFormatString2(prompt, IDS_MEASUREMENT_RANGE, szMin, szMax);
  68.         AfxMessageBox(prompt, MB_ICONEXCLAMATION, AFX_IDS_APP_TITLE);
  69.         prompt.Empty(); // exception prep
  70.         pDX->Fail();
  71.     }
  72. }
  73.