1、在网看到的一段类似QQ的代码,好象是这里的一个版主(对不住没有记住)写的,因为本人是菜鸟刚开始学习,请高手给加上解释(有*号的行),特别是其中的许多变量等代表的意思,越详细分越多。
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
FAnchors: TAnchors;//*************
procedure WMMOVING(var Msg: TMessage); message WM_MOVING;//******
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}uses Math;procedure TForm1.WMMOVING(var Msg: TMessage);
begin
inherited;//**********
with PRect(Msg.LParam)^ do begin//*********
Left := Min(Max(0, Left), Screen.Width - Width);//**********
Top := Min(Max(0, Top), Screen.Height - Height);
Right := Min(Max(Width, Right), Screen.Width);
Bottom := Min(Max(Height, Bottom), Screen.Height);
FAnchors := [];//*******
if Left = 0 then Include(FAnchors, akLeft);//***
if Right = Screen.Width then Include(FAnchors, akRight);
if Top = 0 then Include(FAnchors, akTop);
if Bottom = Screen.Height then Include(FAnchors, akBottom);
Timer1.Enabled := FAnchors <> [];//****
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled := False;
Timer1.Interval := 200;
FormStyle := fsStayOnTop;
end;procedure TForm1.Timer1Timer(Sender: TObject);
const
cOffset = 2;
var
vHandle: THandle;//****
begin
vHandle := WindowFromPoint(Mouse.CursorPos);//***
while (vHandle <> 0) and (vHandle <> Handle) do //****
vHandle := GetParent(vHandle);//***
if vHandle = Handle then begin
if akLeft in FAnchors then Left := 0;//***
if akTop in FAnchors then Top := 0;
if akRight in FAnchors then Left := Screen.Width - Width;
if akBottom in FAnchors then Top := Screen.Height - Height;
end else begin
if akLeft in FAnchors then Left := -Width + cOffset;
if akTop in FAnchors then Top := -Height + cOffset;
if akRight in FAnchors then Left := Screen.Width - cOffset;
if akBottom in FAnchors then Top := Screen.Height - cOffset;
end;
end;end.2、将这段代码改成:程度开始的时候窗口就自动停留在屏幕上端,和屏幕等宽,有自动隐藏功能。
留言后请给:DJC@GENERSOFT.COM发消息,提醒我给你加分。谢谢
MSN:DONG6785@HOTMAIL.COM
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
FAnchors: TAnchors;//*************
procedure WMMOVING(var Msg: TMessage); message WM_MOVING;//******
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}uses Math;procedure TForm1.WMMOVING(var Msg: TMessage);
begin
inherited;//**********
with PRect(Msg.LParam)^ do begin//*********
Left := Min(Max(0, Left), Screen.Width - Width);//**********
Top := Min(Max(0, Top), Screen.Height - Height);
Right := Min(Max(Width, Right), Screen.Width);
Bottom := Min(Max(Height, Bottom), Screen.Height);
FAnchors := [];//*******
if Left = 0 then Include(FAnchors, akLeft);//***
if Right = Screen.Width then Include(FAnchors, akRight);
if Top = 0 then Include(FAnchors, akTop);
if Bottom = Screen.Height then Include(FAnchors, akBottom);
Timer1.Enabled := FAnchors <> [];//****
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled := False;
Timer1.Interval := 200;
FormStyle := fsStayOnTop;
end;procedure TForm1.Timer1Timer(Sender: TObject);
const
cOffset = 2;
var
vHandle: THandle;//****
begin
vHandle := WindowFromPoint(Mouse.CursorPos);//***
while (vHandle <> 0) and (vHandle <> Handle) do //****
vHandle := GetParent(vHandle);//***
if vHandle = Handle then begin
if akLeft in FAnchors then Left := 0;//***
if akTop in FAnchors then Top := 0;
if akRight in FAnchors then Left := Screen.Width - Width;
if akBottom in FAnchors then Top := Screen.Height - Height;
end else begin
if akLeft in FAnchors then Left := -Width + cOffset;
if akTop in FAnchors then Top := -Height + cOffset;
if akRight in FAnchors then Left := Screen.Width - cOffset;
if akBottom in FAnchors then Top := Screen.Height - cOffset;
end;
end;end.2、将这段代码改成:程度开始的时候窗口就自动停留在屏幕上端,和屏幕等宽,有自动隐藏功能。
留言后请给:DJC@GENERSOFT.COM发消息,提醒我给你加分。谢谢
MSN:DONG6785@HOTMAIL.COM
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
FAnchors: TAnchors;//*************这里是定义一个窗体类成员
procedure WMMOVING(var Msg: TMessage); message WM_MOVING;//****** 捕捉移动消息
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}uses Math;procedure TForm1.WMMOVING(var Msg: TMessage);
begin
inherited;//********** 继承原来的事件
with PRect(Msg.LParam)^ do begin//*********这句PRECT不知道
Left := Min(Max(0, Left), Screen.Width - Width);//**********计算窗体LEFT,不让窗体位于屏幕左边之外,
Top := Min(Max(0, Top), Screen.Height - Height);
Right := Min(Max(Width, Right), Screen.Width);
Bottom := Min(Max(Height, Bottom), Screen.Height);
FAnchors := [];//*******等于空集合
if Left = 0 then Include(FAnchors, akLeft);//***
if Right = Screen.Width then Include(FAnchors, akRight);
if Top = 0 then Include(FAnchors, akTop);
if Bottom = Screen.Height then Include(FAnchors, akBottom);
Timer1.Enabled := FAnchors <> [];//****集合不为空时TIMER1开始记时
end;
end;procedure TForm1.FormCreate(Sender: TObject);
begin
Timer1.Enabled := False;
Timer1.Interval := 200;
FormStyle := fsStayOnTop;
end;procedure TForm1.Timer1Timer(Sender: TObject);
const
cOffset = 2;
var
vHandle: THandle;//****定义句柄
begin
vHandle := WindowFromPoint(Mouse.CursorPos);//***取鼠标所在的窗口句柄
while (vHandle <> 0) and (vHandle <> Handle) do //**** 取得窗口成功
vHandle := GetParent(vHandle);//*** 取父窗体
if vHandle = Handle then begin
if akLeft in FAnchors then Left := 0;//***akLeft是集合成员时,LEFT=0
if akTop in FAnchors then Top := 0;
if akRight in FAnchors then Left := Screen.Width - Width;
if akBottom in FAnchors then Top := Screen.Height - Height;
end else begin
if akLeft in FAnchors then Left := -Width + cOffset;
if akTop in FAnchors then Top := -Height + cOffset;
if akRight in FAnchors then Left := Screen.Width - cOffset;
if akBottom in FAnchors then Top := Screen.Height - cOffset;
end;
end;end.