📄 filesend1dlg.cpp
字号:
ON_MESSAGE(WM_SENDSERIAL1,OnSendSerial1)
ON_MESSAGE(WM_SENDSERIAL2,OnSendSerial2)
ON_MESSAGE(WM_SENDSERIAL3,OnSendSerial3)
ON_MESSAGE(WM_SENDSERIAL4,OnSendSerial4)
ON_MESSAGE(WM_SENDSERIAL5,OnSendSerial5)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFilesend1Dlg message handlers
BOOL CFilesend1Dlg::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);
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);
}
}
//SetDialogBkColor(RGB(192.192.192));
// 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
///////////////////////////////////////////////////////////////////////
cont1="D:\\GH\\Channels\\ChannelInfo\\Channel_1\\";
cont2="D:\\GH\\Channels\\ChannelInfo\\Channel_2\\";
file1="D:\\GH\\Channels\\Buffer\\Channel_1\\";
file2="D:\\GH\\Channels\\Buffer\\Channel_2\\";
filecont=0;
filefile=1;
//////////////////////////////////////////////////////////////////////
return TRUE; // return TRUE unless you set the focus to a control
}
void CFilesend1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CFilesend1Dlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
/* CRect rect;
GetClientRect(rect);
CDC memDC;//定义一个兼容DC
memDC.CreateCompatibleDC(&dc);//创建DC
CBitmap bmpDraw;
bmpDraw.LoadBitmap(IDB_BITMAP1);//装入DDB
CBitmap* pbmpOld=memDC.SelectObject(&bmpDraw);//保存原有DDB,并选入新DDB入DC
dc.BitBlt(0,0,rect.Width(),rect.Height(),&memDC,0,0,SRCCOPY);//将源DC中(0,0,20,20)复制到目的DC(0,0,20,20)
memDC.SelectObject(pbmpOld);//选入原DDB*/
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 CFilesend1Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFilesend1Dlg::OnHelp()
{
// TODO: Add your command handler code here
//AfxMessageBox("西南科技大学,基于网络的信息智能信息处理研究室,版本信息1.1");
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
void CFilesend1Dlg::OnBrowse1()
{
// TODO: Add your control notification handler code here
CString strFilePath; //定义一个字符串变量,暂存“接收文件存放路径”
char pszBuffer[MAX_PATH];
BROWSEINFO bi;
LPITEMIDLIST pidl;
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("[接收文件存放目录]请选择:");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
if((pidl = SHBrowseForFolder(&bi)) != NULL)
{
if(SHGetPathFromIDList(pidl, pszBuffer))
{
CString strTemp(pszBuffer);
strFilePath = strTemp;
if (strFilePath.GetLength() <= 1)
{ }
else
if (strFilePath.Right(1) != _T("\\"))
strFilePath += _T("\\");
}
}
m_Fileaddr1=strFilePath;
UpdateData(false);
}
void CFilesend1Dlg::OnBrowse2()
{
// TODO: Add your control notification handler code here
CString strFilePath; //定义一个字符串变量,暂存“接收文件存放路径”
char pszBuffer[MAX_PATH];
BROWSEINFO bi;
LPITEMIDLIST pidl;
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("[接收文件存放目录]请选择:");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
if((pidl = SHBrowseForFolder(&bi)) != NULL)
{
if(SHGetPathFromIDList(pidl, pszBuffer))
{
CString strTemp(pszBuffer);
strFilePath = strTemp;
if (strFilePath.GetLength() <= 1)
{ }
else
if (strFilePath.Right(1) != _T("\\"))
strFilePath += _T("\\");
}
}
m_Fileaddr2=strFilePath;
UpdateData(false);
}
void CFilesend1Dlg::OnBrowse3()
{
// TODO: Add your control notification handler code here
CString strFilePath; //定义一个字符串变量,暂存“接收文件存放路径”
char pszBuffer[MAX_PATH];
BROWSEINFO bi;
LPITEMIDLIST pidl;
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("[接收文件存放目录]请选择:");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
if((pidl = SHBrowseForFolder(&bi)) != NULL)
{
if(SHGetPathFromIDList(pidl, pszBuffer))
{
CString strTemp(pszBuffer);
strFilePath = strTemp;
if (strFilePath.GetLength() <= 1)
{ }
else
if (strFilePath.Right(1) != _T("\\"))
strFilePath += _T("\\");
}
}
m_Fileaddr3=strFilePath;
UpdateData(false);
}
void CFilesend1Dlg::OnBrowse4()
{
// TODO: Add your control notification handler code here
CString strFilePath; //定义一个字符串变量,暂存“接收文件存放路径”
char pszBuffer[MAX_PATH];
BROWSEINFO bi;
LPITEMIDLIST pidl;
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("[接收文件存放目录]请选择:");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
if((pidl = SHBrowseForFolder(&bi)) != NULL)
{
if(SHGetPathFromIDList(pidl, pszBuffer))
{
CString strTemp(pszBuffer);
strFilePath = strTemp;
if (strFilePath.GetLength() <= 1)
{ }
else
if (strFilePath.Right(1) != _T("\\"))
strFilePath += _T("\\");
}
}
m_Fileaddr4=strFilePath;
UpdateData(false);
}
void CFilesend1Dlg::OnBrowse5()
{
// TODO: Add your control notification handler code here
CString strFilePath; //定义一个字符串变量,暂存“接收文件存放路径”
char pszBuffer[MAX_PATH];
BROWSEINFO bi;
LPITEMIDLIST pidl;
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = pszBuffer;
bi.lpszTitle = _T("[接收文件存放目录]请选择:");
bi.ulFlags = BIF_RETURNFSANCESTORS | BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = 0;
if((pidl = SHBrowseForFolder(&bi)) != NULL)
{
if(SHGetPathFromIDList(pidl, pszBuffer))
{
CString strTemp(pszBuffer);
strFilePath = strTemp;
if (strFilePath.GetLength() <= 1)
{ }
else
if (strFilePath.Right(1) != _T("\\"))
strFilePath += _T("\\");
}
}
m_Fileaddr5=strFilePath;
UpdateData(false);
}
void CFilesend1Dlg::OnSend1()
{
// TODO: Add your command handler code here
UpdateData(TRUE);
// 判断参数是否正确。
CStatDir statdir;
if(m_Fileaddr1=="地址栏")
{
AfxMessageBox("请输入文件夹路径!");
return;
}
//构造类对象
else
{
int len=strlen(m_Fileaddr1);
if (m_Fileaddr1[len-1] != '\\') //判断目录的最后一位是否为"\",如果不是就加上一个
m_Fileaddr1=m_Fileaddr1+"\\";
//CStatDir statdir;
//设置要遍历的目录
if (!statdir.SetInitDir(m_Fileaddr1))
{
puts("目录不存在。");
return;
}
//开始遍历
statdir.BeginBrowse("*.*");
//统计结果中,子目录个数不含 . 及 ..
numFileList1=statdir.GetFileCount();
wsprintf(Output,"文件总数: %d\r\n",numFileList1);
m_OutputCtrl.ReplaceSel(Output);
wsprintf(Output,"子目录总数: %d\r\n",statdir.GetSubdirCount());
m_OutputCtrl.ReplaceSel(Output);
//得到文件个数
}
// if(numFileList==0)
// {
// AfxMessageBox("请先添加文件。");
// return;
// }
// m_SendTo_Ip=m_Ipaddr;//从界面获取用户键入的“客户端IP地址”
//UpdateData(false);//刷新数据
// if(m_SendTo_Ip=="")//如果没有按要求键入客户端IP地址
// {
// AfxMessageBox("IP Input Error!\r\n\r\n请输入客户端IP地址先!");
//弹出一个警告消息框以提醒用户
// return;//返回
// }
// if ( m_Port<7001||m_Port>7032)//端口号检查。
// {
// AfxMessageBox("您输入的端口号不正确,请注意有效范围!");//弹出一个警告消息框以提醒用户
// return;
// }
// m_Send.EnableWindow(0);//将“发送”按钮置为不可用(变灰)
bStop1=false;
UpdateData();
//---------------------获取文件名------------------------------------------------------------
GetFileName1(m_Fileaddr1,"*.*");
AfxMessageBox("获取文件名成功");
HWND hwnd=GetSafeHwnd();//获得一个句柄值
AfxBeginThread(SourceFile1,hwnd,THREAD_PRIORITY_NORMAL);
//调用UINT SourceFile(LPVOID param)函数
//向指定目的地(用户所键入的IP地址)发送数据
}
void CFilesend1Dlg::OnSend2()
{
UpdateData(TRUE);
// 判断参数是否正确。
CStatDir statdir;
if(m_Fileaddr2=="地址栏")
{
AfxMessageBox("请输入文件夹路径!");
return;
}
//构造类对象
else
{
int len=strlen(m_Fileaddr2);
if (m_Fileaddr2[len-1] != '\\') //判断目录的最后一位是否为"\",如果不是就加上一个
m_Fileaddr2=m_Fileaddr2+"\\";
//CStatDir statdir;
//设置要遍历的目录
if (!statdir.SetInitDir(m_Fileaddr2))
{
puts("目录不存在。");
return;
}
//开始遍历
statdir.BeginBrowse("*.*");
//统计结果中,子目录个数不含 . 及 ..
numFileList2=statdir.GetFileCount();
wsprintf(Output,"文件总数: %d\r\n",numFileList2);
m_OutputCtrl.ReplaceSel(Output);
wsprintf(Output,"子目录总数: %d\r\n",statdir.GetSubdirCount());
m_OutputCtrl.ReplaceSel(Output);
//得到文件个数
}
// if(numFileList==0)
// {
// AfxMessageBox("请先添加文件。");
// return;
// }
// m_SendTo_Ip=m_Ipaddr;//从界面获取用户键入的“客户端IP地址”
//UpdateData(false);//刷新数据
// if(m_SendTo_Ip=="")//如果没有按要求键入客户端IP地址
// {
// AfxMessageBox("IP Input Error!\r\n\r\n请输入客户端IP地址先!");
//弹出一个警告消息框以提醒用户
// return;//返回
// }
// if ( m_Port<7001||m_Port>7032)//端口号检查。
// {
// AfxMessageBox("您输入的端口号不正确,请注意有效范围!");//弹出一个警告消息框以提醒用户
// return;
// }
// m_Send.EnableWindow(0);//将“发送”按钮置为不可用(变灰)
bStop2=false;
UpdateData();
//---------------------获取文件名------------------------------------------------------------
GetFileName2(m_Fileaddr2,"*.*");
AfxMessageBox("获取文件名成功");
HWND hwnd=GetSafeHwnd();//获得一个句柄值
AfxBeginThread(SourceFile2,hwnd,THREAD_PRIORITY_NORMAL);
//调用UINT SourceFile(LPVOID param)函数
//向指定目的地(用户所键入的IP地址)发送数据
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -