unit IpInput;
interface
uses
Windows,Dialogs,SysUtils,Classes,Graphics,Forms,Controls,StdCtrls,Buttons,ExtCtrls,
ComCtrls,Commctrl;
type
TInputIpFrm = class(TForm)
SpdBfdftnCancle: TLabel;
SpdBtnOK: TSpeedButton;
SpdBtnCancle: TSpeedButton;
procedure FormShow(Sender: TObject);
procedure SpdBtnOKClick(Sender: TObject);
procedure SpdBtnCancleClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
ipEdit:HWND;
m_CommunicationIP:String;
ipAddress:integer;
procedure GetIPNum(strIniIP:String;out nFirst,nSecond,nThird,nForth:integer);
end;
var
InputIpFrm: TInputIpFrm;
implementation
{$R *.dfm}
procedure TInputIpFrm.GetIPNum(strIniIP:String;out nFirst,nSecond,nThird,nForth:integer);
var
str,strNum,strTemp:String;
begin
str:='.';
try
strTemp:=strPos(PChar(strIniIP),PChar(str));
strNum:=Copy(strIniIP,1,Length(strIniIP) - Length(strTemp));
nFirst:=StrToInt(strNum);
strIniIP:=Copy(strTemp,2, Length(strTemp));
strTemp:=strPos(PChar(strIniIP),PChar(str));
strNum:=Copy(strIniIP,1,Length(strIniIP) - Length(strTemp));
nSecond:=StrToInt(strNum);
strIniIP:=Copy(strTemp,2, Length(strTemp));
strTemp:=strPos(PChar(strIniIP),PChar(str));
strNum:=Copy(strIniIP,1,Length(strIniIP) - Length(strTemp));
nThird:=StrToInt(strNum);
strIniIP:=Copy(strTemp,2, Length(strTemp));
strTemp:=strPos(PChar(strIniIP),PChar(str));
strNum:=Copy(strIniIP,1,Length(strIniIP) - Length(strTemp));
nForth:=StrToInt(strNum);
except
nFirst:=192;
nSecond:=168;
nThird:=0;
nForth:=198;
showmessage('');
end;
end;
procedure TInputIpFrm.FormShow(Sender: TObject);
var
nFirst,nSecond,nThird,nForth:integer;
begin
GetIPNum(m_CommunicationIP, nFirst, nSecond, nThird, nForth);
ipAddress:=MAKEIPADDRESS(nFirst,nSecond,nThird,nForth);//初始化 IP地址
SendMessage(ipEdit,IPM_SETADDRESS,0,ipAddress);//show the current address
SendMessage(ipEdit,IPM_SETFOCUS,0,0); //select the first field
{ }
end;
procedure TInputIpFrm.SpdBtnOKClick(Sender: TObject);
begin
SendMessage(ipEdit,IPM_GETADDRESS,0,longint(@ipAddress));
if ipAddress = 0 then
begin
beep;
SendMessage(ipEdit,IPM_SETFOCUS,0,0);//select the first field
Application.MessageBox('IP地址非法!','警告',mb_OK + MB_ICONWARNING);
modalResult:=mrNone;
end
else
begin
m_CommunicationIP:=IntToStr(FIRST_IPADDRESS(ipAddress))+'.'
+IntToStr(SECOND_IPADDRESS(ipAddress))+'.'
+IntToStr(THIRD_IPADDRESS(ipAddress))+'.'
+IntToStr(FOURTH_IPADDRESS(ipAddress));
{ }
self.Close;
end;
end;
procedure TInputIpFrm.SpdBtnCancleClick(Sender: TObject);
begin
self.Close;
end;
procedure TInputIpFrm.FormDestroy(Sender: TObject);
begin
InputIpFrm:=nil;
end;
procedure TInputIpFrm.FormCreate(Sender: TObject);
begin
InitCommonControl(ICC_INTERNET_CLASSES);
ipEdit:=CreateWindow(WC_IPADDRESS,nil,WS_CHILD or WS_VISIBLE,
65,20,160,25,self.Handle,0,hInstance,nil);
end;
end.