弹出信息框
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFloatWnd = class(TForm)
private
procedure WMActivate(var Message: TWMActivate); message WM_ACTIV
ATE;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
public
constructor CreateEx(AOwner: TComponent; CFrame: TWinControlClass);
procedure ShowAt(X, Y: Integer);
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure WMActivate(var Message: TWMActivate); message WM_ACTIV
ATE;
end;
var
Form1: TForm1;
implementation
uses
Unit2;
{$R *.dfm}
{ TFloatWnd }
constructor TFloatWnd.CreateEx(AOwner: TComponent; CFrame: TWinControlClass);
begin
inherited CreateNew(AOwner);
AutoSize := True;
FormStyle := fsStayOnTop;
BorderStyle := bsToolWindow;
with CFrame.Create(self) do
Parent := Self;
OnClose := FormClose;
end;
procedure TFloatWnd.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
procedure TFloatWnd.ShowAt(X, Y: Integer); begin
Left := X;
Top := Y;
Show;
end;
procedure TFloatWnd.WMActivate(var Message: TWMActivate); var
i: Integer;
begin
for i := 0 to Screen.FormCount - 1 do
if Screen.Forms[i].Handle <> Handle then
SendMessage(Screen.Forms[i].Handle, WM_NCACTIVATE,
Ord(Message.Active <> WA_INACTIVE), 0); end;
procedure TForm1.Button1Click(Sender: TObject); var
FloatWnd: TFloatWnd;
begin
FloatWnd := TFloatWnd.CreateEx(Self, TFrame2);
FloatWnd.ShowAt(Left + 10, Top + 20); end;
procedure TForm1.WMActivate(var Message: TWMActivate); var
i: Integer;
begin
for i := 0 to Screen.FormCount - 1 do
if Screen.Forms[i].Handle <> Handle then
SendMessage(Screen.Forms[i].Handle, WM_NCACTIVATE,
Ord(Message.Active <> WA_INACTIVE), 0); end;
end.