- 积分
- 7
- 最后登录
- 2018-1-31
- 阅读权限
- 10
- 积分
- 7
- 帖子
- 27
- 精华
- 1
TA的每日心情 | 郁闷 2026-2-11 11:36 |
|---|
签到天数: 8 天 连续签到: 1 天 [LV.3]偶尔看看II 老百姓

- UID
- 14
- 小七币
- 33
- 贡献
- 2
- 在线时间
- 6 小时
- 注册时间
- 2011-12-26
|
Mainform.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Mainform.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
{
this->OpenDialog1->Filter="Text files(*.txt)|*.txt|All files(*.*)|*.*";
if(this->OpenDialog1->Execute())
{
this->Edit1->Text=this->OpenDialog1->FileName;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
if(this->Edit1->Text.Length()<1)
return;
if(this->Edit2->Text.Length()<1)
return;
TFileStream *MyFStream;
MyFStream=new TFileStream(this->Edit1->Text,fmOpenRead);
try
{
this->NMStrm1->Host=this->Edit2->Text;
this->NMStrm1->FromName="NetMasters";
this->NMStrm1->PostIt(MyFStream);
MessageBox(Handle,"发送文件到目标主机操作成功!","信息提示",MB_OK);
}
catch(...)
{
MessageBox(Handle,"发送文件到目标主机操作失败!","信息提示",MB_OK);
}
MyFStream->Free();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
this->Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::NMStrmServOnMSG(TComponent *Sender,
const AnsiString sFrom, TStream *strm)
{
if(this->SaveDialog1->Execute())
{
if(FileExists(this->SaveDialog1->FileName))
{
if(MessageBox(Handle,"目标文件已经存在,是否删除之?","信息提示",MB_YESNO)==IDNO)
{
return;
}
DeleteFile(this->SaveDialog1->FileName);
}
TFileStream *MyFStream;
//建立文件
MyFStream=new TFileStream(this->SaveDialog1->FileName,fmCreate);
try
{
MyFStream->CopyFrom(strm,strm->Size);
MessageBox(Handle,"接收目标主机发来的文件操作成功!","信息提示",MB_OK);
}
catch(...)
{
MessageBox(Handle,"接收目标主机发来的文件操作失败!","信息提示",MB_OK);
}
MyFStream->Free();
}
}
//---------------------------------------------------------------------------
Mainform.h
//---------------------------------------------------------------------------
#ifndef MainformH
#define MainformH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <Buttons.hpp>
#include <Dialogs.hpp>
#include <NMSTRM.hpp>
#include <Psock.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TEdit *Edit1;
TLabel *Label2;
TEdit *Edit2;
TBitBtn *BitBtn1;
TBitBtn *BitBtn2;
TBitBtn *BitBtn3;
TOpenDialog *OpenDialog1;
TSaveDialog *SaveDialog1;
TNMStrm *NMStrm1;
TNMStrmServ *NMStrmServ1;
void __fastcall BitBtn1Click(TObject *Sender);
void __fastcall BitBtn2Click(TObject *Sender);
void __fastcall BitBtn3Click(TObject *Sender);
void __fastcall NMStrmServOnMSG(TComponent *Sender,
const AnsiString sFrom, TStream *strm);
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
Transfer.cpp
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
//---------------------------------------------------------------------------
USEFORM("Mainform.cpp", Form1);
//---------------------------------------------------------------------------
WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
try
{
Application->Initialize();
Application->CreateForm(__classid(TForm1), &Form1);
Application->Run();
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
catch (...)
{
try
{
throw Exception("");
}
catch (Exception &exception)
{
Application->ShowException(&exception);
}
}
return 0;
}
//---------------------------------------------------------------------------
|
|