我有一个Delphi DirectX项目机智“DXDraw01”,“DXDIB01”,“DXDIB02”,“背景”,“BitBtn01”,“BitBtn02,”DXTimer01“。我的要求是存储在”背景“中的图像将应用程序运行时显示。根据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.
但事实并非如此。设置如下:
“背景”总是在后台缓冲区而不是前台缓冲区,它在关闭应用程序后显示在“桌面”上我刷新了我的“桌面”。拜托,请帮助我。