void __fastcall TForm1::NMStrm1HostResolved(TComponent *Sender)
{
StatusBar1-$#@62;SimpleText = "Host Resolved";
}
//---------------------------------------------------------------------------
//当文件发送到对方时产生此事件
void __fastcall TForm1::NMStrm1MessageSent(TObject *Sender)
{
ShowMessage("有文件发送到对方");
}
//---------------------------------------------------------------------------
//数据发送到对方时产生此事件
void __fastcall TForm1::NMStrm1PacketSent(TObject *Sender)
{
StatusBar1-$#@62;SimpleText = IntToStr(NMStrm1-$#@62;BytesRecvd)+" bytes of "
+NMStrm1-$#@62;BytesTotal+" sent";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMStrm1Status(TComponent *Sender,AnsiString Status)
{
if (StatusBar1 != 0)
StatusBar1-$#@62;SimpleText = Status;
}
//---------------------------------------------------------------------------
//没有主机名时产生此事件
void __fastcall TForm1::NMStrm1InvalidHost(bool &Handled)
{
AnsiString NewHost;
if (InputQuery("没有主机", "请输入要发送的主机名:", NewHost))
{
NMStrm1-$#@62;Host = NewHost;
Edit1-$#@62;Text=NewHost;
}
}
//---------------------------------------------------------------------------
//表示客户机已连接到服务器了
void __fastcall TForm1::NMStrmServ1ClientContact(TObject *Sender)
{
StatusBar1-$#@62;SimpleText = "Client Contacted";
}
//---------------------------------------------------------------------------
//接收客户端发送来的文件
void __fastcall TForm1::NMStrmServ1MSG(TComponent *Sender,
const AnsiString sFrom, TStream *strm)
{
if (FileExists(".\\tmp.bmp"))
DeleteFile(".\\tmp.bmp");
TFileStream *MyFStream;
MyFStream = new TFileStream(".\\tmp.bmp", fmCreate);
try
{
MyFStream-$#@62;CopyFrom(strm, strm-$#@62;Size);
}
catch(...)
{
}
MyFStream-$#@62;Free();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMStrmServ1Status(TComponent *Sender,
AnsiString Status)
{
if (StatusBar1 != 0)
StatusBar1-$#@62;SimpleText = Status;
}
//---------------------------------------------------------------------------
编好代码以后,编译源程序,在两台计算机上运行它就行了,每一方都可以做服务器或工作站,只要对方运行了该程序,都可以向其发送图象文件,也可以在单机上操作,快来试试吧!