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.5 KiB

  1. //============================================================================
  2. // Copyright (C) Microsoft Corporation, 1996 - 1999
  3. //
  4. // File: ipcontrol.h
  5. //
  6. // History:
  7. // ??/??/?? Tony Romano Created.
  8. // 05/16/96 Abolade Gbadegesin Revised.
  9. //============================================================================
  10. #ifndef _IPCTRL_H
  11. #define _IPCTRL_H
  12. //----------------------------------------------------------------------------
  13. // Class: IPControl
  14. //
  15. // Controls an IP-address edit-control.
  16. //----------------------------------------------------------------------------
  17. class IPControl {
  18. public:
  19. IPControl( );
  20. ~IPControl( );
  21. BOOL
  22. Create(
  23. HWND hParent,
  24. UINT nID );
  25. operator
  26. HWND( ) { ASSERT(m_hIPaddr); return m_hIPaddr; }
  27. BOOL
  28. IsBlank( );
  29. VOID
  30. SetFocusField(
  31. DWORD dwField );
  32. VOID
  33. SetFieldRange(
  34. DWORD dwField,
  35. DWORD dwMin,
  36. DWORD dwMax );
  37. VOID
  38. ClearAddress( );
  39. VOID
  40. SetAddress(
  41. DWORD ardwAddress[4] );
  42. VOID
  43. SetAddress(
  44. DWORD a1,
  45. DWORD a2,
  46. DWORD a3,
  47. DWORD a4 );
  48. VOID
  49. SetAddress(
  50. LPCTSTR lpszString );
  51. INT
  52. GetAddress(
  53. DWORD ardwAddress[4] );
  54. INT
  55. GetAddress(
  56. DWORD* a1,
  57. DWORD* a2,
  58. DWORD* a3,
  59. DWORD* a4 );
  60. INT
  61. GetAddress(
  62. CString& address );
  63. LRESULT
  64. SendMessage(
  65. UINT uMsg,
  66. WPARAM wParam,
  67. LPARAM lParam );
  68. protected:
  69. HWND m_hIPaddr;
  70. };
  71. //----------------------------------------------------------------------------
  72. // Macro: MAKEADDR
  73. //
  74. // Given an a, b, c, and d, constructs a network-order DWORD corresponding
  75. // to the IP-address a.b.c.d
  76. //----------------------------------------------------------------------------
  77. #define MAKEADDR(a, b, c, d) \
  78. (((a) & 0xff) | (((b) & 0xff) << 8) | (((c) & 0xff) << 16) | (((d) & 0xff) << 24))
  79. //----------------------------------------------------------------------------
  80. // Macros: INET_NTOA
  81. // INET_ADDR
  82. //
  83. // Generic-text macros for IP-address conversion.
  84. //----------------------------------------------------------------------------
  85. #ifndef UNICODE
  86. #define INET_NTOA(a) inet_ntoa(*(struct in_addr *)&(a))
  87. #define INET_ADDR inet_addr
  88. #else
  89. #define INET_NTOA(a) inet_ntoaw(*(struct in_addr *)&(a))
  90. #define INET_ADDR inet_addrw
  91. #endif
  92. //----------------------------------------------------------------------------
  93. // Macro: INET_CMP
  94. //
  95. // Comparison macro for IP addresses.
  96. //
  97. // This macro compares two IP addresses in network order by
  98. // masking off each pair of octets and doing a subtraction;
  99. // the result of the final subtraction is stored in the third argument
  100. //----------------------------------------------------------------------------
  101. inline int INET_CMP(DWORD a, DWORD b)
  102. {
  103. DWORD t;
  104. return ((t = ((a & 0x000000ff) - (b & 0x000000ff))) ? t :
  105. ((t = ((a & 0x0000ff00) - (b & 0x0000ff00))) ? t :
  106. ((t = ((a & 0x00ff0000) - (b & 0x00ff0000))) ? t :
  107. ((t = (((a>>8) & 0x00ff0000) - ((b>>8) & 0x00ff0000)))))));
  108. }
  109. #endif