庞大资源库的计算机教程网站!
设为首页
加入收藏
总编信箱
投稿或申请专栏请先 [登 陆]
首页 操作系统 程序设计 图形图像 媒体动画 机械电子 WEB开发 数 据 库 办公系列 路由技术 网络原理 网络应用
认证考试 安全技术
首页>程序设计>Delphi语言>实例分析>正文
资料搜索
Google搜索
Google
返回上级列表

推荐文章

快速保存网页中所有图片的方法
Windows中让光驱巧妙“隐身”技
防范非法用户入侵Win 2000/XP系
两款比较典型的ASP木马防范方法
有关表格边框的css语法整理
Windows XP中可以被禁用的服务
SQL Server导出导入数据方法
Javascript所有对象的属性的获
网页(HTML)中的特殊字符
与篮球共舞,尽显模式本色
QQ病毒的手工清除方法
Photoshop为极品美女打造性感睫
天衣无缝:IIS与PHP水火也相容
SQL Server存储过程编写和优化

磁性”窗口新篇

 作者:本站收集   日期:2005-3-14
字号选择〖 〗/ 双击滚屏 单击停止   
file://创建军于2004.6.15
file://作者:透明墨豆(昵称)
file://QQ:33125083
file://说明:本程序是从《“磁性”窗口》--- wujian2的文章修改的,原因是原文章不全和
file://有错误,并且觉得有不完善的地方,如不能分辨出两窗口是否在同一个区域,不能
file://停靠屏幕边缘等。但此程序还有不足之处,如窗口Form不能跟随Winamp的窗口一起移动
file://希望大家多多指教,这是我第一篇文章。
file://详细的说明请看原文

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Magnetize(var nl,nt:integer);
procedure Edgetize(var nL,nT:integer);//定义接近屏幕边缘时的过程
private
{ Private declarations }
public
{ Public declarations }
end;

const MagneticForce:integer=20;

var
Form1: TForm1; file://把主窗口Form1适当改小些,并将BorderStyle设为bsNone
LastX,LastY:integer;
WinampRect:TRect;
HWND_Winamp:HWND;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
Close; file://关闭窗口
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
const classname='Winamp v1.x'; file://如果改成ClassName=‘TAppBuilder’,
// 你就会发现连Delphi也有引力啦
begin
LastX:=X; file://保存指针坐标
LastY:=Y;
HWND_Winamp:=FindWindow(classname,nil); file://获取Winamp的窗口句柄
if HWND_Winamp>0 then
getwindowrect(HWND_Winamp,WinampRect); file://获取Winamp窗口的区域
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var nLeft,nTop:integer;
begin
if HiWord(GetAsyncKeyState(VK_LBUTTON)) >0 then
begin
nLeft:=Left+X-LastX; file://计算窗口位置
nTop:=Top+Y-LastY;
if HWND_Winamp>0 then file://这里进行了少许修改
Magnetize(nLeft,nTop) file://当窗口不存在时也可以进行屏幕边缘停靠
else Edgetize(nLeft,nTop);
SetBounds(nLeft,nTop,width,height);//设定窗口位置
end;
end;
file://=============以上部分为抄录别人,下面为自已之写的======================/////
procedure TForm1.Magnetize(var nL,nT:integer);
var
B_LR,B_TB,V_L,V_R,V_T,V_B:boolean; file://定义中间变量,B_LR,B_TB用来分别标识窗口
file://是否在要靠近的区域内,V_L,V_R,V_T,V_B分别用来标识窗口是否靠近
nR,nB,tL,tR,tT,tB:integer;//nR,nB分别用来保存Form1的右边位置和下边位置
begin
nR:=nL+Width; file://计算Form1的Right,Bottom
nB:=nT+Height;
file://判断窗口是否在目标窗口的范围内(不知大家有没有更简单的算法呢)
if Width<=(WinampRect.Right-WinampRect.Left) then file://如果Form的宽少于目标Form
B_LR:=((nL>=WinampRect.Left)and(nL<=WinampRect.Right))or((nR>=WinampRect.Left)
and(nR<=WinampRect.Right))
else B_LR:=((nL<=WinampRect.Right)and(nR>=WinampRect.Right))or((nL<=WinampRect.Left)
and(nR>=WinampRect.Left));
if Height<=(WinampRect.Bottom-WinampRect.Top) then file://如果Form的高少于目标Form
B_TB:=((nT>=WinampRect.Top)and(nT<=WinampRect.Bottom))or((nB>=WinampRect.Top)
and(nB<=WinampRect.Bottom))
else B_TB:=((nT<=WinampRect.Top)and(nB>=WinampRect.Top))or((nT<=WinampRect.Bottom)
and(nB>=WinampRect.Bottom));
//判断两窗口否足够接近
//计算边框的距离绝对值
tL:=abs(WinampRect.Right-nL);
tR:=abs(WinampRect.Left-nR);
tT:=abs(WinampRect.Bottom-nT);
tB:=abs(WinampRect.Top-nB);
V_L:=tL<MagneticForce;
V_R:=tR<MagneticForce;
V_T:=tT<MagneticForce;
V_B:=tB<MagneticForce;
//如果足够接近就修改坐标
if B_TB then
if V_L then
nL:=WinampRect.Right
else if V_R then nL:=WinampRect.Left-Width;
if B_LR then
if V_T then nT:=WinampRect.Bottom
else if V_B then nT:=WinampRect.Top-Height;
//接近屏幕边缘时实现停靠
if (not V_L)and(not V_R)and(not V_T)and(not V_B) then Edgetize(nL,nT);
end;
//定义接近屏幕边缘时的过程
procedure TForm1.Edgetize(var nL,nT:integer);
var nB,nR:integer;
begin
nR:=nL+Width; file://计算Form1的Right,Bottom
nB:=nT+Height; file://Screen是用来获取屏幕分辨率的
if nT<=MagneticForce then nT:=0
else if abs(nB-Screen.Height)<=MagneticForce then nT:=Screen.Height-Height;
if nL<=MagneticForce then nL:=0
else if abs(nR-Screen.Width)<=MagneticForce then nL:=Screen.Width-Width;
end;

end.

上一篇:COM程序编写入门(一)    下一篇:Delphi编写后台监控软件  
[发送给好友]  [关闭窗口]  [返回顶部]   转载请注明来源:www.it00.com   
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
责任编辑: 原点 投稿作者: 本站收集
信息来源: 网络 录入时间: 2005-3-14
关于我们 - 广告服务 - 版权申明 - 网站地图 - 联系方式 - 总编信箱 - 会员投稿