1

我有一个带有“DXDraw01”、“DXDIB01”、“DXDIB02”、“背景”、“BitBtn01”、“BitBtn02”、“DXTimer01”的 Delphi DirectX 项目。我的要求是存储在“背景”中的图像将在应用程序将运行。根据 DelphiX 教程,我实现了以下代码:

unit KoushikHalder01;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Winapi.DirectDraw,
  DXClass, DXDraws, DIB, Math, Menus;

type
  TForm01 = class(TDXForm)
    DXDraw01: TDXDraw;
    DXDIB01: TDXDIB;
    DXDIB02: TDXDIB;
    Background: TDXDIB;
    BitBtn01: TBitBtn;
    BitBtn02: TBitBtn;
    DXTimer01: TDXTimer;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure DXTimer01Timer(Sender: TObject; LagCount: Integer);
    procedure FormDestroy(Sender: TObject);
    procedure DXDraw01Finalize(Sender: TObject);
    procedure DXDraw01Initialize(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form01: TForm01;
  Closing: Boolean;

implementation

{$R *.dfm}

procedure TForm01.DXDraw01Finalize(Sender: TObject);
begin
  DXTimer01.Enabled := false;
end;

procedure TForm01.DXDraw01Initialize(Sender: TObject);
begin
  DXTimer01.Enabled := true;
end;

procedure TForm01.DXTimer01Timer(Sender: TObject; LagCount: Integer);
begin
  if not DXDraw01.CanDraw then exit;

  DXDraw01.Surface.Fill(0);

  with DXDraw01.Surface.Canvas do
  begin
  DXDraw01.Surface.Assign(Background.DIB);
    Brush.Style := bsClear;
    Font.Color := clWhite;
    Font.Size := 30;
    Textout(130, 30, DateTimeToStr(Now));
    Release; {  Indispensability  }
  end;
  DXDraw01.Flip;
  Application.ProcessMessages;
end;

procedure TForm01.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Closing := True;
end;

procedure TForm01.FormCreate(Sender: TObject);
 begin
  DXTimer01.Enabled := true;
end;

procedure TForm01.FormDestroy(Sender: TObject);
begin
  DXDIB01.Free;
  DXDIB02.Free;
  DXDraw01.Free;
  Background.Free;
end;

end.

但事实并非如此。设置如下: DXDraw 设置 DXTimer 设置

“背景”始终在后缓冲区中,而不是翻转到前缓冲区,并且在关闭应用程序后它显示在“桌面”上,除非我刷新我的“桌面”。请,请帮助我。

4

0 回答 0