高分求解:如何实现在DirectX的程序窗口中显示文本而且不闪烁,就像游戏外挂一样(300分)

E

estorm

Unregistered / Unconfirmed
GUEST, unregistred user!
如何实现在DirectX的程序中显示文本,就像游戏外挂一样<br>比如说传奇的外挂,在上面显示HP,MP等<br>我初步用了下面的方法(win2000上测试)<br>FHWnd:=FindWindow(nil,SMir3WindowCaption);//SSsjWindowCaption为传奇窗口Caption<br>if FHWnd=0 then exit;<br>FHDC:=GetDC(FHWnd);<br>FCanvas:=TCanvas.Create;<br>FCanvas.Handle:=FHDC;<br>SetBKMode(FCanvas.Handle,TRANSPARENT);<br>FCanvas.TextOut(10,10,'Hello World! Hello World!');<br>FreeAndNil(FCanvas);<br>DeleteDC(FHDC);<br><br>以上这段程序在一个线程中循环执行,但是会有这样的问题:<br>1。如果用Sync发现,根本不显示文本,线程阻塞掉了<br>2。如果用不用sync,会有闪烁的现象<br>请各位讨论讨论,那位高手有好的办法<br>
 
我記得寫遊戲的時候,為了避免閃爍,都是利用雙緩存的機制,就是在內存中也該有個圖片,對任何的動作都對內存中的那個進行。然後再把內存中的圖片畫到屏幕上就行了。
 
游戏的窗体都是dIRECTx画的,你GetDC(FHWND)不太对劲。我想应该在DirectX这边下手才对
 
各位,有没有具体点的方法呢
 
下載一個控件delphix就行了。
 
你的办法基本上一定会闪。因为 mir3 也要写屏幕,也要前、后翻转。。。得想想~。
 
对啊,有没有好一点的方法啊
 
還是用那個控件吧,delphix可以只讓你進行遊戲的開發,其它那些底層的完全不用管。如果一下問題太多,會影響你學習寫遊戲的熱情的。
 
