头文件:
#include <io.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <share.h>
/*****************************************************************************
* @brief : 生成的放在工程路径下的doc文件是否被打开
* @author : mahongkai
* @date : 2019/4/24 16:55
* @version : ver 1.0
* @inparam : 文件名
* @outparam : TRUE,被打开; FALSE,没有被打开
*****************************************************************************/
BOOL bOpenedDocXml(LPCTSTR strDocxName)
{
if (strDocxName != NULL)
{
// 获取文件所在的工程所在路径
wchar_t *wProPath = getProjectPathXml();
if (wProPath != NULL)
{
wcscat(wProPath, _T("\\"));
wcscat(wProPath, strDocxName);
int fh, numread;
errno_t err = _wsopen_s(&fh, wProPath, _O_WRONLY, _SH_DENYNO, _S_IREAD | _S_IWRITE);
if (err == EACCES) // _Open并 _O_EXCL标志指定,但filename已存在。
{
CString str1 = _T("即将关闭 '");
CString str2 = wProPath;
CString str3 = _T(" ' 文件,如需要请另存!!!");
CString str = str1 + str2 + str3;
MessageBoxW(NULL, str, _T("关闭文档"), MB_OK);
delete[] wProPath;
wProPath = NULL;
return TRUE;
}
else
{
//close(fh);
delete[] wProPath;
wProPath = NULL;
return FALSE;
}
}
}
}