Unicode下 CString转 char *
CString strPath = _T("../bin/.jpg");
USES_CONVERSION; //声明标识符
char *p = T2A(strPath);
参考 https://blog.csdn.net/neverup_/article/details/5664733
cs
Unicode下CString转const char *
char cAscii[MAX_PATH] = { 0 };
int nAsciiLen = WideCharToMultiByte(CP_ACP, 0, strPath.GetString(), -1, nullptr, 0, nullptr, nullptr);
// 开始向缓冲区转换字节
WideCharToMultiByte(CP_ACP, 0, strPath.GetString(), -1, cAscii, nAsciiLen, nullptr, nullptr);
CTime 与 CString转换
CTime time = CTime::GetCurrentTime();//必须使用CTime::下的get函数,否则得到的时间不对
CString strFile = time.Format("%Y%m%d-%H%M%S");
mfc界面添加最大化最小化按钮
下面两个最大最小化按钮 属性中 改为true就可以了
WritePrivateProfileString 在ini写入文件时
对于路径:CString strPath = _T("…//bin//data//config.ini");
在bin下不存在data文件夹时,是写入不成功的,需要提前创建data文件夹,然后再使用 WritePrivateProfileString 时,可以创建ini文件,但不会创建data文件。
判断文件是否存在
CFileFind file;
if (!file.FindFile(strPath))
{
//将路径分开
int nIndex = strPath.ReverseFind('/');
CString strDir = strPath.Left(nIndex);
::CreateDirectory(strDir, NULL);
}
判断文件夹是否存在
if (!PathIsDirectory(strDir))
{
::CreateDirectory(strDir, NULL);
}