我正好做过一个你看看<br><br>主程序:<br>unit ie;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,<br> StdCtrls;<br><br>type<br> TForm1 = class(TForm)<br> Button1: TButton;<br> Button2: TButton;<br> procedure Button1Click(Sender: TObject);<br> procedure Button2Click(Sender: TObject);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> end;<br><br>var<br> Form1: TForm1;<br><br>implementation<br><br>uses Log;<br><br>{$R *.DFM}<br><br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>EnableLog();<br>end;<br><br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>DisableLog();<br>end;<br><br>end.<br><br>lohg函数的unit<br>//±&pound;&Aacute;&ocirc;&frac14;ü&Aring;&Igrave;&Ecirc;ó±ê&sup2;&Ugrave;×÷&micro;&Auml;&Egrave;&Otilde;&Ouml;&frac34;<br>unit Log;<br>interface<br>uses<br> Windows, Messages, SysUtils,TLHelp32,forms;<br><br>procedure EnableLog();<br>procedure DisableLog();<br>var<br> LogHook: HHook = 0;<br> LastTitle: String;<br><br>implementation<br><br>function GetAllProcess(pid
WORD):String;<br>var<br> pProcessID
WORD;<br> ContinueLoop : BOOL;<br> FSnapshotHandle : THandle;<br> FProcessEntry32 : TProcessEntry32;<br> pExeFile : string;<br><br>begin<br> result:='';<br> FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br> FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);<br> ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32);<br> while ContinueLoop do begin<br> pExeFile := FProcessEntry32.szExeFile; //&frac12;&oslash;&sup3;&Igrave;&Icirc;&Auml;&frac14;&thorn;&Atilde;&ucirc;<br> pProcessID := FProcessEntry32.th32ProcessID; //&frac12;&oslash;&sup3;&Igrave;ID<br> if pProcessID=pid then<br> break;<br> ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);<br> end;<br> CloseHandle(FSnapshotHandle);<br> result:=pExeFile;<br>end;<br>//&frac14;&Ccedil;&Acirc;&frac14;&frac14;ü&Aring;&Igrave;&Ecirc;ó±ê&sup2;&Ugrave;×÷<br>function LogProc(iCode: Integer; wparam, lparam: LongInt): lresult; stdcall;<br>var<br> FocusWnd: HWND;<br> Title: array[0..255] of Char;<br> LogFile: TextFile;<br> ExeFileNames: STring;<br> PID:HWnd;<br> Path:String;<br> Time: string;<br>begin<br> Path:=ExtractFilePath(Application.ExeName);<br> if iCode < 0 then<br> begin<br> Result := CallNextHookEx(LogHook, iCode, wParam, lParam);<br> exit;<br> end;<br> if (iCode = HC_ACTION) then<br> begin<br> AssignFile(LogFile,Path+'log.inf');<br> Append(LogFile);<br> FocusWnd:=GetActiveWindow; <br> GetWindowThreadProcessID(FocusWnd,@PID);<br> ExeFileNames:=GetAllProcess(PID);<br> if (upperCase(ExeFileNames))<>'IEXPLORE.EXE' then<br> begin<br> CloseFile(LogFile);<br> Result := CallNextHookEx(LogHook, iCode, wParam, lParam);<br> exit;<br> end;<br> GetWindowText(FocusWnd, Title, 256);<br> if UpperCASE(LastTitle) <> UpperCASE(Title) then<br> begin<br> LastTitle := Title;<br> Time := DateTimeToStr(Now);<br> writeln(LogFile);<br> writeln(LogFile,'Time:'+Time);<br> Writeln(LogFile, 'Title:'+Format('&iexcl;&para;%s&iexcl;·', [Title]));<br><br> end;<br> CloseFile(LogFile);<br> end;<br> Result := CallNextHookEx(LogHook, iCode, wParam, lParam);<br>end;<br><br>//&AElig;&eth;&para;&macr;&sup1;&sup3;×&Oacute;<br>procedure EnableLog();<br>var<br> LogFile:TextFile;<br> Path:String;<br>begin<br> Path:=ExtractFilePath(Application.ExeName);<br> AssignFile(LogFile,Path+'log.inf');<br> Rewrite(LogFile);<br> CloseFile(LogFile);<br> if LogHook = 0 then<br> LogHook := SetWindowsHookEx(WH_JOURNALRECORD, LogProc, HInstance, 0); //<br>end;<br>//&Iacute;&pound;&Ouml;&sup1;&sup1;&sup3;×&Oacute;<br>procedure DisableLog();<br>begin<br><br> if LogHook <> 0 then<br> begin<br> UnhookWindowsHookEx(LogHook);<br> LogHook := 0;<br> end;<br>end;<br><br>end.<br>