程式转换(200分)

  • 主题发起人 主题发起人 Luben
  • 开始时间 开始时间
L

Luben

Unregistered / Unconfirmed
GUEST, unregistred user!
请教各位高手:<br><br>在本网站中有人提到:<br>’如何象许多字典一样动态截取Window95 和NT 屏幕上的字符?‘而且也有答案,但<br>弟现在针对这个程式要如何转换成Delphi的程式?<br>弟现愿意出200分请各位帮忙解决一下.<br><br>谢谢
 
源程序是何种语言,在哪儿?<br>E-Mail 一份给我,就可以了。<br>
 
原来的答案是我提供的,至于使用Delphi,并不需要转换,<br>因为原先的程序是编译生成的DLL, 您只要在Delphi里<br>面使用这个DLL就行了, DLL会把鼠标下面的字符串通知<br>给你的程序的,:)
 
抱歉!小弟比较不懂C所以不知道要如何从Delphi中呼叫这个DLL中的函式!<br>可否请您用程式说明之。<br><br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Luben<br><br>
 
啊?这个DLL在哪儿?我要了!
 
luben象是个台湾哥们!大富翁人气很旺呀!
 
叫拜??瞷?硂?拜肈Τ秆?盾?и璶非称倒だ??
 
要什么版本的?<br><br>让我试试吧!
 
pega(随曹晓刚称呼):您还有时间吗?<br><br>Luben,其实调用Dll还是比较容易的,您学会了吗?如果学会的话,请结束问题吧
 
刚看了报纸,1998年10月份“中国计算机报”有屏幕截字的介绍,可作参考。
 
