⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 filetransdlg.cpp

📁 visual c++ 实例编程
💻 CPP
字号:
// FileTransDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FileTrans.h"
#include "FileTransDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// FileTransDlg dialog

FileTransDlg::FileTransDlg(CWnd* pParent /*=NULL*/)
	: CDialog(FileTransDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(FileTransDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	this->m_phTCPListenThreadParam	=NULL;
	this->m_phUDPListenThreadParam	=NULL;
	this->m_sockConnect				=INVALID_SOCKET;
}

void FileTransDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(FileTransDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	DDX_Control(pDX, IDC_BTNUDPSEND, m_btnUdpSend);
	DDX_Control(pDX, IDC_BTNUDPRECV, m_btnUdpRecv);
	DDX_Control(pDX, IDC_BTNUDPLISTEN, m_btnUdpListen);
	DDX_Control(pDX, IDC_BTNTCPSEND, m_btnTcpSend);
	DDX_Control(pDX, IDC_BTNTCPRECV, m_btnTcpRecv);
	DDX_Control(pDX, IDC_BTNTCPLISTEN, m_btnTcpListen);
	DDX_Control(pDX, IDC_BTNJOIN, m_btnJoin);
	DDX_Control(pDX, IDC_COMBOIP, m_comboIP);
	DDX_Control(pDX, IDC_CHECKNET, m_checkNet);
	DDX_Control(pDX, IDC_CHECKCRC, m_checkCrc);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(FileTransDlg, CDialog)
	//{{AFX_MSG_MAP(FileTransDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BTNJOIN, OnBtnjoin)
	ON_BN_CLICKED(IDC_BTNTCPLISTEN, OnBtntcplisten)
	ON_BN_CLICKED(IDC_BTNTCPRECV, OnBtntcprecv)
	ON_BN_CLICKED(IDC_BTNUDPLISTEN, OnBtnudplisten)
	ON_BN_CLICKED(IDC_BTNUDPRECV, OnBtnudprecv)
	//}}AFX_MSG_MAP
	ON_MESSAGE(BitSpider::MSG_SENDCOMPLETE,OnSendComplete)
	ON_MESSAGE(BitSpider::MSG_GETFILENAME,OnGetFilename)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// FileTransDlg message handlers

BOOL FileTransDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	this->m_btnTcpSend.EnableWindow(FALSE);
	this->m_btnUdpSend.EnableWindow(FALSE);
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void FileTransDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR FileTransDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void FileTransDlg::OnBtntcplisten() 
{
	// TODO: Add your control notification handler code here
	//禁止重新选择连接类型
	this->m_checkNet.EnableWindow(FALSE);

	//禁止监听按钮
	this->m_btnTcpListen.EnableWindow(FALSE);

	this->m_phTCPListenThreadParam				=new BitSpider::_SENDTHREADPARAM();
	this->m_phTCPListenThreadParam->hwnd		=this->m_hWnd;
	this->m_phTCPListenThreadParam->bInternet	=(this->m_checkNet.GetCheck())?false:true;
	this->m_phTCPListenThreadParam->wPort		=TCPLISTEN_PORT;
	this->m_phTCPListenThreadParam->pFunc		=NULL;
	this->m_phTCPListenThreadParam->pThread		=::AfxBeginThread(BitSpider::TCPListenThread,(LPVOID)this->m_phTCPListenThreadParam);
}

LRESULT FileTransDlg::OnSendComplete(WPARAM wParam, LPARAM lParam)
{
	//允许重新选择是否校验
	this->m_checkCrc.EnableWindow();
	return 0;
};

LRESULT FileTransDlg::OnGetFilename(WPARAM wParam, LPARAM lParam)
{
	//打开对话框,选择需要被传送的文件名

	BitSpider::_FILEDETAIL& fd	=*(BitSpider::_FILEDETAIL*)wParam;
	CFileDialog fileDialog(TRUE,NULL,fd.strFilename,OFN_PATHMUSTEXIST | OFN_HIDEREADONLY | OFN_FILEMUSTEXIST);
	if(fileDialog.DoModal()==IDOK)
	{
		//得到被选择的文件名
		fd.strPathname	=fileDialog.GetPathName();
	}
	return 0;
};

void FileTransDlg::OnBtntcprecv() 
{
	// TODO: Add your control notification handler code here
	POINT point;
	CWnd* pWnd;
	int	row		=15;
	int delta	=BitSpider::WND_HEIGHT+5;
	point.x		=850;
	for(;row<500;row+=delta)
	{
		point.y	=row;
		pWnd	=CWnd::WindowFromPoint(point);
		if(pWnd!=NULL)
		{
			if(pWnd->GetParent()==this)
				continue;
		}

		//如果找到了一个空的位置
		BitSpider*	bs		=new BitSpider;
		
		int nScreenWidth	=BitSpider::GetScreenWidth();

		bs->Create(nScreenWidth-180,row,170,this);
		bs->ShowWindow(SW_SHOW);
		bs->m_bInternet	=(this->m_checkNet.GetCheck())?false:true;

		//打开对话框,选择需要下载的文件名
		CFileDialog fileDialog(FALSE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST);
		if(fileDialog.DoModal()==IDOK)
		{
			//得到被选择的文件名
			bs->RunSpider(fileDialog.GetFileName(),fileDialog.GetPathName(),bs->m_hWnd,3);
		}
		break;
	}
}

void FileTransDlg::OnBtnjoin() 
{
	// TODO: Add your control notification handler code here
	if(BitSpider::pCurrRecvWnd!=NULL)
	{
		CString str;
		this->m_comboIP.GetWindowText(str);
		if(str=="")
		{
			::AfxMessageBox("请首先选择一个IP或者输入一个新的IP,然后再点击加入按钮。");
			return;
		}
		if(BitSpider::pCurrRecvWnd->AddIP(str,(BitSpider::pCurrRecvWnd->IsUDP())?UDPLISTEN_PORT:TCPLISTEN_PORT))
		{
			if(this->m_comboIP.GetCurSel()<0)
				this->m_comboIP.AddString(str);
		}
	}
}

void FileTransDlg::OnBtnudplisten() 
{
	// TODO: Add your control notification handler code here
	//禁止重新选择连接类型
	this->m_checkNet.EnableWindow(FALSE);

	//禁止监听按钮
	this->m_btnUdpListen.EnableWindow(FALSE);

	this->m_phUDPListenThreadParam				=new BitSpider::_SENDTHREADPARAM();
	this->m_phUDPListenThreadParam->hwnd		=this->m_hWnd;
	this->m_phUDPListenThreadParam->bInternet	=(this->m_checkNet.GetCheck())?false:true;
	this->m_phUDPListenThreadParam->wPort		=UDPLISTEN_PORT;
	this->m_phUDPListenThreadParam->pFunc		=NULL;
	this->m_phUDPListenThreadParam->pThread		=::AfxBeginThread(BitSpider::UDPListenThread,(LPVOID)this->m_phUDPListenThreadParam);
}

void FileTransDlg::OnBtnudprecv() 
{
	// TODO: Add your control notification handler code here
	POINT point;
	CWnd* pWnd;
	int	row		=15;
	int delta	=BitSpider::WND_HEIGHT+5;
	point.x		=850;
	for(;row<500;row+=delta)
	{
		point.y	=row;
		pWnd	=CWnd::WindowFromPoint(point);
		if(pWnd!=NULL)
		{
			if(pWnd->GetParent()==this)
				continue;
		}

		//如果找到了一个空的位置
		BitSpider*	bs		=new BitSpider;
		
		int nScreenWidth	=BitSpider::GetScreenWidth();

		bs->Create(nScreenWidth-180,row,170,this);
		bs->ShowWindow(SW_SHOW);
		bs->m_bInternet	=(this->m_checkNet.GetCheck())?false:true;

		//打开对话框,选择需要下载的文件名
		CFileDialog fileDialog(FALSE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST);
		if(fileDialog.DoModal()==IDOK)
		{
			//得到被选择的文件名
			bs->RunSpider(fileDialog.GetFileName(),fileDialog.GetPathName(),bs->m_hWnd,3,0,true);
		}
		break;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -