设为首页 加入收藏

TOP

VC笔记 (四)
2014-11-23 19:09:42 来源: 作者: 【 】 浏览:104
Tags:笔记
nge(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLOVEDlg)
DDX_Control(pDX, IDC_LIST1, m_list);
//}}AFX_DATA_MAP
m_list.InsertColumn(0,"文件名", LVCFMT_LEFT, 100, -1);
m_list.InsertColumn(1,"文件大小", LVCFMT_LEFT, 100, -1);
m_list.InsertColumn(2,"文件路径", LVCFMT_LEFT, 200, -1);


int iCount = GetPrivateProfileInt("Cont","count",0,"d:\\program\\本地共享文件.ini");
CString File;
char name[20];
char size[20];
char path[50];
memset(name, 0, 20);
memset(size, 0, 20);
memset(path, 0, 50);
for(int i = 1; i <= iCount; i++)
{
File.Empty();
File.Format("%d", i);
File = "file" + File;
::GetPrivateProfileString(File,"filename","error",name,20,"d:\\program\\本地共享文件.ini");
::GetPrivateProfileString(File,"filesize","error",size, 20,"d:\\program\\本地共享文件.ini");
::GetPrivateProfileString(File,"filepath","error",path, 50,"d:\\program\\本地共享文件.ini");

m_list.InsertItem(i - 1, name);
m_list.SetItemText(i - 1,1, size);
m_list.SetItemText(i - 1,1, path);
}
}

//删除文件
void CLOVEDlg::OnDelete()
{
// TODO: Add your control notification handler code here
/*CFileDialog fileDlg(TRUE);
fileDlg.m_ofn.lpstrTitle="删除文件";
fileDlg.m_ofn.lpstrFilter="All Files(*.*)\0*.*\0\0";
fileDlg.m_ofn.lpstrInitialDir=path;//打开共享目录
int result=fileDlg.DoModal();
if(result==IDOK)
{
CString newpath=path+CString("\\")+fileDlg.GetFileName();
DeleteFile(newpath);
//CFile::Remove( newpath );
//记录删除
CFile mFile;
mFile.Open(path+CString("\\file.txt"),CFile::modeNoTruncate|CFile::modeWrite);
mFile.SeekToEnd();//移至文件末端输入
//获取当前时间
CTime time=CTime::GetCurrentTime();
CString strTime = time.Format("%Y-%m-%d %H:%M:%S");
mFile.Write(strTime,strlen(strTime));
mFile.Write("将",2);
mFile.Write(fileDlg.GetPathName(),strlen(fileDlg.GetPathName()));
mFile.Write("从共享目录中删除",16);
mFile.Write("\r\n",2);
mFile.Close();
}
*/

//将文件从列表中删除
Int clickItem;
CFile file;
//CString strFileSize;
CString max;
CString section;
//long FileLength = file.GetLength();
// strFileSize.Format("%0.2fk", ((float)FileLength)/1024);
m_list.DeleteItem(clickItem);
int iCount = GetPrivateProfileInt("Cont","count",0,"d:\\program\\本地共享文件.ini");
max.Format("%d", iCount - 1);
::WritePrivateProfileString("Cont","count",max,"d:\\program\\本地共享文件.ini");
char name[20];
char path[50];
for(int i = clickItem + 2; i <= iCount; i++)
{
section.Format("%d",i);
section = "file" + section;

::GetPrivateProfileString(section,"filename","error",name,20,"d:\\program\\本地共享文件.ini");
::GetPrivateProfileString(section,"filepath","error",path, 50,"d:\\program\\本地共享文件.ini");
section.Format("%d",i - 1);
section = "file" + section;
::WritePrivateProfileString(section,NULL,NULL,"d:\\program\\本地共享文件.ini");
::WritePrivateProfileString(section,"filename",name,"d:\\program\\本地共享文件.ini");
//::WritePrivateProfileString(section,"filesize",strFileSize,"d:\\program\\本地共享文件.ini");
::WritePrivateProfileString(section,"filepath",path,"d:\\program\\本地共享文件.ini");
}
section.Format("%d",iCount);
section = "file" + section;
::WritePrivateProfileString(section,NULL,NULL,"d:\\program\\本地共享文件.ini");


}


//添加文件,将文件写入TXT文件中
void CLOVEDlg::OnAdd()
{
// TODO: Add your control notification handler code here
CFileDialog fileDlg(TRUE);//TRUE为OPEN对话框,FALSE为SAVE AS对话框
BROWSEINFO bInfo;
ZeroMemory(&bInfo, sizeof(bInfo));
bInfo.hwndOwner=G

首页 上一页 1 2 3 4 5 下一页 尾页 4/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇VC++ 树的孩子兄弟表示法 下一篇窗口滚动条与滚动条控件的区别

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: