我提问过这个问题,上次没有测试完全,只拿了一个空白Form测试了一下,但是现在发现BUG了:
就是当鼠标在窗体空白处的时候 没有BUG,但是当把鼠标焦点放在某个控件上,比如button,Edit上面的时候,窗体会自动隐藏,而实际上想要的效果应该是不隐藏,因为这些控件也是窗体上的,比如把鼠标放在QQ上某个按钮上,窗体就不会隐藏。应该怎么解决?谢谢
那个贴子地址是
http://topic.csdn.net/u/20080616/21/e5d5adcf-d2be-43c4-923f-744ea740bd97.html
附上代码
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
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, Types; { TForm1 }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;
Animate_Steps = 20; //可调
var
iLeft, iTop, i: Integer;
dx, dy, dLeft, dTop: Double;
begin
iTop := Top;
iLeft := Left;
if WindowFromPoint(Mouse.CursorPos) = Handle then
begin
if akLeft in FAnchors then
iLeft := 0;
if akTop in FAnchors then
iTop := 0;
if akRight in FAnchors then
iLeft := Screen.Width - Width;
if akBottom in FAnchors then
iTop := Screen.Height - Height;
end
else
begin
if akLeft in FAnchors then
iLeft := -Width + cOffset;
if akTop in FAnchors then
iTop := -Height + cOffset;
if akRight in FAnchors then
iLeft := Screen.Width - cOffset;
if akBottom in FAnchors then
iTop := Screen.Height - cOffset;
end; if (iTop <> Top) or (iLeft <> Left) then
begin
dx := (iLeft - Left) / Animate_Steps;
dy := (iTop - Top) / Animate_Steps;
dTop := Top;
dLeft := Left;
for i := 1 to Animate_Steps - 1 do
begin
dLeft := dLeft + dx;
dTop := dTop + dy;
Top := Trunc(dTop);
Left := Trunc(dLeft);
Self.Update;
Sleep(10);//睡一下zzz
end;
Top := iTop;
Left := iLeft;
end;
end;end.
就是当鼠标在窗体空白处的时候 没有BUG,但是当把鼠标焦点放在某个控件上,比如button,Edit上面的时候,窗体会自动隐藏,而实际上想要的效果应该是不隐藏,因为这些控件也是窗体上的,比如把鼠标放在QQ上某个按钮上,窗体就不会隐藏。应该怎么解决?谢谢
那个贴子地址是
http://topic.csdn.net/u/20080616/21/e5d5adcf-d2be-43c4-923f-744ea740bd97.html
附上代码
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
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, Types; { TForm1 }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;
Animate_Steps = 20; //可调
var
iLeft, iTop, i: Integer;
dx, dy, dLeft, dTop: Double;
begin
iTop := Top;
iLeft := Left;
if WindowFromPoint(Mouse.CursorPos) = Handle then
begin
if akLeft in FAnchors then
iLeft := 0;
if akTop in FAnchors then
iTop := 0;
if akRight in FAnchors then
iLeft := Screen.Width - Width;
if akBottom in FAnchors then
iTop := Screen.Height - Height;
end
else
begin
if akLeft in FAnchors then
iLeft := -Width + cOffset;
if akTop in FAnchors then
iTop := -Height + cOffset;
if akRight in FAnchors then
iLeft := Screen.Width - cOffset;
if akBottom in FAnchors then
iTop := Screen.Height - cOffset;
end; if (iTop <> Top) or (iLeft <> Left) then
begin
dx := (iLeft - Left) / Animate_Steps;
dy := (iTop - Top) / Animate_Steps;
dTop := Top;
dLeft := Left;
for i := 1 to Animate_Steps - 1 do
begin
dLeft := dLeft + dx;
dTop := dTop + dy;
Top := Trunc(dTop);
Left := Trunc(dLeft);
Self.Update;
Sleep(10);//睡一下zzz
end;
Top := iTop;
Left := iLeft;
end;
end;end.
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;type
TForm1 = class(TForm)
Timer1: TTimer;
Button1: TButton;
Button2: TButton;
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;implementationuses Math, Types;{$R *.dfm}{ TForm1 }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;
Animate_Steps = 20; //可调
var
iLeft, iTop, i: Integer;
dx, dy, dLeft, dTop: Double;
begin
iTop := Top;
iLeft := Left;
if WindowFromPoint(Mouse.CursorPos) = Handle then
begin
if akLeft in FAnchors then
iLeft := 0;
if akTop in FAnchors then
iTop := 0;
if akRight in FAnchors then
iLeft := Screen.Width - Width;
if akBottom in FAnchors then
iTop := Screen.Height - Height;
end
else
begin
if akLeft in FAnchors then
iLeft := -Width + cOffset;
if akTop in FAnchors then
iTop := -Height + cOffset;
if akRight in FAnchors then
iLeft := Screen.Width - cOffset;
if akBottom in FAnchors then
iTop := Screen.Height - cOffset;
end; if (iTop <> Top) or (iLeft <> Left) then
begin
dx := (iLeft - Left) / Animate_Steps;
dy := (iTop - Top) / Animate_Steps;
dTop := Top;
dLeft := Left;
for i := 1 to Animate_Steps - 1 do
begin
dLeft := dLeft + dx;
dTop := dTop + dy;
Top := Trunc(dTop);
Left := Trunc(dLeft);
Self.Update;
Sleep(10);//睡一下zzz
end;
Top := iTop;
Left := iLeft;
end;
end;end.
http://www.ccrun.com/view.asp?id=164
(妖哥的网站)//TAppEvents的OnMinimize事件 最小化隐藏
procedure TFormMain.AppEvents1Minimize(Sender: TObject);
begin
if NewStyleControls then
ShowWindow(Application.Handle, SW_HIDE);
end;
//TRxTrayIcon的DblClick事件 双击显示
procedure TFormMain.RxTrayIcon1DblClick(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_RESTORE);
SetWindowPos(Application.handle,HWND_TOPMOST,0,0,0,0,swp_hidewindow);
end;