📄 client.h
字号:
#if !defined(AFX_CLIENT_H__F1BBF9D0_536F_487D_8DDA_B230047CA79C__INCLUDED_)
#define AFX_CLIENT_H__F1BBF9D0_536F_487D_8DDA_B230047CA79C__INCLUDED_
#include "Global.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Client.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CClient command target
class CClient : public CSocket
{
public:
class RECV_BUF_INFO
{
public:
enum{MAX_BUF_LEN = 32*1024};
RECV_BUF_INFO()
{
pBuf = new char[MAX_BUF_LEN];
ASSERT(pBuf);
ASSERT(AfxIsValidAddress(pBuf, MAX_BUF_LEN));
nLeft = 0;
};
virtual ~RECV_BUF_INFO()
{
if(pBuf)
delete []pBuf;
};
public:
char* pBuf;
int nLeft;
};
class COMMAND_INFO
{
public:
COMMAND_INFO()
{
pCmd = NULL;
nPos = 0;
nLen = 0;
};
virtual ~COMMAND_INFO()
{
if(pCmd)
delete []pCmd;
};
void ResetBufLen(int nNewLen)
{
if(pCmd)
{
delete []pCmd;
pCmd = NULL;
}
if(nNewLen > 0)
{
pCmd = new char[nNewLen];
ASSERT(pCmd);
}
nPos = 0;
nLen = nNewLen;
};
public:
char* pCmd;
int nPos;
int nLen;
};
class TF_INFO
{
public:
TF_INFO()
{
pFile = NULL;
dwFileLen = 0;
dwReceivedLen = 0;
posNext = NULL;
};
virtual ~TF_INFO()
{
if(pFile && pFile->m_hFile != CFile::hFileNull)
pFile->Close();
if(pFile)
{
delete pFile;
pFile = NULL;
}
dwFileLen = 0;
dwReceivedLen = 0;
posNext = NULL;
};
CString strFileName;
CFile* pFile;
DWORD dwFileLen;
DWORD dwReceivedLen;
POSITION posNext; //当前文件的下一文件在下载列表中的位置
};
struct FILE_INFO
{
CString strFileName; //文件名
DWORD dwFileSize; //文件大小
CTime tmFileCreated; //文件创建时间
};
// Attributes
public:
CWnd* m_pParent;
CPtrList m_listAvailableFiles; //可供下载的文件信息链表,FILE_INFO结构
CStringList m_listExpectedFiles; //需下载的文件信息链表
TF_INFO m_CurFile; //当前正在下载的文件信息
// Operations
public:
CClient();
virtual ~CClient();
// Overrides
public:
BOOL m_bCanceled;
void CloseSocket();
int ExtractCommand(void* pData, int nLen);
void AttemptToDisconnect();
BOOL AttemptToConnect(CString strIP, UINT uPort);
BOOL InitDownload();
void ReceiveData();
void SetParent(CWnd* pParent);
void RequestBrowse();
void RequestDownloadNext();
void CancelTransfer();
void OnBrowseFiles();
void OnDownloadFile();
void OnTransferFile(int nFileDataLen);
void TerminateTransfer();
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CClient)
public:
virtual void OnClose(int nErrorCode);
virtual void OnReceive(int nErrorCode);
//}}AFX_VIRTUAL
// Generated message map functions
//{{AFX_MSG(CClient)
// NOTE - the ClassWizard will add and remove member functions here.
//}}AFX_MSG
// Implementation
protected:
void HandleCommand();
void CleanupAvailableFilesList();
void TransferResponse(BYTE nErrorFlag);
RECV_BUF_INFO m_Data;
COMMAND_INFO m_CurCmd;
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_CLIENT_H__F1BBF9D0_536F_487D_8DDA_B230047CA79C__INCLUDED_)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -