我想让主窗体,永远置于最前面,应怎样实现?
setwindowpos()这个函数好像不能永远置于前面?
5 个解决方案
#1
类似网络蚂蚁,FlashGet的悬浮窗体 不被win+m键全部最小化
源码:
procedure CreateParams(var Params:TCreateParams);override;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CreateParams(var Params:TCreateParams);
begin
inherited CreateParams(Params);
//去掉窗口标题区
Params.Style:=Params.Style and WS_CAPTION;
Params.Style:=Params.Style or WS_POPUP;
//设为总在最上面
Params.ExStyle:=Params.ExStyle or WS_EX_TOPMOST;
//设Windows Owner为Desktop Window,连messagebox都跑到他后面!!
Params.WndParent:=GetDesktopWindow();
end
源码:
procedure TForm1.FormCreate(Sender: TObject);
begin
with Application do
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) and
not WS_EX_APPWINDOW or WS_EX_TOOLWINDOW);
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
end;
源码:
Public
procedure Createparams(Var Params:TCreateParams);override;
...
procedure TFormDrop.Createparams(var Params:TCreateParams);
begin
Inherited CreateParams(Params);
With Params do
begin
EXStyle:=ExStyle or WS_EX_TOPMOST OR WS_EX_ACCEPTFILES or WS_DLGFRAME
wndParnet:=GetDesktopWindow; //关键一行,用SetParent都不行!!
end;
end;
源码:
procedure SetFormOnTop(Form: TForm; const bFlag: Boolean);
begin
if bFlag then
SetWindowPos(Form.handle, HWND_TOPMOST, 0, 0, 0, 0, swp_nomove or swp_nosize)
else
SetWindowPos(Form.handle, HWND_NOTOPMOST, 0, 0, 0, 0, swp_nomove or swp_nosize);
end;
源码:
procedure CreateParams(var Params:TCreateParams);override;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CreateParams(var Params:TCreateParams);
begin
inherited CreateParams(Params);
//去掉窗口标题区
Params.Style:=Params.Style and WS_CAPTION;
Params.Style:=Params.Style or WS_POPUP;
//设为总在最上面
Params.ExStyle:=Params.ExStyle or WS_EX_TOPMOST;
//设Windows Owner为Desktop Window,连messagebox都跑到他后面!!
Params.WndParent:=GetDesktopWindow();
end
源码:
procedure TForm1.FormCreate(Sender: TObject);
begin
with Application do
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) and
not WS_EX_APPWINDOW or WS_EX_TOOLWINDOW);
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
end;
源码:
Public
procedure Createparams(Var Params:TCreateParams);override;
...
procedure TFormDrop.Createparams(var Params:TCreateParams);
begin
Inherited CreateParams(Params);
With Params do
begin
EXStyle:=ExStyle or WS_EX_TOPMOST OR WS_EX_ACCEPTFILES or WS_DLGFRAME
wndParnet:=GetDesktopWindow; //关键一行,用SetParent都不行!!
end;
end;
源码:
procedure SetFormOnTop(Form: TForm; const bFlag: Boolean);
begin
if bFlag then
SetWindowPos(Form.handle, HWND_TOPMOST, 0, 0, 0, 0, swp_nomove or swp_nosize)
else
SetWindowPos(Form.handle, HWND_NOTOPMOST, 0, 0, 0, 0, swp_nomove or swp_nosize);
end;
#2
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
#3
form1.FormStyle:=fsStayOnTop;
#4
同意 jackie168(花好月圓)的意见
#5
form1.FormStyle:=fsStayOnTop;
#1
类似网络蚂蚁,FlashGet的悬浮窗体 不被win+m键全部最小化
源码:
procedure CreateParams(var Params:TCreateParams);override;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CreateParams(var Params:TCreateParams);
begin
inherited CreateParams(Params);
//去掉窗口标题区
Params.Style:=Params.Style and WS_CAPTION;
Params.Style:=Params.Style or WS_POPUP;
//设为总在最上面
Params.ExStyle:=Params.ExStyle or WS_EX_TOPMOST;
//设Windows Owner为Desktop Window,连messagebox都跑到他后面!!
Params.WndParent:=GetDesktopWindow();
end
源码:
procedure TForm1.FormCreate(Sender: TObject);
begin
with Application do
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) and
not WS_EX_APPWINDOW or WS_EX_TOOLWINDOW);
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
end;
源码:
Public
procedure Createparams(Var Params:TCreateParams);override;
...
procedure TFormDrop.Createparams(var Params:TCreateParams);
begin
Inherited CreateParams(Params);
With Params do
begin
EXStyle:=ExStyle or WS_EX_TOPMOST OR WS_EX_ACCEPTFILES or WS_DLGFRAME
wndParnet:=GetDesktopWindow; //关键一行,用SetParent都不行!!
end;
end;
源码:
procedure SetFormOnTop(Form: TForm; const bFlag: Boolean);
begin
if bFlag then
SetWindowPos(Form.handle, HWND_TOPMOST, 0, 0, 0, 0, swp_nomove or swp_nosize)
else
SetWindowPos(Form.handle, HWND_NOTOPMOST, 0, 0, 0, 0, swp_nomove or swp_nosize);
end;
源码:
procedure CreateParams(var Params:TCreateParams);override;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.CreateParams(var Params:TCreateParams);
begin
inherited CreateParams(Params);
//去掉窗口标题区
Params.Style:=Params.Style and WS_CAPTION;
Params.Style:=Params.Style or WS_POPUP;
//设为总在最上面
Params.ExStyle:=Params.ExStyle or WS_EX_TOPMOST;
//设Windows Owner为Desktop Window,连messagebox都跑到他后面!!
Params.WndParent:=GetDesktopWindow();
end
源码:
procedure TForm1.FormCreate(Sender: TObject);
begin
with Application do
SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) and
not WS_EX_APPWINDOW or WS_EX_TOOLWINDOW);
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
end;
源码:
Public
procedure Createparams(Var Params:TCreateParams);override;
...
procedure TFormDrop.Createparams(var Params:TCreateParams);
begin
Inherited CreateParams(Params);
With Params do
begin
EXStyle:=ExStyle or WS_EX_TOPMOST OR WS_EX_ACCEPTFILES or WS_DLGFRAME
wndParnet:=GetDesktopWindow; //关键一行,用SetParent都不行!!
end;
end;
源码:
procedure SetFormOnTop(Form: TForm; const bFlag: Boolean);
begin
if bFlag then
SetWindowPos(Form.handle, HWND_TOPMOST, 0, 0, 0, 0, swp_nomove or swp_nosize)
else
SetWindowPos(Form.handle, HWND_NOTOPMOST, 0, 0, 0, 0, swp_nomove or swp_nosize);
end;
#2
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE);
#3
form1.FormStyle:=fsStayOnTop;
#4
同意 jackie168(花好月圓)的意见
#5
form1.FormStyle:=fsStayOnTop;