重載Createparams,改變窗體風格爲<FONT color=#000000>WS_EX_APPWINDOW即可
Unit1.pas文件如下:
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- type
- TForm1 = class(TForm)
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- private
- { Private declarations }
- procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
- public
- { Public declarations }
- procedure CreateParams(var Params: TCreateParams); override;
- end;
- var
- Form1: TForm1;
- implementation
- uses Unit2;
- {$R *.dfm}
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- if not Assigned(Form2) then
- Form2 := TForm2.Create(nil);
- Form2.Show;
- end;
- procedure TForm1.CreateParams(var Params: TCreateParams);
- begin
- inherited CreateParams(Params);
- Params.ExStyle := WS_EX_APPWINDOW;
- end;
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- SetWindowLong(Application.Handle, GWL_EXSTYLE,
- GetWindowLong(Application.Handle, GWL_EXSTYLE) or WS_EX_TOOLWINDOW);
- end;
- procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
- begin
- if Msg.CmdType = SC_MINIMIZE then
- begin
- DefaultHandler(Msg);
- WindowState := wsMinimized;
- end
- else
- inherited;
- end;
- end.
Unit2.pas文件如下:
- unit Unit2;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- type
- TForm2 = class(TForm)
- Button1: TButton;
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- procedure FormDestroy(Sender: TObject);
- private
- { Private declarations }
- 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);
- Params.ExStyle := WS_EX_APPWINDOW;
- end;
- procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- Action := caFree;
- end;
- procedure TForm2.FormDestroy(Sender: TObject);
- begin
- Form2 := nil;
- end;
- end.