⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dkfbaseform.pas

📁 EXE+BPL+DLL+Interface項目解決方案演示 經典
💻 PAS
字号:
unit dkFBaseForm;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TFBaseForm = class(TForm)
  private
    { Private declarations }
  protected
    { Protected declarations }
    FParentControl: TWinControl; //
    FParentHandle: THandle; //
    FAsChild: Boolean;
    procedure CreateParams(var Params: TCreateParams); override;
    procedure Loaded; override;
    procedure InitComponent; dynamic;
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); overload; override;
    constructor Create(AOwner: TComponent; AParent: TWinControl); reintroduce; overload;
    constructor Create(AOwner: TComponent; AParentHandle: THandle); reintroduce; overload;

    function dkClose(): Boolean;
  end;


type
  TFBaseFormClass = class of TFBaseForm;

var
  FBaseForm: TFBaseForm;

implementation


{$R *.dfm}

{ TFBaseForm }



procedure TFBaseForm.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
  if FAsChild then
    Params.Style := Params.Style or WS_CHILD;
end;

procedure TFBaseForm.Loaded;
begin
  inherited;
  if FAsChild then
  begin
    align := alClient;
    BorderStyle := bsNone;
    BorderIcons := [];
    if FParentHandle <> 0 then
    begin
      Parent := FindControl(FParentHandle);
    end else
    begin
      Parent := FParentControl;
    end;
    Position := poDefault;
  end;
end;

constructor TFBaseForm.Create(AOwner: TComponent);
begin
  FAsChild := False;
  inherited Create(AOwner);
  InitComponent;
end;

constructor TFBaseForm.Create(AOwner: TComponent; AParent: TWinControl);
begin
  FAsChild := True;
  FParentControl := AParent;
  inherited Create(AOwner);
  InitComponent;
end;

procedure TFBaseForm.InitComponent;
begin
  with Font do
  begin
    Name := '宋体';
    Charset := GB2312_CHARSET;
    Size := 10;
  end;
end;

constructor TFBaseForm.Create(AOwner: TComponent; AParentHandle: THandle);
begin
  FAsChild := True;
  FParentHandle := AParentHandle;
  inherited Create(AOwner);
  InitComponent;
end;

function TFBaseForm.dkClose: Boolean;
var
  CloseAction: TCloseAction;
begin
  result := False;
  if fsModal in FFormState then
  begin
    ModalResult := mrCancel;
    result := true;
  end else
    if CloseQuery then
    begin
      if FormStyle = fsMDIChild then
        if biMinimize in BorderIcons then
          CloseAction := caMinimize else
          CloseAction := caNone
      else
        CloseAction := caFree;
      DoClose(CloseAction);
      if CloseAction <> caNone then
        if Application.MainForm = Self then Application.Terminate
        else if CloseAction = caHide then hide
        else if CloseAction = caMinimize then WindowState := wsMinimized
        else begin Free; result := True; end;
    end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -