//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "code__TGLYIPAddress.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
//-----------------Class TIPRange Implement-------------------------
__fastcall TIPRange::TIPRange(HWND handle,Byte ID)
{
FHigh = 255;
FLow = 0;
FHandle = handle;
FFieldID = ID;
}
//---------------------------------------------------------------------------
void __fastcall TIPRange::SetHandle(HWND handle)
{
FHandle = handle;
}
//---------------------------------------------------------------------------
void __fastcall TIPRange::SetMaxRange(Byte value)
{
if(value!=FHigh)
{
if(value>=FLow)
{
FHigh = value;
SendMessage(FHandle,UM_RANGECHANGEEVENT,FFieldID,1);
}
else
{
High = FHigh;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TIPRange::SetMinRange(Byte value)
{
if(value!=FLow)
{
if(value<=FHigh)
{
FLow = value;
SendMessage(FHandle,UM_RANGECHANGEEVENT,FFieldID,0);
}
else
{
Low = FLow;
}
}
}
//---------------------------------------------------------------------------
// ValidCtrCheck is used to assure that the components created do not have
// any pure virtual functions.
//
static inline void ValidCtrCheck(TGLYIPAddress *)
{
new TGLYIPAddress(NULL);
}
//---------------------------------------------------------------------------
__fastcall TGLYIPAddress::TGLYIPAddress(TComponent* Owner)
: TWinControl(Owner)
{
FOnIPChange = NULL;
FOnIPFieldChange = NULL;
FField0Range = new TIPRange(this->WindowHandle,0);
FField1Range = new TIPRange(this->WindowHandle,1);
FField2Range = new TIPRange(this->WindowHandle,2);
FField3Range = new TIPRange(this->WindowHandle,3);
FMaxIP = "255.255.255.255";
FMinIP = "0.0.0.0";
FDefaultIP = "";
FActiveField = 0;
ParentColor = false;
Width = 175;
Height = 25;
TabStop = true;
OnEnter = NULL;
OnExit = NULL;
}
//---------------------------------------------------------------------------
__fastcall TGLYIPAddress::~TGLYIPAddress()
{
delete FField0Range;
delete FField1Range;
delete FField2Range;
delete FField3Range;
}
//---------------------------------------------------------------------------
void __fastcall TGLYIPAddress::CreateHandle(void)
{
TWinControl::CreateHandle();
FField0Range->SetHandle(Handle);
FField1Range->SetHandle(Handle);
FField2Range->SetHandle(Handle);
FField3Range->SetHandle(Handle);
}
void __fastcall TGLYIPAddress::CreateParams(TCreateParams &Params)
{
InitCommonControl(ICC_INTERNET_CLASSES);
TWinControl::CreateParams(Params);
CreateSubClass(Params, UnicodeString(WC_IPADDRESS).c_str());
}
//---------------------------------------------------------------------------
void __fastcall TGLYIPAddress::CNCommand(TWMCommand &Message) //CN_COMMAND;
{
if((Message.NotifyCode == EN_CHANGE))
{
DWORD maxip = ntohl(inet_addr(AnsiString(FMaxIP).c_str()));
DWORD minip = ntohl(inet_addr(AnsiString(FMinIP).c_str()));
DWORD IPAddress = GetIPAddress();
if( IPAddress>maxip )
{
SendMessage(Handle, IPM_SETADDRESS, 0, maxip);
}
else if(IPAddress<minip)
{
SendMessage(Handle, IPM_SETADDRESS, 0, minip);
}
if(OnIPChange)
{
OnIPChange(this, IPAddress);
}
}
else if(Message.NotifyCode == EN_KILLFOCUS )
{
if(GetEmpty())
{
//SetIPAddress(ntohl(inet_addr(AnsiString(Text).c_str())));
//SetIPAddress(ntohl(inet_addr(AnsiString(DefaultIP).c_str())));
//SendMessage(Handle, IPM_SETADDRESS, 0, IPAddress);
}
else
{
SetIPAddress(GetIPAddress());
}
}
else if(Message.NotifyCode == EN_SETFOCUS )
{
if(GetEmpty()&&DefaultIP.Trim()!="")
{
SetIPAddress(ntohl(inet_addr(AnsiString(DefaultIP).c_str())));
}
}
}
//---------------------------------------------------------------------------
void __fastcall TGLYIPAddress::CNNotify(TWMNotify &Message) //CN_NOTIFY;
{
switch(Message.NMHdr-> code)
{
case IPN_FIELDCHANGED:
{
FActiveField = (PNMIPAddress(Message.NMHdr))-> iField;
if(OnIPFieldChange)
{
OnIPFieldChange(this, (PNMIPAddress(Message.NMHdr))-> iField,
(PNMIPAddress(Message.NMHdr))-> iValue);
}
}
break;
}
}
void __fastcall TGLYIPAddress::RangeChange(TMessage &Message)
{
switch(Message.WParam)
{
case 0:
SetIPRange(Field0Range);
break;
case 1:
SetIPRange(Field1Range);
break;
case 2:
SetIPRange(Field2Range);
break;
case 3:
SetIPRange(Field3Range);
break;
}
}
//---------------------------------------------------------------------------
DWORD __fastcall TGLYIPAddress::GetIPAddress()
{
DWORD IP = 0;
SendMessage(Handle, IPM_GETADDRESS, 0, (LPARAM)&IP);
return IP;
}
//---------------------------------------------------------------------------
void __fastcall TGLYIPAddress::SetIPAddress(DWORD Value)
{
DWORD maxip = ntohl(inet_addr(AnsiString(FMaxIP).c_str()));
DWORD minip = ntohl(inet_addr(AnsiString(FMinIP).c_str()));
if( Value>maxip )
{
SendMessage(Handle, IPM_SETADDRESS, 0, maxip);
}
else if(Value<minip)
{
SendMessage(Handle, IPM_SETADDRESS, 0, minip);
}
else
{
SendMessage(Handle, IPM_SETADDRESS, 0, Value);
}
//FText = UnicodeString(AnsiString(FIRST_IPADDRESS(IPAddress))+"."+AnsiString(SECOND_IPADDRESS(IPAddress))+"."+AnsiString(THIRD_IPADDRESS(IPAddress))+"."+AnsiString(FOURTH_IPADDRESS(IPAddress)));
//FIP = IPAddress;
}
//---------------------------------------------------------------------------
void __fastcall TGLYIPAddress::SetMaxIP(UnicodeString value)
{
DWORD maxip = ntohl(inet_addr(AnsiString(value).c_str()));
DWORD minip = ntohl(inet_addr(AnsiString(FMinIP).c_str()));
if(maxip>=minip)
{
FMaxIP = UnicodeString(FIRST_IPADDRESS(maxip))+".";
FMaxIP += UnicodeString(SECOND_IPADDRESS(maxip))+".";
FMaxIP += UnicodeString(THIRD_IPADDRESS(maxip))+".";
FMaxIP += UnicodeString(FOURTH_IPADDRESS(maxip));
}
else
{
MaxIP = FMaxIP;
}
}
//---------------------------------------------------------------------------
void __fastcall TGLYIPAddress::SetMinIP(UnicodeString value)
{
DWORD maxip = ntohl(inet_addr(AnsiString(FMaxIP).c_str()));
DWORD minip = ntohl(inet_addr(AnsiString(value).c_str()));
if(maxip>=minip)
{
FMinIP = UnicodeString(FIRST_IPADDRESS(minip))+".";
FMinIP += UnicodeString(SECOND_IPADDRESS(minip))+".";
FMinIP += UnicodeString(THIRD_IPADDRESS(minip))+".";
FMinIP += UnicodeString(FOURTH_IPADDRESS(minip));
}
else
{
MinIP = FMinIP;
}
}
//---------------------------------------------------------------------------
void __fastcall TGLYIPAddress::SetIPRange(TIPRange * value)
{
switch(value->FieldID)
{
case 0:
{
SendMessage(Handle,IPM_SETRANGE,0,MAKEIPRANGE(value->Low,
value->High));
break;
}
case 1:
{
SendMessage(Handle,IPM_SETRANGE,1,MAKEIPRANGE(value->Low,
value->High));
break;
}
case 2:
{
SendMessage(Handle,IPM_SETRANGE,2,MAKEIPRANGE(value->Low,
value->High));
break;
}
case 3:
{
SendMessage(Handle,IPM_SETRANGE,3,MAKEIPRANGE(value->Low,
value->High));
break;
}
}
}
//---------------------------------------------------------------------------
bool __fastcall TGLYIPAddress::GetEmpty()
{
return (bool)(SendMessage(Handle, IPM_ISBLANK, 0, 0));
}
//---------------------------------------------------------------------------
void __fastcall TGLYIPAddress::Clear()
{
Send
- 1
- 2
前往页