
代码:
UINT CSendFDlg::Send(LPVOID lpParam)
{
CSendFDlg * ths = (CSendFDlg *)lpParam;
bool isFileEof = false;
long pos;
CString str;
long lReadNum = 0;
while (!isFileEof)
{
pos = ths->m_file.Read(ths->data,1);
if (lReadNum == ths->m_lFileLength)
{
isFileEof = true;
}
if (!isFileEof)
{
lReadNum++;
ths->data++;
ths->m_ctl_progress_sendfile.OffsetPos(1);
}
str.Format("%d",lReadNum);
ths->GetDlgItem(IDC_STATIC_POS)->SetWindowText(str);
}
return 0;
}
{
isFileEof = true;
}
if (!isFileEof)
{
lReadNum++;
ths->data++;
ths->m_ctl_progress_sendfile.OffsetPos(1);
}
str.Format("%d",lReadNum);
ths->GetDlgItem(IDC_STATIC_POS)->SetWindowText(str);
}
return 0;
}
void CSendFDlg::OnButtonStartSend()
{
// 分批读入流文件,每次发送0x 00 00 00 01之前的部分
bs_t bst;
//bs_init( &bsp, data, i_data )
{
// 分批读入流文件,每次发送0x 00 00 00 01之前的部分
bs_t bst;
//bs_init( &bsp, data, i_data )
//根据文件大小设置进度条范围
if(m_file.Open(m_strFilePath,CFile::modeRead)==0)
{
;
}
else
{
if(m_file.Open(m_strFilePath,CFile::modeRead)==0)
{
;
}
else
{
m_lFileLength = m_file.GetLength();
//显示文件信息
CString str;
str.Format("%s :%d Byte",m_file.GetFilePath(),m_file.GetLength());
GetDlgItem(IDC_STATIC_FILE_MSG)->SetWindowText(str);
//显示文件信息
CString str;
str.Format("%s :%d Byte",m_file.GetFilePath(),m_file.GetLength());
GetDlgItem(IDC_STATIC_FILE_MSG)->SetWindowText(str);
//设置进度条范围和增量
str.Format("%d",m_file.GetLength());
GetDlgItem(IDC_STATIC_UPPER)->SetWindowText(str);
m_ctl_progress_sendfile.SetRange32( 0, m_file.GetLength());
}
str.Format("%d",m_file.GetLength());
GetDlgItem(IDC_STATIC_UPPER)->SetWindowText(str);
m_ctl_progress_sendfile.SetRange32( 0, m_file.GetLength());
}
AfxBeginThread( Send, this);//另一种,调用类的静态成员函数
}
BOOL CSendFDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
//初始化
m_ctl_progress_sendfile.SetRange32( 0, 100);//为进度条控件设置范围的最小值和最大值,并重画进度条来反映新的范围,默认为0~100
m_ctl_progress_sendfile.SetStep(1);//为一个进度条控件指定每一步的增量,返回原来步长
m_ctl_progress_sendfile.SetPos(0);// 设置进度条的当前位置并重画进度条来反映新的位置
m_ctl_progress_sendfile.OffsetPos(10);//用一个指定的增量来增加进度条控件的当前位置,并重画此进度条来反映新的位置
// 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
//初始化
m_ctl_progress_sendfile.SetRange32( 0, 100);//为进度条控件设置范围的最小值和最大值,并重画进度条来反映新的范围,默认为0~100
m_ctl_progress_sendfile.SetStep(1);//为一个进度条控件指定每一步的增量,返回原来步长
m_ctl_progress_sendfile.SetPos(0);// 设置进度条的当前位置并重画进度条来反映新的位置
m_ctl_progress_sendfile.OffsetPos(10);//用一个指定的增量来增加进度条控件的当前位置,并重画此进度条来反映新的位置
m_strFilePath = "c:\\tmp.x264";
m_lFileLength = 0;
//目标地址
m_ctl_IP_Dst.SetAddress(127,0,0,1);
m_i_dst_port=8000;
m_lFileLength = 0;
//目标地址
m_ctl_IP_Dst.SetAddress(127,0,0,1);
m_i_dst_port=8000;
data = (uint8_t *)malloc(DATA_MAX);
memset(data,0,DATA_MAX);
memset(data,0,DATA_MAX);
this->UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
return TRUE; // return TRUE unless you set the focus to a control
}
以下为头文件代码:
class CSendFDlg : public CDialog
{
// Construction
public:
{
// Construction
public:
CFile m_file;
CSendFDlg(CWnd* pParent = NULL); // standard constructor
uint8_t *data; //发送缓冲区指针
uint8_t i_data; //发送缓冲区中有效比特数
long m_lFileLength; //文件长度
static UINT Send(LPVOID lpParam);
// Dialog Data
//{{AFX_DATA(CSendFDlg)
enum { IDD = IDD_SENDF_DIALOG };
CIPAddressCtrl m_ctl_IP_Dst;
CProgressCtrl m_ctl_progress_sendfile;
CString m_strFilePath;
int m_i_dst_port;
//}}AFX_DATA
CSendFDlg(CWnd* pParent = NULL); // standard constructor
uint8_t *data; //发送缓冲区指针
uint8_t i_data; //发送缓冲区中有效比特数
long m_lFileLength; //文件长度
static UINT Send(LPVOID lpParam);
// Dialog Data
//{{AFX_DATA(CSendFDlg)
enum { IDD = IDD_SENDF_DIALOG };
CIPAddressCtrl m_ctl_IP_Dst;
CProgressCtrl m_ctl_progress_sendfile;
CString m_strFilePath;
int m_i_dst_port;
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSendFDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
//{{AFX_VIRTUAL(CSendFDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
HICON m_hIcon;
protected:
HICON m_hIcon;
// Generated message map functions
//{{AFX_MSG(CSendFDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnButtonBrowse();
afx_msg void OnButtonStartSend();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_MSG(CSendFDlg)
virtual BOOL OnInitDialog();
afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
afx_msg void OnPaint();
afx_msg HCURSOR OnQueryDragIcon();
afx_msg void OnButtonBrowse();
afx_msg void OnButtonStartSend();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};