home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1999 February
/
PCWorld_1999-02_cd.bin
/
temacd
/
HotKeys
/
WComp.pas
< prev
Wrap
Pascal/Delphi Source File
|
1998-08-11
|
2KB
|
74 lines
unit WComp;
interface
uses
Windows, Messages, SysUtils, Classes, 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;
procedure DefaultHandler(var Message); override;
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;
procedure TWindowedComponent.DefaultHandler(var Message);
begin
if FHandle <> 0 then
with TMessage(Message) do
Result := DefWindowProc(FHandle, Msg, wParam, lParam)
else
inherited DefaultHandler(Message);
end;
end.