Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
4.4 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // DDxDDv.cpp
  7. //
  8. // Abstract:
  9. // Implementation of custom dialog data exchange/dialog data validation
  10. // routines.
  11. //
  12. // Author:
  13. // David Potter (davidp) September 5, 1996
  14. //
  15. // Revision History:
  16. //
  17. // Notes:
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "DDxDDv.h"
  22. #include "resource.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. //++
  30. //
  31. // DDX_Number
  32. //
  33. // Routine Description:
  34. // Do data exchange between the dialog and the class.
  35. //
  36. // Arguments:
  37. // pDX [IN OUT] Data exchange object
  38. // nIDC [IN] Control ID.
  39. // dwValue [IN OUT] Value to set or get.
  40. // dwMin [IN] Minimum value.
  41. // dwMax [IN] Maximum value.
  42. // bSigned [IN] TRUE = value is signed, FALSE = value is unsigned
  43. //
  44. // Return Value:
  45. // None.
  46. //
  47. //--
  48. /////////////////////////////////////////////////////////////////////////////
  49. void AFXAPI DDX_Number(
  50. IN OUT CDataExchange * pDX,
  51. IN int nIDC,
  52. IN OUT DWORD & rdwValue,
  53. IN DWORD dwMin,
  54. IN DWORD dwMax,
  55. IN BOOL bSigned
  56. )
  57. {
  58. HWND hwndCtrl;
  59. DWORD dwValue;
  60. ASSERT(pDX != NULL);
  61. ASSERT(dwMin < dwMax);
  62. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  63. // Get the control window handle.
  64. hwndCtrl = pDX->PrepareEditCtrl(nIDC);
  65. if (pDX->m_bSaveAndValidate)
  66. {
  67. BOOL bTranslated;
  68. dwValue = GetDlgItemInt(pDX->m_pDlgWnd->m_hWnd, nIDC, &bTranslated, bSigned);
  69. if (!bTranslated
  70. || (dwValue < dwMin)
  71. || (dwValue > dwMax)
  72. )
  73. {
  74. TCHAR szMin[32];
  75. TCHAR szMax[32];
  76. CString strPrompt;
  77. wsprintf(szMin, _T("%lu%"), dwMin);
  78. wsprintf(szMax, _T("%lu%"), dwMax);
  79. AfxFormatString2(strPrompt, AFX_IDP_PARSE_INT_RANGE, szMin, szMax);
  80. AfxMessageBox(strPrompt, MB_ICONEXCLAMATION, AFX_IDP_PARSE_INT_RANGE);
  81. strPrompt.Empty(); // exception prep
  82. pDX->Fail();
  83. } // if: invalid string
  84. else
  85. rdwValue = dwValue;
  86. } // if: saving data
  87. else
  88. {
  89. CString strMaxValue;
  90. // Set the maximum number of characters that can be entered.
  91. if (bSigned)
  92. strMaxValue.Format(_T("%ld"), dwMax);
  93. else
  94. strMaxValue.Format(_T("%lu"), dwMax);
  95. SendMessage(hwndCtrl, EM_LIMITTEXT, strMaxValue.GetLength(), 0);
  96. // Set the value into the control.
  97. DDX_Text(pDX, nIDC, rdwValue);
  98. } // else: setting data onto the dialog
  99. } //*** DDX_Number()
  100. /////////////////////////////////////////////////////////////////////////////
  101. //++
  102. //
  103. // DDV_RequiredText
  104. //
  105. // Routine Description:
  106. // Validate that the dialog string is present.
  107. //
  108. // Arguments:
  109. // pDX [IN OUT] Data exchange object
  110. // nIDC [IN] Control ID.
  111. // nIDCLabel [IN] Label control ID.
  112. // rstrValue [IN] Value to set or get.
  113. //
  114. // Return Value:
  115. // None.
  116. //
  117. //--
  118. /////////////////////////////////////////////////////////////////////////////
  119. void AFXAPI DDV_RequiredText(
  120. IN OUT CDataExchange * pDX,
  121. IN int nIDC,
  122. IN int nIDCLabel,
  123. IN const CString & rstrValue
  124. )
  125. {
  126. ASSERT(pDX != NULL);
  127. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  128. if (pDX->m_bSaveAndValidate)
  129. {
  130. if (rstrValue.GetLength() == 0)
  131. {
  132. HWND hwndLabel;
  133. TCHAR szLabel[1024];
  134. TCHAR szStrippedLabel[1024];
  135. int iSrc;
  136. int iDst;
  137. TCHAR ch;
  138. CString strPrompt;
  139. // Get the label window handle
  140. hwndLabel = pDX->PrepareEditCtrl(nIDCLabel);
  141. // Get the text of the label.
  142. GetWindowText(hwndLabel, szLabel, sizeof(szLabel) / sizeof(TCHAR));
  143. // Remove ampersands (&) and colons (:).
  144. for (iSrc = 0, iDst = 0 ; szLabel[iSrc] != _T('\0') ; iSrc++)
  145. {
  146. ch = szLabel[iSrc];
  147. if ((ch != _T('&')) && (ch != _T(':')))
  148. szStrippedLabel[iDst++] = ch;
  149. } // for: each character in the label
  150. szStrippedLabel[iDst] = _T('\0');
  151. // Format and display a message.
  152. strPrompt.FormatMessage(IDS_REQUIRED_FIELD_EMPTY, szStrippedLabel);
  153. AfxMessageBox(strPrompt, MB_ICONEXCLAMATION);
  154. // Do this so that the control receives focus.
  155. (void) pDX->PrepareEditCtrl(nIDC);
  156. // Fail the call.
  157. strPrompt.Empty(); // exception prep
  158. pDX->Fail();
  159. } // if: field not specified
  160. } // if: saving data
  161. } //*** DDV_RequiredText()