var
Form1: TForm1;
oldx,oldy: integer;//添加變量,用做移動(dòng)窗體
oldIp: string;
implementation
{$R *.dfm}
//下面就是關(guān)鍵所在了
function LIP : string;
type
TaPInAddr = array [0..10] of PInAddr;
PaPInAddr = ^TaPInAddr;
var
phe : PHostEnt;
pptr : PaPInAddr;
Buffer : array [0..63] of char;
I : Integer;
GInitData : TWSADATA;
begin
WSAStartup($101, GInitData);
Result := '';
GetHostName(Buffer, SizeOf(Buffer));
phe :=GetHostByName(buffer);
if phe = nil then Exit;
pptr := PaPInAddr(Phe^.h_addr_list);
I := 0;
while pptr^[I] <> nil do begin
result:=StrPas(inet_ntoa(pptr^[I]^));
Inc(I);
end;
WSACleanup;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with Label1 do //定義屬性
begin
Caption:='';
Font.Charset:=ANSI_CHARSET;
Font.Name:='Arial';
Font.Size:=10;
Font.Color:=clRed;
Align:=alClient;
PopupMenu:=popupmenu1;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label1.Caption :='IP:'+LIP;
if oldip <> LIP then
Showmessage('IP地址已經(jīng)改變,請檢查!');//提醒用戶(hù)
end;
procedure TForm1.Label1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if ssleft in shift then //移動(dòng)窗體Form1
begin
Form1.Left:=Form1.Left+x-oldx;
Form1.Top:=Form1.top+y-oldy;
end;
end;