D
dark_eagle
Unregistered / Unconfirmed
GUEST, unregistred user!
我试过了,有时可以,有时又不行,大家一起努力吧!
<code><pre>
<font face="Courier New"><font color="#000080">unit</font> Unit1<font color="#000080">;</font>
<font color="#000080">interface</font>
<font color="#000080">uses</font>
Windows<font color="#000080">,</font> Messages<font color="#000080">,</font> SysUtils<font color="#000080">,</font> Classes<font color="#000080">,</font> Graphics<font color="#000080">,</font> Controls<font color="#000080">,</font> Forms<font color="#000080">,</font> Dialogs<font color="#000080">,</font>
DXDraws<font color="#000080">,</font> StdCtrls<font color="#000080">,</font>DXClass<font color="#000080">,</font> DirectX<font color="#000080">,</font>RLEUnit<font color="#000080">;</font>
<font color="#000080">type</font>
TRGB16<font color="#000080">=</font>TWordArray<font color="#000080">;</font>
PRGB16<font color="#000080">=</font><font color="#000080">^</font>TRGB16<font color="#000080">;</font>
TForm1 <font color="#000080">=</font> <font color="#000080">class</font><font color="#000080">(</font>TForm<font color="#000080">)</font>
DXDraw1<font color="#000080">:</font> TDXDraw<font color="#000080">;</font>
DXTimer1<font color="#000080">:</font> TDXTimer<font color="#000080">;</font>
Label1<font color="#000080">:</font> TLabel<font color="#000080">;</font>
<font color="#000080">procedure</font> DXDraw1InitializeSurface<font color="#000080">(</font>Sender<font color="#000080">:</font> TObject<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">procedure</font> DXDraw1FinalizeSurface<font color="#000080">(</font>Sender<font color="#000080">:</font> TObject<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">procedure</font> FormClose<font color="#000080">(</font>Sender<font color="#000080">:</font> TObject<font color="#000080">;</font> <font color="#000080">var</font> Action<font color="#000080">:</font> TCloseAction<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">procedure</font> FormShow<font color="#000080">(</font>Sender<font color="#000080">:</font> TObject<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">procedure</font> DXTimer1Timer<font color="#000080">(</font>Sender<font color="#000080">:</font> TObject<font color="#000080">;</font> LagCount<font color="#000080">:</font> Integer<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">procedure</font> FormCreate<font color="#000080">(</font>Sender<font color="#000080">:</font> TObject<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">private</font>
<font color="#800000">{ Private declarations }</font>
<font color="#000080">public</font>
<font color="#800000">{ Public declarations }</font>
<font color="#000080">end</font><font color="#000080">;</font>
<font color="#000080">const</font>
WW<font color="#000080">:</font>Integer<font color="#000080">=</font><font color="#FF0000">640</font><font color="#000080">;</font> <font color="#800000">//抓屏宽度和高度</font>
HH<font color="#000080">:</font>Integer<font color="#000080">=</font><font color="#FF0000">480</font><font color="#000080">;</font>
<font color="#000080">var</font>
Form1<font color="#000080">:</font> TForm1<font color="#000080">;</font>
FSurface<font color="#000080">:</font>TDirectDrawSurface<font color="#000080">;</font>
ScrDC<font color="#000080">:</font>HDC<font color="#000080">;</font>
i<font color="#000080">:</font>Integer<font color="#000080">;</font>
mPos<font color="#000080">:</font>TPoint<font color="#000080">;</font>
posX<font color="#000080">,</font>posY<font color="#000080">:</font>Integer<font color="#000080">;</font>
ImgBuf<font color="#000080">:</font>PRGB16<font color="#000080">;</font>
<font color="#000080">procedure</font> ProcImage<font color="#000080">(</font>SrcImgBuf<font color="#000080">:</font>Pointer<font color="#000080">;</font>Count<font color="#000080">:</font>integer<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">implementation</font>
<font color="#000080">uses</font>
unit2<font color="#000080">;</font>
<font color="#800000">{$R *.DFM}</font>
<font color="#000080">procedure</font> TForm1<font color="#000080">.</font>DXDraw1InitializeSurface<font color="#000080">(</font>Sender<font color="#000080">:</font> TObject<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">begin
</font>
<font color="#800000">//Create a offline surface</font>
FSurface<font color="#000080">:=</font>TDirectDrawSurface<font color="#000080">.</font>Create<font color="#000080">(</font>DXDraw1<font color="#000080">.</font>DDraw<font color="#000080">)</font><font color="#000080">;</font>
FSurface<font color="#000080">.</font>SetSize<font color="#000080">(</font>WW<font color="#000080">,</font>HH<font color="#000080">)</font><font color="#000080">;</font>
FSurface<font color="#000080">.</font>SystemMemory<font color="#000080">:=</font>true<font color="#000080">;</font>
fsurface<font color="#000080">.</font>Fill<font color="#000080">(</font><font color="#FF0000">0</font><font color="#000080">)</font><font color="#000080">;</font>
<font color="#800000">//get Screen DC</font>
ScrDC<font color="#000080">:=</font>getDC<font color="#000080">(</font><font color="#FF0000">0</font><font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">end</font><font color="#000080">;</font>
<font color="#000080">procedure</font> TForm1<font color="#000080">.</font>DXDraw1FinalizeSurface<font color="#000080">(</font>Sender<font color="#000080">:</font> TObject<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">begin
</font>
FSurface<font color="#000080">.</font>Free<font color="#000080">;</font>
FSurface<font color="#000080">:=</font><font color="#000080">nil</font><font color="#000080">;</font>
<font color="#000080">end</font><font color="#000080">;</font>
<font color="#000080">procedure</font> TForm1<font color="#000080">.</font>FormCreate<font color="#000080">(</font>Sender<font color="#000080">:</font> TObject<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">begin
</font>
ImgBuf<font color="#000080">:=</font>GlobalAllocPtr<font color="#000080">(</font>GPTR<font color="#000080">,</font>WW<font color="#000080">*</font>HH<font color="#000080">*</font><font color="#FF0000">2</font><font color="#000080">)</font><font color="#000080">;</font> <font color="#800000">//16bits</font>
<font color="#000080">end</font><font color="#000080">;</font>
<font color="#000080">procedure</font> TForm1<font color="#000080">.</font>FormClose<font color="#000080">(</font>Sender<font color="#000080">:</font> TObject<font color="#000080">;</font> <font color="#000080">var</font> Action<font color="#000080">:</font> TCloseAction<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">begin
</font>
DXTimer1<font color="#000080">.</font>Enabled<font color="#000080">:=</font>False<font color="#000080">;</font>
GlobalFreePtr<font color="#000080">(</font>ImgBuf<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">end</font><font color="#000080">;</font>
<font color="#000080">procedure</font> TForm1<font color="#000080">.</font>FormShow<font color="#000080">(</font>Sender<font color="#000080">:</font> TObject<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">begin
</font>
DXTimer1<font color="#000080">.</font>Enabled<font color="#000080">:=</font>True<font color="#000080">;</font>
<font color="#000080">end</font><font color="#000080">;</font>
<font color="#000080">procedure</font> TForm1<font color="#000080">.</font>DXTimer1Timer<font color="#000080">(</font>Sender<font color="#000080">:</font> TObject<font color="#000080">;</font> LagCount<font color="#000080">:</font> Integer<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">var</font>
<font color="#800000">//the structure of surface</font>
SurfaceDESC<font color="#000080">:</font>TDDSurfaceDesc<font color="#000080">;</font>
<font color="#000080">begin
</font>
<font color="#800000">//GetCursorPos(mPos);</font>
mPos<font color="#000080">.</font>x<font color="#000080">:=</font><font color="#FF0000">400</font><font color="#000080">;</font>
mPos<font color="#000080">.</font>y<font color="#000080">:=</font><font color="#FF0000">300</font><font color="#000080">;</font>
<font color="#800000">//clear surface</font>
FSurface<font color="#000080">.</font>Fill<font color="#000080">(</font><font color="#FF0000">0</font><font color="#000080">)</font><font color="#000080">;</font>
<font color="#800000">// use hardware bitblt Image form ScreenDC to Surface</font>
BitBlt<font color="#000080">(</font>FSurface<font color="#000080">.</font>Canvas<font color="#000080">.</font>Handle<font color="#000080">,</font><font color="#FF0000">0</font><font color="#000080">,</font><font color="#FF0000">0</font><font color="#000080">,</font>WW<font color="#000080">,</font>HH<font color="#000080">,</font>ScrDC<font color="#000080">,</font>mPos<font color="#000080">.</font>x<font color="#000080">-</font>WW <font color="#000080">div</font> <font color="#FF0000">2</font><font color="#000080">,</font>mPos<font color="#000080">.</font>y<font color="#000080">-</font>HH <font color="#000080">div</font> <font color="#FF0000">2</font><font color="#000080">,</font>SRCCOPY<font color="#000080">)</font><font color="#000080">;</font>
<font color="#800000">// Free Surface DC Handel</font>
FSurface<font color="#000080">.</font>Canvas<font color="#000080">.</font>Release<font color="#000080">;</font>
<font color="#800000">{Get Image Data from Surface bits}</font>
<font color="#000080">if</font> FSurface<font color="#000080">.</font>Lock<font color="#000080">(</font>SurfaceDESC<font color="#000080">)</font><font color="#000080">=</font>true <font color="#000080">then
</font>
<font color="#000080">begin
</font>
ProcImage<font color="#000080">(</font>SurfaceDesc<font color="#000080">.</font>lpSurface<font color="#000080">,</font>WW<font color="#000080">*</font>HH<font color="#000080">*</font><font color="#FF0000">2</font><font color="#000080">)</font><font color="#000080">;</font>
FSurface<font color="#000080">.</font>UnLock<font color="#000080">;</font>
<font color="#000080">end</font>
<font color="#000080">else
</font> Beep<font color="#000080">;</font>
Caption<font color="#000080">:=</font>Format<font color="#000080">(</font><font color="#008080">'Current FPS: %d'</font><font color="#000080">,</font><font color="#000080">[</font>dxtimer1<font color="#000080">.</font>FrameRate<font color="#000080">]</font><font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">end</font><font color="#000080">;</font>
<font color="#000080">procedure</font> ProcImage<font color="#000080">(</font>SrcImgBuf<font color="#000080">:</font>Pointer<font color="#000080">;</font>Count<font color="#000080">:</font>integer<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">begin
</font>
Move<font color="#000080">(</font>srcImgBuf<font color="#000080">^</font><font color="#000080">,</font>ImgBuf<font color="#000080">^</font><font color="#000080">,</font>Count<font color="#000080">)</font><font color="#000080">;</font>
unit2<font color="#000080">.</font>showImg<font color="#000080">(</font>ImgBuf<font color="#000080">,</font>Count<font color="#000080">)</font><font color="#000080">;</font>
<font color="#000080">end</font><font color="#000080">;</font>
<font color="#000080">end</font><font color="#000080">.</font></font>
</pre></code>