//----------------------打码
rang:=((self.webbrowser1.Document as ihtmldocument2).body as htmlbody).createControlRange as ihtmlcontrolrange;
rang.add(yuansu as ihtmlcontrolelement );
rang.execCommand('Copy',False,0);
bitmap1:=tbitmap.Create;
bitmap1.Assign(clipboard);
// showmessage('3');
self.Image1.Picture.Assign(bitmap1);
// showmessage('4');
self.TcpClient1.RemoteHost :=trim(edit32.Text);
self.TcpClient1.RemotePort :=trim(edit33.Text);
// showmessage('5');
self.TcpClient1.Connect;
// showmessage('7');
neicun:=tmemorystream.Create;
bitmap1.SaveToStream(neicun);
bitmap1.Free;
neicun.Seek(0,0);
// showmessage('8');
self.TcpClient1.Sendln(IntToStr(neicun.Size)); //给对方发送文件大小
self.TcpClient1.SendStream(neicun); //发送文件流
neicun.Free;
sa:='11';
// showmessage('9');
i:=0;
zvm3:
i:=i+1;
if i>=30 then goto v0;
application.ProcessMessages;sleep(111); application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);
// showmessage('10');
if not TcpClient1.WaitForData(100) then goto zvm3;
// showmessage('11');
sa:=self.TcpClient1.Receiveln();
// showmessage('hahah'+sa);
// showmessage('客户端 验证码'+sa);
self.TcpClient1.Disconnect;//关闭连接
//============================打码
下面是服务器 哈哈
procedure TForm7.TcpServer1Accept(Sender: TObject;
ClientSocket: TCustomIpClient);
label v1,v2,v3,v4,v5,v6,v7,v8,v9,v0;
var
f : TmemoryStream; //文件流
iFileSize : Integer; //文件大小
iTotalRec : Integer; //总接收到的字节数,用来和文件大小比较,如果比文件大小的值要小,就还要继续接收
iacRec : Integer; //每一次ReceiveBuf实际接收到的字节数
pbuf : Pointer; //缓存指针
i : Integer;
fn : string; //文件名
h1,h2,h3:thandle; poi,poi2:tpoint; kk:integer;
begin
GetMem(pbuf,512); //我们一次最多也读取512字节
try
iTotalRec := 0; //先把总接收到的字节数置零
// fn := ClientSocket.Receiveln; //接收文件名
// showmessage(fn);
iFileSize := StrToInt(ClientSocket.Receiveln); //接收文件大小,接收到的字符串,要转成integer
// showmessage('服务端 文件大小'+inttostr(ifilesize));
f := tmemorystream.Create;
try
{如果接收到的总字节数小于文件总字节数且实际接收字节数不为-1就一直循环接收}
while iTotalRec < iFileSize do
begin
iacRec := ClientSocket.ReceiveBuf(pbuf^,512);//一次接收512字节
if iacRec = -1 then
Break;//如果实际接收字节数是-1表示出错了,退出循环(应该写个log,或作出错处理什么的)
f.Write(pbuf^,iacRec);//把接收到的数据写到文件流中
Inc(iTotalRec,iacRec);//叠加接收到的总字节数
end;
f.Seek(0,0);
self.Image1.AutoSize:=true;
self.Image1.Picture.Bitmap.LoadFromStream(f);
// showmessage('1');
f.Seek(0,0);
// showmessage('2');
form1:=tform1.Create(nil);
form1.Visible:=true;
if (IsIconic(Application.Handle)) then
Application.Restore;
SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
//保存鼠标位置,模拟点击窗口,然后再还原鼠标位置
GetCursorPos(poi);
poi2:= Point(0, 0);
Windows.ClientToScreen(Handle, poi2);
SetCursorPos(poi2.X, poi2.Y);
mouse_event(MOUSEEVENTF_LEFTDOWN, poi2.X, poi2.Y, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, poi2.X, poi2.Y, 0, 0);
dengdai(3,0);
SetCursorPos(poi.X, poi.Y);
// showmessage('3');
form1.Image1.AutoSize:=true;
// showmessage('4');
form1.Image1.Picture.Bitmap.LoadFromStream(f);
// showmessage('5');
//// form1.Visible:=true;
// form1.Show ;
kk:=0;
v0:
kk:=kk+1;
// if kk>=15 then begin form1.Button1.Click; yzm2:='nnnn' end;
h1:=findwindow(nil,'验证码2015');
application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);application.ProcessMessages;sleep(111);
if h1<>0 then goto v0;
// form1.Show;
// showmessage('4');
// ClientSocket.Sendln(yzm2);
ClientSocket.Sendln(yzm2);
// showmessage('5');
//
finally
f.Free; //释放流
end;
finally
FreeMem(pbuf);//释放内存
end;
end;