对dx:<br>自己hook,ddraw.dll中的flip函数在其中写屏。<br>对opengl:<br>忘了要hook那个函数了:(<br>你可以艘1下,有一个软件可以在任何dx,opengl中显示出桢数,就是用这个原理<br>
 
没试过,想想看
 
to springson<br>再问一下,知道一个DirectX窗口的Windows句柄,如何在Hook中初始化DirectX,然后作图呢?
 
對不起了,這個底層的操作還不會。不過這方面的書多看下vc++,就行了。上面有專門講directx的。
 
to:springson<br>:(
 
to tt.t<br>显示出桢数的软件叫什么呢?
 
http://www.fraps.com/<br>it's really COOL
 
to tt.t<br>这个程序我研究过了,实际上它可能是在最前端显示了一个窗口<br><br>各位,有没有嵌入到,directx游戏程序中去作图,就是说,当游戏作图完,在Blt或者Flip之前,我把我的内容显示到缓冲中去
 
拜托,不知道你是怎么研究的,那个程序根本就不是你说的那样时显示什么窗口。如果你仅仅是运行了一下就瞎猜他是怎么实现的就不要说是研究出来的好不好。你有反汇编看过么?没有的话就不要说什么研究过了!如果你反汇编了还得出这样的结论那我也不好说什么了,因为实在是没必要和你说了。<br>ok,你可以反汇编看看,如果看不出什么的话那就去他主页上的FAQ栏看看,里面也说的很清楚了。<br>思路我告诉你了,能不能实现就看你的功力了。<br>
 
光说你好像并不好哦,翻出来好久以前写的全屏dx下显示文字+抓屏的代码,贴出来。<br>这段代码*不符合*你的要求,但你可以看到一种思路。如果要达到你的要求,除了HOOK(这是一种通用的方法,当然对特定程序或许有其他简便的方法)暂时我想不出其他什么好办法。<br>这段代码*兼容性并不好*,但可以在callus(不要问我是什么)下(当然还有许多其他程序)完美运行:)你可以用callus测试一下。<br>代码未经整理,凑活看吧。<br><br>library ptdll;<br><br>uses<br>&nbsp; SysUtils,<br>&nbsp; Classes,<br>&nbsp; Windows,<br>&nbsp; Messages,<br>&nbsp; dll_vol in 'dll_vol.pas';<br><br>{$R *.RES}<br><br>exports sethook,endhook;<br><br>begin<br>hNextHookProc := 0;<br>procSaveExit := ExitProc;<br>ExitProc := @HotKeyHookExit;<br>end.<br>----------------dll_vol-------------<br>unit dll_vol;<br><br>interface<br><br>uses Windows,Messages,Dialogs,Sysutils,directdraw,Graphics;<br><br>var<br>&nbsp; hNextHookProc: HHook;<br>&nbsp; procSaveExit: Pointer;<br><br>&nbsp; function sethook:bool;export;<br>&nbsp; function hookproc(iCode:Integer;wParam: WPARAM;lParam: LPARAM): LRESULT; stdcall;<br>&nbsp; function endhook:bool;export;<br>&nbsp; procedure HotKeyHookExit;far;<br><br>implementation<br><br>function HookProc(iCode: integer; wParam: wParam; lParam: lParam): LResult; stdcall;<br>var<br>&nbsp; hwnd:dword;<br>&nbsp; DC:HDC;<br>&nbsp; a,b,c,d:dword;<br>&nbsp; pp:pointer;<br>&nbsp; FD:IDirectDraw;<br>&nbsp; sur:array [0..5] of dword;<br>&nbsp; i,j:integer;<br>&nbsp; bm:tbitmap;<br>&nbsp; Desc: TDDSurfaceDesc;<br>&nbsp; PID:Cardinal;<br>begin<br>&nbsp; result:=0;<br>&nbsp; &nbsp; if iCode&lt;0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; CallNextHookEx(hnexthookproc,iCode,wParam,lParam);<br>&nbsp; &nbsp; &nbsp; result:=0;<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br>&nbsp; if ((lParam and $80000000)=0) and<br>&nbsp; &nbsp; &nbsp;(GetKeyState(VK_LWIN)&lt;0) and (wParam=$6a) then &nbsp;//热键:左win键+数字键盘*<br>&nbsp; begin<br>&nbsp; if getmodulehandle('ddraw.dll')&lt;&gt;0 then<br>&nbsp; &nbsp; if DirectDrawCreate(nil,FD,nil)=DD_OK then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; Messagebeep(0);<br>&nbsp; &nbsp; PID:=GetCurrentProcessId;<br>&nbsp; &nbsp; &nbsp; pp:=@fd;<br>&nbsp; &nbsp; &nbsp; a:=dword(pointer(dword(pp^)+8)^); &nbsp; &nbsp; &nbsp;//IDirectDraw<br>&nbsp; &nbsp; &nbsp; sur[0]:=dword(pointer(dword(pointer(a+4)^)+44)^); //point to PrimarySurface structure<br>&nbsp; &nbsp; &nbsp; b:=sur[0];<br>&nbsp; &nbsp; &nbsp; for i:=1 to 5 do<br>&nbsp; &nbsp; &nbsp; begin &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//point to backSurface structure<br>&nbsp; &nbsp; &nbsp; &nbsp; b:=dword(pointer(dword(pointer(dword(pointer(b+4)^)+12)^)+12)^);<br>&nbsp; &nbsp; &nbsp; &nbsp; if b&lt;=0 then break;<br>&nbsp; &nbsp; &nbsp; &nbsp; if dword(pointer(dword(pointer(b+4)^)+24)^)&lt;&gt;PID then break;<br>&nbsp; &nbsp; &nbsp; &nbsp; if dword(pointer(b+12)^)&lt;dword(pointer(sur[i-1]+12)^) then break;<br>&nbsp; &nbsp; &nbsp; &nbsp; sur:=b;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; j:=0;<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; pp:=pointer(sur[j]);<br>&nbsp; &nbsp; ////////////1<br>&nbsp; &nbsp; &nbsp; asm &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //getdc<br>&nbsp; &nbsp; &nbsp; &nbsp; lea edx,dc<br>&nbsp; &nbsp; &nbsp; &nbsp; push edx<br>&nbsp; &nbsp; &nbsp; &nbsp; mov eax,pp<br>&nbsp; &nbsp; &nbsp; &nbsp; push eax<br>&nbsp; &nbsp; &nbsp; &nbsp; mov eax,[eax]<br>&nbsp; &nbsp; &nbsp; &nbsp; call [eax+$44]<br>&nbsp; &nbsp; &nbsp; &nbsp; mov d,eax<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; if d&lt;&gt;DD_OK then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; fd:=nil;<br>&nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; bm:=tbitmap.Create;<br>&nbsp; &nbsp; &nbsp; bm.Width:=GetDeviceCaps(dc,HORZRES);<br>&nbsp; &nbsp; &nbsp; bm.Height:=GetDeviceCaps(dc,VERTRES);<br>&nbsp; &nbsp; &nbsp; SetBKColor(dc,RGB(0,0,255));<br>&nbsp; &nbsp; &nbsp; SetTextColor(DC,RGB(255,255,0));<br>&nbsp; &nbsp; &nbsp; TextOut(dc,0,0,PChar('XYZAB'),5);<br>{ &nbsp; &nbsp;asm<br>&nbsp; &nbsp; &nbsp; push 0<br>&nbsp; &nbsp; &nbsp; push DDLOCK_WAIT or DDLOCK_READONLY<br>&nbsp; &nbsp; &nbsp; lea eax,desc<br>&nbsp; &nbsp; &nbsp; push eax<br>&nbsp; &nbsp; &nbsp; push 0<br>&nbsp; &nbsp; &nbsp; mov eax,pp<br>&nbsp; &nbsp; &nbsp; push eax<br>&nbsp; &nbsp; &nbsp; mov eax,[eax]<br>&nbsp; &nbsp; &nbsp; call [eax+$64]<br>&nbsp; &nbsp; end; &nbsp;}<br>&nbsp; &nbsp; &nbsp; bitblt(bm.Canvas.Handle,0,0,bm.Width,bm.Height,dc,0,0,SRCCOPY);<br>{ &nbsp; &nbsp;asm<br>&nbsp; &nbsp; @@a:<br>&nbsp; &nbsp; &nbsp; push 0<br>&nbsp; &nbsp; &nbsp; mov eax,pp<br>&nbsp; &nbsp; &nbsp; push eax<br>&nbsp; &nbsp; &nbsp; mov eax,[eax]<br>&nbsp; &nbsp; &nbsp; call [eax+$80]<br>&nbsp; &nbsp; &nbsp; cmp eax,0<br>&nbsp; &nbsp; &nbsp; jz @@a<br>&nbsp; &nbsp; end; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; bm.SaveToFile('C:/1.bmp');<br>&nbsp; &nbsp; &nbsp; bm.Free;<br>&nbsp; &nbsp; &nbsp; asm &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//releasedc<br>&nbsp; &nbsp; &nbsp; @@a:<br>&nbsp; &nbsp; &nbsp; &nbsp; lea edx,dc<br>&nbsp; &nbsp; &nbsp; &nbsp; push edx<br>&nbsp; &nbsp; &nbsp; &nbsp; mov eax,pp<br>&nbsp; &nbsp; &nbsp; &nbsp; push eax<br>&nbsp; &nbsp; &nbsp; &nbsp; mov eax,[eax]<br>&nbsp; &nbsp; &nbsp; &nbsp; call [eax+$68]<br>&nbsp; &nbsp; &nbsp; &nbsp; cmp eax,0<br>&nbsp; &nbsp; &nbsp; &nbsp; jz @@a<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; fd:=nil;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; result:=1;<br>&nbsp; end;<br>end;<br><br>function sethook:bool;export;<br>begin<br>&nbsp; result:=false;<br>&nbsp; if hnexthookproc&lt;&gt;0 then exit;<br>&nbsp; hNextHookProc := SetWindowsHookEx(WH_KEYBOARD,hookproc,HInstance,0); <br>&nbsp; Result := hNextHookProc &lt;&gt; 0;<br>end;<br><br>procedure hotkeyhookexit;<br>begin<br>&nbsp; if hNextHookProc &lt;&gt; 0 then endHook;<br>&nbsp; ExitProc := procSaveExit;<br>end;<br><br>function endhook:bool;export;<br>begin<br>&nbsp; if hNextHookProc &lt;&gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; UnhookWindowshookEx(hNextHookProc);<br>&nbsp; &nbsp; hNextHookProc := 0;<br>&nbsp; end;<br>&nbsp; Result := hNextHookProc = 0;<br>end;<br><br>end.<br>--------example project--------------<br>unit test;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br>&nbsp; StdCtrls;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Label1: TLabel;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; Exit_Message:Cardinal;<br><br>implementation<br><br>{$R *.DFM}<br>function sethook:bool;external 'ptdll.dll';<br>function endhook:bool;external 'ptdll.dll';<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; if button1.Caption='HOOK!!' then<br>&nbsp; begin<br>&nbsp; &nbsp; sethook;<br>&nbsp; &nbsp; button1.Caption:='UNHOOK';<br>&nbsp; &nbsp; Label1.Caption:='HOOKED!!';<br>&nbsp; end<br>&nbsp; else<br>&nbsp; begin<br>&nbsp; &nbsp; endhook;<br>&nbsp; &nbsp; button1.Caption:='HOOK!!';<br>&nbsp; &nbsp; Label1.Caption:='UNHOOKED!!';<br>&nbsp; end<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>&nbsp; endhook;<br>end;<br><br>end.
 
基本解决了:)<br>等有时间整理一下发上来
 
顶部