这里有Delphi源程序+Dll源程序,不过不是我写的,贴出来吧.<br><br>smth的delphi版有源代码.发信人: raphaelzl (小飞熊), 信区: Delphi <br>标 &nbsp;题: 数据定义文件 u_def.pas <br>发信站: BBS 水木清华站 (Sat Jan &nbsp;1 11:25:21 2000) <br>&nbsp; <br>unit U_Def; <br>interface <br>uses <br>&nbsp; Messages, Windows; <br>const <br>&nbsp; WM_MOUSEPT = WM_USER + 1000 + Ord('M') + Ord('P') + Ord('T'); <br>&nbsp; MappingFileName = 'Mapping File By Raphael'; <br>&nbsp; MaxStringLen = 50; <br>&nbsp; CodeJump = $E9909090; <br>type <br>&nbsp; PInt = ^integer; <br>&nbsp; _ExtTextOutA = function (theDC :HDC; nXStart, nYStart :integer; toOptions <br>: Longint; rect : PRect; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpStr :PAnsiChar; nCount :integer; Dx : PInteger) <br>:BOOL; stdcall; <br>&nbsp; _PExtTextOutA = ^_ExtTextOutA; <br>&nbsp; TLongJump = packed record <br>&nbsp; &nbsp; JmpOp : Cardinal; <br>&nbsp; &nbsp; Addr : Pointer; <br>&nbsp; end; <br>&nbsp; TShareMem = packed record <br>&nbsp; &nbsp; hProcWnd : HWND; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //The main window of the program <br>&nbsp; &nbsp; hHookWnd : HWND; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //The window currently being hooked <br>&nbsp; &nbsp; hWndPseudo : HWND; &nbsp; &nbsp; &nbsp; &nbsp; //The pseudo window used to repaint the other <br>&nbsp;window <br>&nbsp; &nbsp; hProc : THandle; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //The process ID of the main program <br>&nbsp; &nbsp; pMouse : TPoint; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //the mouse position <br>&nbsp; &nbsp; fStrMouseQueue : array [0..MaxStringLen] of Char; //mouse info <br>&nbsp; &nbsp; nTimePassed : integer; &nbsp; &nbsp; //the time passed since last time's mousemove <br>&nbsp; <br>&nbsp; &nbsp; bCanSpyNow : Boolean; <br>&nbsp; &nbsp; bHookExtTextOutA : Boolean; <br>&nbsp; &nbsp; pOldExtTextOutA : TLongJump; <br>&nbsp; &nbsp; fStrExtTextOutA : array [0..MaxStringLen] of Char; <br>&nbsp; end; <br>&nbsp; PShareMem = ^TShareMem; <br>implementation <br>end. <br>-- <br><br>&nbsp; &nbsp; &nbsp; &nbsp;真的好想拍拍小翅膀, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;就飞上那晴朗的天空。 <br>&nbsp; <br><br>发信人: raphaelzl (小飞熊), 信区: Delphi <br>标 &nbsp;题: hook的dll源文件 <br>发信站: BBS 水木清华站 (Sat Jan &nbsp;1 11:26:17 2000) <br>&nbsp; <br>library dll_HookMouse; <br>uses <br>&nbsp; SysUtils, <br>&nbsp; Windows, <br>&nbsp; Classes, <br>&nbsp; Messages, <br>&nbsp; Math, <br>&nbsp; Dialogs, <br>&nbsp; U_Def in 'U_Def.pas'; <br>{$R *.RES} <br>var <br>&nbsp; hMouseHook : HHOOK; <br>&nbsp; SpyInstalled : Boolean; <br>&nbsp; fTimerID : Cardinal; <br>&nbsp; pShMem : PShareMem; <br>&nbsp; hMappingFile : THandle; <br>function InstallSpy:Boolean; forward; <br>function UnWiseSpy:Boolean; forward; <br>function fExtTextOutA(theDC :HDC; nXStart, nYStart :integer; toOptions : Lon <br>gint; rect : PRect; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; lpStr :PAnsiChar; nCount :Longint; Dx: PInteger):BOOL; <br>&nbsp;stdcall; <br>var <br>&nbsp; dwBytes, dwCallingProc : DWORD; <br>&nbsp; pOldExtTextOut : _ExtTextOutA; <br>&nbsp; hModuleGDI : THandle; <br>&nbsp; poOri, poDC, poText, poMouse : TPoint; <br>&nbsp; Size : TSize; <br>begin <br>&nbsp; UnWiseSpy; <br>&nbsp; GetWindowThreadProcessID(pShMem^.hHookWnd, @dwCallingProc); <br>&nbsp; try <br>&nbsp; &nbsp; if pShMem^.bCanSpyNow and (dwCallingProc &lt;&gt; pShMem^.hProc) then <br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; dwBytes := Min(nCount, MaxStringLen); <br>&nbsp; &nbsp; &nbsp; CopyMemory(@(pShMem^.fStrExtTextOutA), lpStr, dwBytes); <br>&nbsp; &nbsp; &nbsp; //Get lpStr Content <br>&nbsp; &nbsp; &nbsp; //The following codes for get the right text <br>&nbsp; &nbsp; &nbsp; GetDCOrgEx(theDC, poOri); <br>&nbsp; &nbsp; &nbsp; // 取得本窗口设备相关坐标原点的全局逻辑坐标 <br>&nbsp; &nbsp; &nbsp; poDC.x := nXStart; <br>&nbsp; &nbsp; &nbsp; poDC.y := nYStart; <br>&nbsp; &nbsp; &nbsp; // <br>&nbsp; &nbsp; &nbsp; LPToDP(theDC, poDC, 1); <br>&nbsp; &nbsp; &nbsp; //全局逻辑坐标转化为设备相关坐标 <br>&nbsp; &nbsp; &nbsp; GetCursorPos(poMouse); <br>&nbsp; &nbsp; &nbsp; poText.x := poDC.x + poOri.x; <br>&nbsp; &nbsp; &nbsp; poText.y := poDC.y + poOri.y; <br>&nbsp; &nbsp; &nbsp; if (GetTextAlign(theDC) and TA_UPDATECP) &lt;&gt; 0 then <br>&nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; GetCurrentPositionEx(theDC, @poOri); <br>&nbsp; &nbsp; &nbsp; &nbsp; poText.x := poText.x + poOri.x; <br>&nbsp; &nbsp; &nbsp; &nbsp; poText.y := poText.y + poOri.y; <br>&nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; &nbsp; GetTextExtentPoint(theDC, lpStr, nCount, Size); <br>&nbsp; &nbsp; &nbsp; // 取得要输出的字符串的实际显示大小 <br>&nbsp; &nbsp; &nbsp; if (poMouse.x &gt;= poText.x) and (poMouse.x &lt;= poText.x + Size.cx) and <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(poMouse.y &gt;= poText.y) and (poMouse.y &lt;= poText.y + Size.cy) then <br>&nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; pShMem^.bCanSpyNow := False; <br>&nbsp; &nbsp; &nbsp; &nbsp; pShMem^.nTimePassed := -1; <br>&nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; &nbsp; pShMem^.fStrExtTextOutA[dwBytes] := Chr(0); <br>&nbsp; &nbsp; &nbsp; FlushViewOfFile(pShMem, 0); <br>&nbsp; &nbsp; &nbsp; if dwCallingProc &lt;&gt; pShMem^.hProc then <br>&nbsp; &nbsp; &nbsp; &nbsp; PostMessage(pShMem^.hProcWnd, WM_MOUSEPT, 2, 2); <br>&nbsp; &nbsp; end; <br>&nbsp; &nbsp; if (dwCallingProc = pShMem^.hProc) or pShMem^.bHookExtTextOutA then <br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; hModuleGDI := GetModuleHandle(PChar('GDI32')); <br>&nbsp; &nbsp; &nbsp; @pOldExtTextOut := GetProcAddress(hModuleGDI, PChar('ExtTextOutA')); <br>&nbsp; &nbsp; &nbsp; Result := pOldExtTextOut(theDC, nXStart, nYStart, toOptions, rect, lpS <br>tr, nCount, Dx); <br>&nbsp; &nbsp; end else <br>&nbsp; &nbsp; &nbsp; Result := True; <br>&nbsp; except <br>&nbsp; &nbsp; Result := False; <br>&nbsp; end; <br>&nbsp; SpyInstalled := True; <br>&nbsp; InstallSpy; <br>end; <br>function UnWiseSpy:Boolean; <br>var <br>&nbsp; dwBytesWritten, dwOldProtect : DWORD; <br>&nbsp; pOldExtTextOut : _ExtTextOutA; <br>&nbsp; hModuleGDI : THandle; <br>begin <br>&nbsp; hModuleGDI := GetModuleHandle(PChar('GDI32')); <br>&nbsp; @pOldExtTextOut := GetProcAddress(hModuleGDI, PChar('ExtTextOutA')); <br>&nbsp; if not VirtualProtect(@pOldExtTextOut, SizeOf(TLongJump), PAGE_EXECUTE_REA <br>DWRITE, @dwOldProtect) then <br>&nbsp; begin <br>&nbsp; &nbsp; Result := False; <br>&nbsp; &nbsp; Exit; <br>&nbsp; end; <br>&nbsp; if not WriteProcessMemory(GetCurrentProcess, @pOldExtTextOut, @pShMem^.pOl <br>dExtTextOutA, SizeOf(TLongJump), dwBytesWritten) then <br>&nbsp; begin <br>&nbsp; &nbsp; Result := False; <br>&nbsp; &nbsp; Exit; <br>&nbsp; end; <br>&nbsp; if not VirtualProtect(@pOldExtTextOut, SizeOf(TLongJump), dwOldProtect, @d <br>wBytesWritten) then <br>&nbsp; begin <br>&nbsp; &nbsp; Result := False; <br>&nbsp; &nbsp; Exit; <br>&nbsp; end; <br>&nbsp; Result := True; <br>end; <br>function InstallSpy:Boolean; <br>var <br>&nbsp; dwBytesWritten, dwOldProtect : DWORD; <br>&nbsp; ljHere : TLongJump; <br>&nbsp; pOldExtTextOut : _ExtTextOutA; <br>&nbsp; hModuleGDI : THandle; <br>begin <br>&nbsp; hModuleGDI := GetModuleHandle(PChar('GDI32')); <br>&nbsp; @pOldExtTextOut := GetProcAddress(hModuleGDI, PChar('ExtTextOutA')); <br>&nbsp; if not VirtualProtect(@pOldExtTextOut, SizeOf(TLongJump), PAGE_EXECUTE_REA <br>DWRITE, @dwOldProtect) then <br>&nbsp; begin <br>&nbsp; &nbsp; Result := False; <br>&nbsp; &nbsp; Exit; <br>&nbsp; end; <br>&nbsp; ljHere.JmpOp := CodeJump; <br>&nbsp; ljHere.Addr := Pointer( Cardinal(@fExtTextOutA) - Cardinal(@pOldExtTextOut <br>) - SizeOf(TLongJump) ); <br>&nbsp; if not WriteProcessMemory(GetCurrentProcess, @pOldExtTextOut, @ljHere, Siz <br>eOf(TLongJump), dwBytesWritten) then <br>&nbsp; begin <br>&nbsp; &nbsp; Result := False; <br>&nbsp; &nbsp; Exit; <br>&nbsp; end; <br>&nbsp; if not VirtualProtect(@pOldExtTextOut, SizeOf(TLongJump), dwOldProtect, @d <br>wBytesWritten) then <br>&nbsp; begin <br>&nbsp; &nbsp; Result := False; <br>&nbsp; &nbsp; Exit; <br>&nbsp; end; <br>&nbsp; Result := True; <br>end; <br>function MouseHookProc(nCode : integer; wPar : WParam; lPar : LParam) : lRes <br>ult; stdcall; <br>var <br>&nbsp; pMouseInf : TMouseHookStruct; <br>begin <br>&nbsp; if (not SpyInstalled) and pShMem^.bHookExtTextOutA then <br>&nbsp; &nbsp; InstallSpy; <br>&nbsp; if SpyInstalled and (not pShMem^.bHookExtTextOutA) then <br>&nbsp; begin <br>&nbsp; &nbsp; UnwiseSpy; <br>&nbsp; &nbsp; SpyInstalled := False; <br>&nbsp; end; <br>&nbsp; pShMem^.nTimePassed := 0 ; <br>&nbsp; if (nCode &gt;= 0) and (wPar = WM_MOUSEMOVE) then <br>&nbsp; begin <br>&nbsp; &nbsp; pMouseInf := (PMouseHookStruct(lPar))^; <br>&nbsp; &nbsp; if (pShMem^.pMouse.x &lt;&gt; pMouseInf.pt.x) or <br>&nbsp; &nbsp; &nbsp; &nbsp;(pShMem^.pMouse.y &lt;&gt; pMouseInf.pt.y) then <br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; if nCode = HC_NOREMOVE then <br>&nbsp; &nbsp; &nbsp; &nbsp; pShMem^.fStrMouseQueue := 'Not removed from the queue' <br>&nbsp; &nbsp; &nbsp; else &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//then HC_ACTION <br>&nbsp; &nbsp; &nbsp; &nbsp; pShMem^.fStrMouseQueue := 'Removed from the queue'; <br>&nbsp; &nbsp; &nbsp; pShMem^.pMouse := pMouseInf.pt; <br>&nbsp; &nbsp; &nbsp; pShMem^.hHookWnd := pMouseInf.hwnd; <br>&nbsp; &nbsp; &nbsp; PostMessage(pShMem^.hProcWnd, WM_MOUSEPT, 1, 1); //1 indicates mouse m <br>essage <br>&nbsp; &nbsp; end; <br>&nbsp; end; <br>&nbsp; FlushViewOfFile(pShMem, 0); <br>&nbsp; Result := CallNextHookEx(hMouseHook, nCode, wPar, lPar); <br>end; <br>procedure fOnTimer(theWnd : HWND; msg, idTimer : Cardinal; dwTime : DWORD);f <br>ar pascal; //CallBack Type <br>begin <br>&nbsp; if pShMem^.nTimePassed = -1 then <br>&nbsp; &nbsp; Exit; <br>&nbsp; pShMem^.nTimePassed := pShMem^.nTimePassed + 1; <br>&nbsp; if pShMem^.nTimePassed &gt; 21 then <br>&nbsp; begin <br>&nbsp; &nbsp; pShMem^.nTimePassed := 21; <br>&nbsp; &nbsp; FlushViewOfFile(pShMem, 0); <br>&nbsp; &nbsp; Exit; <br>&nbsp; end; <br>&nbsp; if pShMem^.nTimePassed &gt; 20 then <br>&nbsp; begin <br>&nbsp; &nbsp; pShMem^.bCanSpyNow := True; <br>&nbsp; &nbsp; FlushViewOfFile(pShMem, 0); <br>&nbsp; &nbsp; SetWindowPos(pShMem^.hWndPseudo, HWND_TOPMOST, pShMem^.pMouse.x, pShMem^ <br>.pMouse.y, 1, 8, SWP_NOACTIVATE or SWP_SHOWWINDOW); <br>&nbsp; &nbsp; ShowWindow(pShMem^.hWndPseudo , SW_HIDE); <br>&nbsp; end; <br>end; <br>function MouseWndProc(theWnd : HWND; theMess : Cardinal; wPar : wParam; lPar <br>&nbsp;: lParam): LResult;stdcall; <br>begin <br>&nbsp; case theMess of <br>&nbsp; &nbsp; WM_CLOSE : <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;DestroyWindow(theWnd); <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PostQuitMessage(0); <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; else <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := DefWindowProc(theWnd, theMess, wPar, lPar); <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Exit; <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end; <br>&nbsp; end; <br>&nbsp; Result := 0; <br>end; <br>function InstallMouseHook(hInst : LongWord):Boolean; <br>begin <br>&nbsp; hMouseHook := SetWindowsHookEx(WH_MOUSE, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;MouseHookProc, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetModuleHandle(PChar('dll_HookMouse')), <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0); <br>&nbsp; if hMouseHook = 0 then <br>&nbsp; begin <br>&nbsp; &nbsp; Result := False; <br>&nbsp; &nbsp; Exit; <br>&nbsp; end; <br>&nbsp; pShMem^.hWndPseudo := CreateWindowEx(WS_EX_TOPMOST or WS_EX_TOOLWINDOW, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'ZL_MOUSE_WND_PSEUDO', <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'ZL_MOUSE_WND_PSEUDO', <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WS_CLIPSIBLINGS or WS_POPUP , <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, 0, 1, 8, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, 0, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hInst, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;nil); <br>&nbsp; ShowWindow(pShMem^.hWndPseudo, SW_HIDE); <br>&nbsp; UpdateWindow(pShMem^.hWndPseudo); <br>&nbsp; fTimerID := SetTimer(0, 0, 10, @fOnTimer); <br>&nbsp; FlushViewOfFile(pShMem, 0); <br>&nbsp; Result := True; <br>end; <br>function UnWiseMouseHook:Boolean; <br>begin <br>&nbsp; KillTimer(0, fTimerID); <br>&nbsp; DestroyWindow(pShMem^.hWndPseudo); <br>&nbsp; if SpyInstalled then <br>&nbsp; &nbsp; UnWiseSpy; <br>&nbsp; pShMem^.bHookExtTextOutA := False; <br>&nbsp; FlushViewOfFile(pShMem, 0); <br>&nbsp; Result := UnHookWindowsHookEx(hMouseHook); <br>end; <br>procedure DllEntry(nReason : integer); <br>begin <br>&nbsp; case nReason Of <br>&nbsp; &nbsp; DLL_PROCESS_ATTACH: <br>&nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; hMappingFile := CreateFileMapping($FFFFFFFF, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; nil, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PAGE_READWRITE, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SizeOf(TShareMem), <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PChar(MappingFileName)); <br>&nbsp; &nbsp; &nbsp; &nbsp; if hMappingFile&lt;&gt;0 then //if h..=0 , the work is done by OS <br>&nbsp; &nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pShMem := PShareMem( MapViewOfFile(hMappingFile, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_MAP_WRITE, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, //hi_order offset where mapp <br>ing begins <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, //lo_order offset where mapp <br>ing begins <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0) ); //Size of the mapping <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if pShMem = nil then <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hMappingFile); <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('Cannot create the Share Memory Block!'); <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; &nbsp; &nbsp; end else <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ShowMessage('Cannot create the Share Memory Block!'); <br>&nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; DLL_PROCESS_DETACH: <br>&nbsp; &nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; &nbsp; UnwiseSpy; <br>&nbsp; &nbsp; &nbsp; &nbsp; UnMapViewOfFile(pShMem); <br>&nbsp; &nbsp; &nbsp; &nbsp; CloseHandle(hMappingFile); <br>&nbsp; &nbsp; &nbsp; end; <br>&nbsp; &nbsp; else; <br>&nbsp; end; <br><br>end; <br>exports <br>&nbsp; MouseWndProc, <br>&nbsp; InstallMouseHook, <br>&nbsp; UnWiseMouseHook; <br>begin <br>&nbsp; DllProc := @DllEntry; <br>&nbsp; DllEntry(DLL_PROCESS_ATTACH); <br>end. <br>-- <br>&nbsp; &nbsp; &nbsp; &nbsp;真的好想拍拍小翅膀, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;就飞上那晴朗的天空。 <br>&nbsp; 发信人: raphaelzl (小飞熊), 信区: Delphi <br>标 &nbsp;题: hook的exe部分的源程序 <br>发信站: BBS 水木清华站 (Sat Jan &nbsp;1 11:26:55 2000) <br>&nbsp; <br>unit U_MouseHook; <br>interface <br>uses <br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, <br>&nbsp; StdCtrls, U_Def; <br>type <br>&nbsp; TF_MouseHook = class(TForm) <br>&nbsp; &nbsp; Label1: TLabel; <br>&nbsp; &nbsp; e_MouseInfo: TEdit; <br>&nbsp; &nbsp; btn_HookMouse: TButton; <br>&nbsp; &nbsp; Label2: TLabel; <br>&nbsp; &nbsp; e_ExtTextOutA: TEdit; <br>&nbsp; &nbsp; btn_HookExtTextOutA: TButton; <br>&nbsp; &nbsp; procedure btn_HookMouseClick(Sender: TObject); <br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject); <br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction); <br>&nbsp; &nbsp; procedure btn_HookExtTextOutAClick(Sender: TObject); <br>&nbsp; private <br>&nbsp; &nbsp; fWndClosed, fbMouseHookInstalled : Boolean; <br>&nbsp; &nbsp; hMapObj : THandle; <br>&nbsp; &nbsp; pShMem : PShareMem; <br>&nbsp; &nbsp; procedure getMouseInfo(var theMess:TMessage); message WM_MOUSEPT; <br>&nbsp; public <br>&nbsp; &nbsp; { Public declarations } <br>&nbsp; end; <br>function InstallMouseHook(hInst : LongWord) : Boolean; external 'dll_HookMou <br>se.dll'; <br>function UnWiseMouseHook : Boolean; external 'dll_HookMouse.dll'; <br>function MouseWndProc(theWnd : HWND; theMess : Cardinal; wPar : wParam; lPar <br>&nbsp;: lParam): LResult; stdcall; external 'dll_HookMouse.dll'; <br>var <br>&nbsp; F_MouseHook: TF_MouseHook; <br>implementation <br>{$R *.DFM} <br>procedure TF_MouseHook.btn_HookMouseClick(Sender: TObject); <br>begin <br>&nbsp; if not fbMouseHookInstalled then <br>&nbsp; begin <br>&nbsp; &nbsp; fbMouseHookInstalled := InstallMouseHook(hInstance); <br>&nbsp; &nbsp; if fbMouseHookInstalled then <br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; btn_HookMouse.Caption := 'Stop!'; <br>&nbsp; &nbsp; &nbsp; btn_HookExtTextOutA.Enabled := True; <br>&nbsp; &nbsp; end &nbsp;else <br>&nbsp; &nbsp; &nbsp; ShowMessage('Cannot hook mouse!'); <br>&nbsp; end else <br>&nbsp; begin <br>&nbsp; &nbsp; fbMouseHookInstalled := not UnWiseMouseHook; <br>&nbsp; &nbsp; if not fbMouseHookInstalled then <br>&nbsp; &nbsp; begin <br>&nbsp; &nbsp; &nbsp; btn_HookMouse.Caption := 'Hook Mouse'; <br>&nbsp; &nbsp; &nbsp; btn_HookExtTextOutA.Enabled := False; <br>&nbsp; &nbsp; &nbsp; btn_HookExtTextOutA.Caption := 'Hook ExtTextOutA'; <br>&nbsp; &nbsp; &nbsp; pShMem^.bHookExtTextOutA := False; <br>&nbsp; &nbsp; &nbsp; FlushViewOfFile(pShMem, 0); <br>&nbsp; &nbsp; end else <br>&nbsp; &nbsp; &nbsp; ShowMessage('Cannot unhook mouse!'); <br>&nbsp; end; <br>end; <br>procedure TF_MouseHook.getMouseInfo(var theMess : TMessage); <br>begin <br>&nbsp; if fWndClosed then <br>&nbsp; &nbsp; Exit; <br>&nbsp; if theMess.LParam = 1 then //Get the Mouse info to display <br>&nbsp; &nbsp; e_MouseInfo.Text := 'X:' + IntToStr(pShMem^.pMouse.x) + ' ' + <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'Y:' + IntToStr(pShMem^.pMouse.y) + ' ' + <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'HWND:0x' + IntToHex(pShMem^.hHookWnd, 8) + ' ' + <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pShMem^.fStrMouseQueue <br>&nbsp; else if theMess.LParam = 2 then //Get the ExtTextOutA display <br>&nbsp; &nbsp; e_ExtTextOutA.Text := pShMem^.fStrExtTextOutA; <br>end; <br>procedure TF_MouseHook.FormCreate(Sender: TObject); <br>var <br>&nbsp; hModuleGDI : THandle; <br>&nbsp; wc : TWndClass; <br>begin <br>&nbsp; hMapObj := OpenFileMapping(FILE_MAP_WRITE, &nbsp; &nbsp; //Get full access of the ma <br>pping file <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;False, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//Not inheritable <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;LPCTSTR(MappingFileName)); &nbsp; //Name of the mapp <br>ing file <br>&nbsp; if hMapObj = 0 then <br>&nbsp; begin <br>&nbsp; &nbsp; ShowMessage('Cannot locate the Share Memory Block!'); <br>&nbsp; &nbsp; Halt; <br>&nbsp; end; <br>&nbsp; pShMem := PShareMem( MapViewOfFile(hMapObj, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FILE_MAP_WRITE, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, //hi_order offset where mapping begi <br>ns <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0, //lo_order offset where mapping begi <br>ns <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0) ); //Size of the mapping <br>&nbsp; if pShMem = nil then <br>&nbsp; begin <br>&nbsp; &nbsp; ShowMessage('Map File Mapping Failed! Error '+ IntToStr(GetLastError)); <br>&nbsp; &nbsp; CloseHandle(hMapObj); <br>&nbsp; &nbsp; Halt; <br>&nbsp; end; <br>&nbsp; FillChar(pShMem^, SizeOf(TShareMem), 0); <br>&nbsp; hModuleGDI := GetModuleHandle(PChar('GDI32')); <br>&nbsp; if hModuleGDI = 0 then <br>&nbsp; begin <br>&nbsp; &nbsp; ShowMessage('Cannot get module GDI32! Error ' + IntToStr(GetLastError)); <br>&nbsp; <br>&nbsp; &nbsp; UnmapViewOfFile(pShMem); <br>&nbsp; &nbsp; CloseHandle(hMapObj); <br>&nbsp; &nbsp; Halt; <br>&nbsp; end; <br>&nbsp; CopyMemory(@pShMem^.pOldExtTextOutA, GetProcAddress(hModuleGDI, PChar('Ext <br>TextOutA')), SizeOf(TLongJump)); <br>&nbsp; pShMem^.hProcWnd := Self.Handle; <br>&nbsp; GetWindowThreadProcessID(Self.Handle, @pShMem^.hProc); <br>&nbsp; pShMem^.bHookExtTextOutA := False; <br>&nbsp; pShMem^.bCanSpyNow := False; <br>&nbsp; fbMouseHookInstalled := False; <br>&nbsp; FlushViewOfFile(pShMem, 0); <br>&nbsp; wc.style &nbsp; &nbsp; &nbsp; &nbsp; := 0; <br>&nbsp; wc.lpfnWndProc &nbsp; := TFNWndProc(@MouseWndProc); <br>&nbsp; wc.cbClsExtra &nbsp; &nbsp;:= 0; <br>&nbsp; wc.cbWndExtra &nbsp; &nbsp;:= 0; <br>&nbsp; wc.hInstance &nbsp; &nbsp; := HInstance; <br>&nbsp; wc.hIcon &nbsp; &nbsp; &nbsp; &nbsp; := 0 ; <br>&nbsp; wc.hCursor &nbsp; &nbsp; &nbsp; := 0 ; <br>&nbsp; wc.hbrBackground := 0 ; <br>&nbsp; wc.lpszMenuName &nbsp;:= nil; <br>&nbsp; wc.lpszClassName := 'ZL_MOUSE_WND_PSEUDO'; <br>&nbsp; // register the class for the main window <br>&nbsp; Windows.RegisterClass(wc); <br>&nbsp; fWndClosed := False; <br>end; <br>procedure TF_MouseHook.FormClose(Sender: TObject; <br>&nbsp; var Action: TCloseAction); <br>begin <br>&nbsp; if fbMouseHookInstalled then <br>&nbsp; &nbsp; UnWiseMouseHook; <br>&nbsp; UnMapViewOfFile(pShMem); <br>&nbsp; CloseHandle(hMapObj); <br>&nbsp; Windows.UnRegisterClass('ZL_MOUSE_WND_PSEUDO', hInstance); <br>&nbsp; fWndClosed := True; <br>end; <br>procedure TF_MouseHook.btn_HookExtTextOutAClick(Sender: TObject); <br>begin <br>&nbsp; if pShMem^.bHookExtTextOutA then <br>&nbsp; &nbsp; btn_HookExtTextOutA.Caption := 'Hook ExtTextOutA' <br>&nbsp; else <br>&nbsp; &nbsp; btn_HookExtTextOutA.Caption := 'Stop!'; <br>&nbsp; pShMem^.bHookExtTextOutA := not pShMem^.bHookExtTextOutA; <br>&nbsp; FlushViewOfFile(pShMem, 0); <br>end; <br><br>//RaiseLastWin32Error can be used to create a GetLastError <br>//Message <br>end. <br>
 
多人接受答案了。
 
后退
顶部