选择显示字体大小

delphi实现随时随刻知道自己的ip

随时随刻知道自己的ip

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

  废话不多说了,马上开工。首先打开delphi新建一个工程,添加一个定时器timer1、一个标签label1、一个popupmenu1,并且为popupmenu1添加一个exit菜单项。下面就是全部的源代码:

unit unit1;
interface
uses
windows, messages, sysutils, variants, classes, graphics, controls, forms,
dialogs, menus, stdctrls, extctrls, winsock; //首先要添加winsock
type
tform1 = class(tform)
timer1: ttimer;
label1: tlabel;
popupmenu1: tpopupmenu;
exit: tmenuitem;
procedure formcreate(sender: tobject);
procedure timer1timer(sender: tobject);
procedure label1mousemove(sender: tobject; shift: tshiftstate; x,
y: integer);
procedure label1mousedown(sender: tobject; button: tmousebutton;
shift: tshiftstate; x, y: integer);
procedure exitclick(sender: tobject);
private
{ private declarations }
public
{ public declarations }
end;

var
form1: tform1;
oldx,oldy: integer;//添加变量,用做移动窗体
oldip: string;
implementation
{$r *.dfm}
//下面就是关键所在了
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(.net_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;

timer1.interval:=1000;
timer1.enabled:=true;
label1.caption:='ip:'+lip; //赋值,把ip赋值给label1
oldip:=lip;
borderstyle:=bsnone;
alphablend:=true; //呵呵,这个就是让窗口变透明的办法了
alphablendvalue:=100;
formstyle:=fsstayontop; //让窗体总在最前面
end;

procedure tform1.timer1timer(sender: tobject);
begin
label1.caption :='ip:'+lip;
if oldip <> lip then
showmessage('ip地址已经改变,请检查!');//提醒用户
end;

procedure tform1.label1mousemove(sender: tobject; shift: tshiftstate; x,
y: integer);
begin
if ssleft in shift then //移动窗体form1
begin
form1.left:=form1.left+x-oldx;
form1.top:=form1.top+y-oldy;
end;
end;

procedure tform1.label1mousedown(sender: tobject; button: tmousebutton;
shift: tshiftstate; x, y: integer);
begin
oldx:=x;
oldy:=y;
end;

procedure tform1.exitclick(sender: tobject);
begin
close;
end;
end.


  程序比较简单,我只想再说说透明窗体。使窗体透明的方法有好几种,其中一种是我用的这种,方法比较简单。还有一种是调用api函数setlayeredwindowattributes,它有4个参数,分别是hwnd、crkey、balpha和dwflags。hwnd指操作的窗口的句柄,crkey是指定要透明的颜色值,是和第四个参数配合使用的(当第四个参数为lwa_colorkey),balpha是透明参数,当balpha为0时窗口全透明,当值为255时为正常的窗口。比如要form1透明的话,相应的语句是setlayeredwindowattributes(form1.handle, 0, 100, lwa_alpha),不过这个api只能在win2000下用,不支持win98。

本程序在delphi6.0+win2000下调试通过。
源程序下载地址: http://www.cfan.net.cn/qikan/cxg/0203sss.zip


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons