etSafeHwnd();
bInfo.lpszTitle=_T("请选择共享文件夹的路径:");
bInfo.ulFlags=BIF_RETURNONLYFSDIRS;
LPITEMIDLIST lpDlist; //用来保存返回信息的IDList
lpDlist=SHBrowseForFolder(&bInfo); //显示选择对话框
if(lpDlist!=NULL) //用户按了确定按钮
{
TCHAR chPath[MAX_PATH]; //用来存储路径的字符串
SHGetPathFromIDList(lpDlist, chPath);//把项目标识列表转化成字符串
CString m_strPath = chPath; //将TCHAR类型的字符串转换为CString类型的字符串
CString prepath=path;
strncpy(path,(LPCTSTR)m_strPath,sizeof(path));
CString newpath1=path+CString("\\file.txt");
CopyFile(prepath+CString("\\file.txt"),newpath1,FALSE);
CString m_flpath=path+CString("\\")+fileDlg.GetFileName();
CString m_flname=fileDlg.GetFileName();
CFileDialog dlg(TRUE);//TRUE为OPEN对话框,FALSE为SAVE AS对话框
if (dlg.DoModal() == IDOK)
m_flpath=dlg.GetPathName();
CFile file("file.txt",CFile::modeCreate | CFile::modeWrite);
CString str1(m_flpath);
CString str2(m_flname);
file.Write(str1,strlen(m_flpath));
file.Write(str2,strlen(m_flname));
file.Close();
}
}
(2)//添加文件并显示到List Control
void CFileTransferClientDlg::OnAddFile() //添加文件
{
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT, "All Files(*.*)|*.*||", this);
if(dlg.DoModal() == IDOK)
{
POSITION pos = dlg.GetStartPosition();
int nItem;
while(pos != NULL)
{
CString strPathName = dlg.GetNextPathName(pos);
CFile file;
BOOL bResult = file.Open(strPathName, CFile::modeRead|CFile::shareDenyNone, NULL);
if(!bResult)
continue;
CString strFileName = file.GetFileName();
long lFileLength = file.GetLength();
file.Close();
CString strFileSize;
strFileSize.Format("%0.2fk", ((float)lFileLength)/1024);
nItem = m_SendFileList.InsertItem(0,strFileName);
m_SendFileList.SetItemText(nItem,1,strFileSize);
m_SendFileList.SetItemText(nItem,2,strPathName);
}
}
}
3.窗口操作
//窗口转换
void CLOVEDlg::OnExchenge()
{
// TODO: Add your control notification handler code here
//CTestDlg DLG;
//DLG.DoModal();
CTestDlg *pDlg = new CTestDlg;
pDlg->Create(IDD_DIALOG1);//要转换的窗口的ID
pDlg->ShowWindow(SW_NORMAL);
}
//打开窗口
CFileDialog fileDlg(TRUE);
fileDlg.m_ofn .lpstrTitle=TEXT("我的文件打开对话框");
fileDlg.m_ofn .lpstrFilter=TEXT("Text Files(*.txt)\0*.txt\0All Files(*.*)\0*.*\0\0");
fileDlg.DoModal() ;*
CFileDialog dlg(TRUE);//TRUE为OPEN对话框,FALSE为SAVE对话框
dlg.DoModal();
//消息处理
AfxMessageBox("连接服务器成功!");在vs2005中为AfxMessageBox(L"连接服务器成功!");
if (AfxMessageBox("无法连接服务器!\n重试?",MB_YESNO)==IDNO)
{
AfxMessageBox("连接服务器成功!");
return ;
}
//画对话框背景
BOOL CFileTransferClientDlg::OnEraseBkgnd(CDC* pDC) //画对话框背景
{
CRect rc;
GetClientRect(&rc);
CBrush brush, *pOldbrush;
brush.CreateSolidBrush(RGB(200, 150, 250));
pOldbrush=pDC->SelectObject(&brush);
pDC->FillRect(&rc, &brush);
pDC->SelectObject(pOldbrush);
return true;
}