wcomp.pas

来自「详细说明:毕业论文中关于小型宾馆管理系统的详细设计毕 业论文中关于小型宾馆...」· PAS 代码 · 共 64 行

PAS
64
字号
unit WComp;

interface

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

type
  TWindowedComponent = class(TComponent)
  private
    FHandle : THandle;
    function GetHandle: THandle;
    { Private declarations }
  protected
    procedure WndProc(var Msg : TMessage); virtual;
    { Protected declarations }
  public
    function HandleAllocated: Boolean;
    procedure HandleNeeded;
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
    property Handle: THandle read GetHandle;
  end;


implementation

{ TWindowedComponent }

constructor TWindowedComponent.Create(AOwner : TComponent);
begin
  inherited Create(AOwner);
  FHandle := 0;
end;

destructor TWindowedComponent.Destroy;
begin
  if HandleAllocated then DeAllocateHWnd(FHandle);
  inherited Destroy;
end;

function TWindowedComponent.HandleAllocated: Boolean;
begin
  Result := FHandle<>0;
end;

procedure TWindowedComponent.HandleNeeded;
begin
  if not HandleAllocated then FHandle := AllocateHWnd(WndProc);
end;

function TWindowedComponent.GetHandle: THandle;
begin
  HandleNeeded;
  Result := FHandle;
end;

procedure TWindowedComponent.WndProc(var Msg : TMessage);
begin
  Dispatch(Msg);
end;

end.

⌨️ 快捷键说明

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