您的位置:首页 > 其它

拖动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();
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: