请各位指点!!!用钩子记录下打开过的所有的网页窗口标题栏名称 (100分)

  • 主题发起人 主题发起人 yahle
  • 开始时间 开始时间
好象把它搞的太复杂了吧<br>如果只要"记录下打开过的所有的网页窗口标题栏名称"<br>是不需要钩子的<br>另有别径<br>只要获取所有当前的窗口标题,再判断是不是浏览器的就行了
 
每产生一个窗口,记录一次<br>不是一次性记录
 
我正好做过一个你看看<br><br>主程序:<br>unit ie;<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; Button1: TButton;<br>&nbsp; &nbsp; Button2: TButton;<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; &nbsp; procedure Button2Click(Sender: TObject);<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><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>//±&amp;pound;&amp;Aacute;&amp;ocirc;&amp;frac14;ü&amp;Aring;&amp;Igrave;&amp;Ecirc;ó±ê&amp;sup2;&amp;Ugrave;×÷&amp;micro;&amp;Auml;&amp;Egrave;&amp;Otilde;&amp;Ouml;&amp;frac34;<br>unit Log;<br>interface<br>uses<br>&nbsp; Windows, Messages, SysUtils,TLHelp32,forms;<br><br>procedure EnableLog();<br>procedure DisableLog();<br>var<br>&nbsp; LogHook: HHook = 0;<br>&nbsp; LastTitle: String;<br><br>implementation<br><br>function GetAllProcess(pid:DWORD):String;<br>var<br>&nbsp; pProcessID &nbsp; &nbsp; &nbsp;:DWORD;<br>&nbsp; ContinueLoop &nbsp; &nbsp;: BOOL;<br>&nbsp; FSnapshotHandle : THandle;<br>&nbsp; FProcessEntry32 : TProcessEntry32;<br>&nbsp; pExeFile : string;<br><br>begin<br>&nbsp; result:='';<br>&nbsp; FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);<br>&nbsp; FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);<br>&nbsp; ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32);<br>&nbsp; while ContinueLoop do begin<br>&nbsp; &nbsp; pExeFile := FProcessEntry32.szExeFile; &nbsp; &nbsp; &nbsp; &nbsp; //&amp;frac12;&amp;oslash;&amp;sup3;&amp;Igrave;&amp;Icirc;&amp;Auml;&amp;frac14;&amp;thorn;&amp;Atilde;&amp;ucirc;<br>&nbsp; &nbsp; pProcessID := FProcessEntry32.th32ProcessID; &nbsp; //&amp;frac12;&amp;oslash;&amp;sup3;&amp;Igrave;ID<br>&nbsp; &nbsp; if pProcessID=pid then<br>&nbsp; &nbsp; &nbsp; break;<br>&nbsp; &nbsp; ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);<br>&nbsp; end;<br>&nbsp; CloseHandle(FSnapshotHandle);<br>&nbsp; result:=pExeFile;<br>end;<br>//&amp;frac14;&amp;Ccedil;&amp;Acirc;&amp;frac14;&amp;frac14;ü&amp;Aring;&amp;Igrave;&amp;Ecirc;ó±ê&amp;sup2;&amp;Ugrave;×÷<br>function LogProc(iCode: Integer; wparam, lparam: LongInt): lresult; stdcall;<br>var<br>&nbsp; FocusWnd: HWND;<br>&nbsp; Title: array[0..255] of Char;<br>&nbsp; LogFile: TextFile;<br>&nbsp; ExeFileNames: STring;<br>&nbsp; PID:HWnd;<br>&nbsp; Path:String;<br>&nbsp; Time: string;<br>begin<br>&nbsp; Path:=ExtractFilePath(Application.ExeName);<br>&nbsp; if iCode &lt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; Result := CallNextHookEx(LogHook, iCode, wParam, lParam);<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br>&nbsp; if (iCode = HC_ACTION) then<br>&nbsp; begin<br>&nbsp; &nbsp; AssignFile(LogFile,Path+'log.inf');<br>&nbsp; &nbsp; Append(LogFile);<br>&nbsp; &nbsp; FocusWnd:=GetActiveWindow; &nbsp; <br>&nbsp; &nbsp; GetWindowThreadProcessID(FocusWnd,@PID);<br>&nbsp; &nbsp; ExeFileNames:=GetAllProcess(PID);<br>&nbsp; &nbsp; if (upperCase(ExeFileNames))&lt;&gt;'IEXPLORE.EXE' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseFile(LogFile);<br>&nbsp; &nbsp; &nbsp; &nbsp; Result := CallNextHookEx(LogHook, iCode, wParam, lParam);<br>&nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; GetWindowText(FocusWnd, Title, 256);<br>&nbsp; &nbsp;if UpperCASE(LastTitle) &lt;&gt; UpperCASE(Title) then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; LastTitle := Title;<br>&nbsp; &nbsp; &nbsp; &nbsp; Time := DateTimeToStr(Now);<br>&nbsp; &nbsp; &nbsp; &nbsp; writeln(LogFile);<br>&nbsp; &nbsp; &nbsp; &nbsp; writeln(LogFile,'Time:'+Time);<br>&nbsp; &nbsp; &nbsp; &nbsp; Writeln(LogFile, 'Title:'+Format('&amp;iexcl;&amp;para;%s&amp;iexcl;·', [Title]));<br><br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp;CloseFile(LogFile);<br>&nbsp; &nbsp;end;<br>&nbsp; Result := CallNextHookEx(LogHook, iCode, wParam, lParam);<br>end;<br><br>//&amp;AElig;&amp;eth;&amp;para;&amp;macr;&amp;sup1;&amp;sup3;×&amp;Oacute;<br>procedure EnableLog();<br>var<br>&nbsp; LogFile:TextFile;<br>&nbsp; Path:String;<br>begin<br>&nbsp; Path:=ExtractFilePath(Application.ExeName);<br>&nbsp; AssignFile(LogFile,Path+'log.inf');<br>&nbsp; Rewrite(LogFile);<br>&nbsp; CloseFile(LogFile);<br>&nbsp; if LogHook = 0 then<br>&nbsp; &nbsp; LogHook := SetWindowsHookEx(WH_JOURNALRECORD, LogProc, HInstance, 0); &nbsp; &nbsp;//<br>end;<br>//&amp;Iacute;&amp;pound;&amp;Ouml;&amp;sup1;&amp;sup1;&amp;sup3;×&amp;Oacute;<br>procedure DisableLog();<br>begin<br><br>&nbsp; if LogHook &lt;&gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; UnhookWindowsHookEx(LogHook);<br>&nbsp; &nbsp; LogHook := 0;<br>&nbsp; end;<br>end;<br><br>end.<br>
 
To cnaoszh<br>你的程序有以下不足:<br>1当用户不是用IE,比如用MYIE2时无法记录<br>2每次记录与上一个窗口不同的激活窗口,当用户2个窗口之间来回的切换n次时,会记录2n次,但实际只要记录两次即可<br><br>我的想法是:<br>SetWindowsHookEx(WH_SHELL, &nbsp;shellproc, HInstance, &nbsp;0);<br><br>在shellProc中当产生一个窗口1(iCode=HSHELL_WINDOWCREATED) 时,将 lastHandle对应的上一个窗口信息记录到文本中, lastHandle=窗口1的句柄 如此重复,除了最后一个,其他的都可以记录,而且记录的数量不多<br>
 
虽然问题未完全解决,<br>但是发出这么久了,<br>还是把贴给了
 
多人接受答案了。
 
后退
顶部