1,594
社区成员
发帖
与我相关
我的任务
分享unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Timer1: TTimer;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
OldProc: Pointer;
ThreadCount: integer;
id: Thandle;
Suc: integer;
implementation
{$R *.dfm}
procedure MyProcedure();
var
idhttp1: Tidhttp;
s: string;
username, pass, email: string;
Params: TStringStream;
tmp: string;
begin
try
InterlockedIncrement(ThreadCount);
idhttp1 := Tidhttp.Create(nil);
idhttp1.Request.UserAgent :=
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Maxthon; .NET CLR 1.1.4322)';
s := idhttp1.get('http://www.baidu.com');
tmp := '百度';
if pos(tmp, s) <> 0 then
begin
Windows.SendMessage(Form1.Handle, Messages.WM_USER + 100,
integer(PChar(tmp)), 0);
end;
InterlockedDecrement(ThreadCount);
InterlockedIncrement(Suc);
finally
idhttp1.Free;
Windows.CreateThread(nil, 0, @MyProcedure, nil, 0, id);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
begin
// for i := 1 to 2 do
Windows.CreateThread(nil, 0, @MyProcedure, nil, 0, id)
// MyProcedure();
end;
function NewProc(hwnd, msg, wParam, lParam: longint): LRESULT; stdcall;
begin
case msg of
Messages.WM_USER + 100:
begin
Form1.Label1.caption := PChar(wParam);
Form1.Label2.caption := IntToStr(Suc);
end;
end;
Result := Windows.CallWindowProc(OldProc, hwnd, msg, wParam, lParam);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
OldProc := Pointer(Windows.setwindowlong(self.Handle, Windows.GWL_WNDPROC,
longint(@NewProc)));
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Label3.caption := IntToStr(ThreadCount);
end;
end.