电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

随时随刻知道自己的IP


发布日期:2020/12/4
 

随着网络的普及越来越多的人开始过起了网络生涯网站让你目不暇接可是有的网站却专门钻IE的空子当你浏览了它的主页之后注册表就会被禁止还会修改你的其他设置真是害人不浅还有一招更毒的你浏览它的主页后它会下载一个拨号器在你的硬盘拨号器会断开你当前的连接去拨别的号(想一想拨一个长途国际电话一小时多少钱?!)所以我们这些拨号上网的用户需要一个能随时监测自己IP地址的软件当IP发生改变时它会自动的报警;同时它还应该是透明的这样即使运行时总在最前面也不会影响别的窗体

废话不多说了马上开工首先打开Delphi新建一个工程添加一个定时器Timer一个标签Label一个PopupMenu并且为PopupMenu添加一个Exit菜单项下面就是全部的源代码:

unit Unit;

interface

uses

Windows Messages SysUtils Variants Classes Graphics Controls Forms

Dialogs Menus StdCtrls ExtCtrls Winsock; //首先要添加winsock

type

TForm = class(TForm)

Timer: TTimer;

Label: TLabel;

PopupMenu: TPopupMenu;

Exit: TMenuItem;

procedure FormCreate(Sender: TObject);

procedure TimerTimer(Sender: TObject);

procedure LabelMouseMove(Sender: TObject; Shift: TShiftState; X

Y: Integer);

procedure LabelMouseDown(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X Y: Integer);

procedure ExitClick(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form: TForm;

oldxoldy: integer;//添加变量用做移动窗体

oldIp: string;

implementation

{$R *dfm}

//下面就是关键所在了

function LIP : string;

type

TaPInAddr = array [] of PInAddr;

PaPInAddr = ^TaPInAddr;

var

phe : PHostEnt;

pptr : PaPInAddr;

Buffer : array [] of char;

I : Integer;

GInitData : TWSADATA;

begin

WSAStartup($ GInitData);

Result := ;

GetHostName(Buffer SizeOf(Buffer));

phe :=GetHostByName(buffer);

if phe = nil then Exit;

pptr := PaPInAddr(Phe^h_addr_list);

I := ;

while pptr^[I] <> nil do begin

result:=StrPas(inet_ntoa(pptr^[I]^));

Inc(I);

end;

WSACleanup;

end;

procedure TFormFormCreate(Sender: TObject);

begin

with Label do //定义属性

begin

Caption:=;

FontCharset:=ANSI_CHARSET;

FontName:=Arial;

FontSize:=;

FontColor:=clRed;

Align:=alClient;

PopupMenu:=popupmenu;

end;

TimerInterval:=;

TimerEnabled:=true;

LabelCaption:=IP:+LIP; //赋值把Ip赋值给label

oldIp:=LIP;

BorderStyle:=bsNone;

Alphablend:=true; //呵呵这个就是让窗口变透明的办法了

Alphablendvalue:=;

FormStyle:=fsStayOnTop; //让窗体总在最前面

end;

procedure TFormTimerTimer(Sender: TObject);

begin

LabelCaption :=IP:+LIP;

if oldip <> LIP then

Showmessage(IP地址已经改变请检查!);//提醒用户

end;

procedure TFormLabelMouseMove(Sender: TObject; Shift: TShiftState; X

Y: Integer);

begin

if ssleft in shift then //移动窗体Form

begin

FormLeft:=FormLeft+xoldx;

FormTop:=Formtop+yoldy;

end;

end;

procedure TFormLabelMouseDown(Sender: TObject; Button: TMouseButton;

Shift: TShiftState; X Y: Integer);

begin

oldx:=x;

oldy:=y;

end;

procedure TFormExitClick(Sender: TObject);

begin

Close;

end;

end

程序比较简单我只想再说说透明窗体使窗体透明的方法有好几种其中一种是我用的这种方法比较简单还有一种是调用API函数SetLayeredWindowAttributes它有个参数分别是hwndcrKeybAlpha和dwFlagshwnd指操作的窗口的句柄crKey是指定要透明的颜色值是和第四个参数配合使用的(当第四个参数为LWA_COLORKEY)bAlpha是透明参数当bAlpha为时窗口全透明当值为时为正常的窗口比如要Form透明的话相应的语句是SetLayeredWindowAttributes(formHandle LWA_ALPHA)不过这个API只能在Win下用不支持Win

本程序在Delphi+Win下调试通过

上一篇:进销存管理系统登录功能的实现[3]

下一篇:进销存管理系统管理主界面的实现[3]