16,471
社区成员
发帖
与我相关
我的任务
分享
void CLeakStudyDlg::OnBnClickedButtonFind()
{
CString fa;
CString so;
m_edit_fa.GetWindowTextW(fa);
m_edit_so.GetWindowTextW(so);
if (fa == "")
{
AfxMessageBox(L"第一个字符串为空");
return;
}
if (so == "")
{
AfxMessageBox(L"第二个字符串为空");
return;
}
if (fa.Find(so) != -1)
{
m_edit_re.SetWindowTextW(so + L" is the sun_string of " + fa);
}
//AfxMessageBox(L"完成");
_CrtDumpMemoryLeaks();//放在程序跳出的地方, 检查内存泄漏
}
_CrtDumpMemoryLeaks();
再看看结果。
另外,你使用了一个CString 到 LPTSTR 的强制转化。可能会带来一些小问题。
即: m_edit_fa.GetWindowTextW(fa);
修改为 m_edit_fa.GetWindowTextW(fa.GetBuffer(MAX_PATH));
void CDrawEditDlg::OnButton()
{
// TODO: Add your control notification handler code here
CString fa="ABCDEFG";
CString so="BCDEF";
if (fa == "")
{
AfxMessageBox("第一个字符串为空");
return;
}
if (so == "")
{
AfxMessageBox("第二个字符串为空");
return;
}
if (fa.Find(so) != -1)
{
so += " is the sub_string of " + fa;
}
AfxMessageBox(so);
//`_CrtDumpMemoryLeaks();//不要这句 无 leak !!!
}
void CMiMouseDlg::ShortcutSearch(CString str_path, CStdioFile &file)
{
CFileFind OneFile;
CString name_file;
CString name_dir = str_path + _T("\\*.*");
BOOL iswork;
iswork = OneFile.FindFile(name_dir);
while (iswork)//成功的打开了一个文件夹
{
iswork = OneFile.FindNextFile();//获得一个"文件"
if (OneFile.IsDots())
{
continue; //不是需要的文件,跳过继续寻找下一个File or Folder
}
if (OneFile.IsDirectory())//当前的"文件"是文件夹,不是某一个文件
{
name_dir = OneFile.GetFilePath(); //获取文件夹的路径
ShortcutSearch(name_dir, file);
}
else//当前的"file"是一个文件
{
name_file = OneFile.GetFileName(); //获取文件的名字
if (name_file.Find(L"卸载") != -1 || name_file.Find(L"修复") != -1)
continue;
TCHAR* old_locale = _tcsdup(_tsetlocale(LC_CTYPE, NULL));//为了读取中文不至于乱码
_tsetlocale(LC_CTYPE, _T("chs"));
for (int i = 0; i < (int)shortcut_need.size(); i++)
{
//搜索到了 startmenu.sec 文件中的某一个快捷方式
if (name_file.Find( shortcut_need[i].key ) != -1)
{
CString str_link;
str_link = OneFile.GetFilePath();
CString temp = shortcut_need[i].command + L"," + str_link + L"\n";
file.WriteString(temp);
break;
}
}
_tsetlocale(LC_CTYPE, old_locale);
free(old_locale);
}
}
OneFile.Close();
}