unit Unit2;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;type TForm2 = class(TForm) Button1: TButton; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } FOnTop: Boolean; public { Public declarations } procedure CreateParams(var Params: TCreateParams); override; end;var Form2: TForm2;implementation{$R *.dfm}procedure TForm2.CreateParams(var Params: TCreateParams);begin inherited CreateParams(Params); with params do begin ExStyle := WS_EX_TOOLWINDOW; WndParent := GetDesktopWindow; end;end;procedure TForm2.FormCreate(Sender: TObject);begin FOnTop := False;end;procedure TForm2.Button1Click(Sender: TObject);begin if FOnTop then begin //取消置顶 SetWindowPos(Self.Handle,HWND_NOTOPMOST,Left,Top,Width,Height,0); FOnTop := False; end else begin //置顶 FOnTop := True; SetWindowPos(Self.Handle,HWND_TOPMOST,Left,Top,Width,Height,0); end;end;