gpt4 book ai didi

c++ - 当删除 Combobox 中的项目时,第二个弹出 MFC

转载 作者:行者123 更新时间:2023-11-28 03:24:03 26 4
gpt4 key购买 nike

我有组合框和删除按钮。我想让下一个组合框项目在按下删除按钮时弹出,当最后一个项目被删除时,干净的组合框选择了项目。

我尝试了几种索引方法,但即使是一种方法也帮不了我。

这是我的代码:

if(IDYES == MessageBox(L"Delete save?",L"Delete", MB_YESNO|MB_ICONQUESTION)){
CString pFileName = L"Save\\"+str+".dat";
CFile::Remove(pFileName);
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_SAVE);
pComboBox->ResetContent();
}

如何在按下删除按钮时弹出下一个组合框项目以及在删除最后一个项目时清除干净的组合框选定项目?

最佳答案

我找到了一个解决方案:

void CL2HamsterDlg::OnBnClickedButtonDelete(){
if(Validate()){
if(IDYES == MessageBox(L"Delete save?",L"Delete", MB_YESNO|MB_ICONQUESTION)){
CString pFileName = L"Save\\"+str+".dat";
CFile::Remove(pFileName);
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_SAVE);
lookforfile();
int nIndex = pComboBox->GetCurSel();
if (nIndex == CB_ERR)
pComboBox->SetCurSel(0);
else{
pComboBox->SetEditSel(0, -1);
pComboBox->Clear();
}
}
LoadSave(false);
}else
AfxMessageBox(L"Please select or write correct name!");
}

查找文件刷新索引的函数

void CL2HamsterDlg::lookforfile()
{
Value.GetWindowText(str);
CComboBox* pComboBox = (CComboBox*)GetDlgItem(IDC_COMBO_SAVE);
pComboBox->ResetContent();
GetCurrentDirectory(MAX_PATH,curWorkingDir);
_tcscat_s(curWorkingDir, MAX_PATH, _T("\\Save\\*.dat"));
BOOL bWorking = finder.FindFile(curWorkingDir);
while (bWorking){
bWorking = finder.FindNextFile();
if (!finder.IsDots())
pComboBox->AddString(finder.GetFileTitle());
}
GetDlgItem(IDC_COMBO_SAVE)->SetWindowText(str);
}

关于c++ - 当删除 Combobox 中的项目时,第二个弹出 MFC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14617819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com