可以做到
原理:使用API函数SetWindowPos将其余的窗口设为永在顶层窗口。这样,这些附属窗口就会浮在
主窗口之上。
代码:
在Form1上放置六个Button,再在工程里添加六个窗口
//*********************************************************************
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses Unit2, Unit3, Unit4, Unit5, Unit6, Unit7;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
form2.show;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
form3.show;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
form4.show;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
form5.show;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
form6.show;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
form7.show;
end;
end.
//**************************************************
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;
type
TForm2 = class(TForm)
procedure FormShow(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormShow(Sender: TObject);
begin
SetWindowPos(form2.Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE)
end;
end.
//*******************************************************************
其余窗口代码类似于Form2.
这些窗口的FormStyle均为fsNormal
以上代码在Delphi 6 WindowsXP中运行通过。