程序在打开一个文件后,怎样禁止其他程序删除、修改?
怎样限制:
比如:
CFileDialog dlg(TRUE, NULL, NULL,OFN_READONLY | OFN_OVERWRITEPROMPT, Filetype);if(dlg.DoModal() == IDOK)
{
CString filename = dlg.GetPathName();
…????
OpenDocumentFile(filename);
}
怎样限制:
比如:
CFileDialog dlg(TRUE, NULL, NULL,OFN_READONLY | OFN_OVERWRITEPROMPT, Filetype);if(dlg.DoModal() == IDOK)
{
CString filename = dlg.GetPathName();
…????
OpenDocumentFile(filename);
}
file.Open(filename,CFile::modeRead|CFile::shareDenyWrite);
file.Open(filename,CFile::modeRead|CFile::shareDenyWrite);
好像不行,限制不住;
to:: yinx(yinx)
CFileDialog::OnShareViolation
不会用
谢谢
还是不行,限制不住
to:: yinx(yinx)
CFileDialog::OnShareViolation
怎么用?
谢谢
Opens the file with exclusive mode, denying other processes both read and write access to the file. Construction fails if the file has been opened in any other mode for read or write access, even by the current process.CFile file;
file.Open(filename,CFile::modeRead|CFile::sshareExclusive);
file.Open(filename,CFile::modeRead|CFile::sshareExclusive);
或
file.Open(filename,CFile::modeRead|CFile::shareDenyWrite);
;
可在外部还是可以修改和删除文件;
请教各位高手!
LockFile()
UnLockFile()
LPCTSTR lpszName,
DWORD fdwAccess,
DWORD fdwShareMode,
LPSECURITY_ATTRIBUTES lpsa,
DWORD fdwCreate,
DWORD fdwAttrsAndFlags,
HANDLE hTemplateFile
)
用这个函数,我刚试过了,应该可以