Source code of Windows XP (NT5)
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.

145 lines
3.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: I P C T R L . C P P
  7. //
  8. // Contents:
  9. //
  10. // Notes:
  11. //
  12. // Author: tongl
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #pragma hdrstop
  17. #include "ipctrl.h"
  18. #include "tcpip.h"
  19. ///////////////////////////////////////////////////////////////////////
  20. //
  21. // IP Address control helpers
  22. IpControl::IpControl()
  23. {
  24. m_hIpAddress = 0;
  25. }
  26. IpControl::~IpControl()
  27. {
  28. }
  29. BOOL IpControl::Create(HWND hParent, UINT nId)
  30. {
  31. Assert(IsWindow(hParent));
  32. if (hParent)
  33. m_hIpAddress = GetDlgItem(hParent, nId);
  34. return m_hIpAddress != NULL;
  35. }
  36. LRESULT IpControl::SendMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  37. {
  38. Assert(IsWindow(m_hIpAddress));
  39. return ::SendMessage(m_hIpAddress, uMsg, wParam, lParam);
  40. }
  41. BOOL IpControl::IsBlank()
  42. {
  43. return SendMessage(IPM_ISBLANK, 0, 0);
  44. }
  45. void IpControl::SetAddress(DWORD ardwAddress[4])
  46. {
  47. SendMessage(IPM_SETADDRESS, 0,
  48. MAKEIPADDRESS(ardwAddress[0], ardwAddress[1],
  49. ardwAddress[2], ardwAddress[3]));
  50. }
  51. void IpControl::SetAddress(DWORD a1, DWORD a2, DWORD a3, DWORD a4)
  52. {
  53. SendMessage(IPM_SETADDRESS, 0, MAKEIPADDRESS(a1,a2,a3,a4));
  54. }
  55. void IpControl::SetAddress(PCWSTR pszString)
  56. {
  57. Assert(pszString != NULL);
  58. SendMessage(WM_SETTEXT, 0, (LPARAM)pszString);
  59. }
  60. void IpControl::GetAddress(DWORD *a1, DWORD *a2, DWORD *a3, DWORD *a4)
  61. {
  62. DWORD dwAddress;
  63. Assert(a1 && a2 && a3 && a4);
  64. if (SendMessage(IPM_GETADDRESS,0,(LPARAM)&dwAddress)== 0)
  65. {
  66. *a1 = 0;
  67. *a2 = 0;
  68. *a3 = 0;
  69. *a4 = 0;
  70. }
  71. else
  72. {
  73. *a1 = FIRST_IPADDRESS( dwAddress );
  74. *a2 = SECOND_IPADDRESS( dwAddress );
  75. *a3 = THIRD_IPADDRESS( dwAddress );
  76. *a4 = FOURTH_IPADDRESS( dwAddress );
  77. }
  78. }
  79. void IpControl::GetAddress(DWORD ardwAddress[4])
  80. {
  81. DWORD dwAddress;
  82. if (SendMessage(IPM_GETADDRESS, 0, (LPARAM)&dwAddress ) == 0)
  83. {
  84. ardwAddress[0] = 0;
  85. ardwAddress[1] = 0;
  86. ardwAddress[2] = 0;
  87. ardwAddress[3] = 0;
  88. }
  89. else
  90. {
  91. ardwAddress[0] = FIRST_IPADDRESS( dwAddress );
  92. ardwAddress[1] = SECOND_IPADDRESS( dwAddress );
  93. ardwAddress[2] = THIRD_IPADDRESS( dwAddress );
  94. ardwAddress[3] = FOURTH_IPADDRESS( dwAddress );
  95. }
  96. }
  97. void IpControl::GetAddress(tstring * pstrAddress)
  98. {
  99. WCHAR szIpAddress[1000];
  100. if (SendMessage(WM_GETTEXT, celems(szIpAddress), (LPARAM)&szIpAddress) == 0)
  101. {
  102. *pstrAddress = ZERO_ADDRESS;
  103. }
  104. else
  105. {
  106. *pstrAddress = szIpAddress;
  107. }
  108. }
  109. void IpControl::SetFocusField(DWORD dwField)
  110. {
  111. SendMessage(IPM_SETFOCUS, dwField, 0);
  112. }
  113. void IpControl::ClearAddress()
  114. {
  115. SendMessage(IPM_CLEARADDRESS, 0, 0);
  116. }
  117. void IpControl::SetFieldRange(DWORD dwField, DWORD dwMin, DWORD dwMax)
  118. {
  119. SendMessage(IPM_SETRANGE, dwField, MAKEIPRANGE(dwMin,dwMax));
  120. }