问题并不是太难,但问题太多,请分开发贴: WEB窗口的标题:得到IE窗口句柄,就可以得到标题。 地址栏的地址:得到IE地址栏句柄,就可以得到地址栏内容。 用户是否点击了其中的按钮:遍历控件 截取WEB窗口发往网站的消息:截取本地IP包 参考:旧贴:http://expert.csdn.net/Expert/topic/1201/1201326.xml?temp=.7150385 以下是得到别的程序的窗口句柄,改变窗口标题,要改变窗口文本框内容同样可以举一反三的例举设置了,程序如下: unit unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls, ExtCtrls;type TForm1 = class(TForm) button2: TButton; ListBox1: TListBox; Button1: TButton; procedure tutton2Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Timer1Timer(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}function GetText(Wnd : HWND) : string; var textlength : integer; text : PChar; begin textlength:=SendMessage(Wnd,WM_GETTEXTLENGTH,0,0); if textlength=0 then Result := '' else begin getmem(text,textlength+1); SendMessage(Wnd,WM_GETTEXT,textlength+1,Integer(text)); Result:=text; freemem(text); end; end; function EnumWindowsProc (Wnd: HWND; LParam: LPARAM): BOOL; stdcall; var st:string; begin Result := True; if (IsWindowVisible(Wnd)) and (GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) and (GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then begin st:=GetText(Wnd); Form1.Listbox1.items.add(st); end; end; procedure TForm1.tutton2Click(Sender: TObject); var Param : Longint; begin Form1.Listbox1.Clear; Param := 0 ; EnumWindows(@EnumWindowsProc , Param); end;procedure TForm1.Button1Click(Sender: TObject); function EnumChildWindowsProc(hwnd: Integer; lparam: Longint):Boolean; stdcall; var buffer: array[0..255] of Char; begin Result := True; GetClassName(hwnd,buffer,256); if StrPas(Buffer)='TEdit' then begin PInteger(lparam)^ := hwnd; Result:=False; end; end; var Handle: Integer; buffer: Array[0..1023] of Char; begin Handle := FindWindow(nil,pchar(Form1.listbox1.Items[listbox1.ItemIndex])); if Handle<>0 then begin EnumChildWindows(Handle,@EnumChildWindowsProc,Integer(@Handle)); SendMessage(Handle,WM_SETTEXT,0,Integer(pchar('这是我的文本'))); end; end;end. 取得IE地址栏的handle: var Form1: TForm1;implementation{$R *.DFM} Function GetURL(H:hwnd;lparam:longint):boolean;stdcall; var str,url:array [0..254] of char; begin getclassname(h,@str,255); if strpas(@str)='ComboBoxEx32' then // ComboBoxEx32可以改成Edit. begin SendMessage(h,WM_GETTEXT,255,LongInt(@url)); SendMessage(h,WM_SETTEXT,255,longint(pchar('http://www.sohu.com'))); Sendmessage(h,WM_KEYDOWN,VK_Return,1); //你说的是加这一句吗??不行啊。 改成Edit就可以,相当于在地址栏敲回车 form1.ListBox1.Items.Add(strpas(@url)); end; result:=true; end; function callbackproc(H:HWnd;lparam:longint):Boolean;stdcall; var str:array [1..255] of char; begin getclassname(h,@str,255); if ((strpas(@str)='CabinetWClass') or (strpas(@str)='IEFrame')) then begin Enumchildwindows(h,@GetURL,0); end; result:=true; end;procedure TForm1.findbuttonClick(Sender: TObject); begin listbox1.Clear; Enumwindows(@callbackproc,0); end;end.
对IE的WEB文档窗口控件等的监视可以通过定时对页面上的组件遍历,用IE的COM接口IHTMLDocument提供的方法get_URL我们可以得到和该网页相关的URL的地址值,通过get_forms方法可以该网页中所有的Form对象的集合等,一下例子:function EnumChildWindowsProc(hwnd: Integer; lparam: Longint): Boolean; stdcall; var buffer: array[0..255] of char; begin Result := True; GetClassName(hwnd,buffer,256); if StrPas(Buffer)='Edit' then begin PInteger(lparam)^ := hwnd; Result:=False; end; end;procedure TForm1.Button1Click(Sender: TObject); var hwnd: Integer; buffer: array[0..255] of char; begin hwnd := FindWindow('CabinetWClass',nil); if hwnd<>0 then begin EnumChildWindows(hwnd,@EnumChildWindowsProc,Integer(@hwnd)); StrPCopy(buffer,Edit1.Text); SendMessage(hwnd,WM_SETTEXT,0,Integer(@buffer[0])); end; end;
WEB窗口的标题:得到IE窗口句柄,就可以得到标题。
地址栏的地址:得到IE地址栏句柄,就可以得到地址栏内容。
用户是否点击了其中的按钮:遍历控件
截取WEB窗口发往网站的消息:截取本地IP包
参考:旧贴:http://expert.csdn.net/Expert/topic/1201/1201326.xml?temp=.7150385
以下是得到别的程序的窗口句柄,改变窗口标题,要改变窗口文本框内容同样可以举一反三的例举设置了,程序如下:
unit unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ComCtrls, ExtCtrls;type
TForm1 = class(TForm)
button2: TButton;
ListBox1: TListBox;
Button1: TButton;
procedure tutton2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}function GetText(Wnd : HWND) : string;
var
textlength : integer;
text : PChar;
begin
textlength:=SendMessage(Wnd,WM_GETTEXTLENGTH,0,0);
if textlength=0 then
Result := ''
else begin
getmem(text,textlength+1);
SendMessage(Wnd,WM_GETTEXT,textlength+1,Integer(text));
Result:=text;
freemem(text);
end;
end;
function EnumWindowsProc (Wnd: HWND; LParam: LPARAM): BOOL; stdcall;
var
st:string;
begin
Result := True;
if (IsWindowVisible(Wnd)) and (GetWindowLong(Wnd, GWL_HWNDPARENT) = 0) and (GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then begin
st:=GetText(Wnd);
Form1.Listbox1.items.add(st);
end;
end;
procedure TForm1.tutton2Click(Sender: TObject);
var
Param : Longint;
begin
Form1.Listbox1.Clear;
Param := 0 ;
EnumWindows(@EnumWindowsProc , Param);
end;procedure TForm1.Button1Click(Sender: TObject);
function EnumChildWindowsProc(hwnd: Integer; lparam: Longint):Boolean; stdcall;
var
buffer: array[0..255] of Char;
begin
Result := True;
GetClassName(hwnd,buffer,256);
if StrPas(Buffer)='TEdit' then
begin
PInteger(lparam)^ := hwnd;
Result:=False;
end;
end;
var
Handle: Integer;
buffer: Array[0..1023] of Char;
begin
Handle := FindWindow(nil,pchar(Form1.listbox1.Items[listbox1.ItemIndex]));
if Handle<>0 then
begin
EnumChildWindows(Handle,@EnumChildWindowsProc,Integer(@Handle));
SendMessage(Handle,WM_SETTEXT,0,Integer(pchar('这是我的文本')));
end;
end;end.
取得IE地址栏的handle:
var
Form1: TForm1;implementation{$R *.DFM}
Function GetURL(H:hwnd;lparam:longint):boolean;stdcall;
var str,url:array [0..254] of char;
begin
getclassname(h,@str,255);
if strpas(@str)='ComboBoxEx32' then // ComboBoxEx32可以改成Edit.
begin
SendMessage(h,WM_GETTEXT,255,LongInt(@url));
SendMessage(h,WM_SETTEXT,255,longint(pchar('http://www.sohu.com')));
Sendmessage(h,WM_KEYDOWN,VK_Return,1);
//你说的是加这一句吗??不行啊。 改成Edit就可以,相当于在地址栏敲回车
form1.ListBox1.Items.Add(strpas(@url));
end;
result:=true;
end;
function callbackproc(H:HWnd;lparam:longint):Boolean;stdcall;
var str:array [1..255] of char;
begin
getclassname(h,@str,255);
if ((strpas(@str)='CabinetWClass') or (strpas(@str)='IEFrame')) then
begin
Enumchildwindows(h,@GetURL,0);
end;
result:=true;
end;procedure TForm1.findbuttonClick(Sender: TObject);
begin
listbox1.Clear;
Enumwindows(@callbackproc,0);
end;end.
var
buffer: array[0..255] of char;
begin
Result := True;
GetClassName(hwnd,buffer,256);
if StrPas(Buffer)='Edit' then
begin
PInteger(lparam)^ := hwnd;
Result:=False;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
hwnd: Integer;
buffer: array[0..255] of char;
begin
hwnd := FindWindow('CabinetWClass',nil);
if hwnd<>0 then
begin
EnumChildWindows(hwnd,@EnumChildWindowsProc,Integer(@hwnd));
StrPCopy(buffer,Edit1.Text);
SendMessage(hwnd,WM_SETTEXT,0,Integer(@buffer[0]));
end;
end;
不需要截取ip包,只需要写一个Pluggable Protocol截取http的所有连接。
http://www.csdn.net/Develop/Read_Article.asp?Id=6351