procedure TIPEdit.CreateParams(var Params: TCreateParams);
begin
InitCommonControl(ICC_INTERNET_CLASSES);
inherited CreateParams(Params);
CreateSubClass(Params, WC_IPADDRESS);
with Params do
begin
Style := WS_VISIBLE or WS_BORDER or WS_CHILD;
if NewStyleControls and Ctl3D then
begin
Style := Style and (not WS_BORDER);
ExStyle := ExStyle or WS_EX_CLIENTEDGE;
end;
end;
end;
procedure TIPEdit.CNNotify(var Message: TWMNotify);
begin
with Message.NMHdr^ do
case Code of
IPN_FIELDCHANGED :
begin
FActiveField := PNMIPAddress(Message.NMHdr)^.iField;
if Assigned(OnIpFieldChange) then
with PNMIPAddress(Message.NMHdr)^ do
begin
OnIPFieldChange(Self, iField, iValue);
end;
end;
end;
end;
procedure TIPEdit.CNCommand(var Message: TWMCommand);
begin
if (Message.NotifyCode = EN_CHANGE) then
begin
Perform(IPM_GETADDRESS, 0, LParam(@FIPAddress));
if Assigned(OnIpChange) then OnIPChange(Self, IPAddress);
end;
end;
function TIPEdit.IP2String(const Value: Cardinal): String;
var ia: TInAddr;
pC: PChar;
begin
ia.S_addr := ntohl(Value);
pC := inet_ntoa(ia);
SetLength(Result, StrLen(pC));
StrCopy(PChar(Result), pC);
end;
function TIPEdit.String2IP(const Value: String): Cardinal;
begin
Result := htonl(inet_addr(PChar(Value)));
end;
function TIPEdit.GetIPAddress: String;
begin
Result := IP2String(FIPAddress);
end;
function TIPEdit.GetEmpty: Boolean;
begin
Result := Perform(IPM_ISBLANK, 0, 0) <> 0;
end;
procedure TIPEdit.Clear;
begin
Perform(IPM_CLEARADDRESS, 0, 0);
end;
procedure TIPEdit.SetActiveField(Value: Byte);
begin
if (Value < 4) then
begin
Perform(IPM_SETFOCUS, WParam(Value), 0);
FActiveField := Value;
end;
end;
function TIPEdit.AdjustHeight: Integer;
var
DC: HDC;
oldFont: HFont;
I: Integer;
Metrics: TTextMetric;
begin
DC := GetDC(Handle);
try
oldFont := SelectObject(DC, Font.Handle);
GetTextMetrics(DC, Metrics);
SelectObject(DC, oldFont);
finally
ReleaseDC(Handle, DC);
end;
if NewStyleControls then
begin
if Ctl3D then I := 8 else I := 6;
I := GetSystemMetrics(SM_CYBORDER) * I;
end else
begin
I := Metrics.tmHeight;
I := I div 4 + GetSystemMetrics(SM_CYBORDER) * 4;
end;
Result := Metrics.tmHeight + I;
end;