📄 dxclass.pas
字号:
unit DXClass;
interface
uses
Windows, Messages, SysUtils, Classes, Controls, Forms, MMSystem, DirectX;
type
{ EDirectDrawError }
EDirectXError = class(Exception);
{ TDirectX }
TDirectX = class(TPersistent)
private
procedure SetDXResult(Value: HRESULT);
protected
FDXResult: HRESULT;
procedure Check; virtual;
public
property DXResult: HRESULT read FDXResult write SetDXResult;
end;
{ TDirectXDriver }
TDirectXDriver = class(TCollectionItem)
private
FGUID: PGUID;
FGUID2: TGUID;
FDescription: string;
FDriverName: string;
procedure SetGUID(Value: PGUID);
public
property GUID: PGUID read FGUID write SetGUID;
property Description: string read FDescription write FDescription;
property DriverName: string read FDriverName write FDriverName;
end;
{ TDirectXDrivers }
TDirectXDrivers = class(TCollection)
private
function GetDriver(Index: Integer): TDirectXDriver;
public
constructor Create;
property Drivers[Index: Integer]: TDirectXDriver read GetDriver; default;
end;
{ TControlSubClass }
TControlSubClassProc = procedure(var Message: TMessage; DefWindowProc: TWndMethod) of object;
TControlSubClass = class
private
FControl: TControl;
FDefWindowProc: TWndMethod;
FWindowProc: TControlSubClassProc;
procedure WndProc(var Message: TMessage);
public
constructor Create(Control: TControl; WindowProc: TControlSubClassProc);
destructor Destroy; override;
end;
function DXLoadLibrary(const FileName, FuncName: string): TFarProc;
implementation
uses DXConsts;
var
LibList: TStringList;
function DXLoadLibrary(const FileName, FuncName: string): Pointer;
var
i: Integer;
h: THandle;
begin
if LibList=nil then
LibList := TStringList.Create;
i := LibList.IndexOf(AnsiLowerCase(FileName));
if i=-1 then
begin
{ DLL is loaded. }
h := LoadLibrary(PChar(FileName));
if h=0 then
raise Exception.CreateFmt(SDLLNotLoaded, [FileName]);
LibList.AddObject(AnsiLowerCase(FileName), Pointer(h));
end else
begin
{ DLL has already been loaded. }
h := THandle(LibList.Objects[i]);
end;
Result := GetProcAddress(h, PChar(FuncName));
if Result=nil then
raise Exception.CreateFmt(SDLLNotLoaded, [FileName]);
end;
procedure FreeLibList;
var
i: Integer;
begin
if LibList<>nil then
begin
for i:=0 to LibList.Count-1 do
FreeLibrary(THandle(LibList.Objects[i]));
LibList.Free;
end;
end;
{ TDirectX }
procedure TDirectX.Check;
begin
end;
procedure TDirectX.SetDXResult(Value: HRESULT);
begin
FDXResult := Value;
if FDXResult<>0 then Check;
end;
{ TDirectXDriver }
procedure TDirectXDriver.SetGUID(Value: PGUID);
begin
if not IsBadHugeReadPtr(Value, SizeOf(TGUID)) then
begin
FGUID2 := Value^;
FGUID := @FGUID2;
end else
FGUID := Value;
end;
{ TDirectXDrivers }
constructor TDirectXDrivers.Create;
begin
inherited Create(TDirectXDriver);
end;
function TDirectXDrivers.GetDriver(Index: Integer): TDirectXDriver;
begin
Result := (inherited Items[Index]) as TDirectXDriver;
end;
{ TControlSubClass }
constructor TControlSubClass.Create(Control: TControl;
WindowProc: TControlSubClassProc);
begin
inherited Create;
FControl := Control;
FDefWindowProc := FControl.WindowProc;
FControl.WindowProc := WndProc;
FWindowProc := WindowProc;
end;
destructor TControlSubClass.Destroy;
begin
FControl.WindowProc := FDefWindowProc;
inherited Destroy;
end;
procedure TControlSubClass.WndProc(var Message: TMessage);
begin
FWindowProc(Message, FDefWindowProc);
end;
initialization
finalization
FreeLibList;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -