拖动N个文件,改变文件的最后修改时间,并将文件内容全部设为0
2007-07-25 13:53
721 查看
拖动N个文件,改变文件的最后修改时间,并将文件内容全部设为0
用基于对话框的程序完成
1.在VC6中新建一个基于对话框的EXE工程。
2.在Dlg的OnInitDialog()中加上此句:
CDialog::OnInitDialog();
DragAcceptFiles ();
………………
或者在对话框中Extended Styles的Accept files属性。
3.在Dlg的BEGIN_MESSAGE_MAP(……)和
END_MESSAGE_MAP()
中间加上此句:
ON_WM_DROPFILES();
4.在dlg的头文件中加上
afx_msg void OnDropFiles(HDROP hDropInfo);
其实可以直接在ClassWizard中选中WINDOWS消息WM_DROPFILES消息来自动生成。但我的对话框怎么也找不着这个消息,只好自己手动加上了。
void CDropListDlg::OnDropFiles(HDROP hDropInfo)//处理文件拖动消息
{
char *PFileName=new char[512];
int n_count=DragQueryFile(hDropInfo,0xFFFFFFFF,NULL,512);
for(int i=0;i< n_count;i++)
{
UINT nChars=DragQueryFile(hDropInfo,i,&PFileName[0],512);
CString str(&PFileName[0],nChars);
m_myList.InsertItem(i,str);
m_StrPathName.AddTail(str);
}
DragFinish(hDropInfo);
delete []PFileName;
//拖动完成以后
POSITION pos=m_StrPathName.GetHeadPosition();
while (pos)
{
ModifFile(m_StrPathName.GetNext(pos));
}
m_StrPathName.RemoveAll();//清空链表
MessageBox("修改完成!");
}
void CDropListDlg::ModifFile(CString strPath)//修改文件的函数
{
CFile myfile;
myfile.Open(strPath,CFile::modeRead | CFile::modeWrite );
m_length=myfile.GetLength();
char *pBuf=new char[m_length];
memset(pBuf,'0',m_length);
myfile.Write(pBuf,m_length);
delete []pBuf;
pBuf=NULL;
FILETIME ft;
SYSTEMTIME st;
st.wDay=27;
st.wDayOfWeek=4;
st.wHour=17;
st.wMilliseconds=5;
st.wMinute=5;
st.wMonth=10;
st.wSecond=5;
st.wYear=1980;
SystemTimeToFileTime(&st, &ft);
SetFileTime((HANDLE)myfile.m_hFile, (LPFILETIME) NULL, (LPFILETIME) NULL, &ft);
myfile.Close();
}
用基于对话框的程序完成
1.在VC6中新建一个基于对话框的EXE工程。
2.在Dlg的OnInitDialog()中加上此句:
CDialog::OnInitDialog();
DragAcceptFiles ();
………………
或者在对话框中Extended Styles的Accept files属性。
3.在Dlg的BEGIN_MESSAGE_MAP(……)和
END_MESSAGE_MAP()
中间加上此句:
ON_WM_DROPFILES();
4.在dlg的头文件中加上
afx_msg void OnDropFiles(HDROP hDropInfo);
其实可以直接在ClassWizard中选中WINDOWS消息WM_DROPFILES消息来自动生成。但我的对话框怎么也找不着这个消息,只好自己手动加上了。
void CDropListDlg::OnDropFiles(HDROP hDropInfo)//处理文件拖动消息
{
char *PFileName=new char[512];
int n_count=DragQueryFile(hDropInfo,0xFFFFFFFF,NULL,512);
for(int i=0;i< n_count;i++)
{
UINT nChars=DragQueryFile(hDropInfo,i,&PFileName[0],512);
CString str(&PFileName[0],nChars);
m_myList.InsertItem(i,str);
m_StrPathName.AddTail(str);
}
DragFinish(hDropInfo);
delete []PFileName;
//拖动完成以后
POSITION pos=m_StrPathName.GetHeadPosition();
while (pos)
{
ModifFile(m_StrPathName.GetNext(pos));
}
m_StrPathName.RemoveAll();//清空链表
MessageBox("修改完成!");
}
void CDropListDlg::ModifFile(CString strPath)//修改文件的函数
{
CFile myfile;
myfile.Open(strPath,CFile::modeRead | CFile::modeWrite );
m_length=myfile.GetLength();
char *pBuf=new char[m_length];
memset(pBuf,'0',m_length);
myfile.Write(pBuf,m_length);
delete []pBuf;
pBuf=NULL;
FILETIME ft;
SYSTEMTIME st;
st.wDay=27;
st.wDayOfWeek=4;
st.wHour=17;
st.wMilliseconds=5;
st.wMinute=5;
st.wMonth=10;
st.wSecond=5;
st.wYear=1980;
SystemTimeToFileTime(&st, &ft);
SetFileTime((HANDLE)myfile.m_hFile, (LPFILETIME) NULL, (LPFILETIME) NULL, &ft);
myfile.Close();
}
相关文章推荐
- python笨办法解决zipfile解压会改变文件最后修改时间的问题
- 文件最后修改时间
- C++ win环境修改文件创建时间、最后的修改时间和最后的访问时间
- java 得到文件最后的修改时间
- 创建新文件、写入内容、获取上次修改时间
- 比较二个文件的最后修改时间FileListener
- 如何获知文件最后的修改日期和时间?
- 用 C# 轻松读取、改变文件的创建、修改、访问时间
- PB获取文件最后修改时间
- VC ++实现 对文件的 隐藏, 只读 ,创建时间 , 最后修改时间 ,最后访问时间 属性的修改
- Windows脚本对最后修改时间超过24小时的文件进行处理
- PHP获取网页头部信息、获取文件当前位置、获取文件最后修改时间
- latex中修改源文件编译之后内容仍然不改变的bug
- 获取文件创建、修改最后访问时间
- linux下文件的创建时间、访问时间、修改时间和改变时间
- Python-获取文件最后修改时间
- sharepoint 2007 获取所有网站集前40w个文件中启用历史版本文件的大小/数量/最后修改时间
- C#获取ftp文件最后修改时间
- “WebRequestMethods.Ftp.DownloadFile不能保留文件最后修改时间”的解决方法