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.

238 lines
4.0 KiB

  1. //============================================================================
  2. // Copyright (C) Microsoft Corporation, 1996 - 1999
  3. //
  4. // File: ipctrl.cpp
  5. //
  6. // History:
  7. // Tony Romano Created.
  8. // 06/17/96 Abolade Gbadegesin Revised.
  9. //
  10. // Implements the C++ class encapsulating the IP-address custom control.
  11. //============================================================================
  12. #include "stdafx.h"
  13. extern "C" {
  14. #include "ipaddr.h"
  15. };
  16. #include "ipctrl.h"
  17. IPControl::IPControl( ) { m_hIPaddr = 0; }
  18. IPControl::~IPControl( ) { }
  19. BOOL
  20. IPControl::Create(
  21. HWND hParent,
  22. UINT nID
  23. ) {
  24. ASSERT(IsWindow(hParent));
  25. if (hParent)
  26. m_hIPaddr = GetDlgItem(hParent, nID);
  27. return m_hIPaddr != NULL;
  28. }
  29. LRESULT
  30. IPControl::SendMessage(
  31. UINT uMsg,
  32. WPARAM wParam,
  33. LPARAM lParam
  34. ) {
  35. ASSERT(IsWindow(m_hIPaddr));
  36. return ::SendMessage(m_hIPaddr, uMsg, wParam, lParam);
  37. }
  38. BOOL
  39. IPControl::IsBlank(
  40. ) {
  41. return (BOOL)SendMessage(IP_ISBLANK, 0, 0);
  42. }
  43. VOID
  44. IPControl::SetAddress(
  45. DWORD ardwAddress[4]
  46. ) {
  47. SendMessage(
  48. IP_SETADDRESS, 0,
  49. MAKEIPADDRESS(
  50. ardwAddress[0], ardwAddress[1], ardwAddress[2], ardwAddress[3]
  51. )
  52. );
  53. }
  54. VOID
  55. IPControl::SetAddress(
  56. DWORD a1,
  57. DWORD a2,
  58. DWORD a3,
  59. DWORD a4
  60. ) {
  61. SendMessage(IP_SETADDRESS, 0, MAKEIPADDRESS(a1,a2,a3,a4));
  62. }
  63. VOID
  64. IPControl::SetAddress(
  65. LPCTSTR lpszString
  66. ) {
  67. if (!lpszString) { ClearAddress(); }
  68. SendMessage(WM_SETTEXT, 0, (LPARAM)lpszString);
  69. }
  70. INT
  71. IPControl::GetAddress(
  72. DWORD *a1,
  73. DWORD *a2,
  74. DWORD *a3,
  75. DWORD *a4
  76. ) {
  77. INT_PTR nSet;
  78. DWORD dwAddress;
  79. ASSERT(a1 && a2 && a3 && a4);
  80. if ((nSet = SendMessage(IP_GETADDRESS,0,(LPARAM)&dwAddress)) == 0) {
  81. *a1 = 0;
  82. *a2 = 0;
  83. *a3 = 0;
  84. *a4 = 0;
  85. }
  86. else {
  87. *a1 = FIRST_IPADDRESS( dwAddress );
  88. *a2 = SECOND_IPADDRESS( dwAddress );
  89. *a3 = THIRD_IPADDRESS( dwAddress );
  90. *a4 = FOURTH_IPADDRESS( dwAddress );
  91. }
  92. return (INT)nSet;
  93. }
  94. INT
  95. IPControl::GetAddress(
  96. DWORD ardwAddress[4]
  97. ) {
  98. INT_PTR nSet;
  99. DWORD dwAddress;
  100. if ((nSet = SendMessage(IP_GETADDRESS, 0, (LPARAM)&dwAddress )) == 0) {
  101. ardwAddress[0] = 0;
  102. ardwAddress[1] = 0;
  103. ardwAddress[2] = 0;
  104. ardwAddress[3] = 0;
  105. }
  106. else {
  107. ardwAddress[0] = FIRST_IPADDRESS( dwAddress );
  108. ardwAddress[1] = SECOND_IPADDRESS( dwAddress );
  109. ardwAddress[2] = THIRD_IPADDRESS( dwAddress );
  110. ardwAddress[3] = FOURTH_IPADDRESS( dwAddress );
  111. }
  112. return (INT)nSet;
  113. }
  114. INT
  115. IPControl::GetAddress(
  116. CString& address
  117. ) {
  118. INT_PTR c, nSet;
  119. DWORD dwAddress;
  120. nSet = SendMessage(IP_GETADDRESS, 0, (LPARAM)&dwAddress);
  121. address.ReleaseBuffer((int)(c = SendMessage(WM_GETTEXT, 256, (LPARAM)address.GetBuffer(256))));
  122. return (INT)nSet;
  123. }
  124. VOID
  125. IPControl::SetFocusField(
  126. DWORD dwField
  127. ) {
  128. SendMessage(IP_SETFOCUS, dwField, 0);
  129. }
  130. VOID
  131. IPControl::ClearAddress(
  132. ) {
  133. SendMessage(IP_CLEARADDRESS, 0, 0);
  134. }
  135. VOID
  136. IPControl::SetFieldRange(
  137. DWORD dwField,
  138. DWORD dwMin,
  139. DWORD dwMax
  140. ) {
  141. SendMessage(IP_SETRANGE, dwField, MAKERANGE(dwMin,dwMax));
  142. }
  143. #if 0
  144. WCHAR *
  145. inet_ntoaw(
  146. struct in_addr dwAddress
  147. ) {
  148. static WCHAR szAddress[16];
  149. mbstowcs(szAddress, inet_ntoa(*(struct in_addr *)&dwAddress), 16);
  150. return szAddress;
  151. }
  152. DWORD
  153. inet_addrw(
  154. LPCWSTR szAddressW
  155. ) {
  156. CHAR szAddressA[16];
  157. wcstombs(szAddressA, szAddressW, 16);
  158. return inet_addr(szAddressA);
  159. }
  160. #endif